]> source.dussan.org Git - archiva.git/blob
b63208f045a8b0340007b6799f02cddda63384cd
[archiva.git] /
1 package org.apache.archiva.repository.maven.mock.configuration;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20
21 import org.apache.archiva.components.registry.Registry;
22 import org.apache.archiva.components.registry.RegistryException;
23 import org.apache.archiva.components.registry.RegistryListener;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.Configuration;
26 import org.apache.archiva.configuration.ConfigurationListener;
27 import org.apache.archiva.configuration.IndeterminateConfigurationException;
28 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
29 import org.apache.commons.lang3.StringUtils;
30 import org.springframework.stereotype.Service;
31
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.List;
35 import java.util.Locale;
36
37 @Service("archivaConfiguration#mocked")
38 public class StubConfiguration
39     implements ArchivaConfiguration
40 {
41     private Configuration configuration = new Configuration();
42
43     StubConfiguration() {
44         configuration.setRepositoryScanning( new RepositoryScanningConfiguration() );
45     }
46
47     @Override
48     public Configuration getConfiguration()
49     {
50         return configuration;
51     }
52
53     @Override
54     public void save( Configuration configuration )
55         throws RegistryException, IndeterminateConfigurationException
56     {
57         this.configuration = configuration;
58     }
59
60     @Override
61     public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
62     {
63         this.configuration = configuration;
64     }
65
66     @Override
67     public boolean isDefaulted()
68     {
69         return false;
70     }
71
72     @Override
73     public void addListener( ConfigurationListener listener )
74     {
75         // throw new UnsupportedOperationException();
76     }
77
78     @Override
79     public void removeListener( ConfigurationListener listener )
80     {
81         throw new UnsupportedOperationException();
82     }
83
84     @Override
85     public void addChangeListener( RegistryListener listener )
86     {
87         // throw new UnsupportedOperationException();
88     }
89
90     @Override
91     public void removeChangeListener( RegistryListener listener )
92     {
93         throw new UnsupportedOperationException();
94     }
95
96     @Override
97     public void reload()
98     {
99         // no op
100     }
101
102     @Override
103     public Locale getDefaultLocale( )
104     {
105         return Locale.getDefault();
106     }
107
108     @Override
109     public List<Locale.LanguageRange> getLanguagePriorities( )
110     {
111         return Locale.LanguageRange.parse( "en,fr,de" );
112     }
113
114     @Override
115     public Path getAppServerBaseDir() {
116         if (System.getProperties().containsKey("appserver.base")) {
117             return Paths.get(System.getProperty("appserver.base"));
118         } else {
119             return Paths.get("");
120         }
121     }
122
123     @Override
124     public Path getRepositoryBaseDir() {
125         return getDataDirectory().resolve("repositories");
126     }
127
128     @Override
129     public Path getRemoteRepositoryBaseDir() {
130         return getDataDirectory().resolve("remotes");
131     }
132
133     @Override
134     public Path getRepositoryGroupBaseDir( )
135     {
136         return getDataDirectory().resolve("group");
137     }
138
139     @Override
140     public Path getDataDirectory() {
141         if (configuration!=null && configuration.getArchivaRuntimeConfiguration()!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
142             Path dataDir = Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
143             if (dataDir.isAbsolute()) {
144                 return dataDir;
145             } else {
146                 return getAppServerBaseDir().resolve(dataDir);
147             }
148         } else {
149             return getAppServerBaseDir().resolve("data");
150         }
151
152     }
153
154     @Override
155     public Registry getRegistry( )
156     {
157         return null;
158     }
159 }