1 package org.apache.archiva.proxy;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.configuration.*;
23 import org.apache.archiva.components.registry.Registry;
24 import org.apache.archiva.components.registry.RegistryException;
25 import org.apache.archiva.components.registry.RegistryListener;
26 import org.apache.commons.lang3.StringUtils;
27 import org.easymock.EasyMock;
28 import org.easymock.IMocksControl;
29 import org.springframework.stereotype.Service;
31 import javax.annotation.PostConstruct;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
41 @Service( "archivaConfiguration#mock" )
42 public class MockConfiguration
43 implements ArchivaConfiguration
46 private Configuration configuration = new Configuration();
48 private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
50 private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
52 private IMocksControl registryControl;
54 private Registry registryMock;
56 public MockConfiguration()
58 registryControl = EasyMock.createNiceControl( );
59 registryMock = registryControl.createMock( Registry.class );
63 public void initialize()
67 configuration.setRepositoryScanning( new RepositoryScanningConfiguration()
70 public List<FileType> getFileTypes()
72 FileType fileType = new FileType();
73 fileType.setId( FileTypes.ARTIFACTS );
74 fileType.setPatterns( Collections.singletonList( "**/*" ) );
75 return Collections.singletonList( fileType );
78 ArchivaRuntimeConfiguration rt = new ArchivaRuntimeConfiguration();
79 List<String> checksums = new ArrayList<>();
81 checksums.add("SHA1");
82 checksums.add("SHA256");
83 rt.setChecksumTypes(checksums);
84 configuration.setArchivaRuntimeConfiguration(rt);
89 public void addChangeListener( org.apache.archiva.components.registry.RegistryListener listener )
91 registryListeners.add( listener );
96 public void removeChangeListener( RegistryListener listener )
98 registryListeners.remove( listener );
102 public Configuration getConfiguration()
104 return configuration;
108 public void save( Configuration configuration )
109 throws RegistryException
114 public void triggerChange( String name, String value )
116 for ( org.apache.archiva.components.registry.RegistryListener listener : registryListeners )
120 listener.afterConfigurationChange( registryMock, name, value );
122 catch ( Exception e )
128 for (ConfigurationListener listener : configListeners) {
129 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.CHANGED ) );
134 public void addListener( ConfigurationListener listener )
136 configListeners.add( listener );
140 public void removeListener( ConfigurationListener listener )
142 configListeners.remove( listener );
146 public boolean isDefaulted()
158 public Locale getDefaultLocale( )
160 return Locale.getDefault();
164 public List<Locale.LanguageRange> getLanguagePriorities( )
166 return Locale.LanguageRange.parse( "en,fr,de" );
170 public Path getAppServerBaseDir() {
171 if (System.getProperties().containsKey("appserver.base")) {
172 return Paths.get(System.getProperty("appserver.base"));
174 return Paths.get("");
180 public Path getRepositoryBaseDir() {
181 return getDataDirectory().resolve("repositories");
185 public Path getRemoteRepositoryBaseDir() {
186 return getDataDirectory().resolve("remotes");
190 public Path getRepositoryGroupBaseDir() {
191 return getDataDirectory().resolve("groups");
195 public Path getDataDirectory() {
196 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
197 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
199 return getAppServerBaseDir().resolve("data");