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.mockito.Mockito;
27 import org.springframework.stereotype.Service;
29 import javax.annotation.PostConstruct;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
34 import static org.mockito.Mockito.mock;
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>();
53 private Registry registryMock;
55 public MockConfiguration()
57 registryMock = mock( Registry.class );
61 public void initialize()
65 configuration.setRepositoryScanning( new RepositoryScanningConfiguration()
68 public List<FileType> getFileTypes()
70 FileType fileType = new FileType();
71 fileType.setId( FileTypes.ARTIFACTS );
72 fileType.setPatterns( Collections.singletonList( "**/*" ) );
73 return Collections.singletonList( fileType );
76 ArchivaRuntimeConfiguration rt = new ArchivaRuntimeConfiguration();
77 List<String> checksums = new ArrayList<>();
79 checksums.add("SHA1");
80 checksums.add("SHA256");
81 rt.setChecksumTypes(checksums);
82 configuration.setArchivaRuntimeConfiguration(rt);
87 public void addChangeListener( org.apache.archiva.components.registry.RegistryListener listener )
89 registryListeners.add( listener );
94 public void removeChangeListener( RegistryListener listener )
96 registryListeners.remove( listener );
100 public Configuration getConfiguration()
102 return configuration;
106 public void save( Configuration configuration )
107 throws RegistryException
113 public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
118 public void triggerChange( String name, String value )
120 for ( org.apache.archiva.components.registry.RegistryListener listener : registryListeners )
124 listener.afterConfigurationChange( registryMock, name, value );
126 catch ( Exception e )
132 for (ConfigurationListener listener : configListeners) {
133 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.CHANGED ) );
138 public void addListener( ConfigurationListener listener )
140 configListeners.add( listener );
144 public void removeListener( ConfigurationListener listener )
146 configListeners.remove( listener );
150 public boolean isDefaulted()
162 public Locale getDefaultLocale( )
164 return Locale.getDefault();
168 public List<Locale.LanguageRange> getLanguagePriorities( )
170 return Locale.LanguageRange.parse( "en,fr,de" );
174 public Path getAppServerBaseDir() {
175 if (System.getProperties().containsKey("appserver.base")) {
176 return Paths.get(System.getProperty("appserver.base"));
178 return Paths.get("");
184 public Path getRepositoryBaseDir() {
185 return getDataDirectory().resolve("repositories");
189 public Path getRemoteRepositoryBaseDir() {
190 return getDataDirectory().resolve("remotes");
194 public Path getRepositoryGroupBaseDir() {
195 return getDataDirectory().resolve("groups");
199 public Path getDataDirectory() {
200 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
201 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
203 return getAppServerBaseDir().resolve("data");
208 public Registry getRegistry( )