1 package org.apache.archiva.maven.repository.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
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.components.registry.Registry;
22 import org.apache.archiva.components.registry.RegistryException;
23 import org.apache.archiva.components.registry.RegistryListener;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.ArchivaRuntimeConfiguration;
26 import org.apache.archiva.configuration.Configuration;
27 import org.apache.archiva.configuration.ConfigurationListener;
28 import org.apache.archiva.configuration.FileType;
29 import org.apache.archiva.configuration.IndeterminateConfigurationException;
30 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
31 import org.apache.commons.lang3.StringUtils;
32 import org.easymock.IMocksControl;
33 import org.springframework.stereotype.Service;
35 import java.nio.file.Path;
36 import java.nio.file.Paths;
37 import java.util.ArrayList;
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.Locale;
43 import static org.easymock.EasyMock.createNiceControl;
50 @Service("archivaConfiguration#mock")
51 public class MockConfiguration
52 implements ArchivaConfiguration
55 private Configuration configuration = new Configuration();
57 private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
58 private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
60 private IMocksControl registryControl;
62 private Registry registryMock;
64 public MockConfiguration()
66 registryControl = createNiceControl();
67 registryMock = registryControl.createMock( Registry.class );
68 configuration.setArchivaRuntimeConfiguration(new ArchivaRuntimeConfiguration());
69 configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
70 configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
71 configuration.getArchivaRuntimeConfiguration().addChecksumType("md5");
72 RepositoryScanningConfiguration rpsc = new RepositoryScanningConfiguration( );
73 FileType ft = new FileType( );
74 ft.setId( "artifacts" );
75 ArrayList<String> plist = new ArrayList<>( );
76 plist.add( "**/*.jar" );
77 plist.add( "**/*.pom" );
78 plist.add( "**/*.war" );
79 ft.setPatterns( plist );
80 rpsc.addFileType( ft );
81 ArrayList<FileType> ftList = new ArrayList<>( );
83 rpsc.setFileTypes( ftList );
84 configuration.setRepositoryScanning( rpsc );
88 public void addChangeListener( RegistryListener listener )
90 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(RegistryListener listener: registryListeners)
124 listener.afterConfigurationChange( registryMock, name, value );
126 catch ( Exception e )
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");
204 public Registry getRegistry( )