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
115 public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
120 public void triggerChange( String name, String value )
122 for ( org.apache.archiva.components.registry.RegistryListener listener : registryListeners )
126 listener.afterConfigurationChange( registryMock, name, value );
128 catch ( Exception e )
134 for (ConfigurationListener listener : configListeners) {
135 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.CHANGED ) );
140 public void addListener( ConfigurationListener listener )
142 configListeners.add( listener );
146 public void removeListener( ConfigurationListener listener )
148 configListeners.remove( listener );
152 public boolean isDefaulted()
164 public Locale getDefaultLocale( )
166 return Locale.getDefault();
170 public List<Locale.LanguageRange> getLanguagePriorities( )
172 return Locale.LanguageRange.parse( "en,fr,de" );
176 public Path getAppServerBaseDir() {
177 if (System.getProperties().containsKey("appserver.base")) {
178 return Paths.get(System.getProperty("appserver.base"));
180 return Paths.get("");
186 public Path getRepositoryBaseDir() {
187 return getDataDirectory().resolve("repositories");
191 public Path getRemoteRepositoryBaseDir() {
192 return getDataDirectory().resolve("remotes");
196 public Path getRepositoryGroupBaseDir() {
197 return getDataDirectory().resolve("groups");
201 public Path getDataDirectory() {
202 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
203 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
205 return getAppServerBaseDir().resolve("data");