1 package org.apache.archiva.repository.maven.metadata.storage.mock;
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.components.registry.Registry;
23 import org.apache.archiva.components.registry.RegistryException;
24 import org.apache.archiva.components.registry.RegistryListener;
25 import org.apache.archiva.configuration.ArchivaConfiguration;
26 import org.apache.archiva.configuration.ArchivaRuntimeConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.ConfigurationListener;
29 import org.apache.archiva.configuration.FileType;
30 import org.apache.archiva.configuration.IndeterminateConfigurationException;
31 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
32 import org.apache.commons.lang3.StringUtils;
33 import org.easymock.IMocksControl;
34 import org.springframework.stereotype.Service;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.util.ArrayList;
39 import java.util.HashSet;
40 import java.util.List;
41 import java.util.Locale;
44 import static org.easymock.EasyMock.createNiceControl;
51 @Service("archivaConfiguration#mock")
52 public class MockConfiguration
53 implements ArchivaConfiguration
56 private Configuration configuration = new Configuration();
58 private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
59 private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
61 private IMocksControl registryControl;
63 private Registry registryMock;
65 public MockConfiguration()
67 registryControl = createNiceControl();
68 registryMock = registryControl.createMock( Registry.class );
69 configuration.setArchivaRuntimeConfiguration(new ArchivaRuntimeConfiguration());
70 configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
71 configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
72 configuration.getArchivaRuntimeConfiguration().addChecksumType("md5");
73 RepositoryScanningConfiguration rpsc = new RepositoryScanningConfiguration( );
74 FileType ft = new FileType( );
75 ft.setId( "artifacts" );
76 ArrayList<String> plist = new ArrayList<>( );
77 plist.add( "**/*.jar" );
78 plist.add( "**/*.pom" );
79 plist.add( "**/*.war" );
80 ft.setPatterns( plist );
81 rpsc.addFileType( ft );
82 ArrayList<FileType> ftList = new ArrayList<>( );
84 rpsc.setFileTypes( ftList );
85 configuration.setRepositoryScanning( rpsc );
89 public void addChangeListener( RegistryListener listener )
91 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(RegistryListener listener: registryListeners)
125 listener.afterConfigurationChange( registryMock, name, value );
127 catch ( Exception e )
135 public void addListener( ConfigurationListener listener )
137 configListeners.add(listener);
141 public void removeListener( ConfigurationListener listener )
143 configListeners.remove( listener );
147 public boolean isDefaulted()
159 public Locale getDefaultLocale( )
161 return Locale.getDefault();
165 public List<Locale.LanguageRange> getLanguagePriorities( )
167 return Locale.LanguageRange.parse( "en,fr,de" );
171 public Path getAppServerBaseDir() {
172 if (System.getProperties().containsKey("appserver.base")) {
173 return Paths.get(System.getProperty("appserver.base"));
175 return Paths.get("");
181 public Path getRepositoryBaseDir() {
182 return getDataDirectory().resolve("repositories");
186 public Path getRemoteRepositoryBaseDir() {
187 return getDataDirectory().resolve("remotes");
191 public Path getRepositoryGroupBaseDir() {
192 return getDataDirectory().resolve("groups");
196 public Path getDataDirectory() {
197 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
198 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
200 return getAppServerBaseDir().resolve("data");
205 public Registry getRegistry( )