1 package org.apache.archiva.maven.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
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
21 import org.apache.archiva.configuration.*;
22 import org.apache.archiva.components.registry.Registry;
23 import org.apache.archiva.components.registry.RegistryException;
24 import org.apache.archiva.components.registry.RegistryListener;
25 import org.apache.commons.lang3.StringUtils;
26 import org.easymock.EasyMock;
27 import org.easymock.IMocksControl;
28 import org.springframework.stereotype.Service;
30 import javax.annotation.PostConstruct;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
40 @Service( "archivaConfiguration#mock" )
41 public class MockConfiguration
42 implements ArchivaConfiguration
45 private Configuration configuration = new Configuration();
47 private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
49 private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
51 private IMocksControl registryControl;
53 private Registry registryMock;
55 public MockConfiguration()
57 registryControl = EasyMock.createNiceControl( );
58 registryMock = registryControl.createMock( Registry.class );
62 public void initialize()
66 configuration.setRepositoryScanning( new RepositoryScanningConfiguration()
69 public List<FileType> getFileTypes()
71 FileType fileType = new FileType();
72 fileType.setId( FileTypes.ARTIFACTS );
73 fileType.setPatterns( Collections.singletonList( "**/*" ) );
74 return Collections.singletonList( fileType );
77 ArchivaRuntimeConfiguration rt = new ArchivaRuntimeConfiguration();
78 List<String> checksums = new ArrayList<>();
80 checksums.add("SHA1");
81 checksums.add("SHA256");
82 rt.setChecksumTypes(checksums);
83 configuration.setArchivaRuntimeConfiguration(rt);
88 public void addChangeListener( org.apache.archiva.components.registry.RegistryListener listener )
90 registryListeners.add( listener );
95 public void removeChangeListener( RegistryListener listener )
97 registryListeners.remove( listener );
101 public Configuration getConfiguration()
103 return configuration;
107 public void save( Configuration configuration )
108 throws RegistryException
114 public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
119 public void triggerChange( String name, String value )
121 for ( org.apache.archiva.components.registry.RegistryListener listener : registryListeners )
125 listener.afterConfigurationChange( registryMock, name, value );
127 catch ( Exception e )
133 for (ConfigurationListener listener : configListeners) {
134 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.CHANGED ) );
139 public void addListener( ConfigurationListener listener )
141 configListeners.add( listener );
145 public void removeListener( ConfigurationListener listener )
147 configListeners.remove( listener );
151 public boolean isDefaulted()
163 public Locale getDefaultLocale( )
165 return Locale.getDefault();
169 public List<Locale.LanguageRange> getLanguagePriorities( )
171 return Locale.LanguageRange.parse( "en,fr,de" );
175 public Path getAppServerBaseDir() {
176 if (System.getProperties().containsKey("appserver.base")) {
177 return Paths.get(System.getProperty("appserver.base"));
179 return Paths.get("");
185 public Path getRepositoryBaseDir() {
186 return getDataDirectory().resolve("repositories");
190 public Path getRemoteRepositoryBaseDir() {
191 return getDataDirectory().resolve("remotes");
195 public Path getRepositoryGroupBaseDir() {
196 return getDataDirectory().resolve("groups");
200 public Path getDataDirectory() {
201 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
202 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
204 return getAppServerBaseDir().resolve("data");
209 public Registry getRegistry( )