]> source.dussan.org Git - archiva.git/blob
6a34278f69c7cedede24cc65a8124419b68a0a35
[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 void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
61     {
62         this.configuration = configuration;
63     }
64
65     @Override
66     public boolean isDefaulted()
67     {
68         return false;
69     }
70
71     @Override
72     public void addListener( ConfigurationListener listener )
73     {
74         // throw new UnsupportedOperationException();
75     }
76
77     @Override
78     public void removeListener( ConfigurationListener listener )
79     {
80         throw new UnsupportedOperationException();
81     }
82
83     @Override
84     public void addChangeListener( RegistryListener listener )
85     {
86         // throw new UnsupportedOperationException();
87     }
88
89     @Override
90     public void removeChangeListener( RegistryListener listener )
91     {
92         throw new UnsupportedOperationException();
93     }
94
95     @Override
96     public void reload()
97     {
98         // no op
99     }
100
101     @Override
102     public Locale getDefaultLocale( )
103     {
104         return Locale.getDefault();
105     }
106
107     @Override
108     public List<Locale.LanguageRange> getLanguagePriorities( )
109     {
110         return Locale.LanguageRange.parse( "en,fr,de" );
111     }
112
113     @Override
114     public Path getAppServerBaseDir() {
115         if (System.getProperties().containsKey("appserver.base")) {
116             return Paths.get(System.getProperty("appserver.base"));
117         } else {
118             return Paths.get("");
119         }
120     }
121
122     @Override
123     public Path getRepositoryBaseDir() {
124         return getDataDirectory().resolve("repositories");
125     }
126
127     @Override
128     public Path getRemoteRepositoryBaseDir() {
129         return getDataDirectory().resolve("remotes");
130     }
131
132     @Override
133     public Path getRepositoryGroupBaseDir( )
134     {
135         return getDataDirectory().resolve("group");
136     }
137
138     @Override
139     public Path getDataDirectory() {
140         if (configuration!=null && configuration.getArchivaRuntimeConfiguration()!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
141             Path dataDir = Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
142             if (dataDir.isAbsolute()) {
143                 return dataDir;
144             } else {
145                 return getAppServerBaseDir().resolve(dataDir);
146             }
147         } else {
148             return getAppServerBaseDir().resolve("data");
149         }
150
151     }
152 }