]> source.dussan.org Git - archiva.git/blob
470f24b07c1cea763392a569436fd227190aeb2c
[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.RegistryException;
22 import org.apache.archiva.components.registry.RegistryListener;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.Configuration;
25 import org.apache.archiva.configuration.ConfigurationListener;
26 import org.apache.archiva.configuration.IndeterminateConfigurationException;
27 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
28 import org.apache.commons.lang3.StringUtils;
29 import org.springframework.stereotype.Service;
30
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.List;
34 import java.util.Locale;
35
36 @Service("archivaConfiguration#mocked")
37 public class StubConfiguration
38     implements ArchivaConfiguration
39 {
40     private Configuration configuration = new Configuration();
41
42     StubConfiguration() {
43         configuration.setRepositoryScanning( new RepositoryScanningConfiguration() );
44     }
45
46     @Override
47     public Configuration getConfiguration()
48     {
49         return configuration;
50     }
51
52     @Override
53     public void save( Configuration configuration )
54         throws RegistryException, IndeterminateConfigurationException
55     {
56         this.configuration = configuration;
57     }
58
59     @Override
60     public boolean isDefaulted()
61     {
62         return false;
63     }
64
65     @Override
66     public void addListener( ConfigurationListener listener )
67     {
68         // throw new UnsupportedOperationException();
69     }
70
71     @Override
72     public void removeListener( ConfigurationListener listener )
73     {
74         throw new UnsupportedOperationException();
75     }
76
77     @Override
78     public void addChangeListener( RegistryListener listener )
79     {
80         // throw new UnsupportedOperationException();
81     }
82
83     @Override
84     public void removeChangeListener( RegistryListener listener )
85     {
86         throw new UnsupportedOperationException();
87     }
88
89     @Override
90     public void reload()
91     {
92         // no op
93     }
94
95     @Override
96     public Locale getDefaultLocale( )
97     {
98         return Locale.getDefault();
99     }
100
101     @Override
102     public List<Locale.LanguageRange> getLanguagePriorities( )
103     {
104         return Locale.LanguageRange.parse( "en,fr,de" );
105     }
106
107     @Override
108     public Path getAppServerBaseDir() {
109         if (System.getProperties().containsKey("appserver.base")) {
110             return Paths.get(System.getProperty("appserver.base"));
111         } else {
112             return Paths.get("");
113         }
114     }
115
116     @Override
117     public Path getRepositoryBaseDir() {
118         return getDataDirectory().resolve("repositories");
119     }
120
121     @Override
122     public Path getRemoteRepositoryBaseDir() {
123         return getDataDirectory().resolve("remotes");
124     }
125
126     @Override
127     public Path getRepositoryGroupBaseDir( )
128     {
129         return getDataDirectory().resolve("group");
130     }
131
132     @Override
133     public Path getDataDirectory() {
134         if (configuration!=null && configuration.getArchivaRuntimeConfiguration()!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
135             Path dataDir = Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
136             if (dataDir.isAbsolute()) {
137                 return dataDir;
138             } else {
139                 return getAppServerBaseDir().resolve(dataDir);
140             }
141         } else {
142             return getAppServerBaseDir().resolve("data");
143         }
144
145     }
146 }