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.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
112 public void triggerChange( String name, String value )
114 for(RegistryListener listener: registryListeners)
118 listener.afterConfigurationChange( registryMock, name, value );
120 catch ( Exception e )
128 public void addListener( ConfigurationListener listener )
130 configListeners.add(listener);
134 public void removeListener( ConfigurationListener listener )
136 configListeners.remove( listener );
140 public boolean isDefaulted()
152 public Locale getDefaultLocale( )
154 return Locale.getDefault();
158 public List<Locale.LanguageRange> getLanguagePriorities( )
160 return Locale.LanguageRange.parse( "en,fr,de" );
164 public Path getAppServerBaseDir() {
165 if (System.getProperties().containsKey("appserver.base")) {
166 return Paths.get(System.getProperty("appserver.base"));
168 return Paths.get("");
174 public Path getRepositoryBaseDir() {
175 return getDataDirectory().resolve("repositories");
179 public Path getRemoteRepositoryBaseDir() {
180 return getDataDirectory().resolve("remotes");
184 public Path getRepositoryGroupBaseDir() {
185 return getDataDirectory().resolve("groups");
189 public Path getDataDirectory() {
190 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
191 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
193 return getAppServerBaseDir().resolve("data");