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.springframework.stereotype.Service;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.util.ArrayList;
37 import java.util.HashSet;
38 import java.util.List;
39 import java.util.Locale;
42 import static org.mockito.Mockito.mock;
49 @Service("archivaConfiguration#mock")
50 public class MockConfiguration
51 implements ArchivaConfiguration
54 private Configuration configuration = new Configuration();
56 private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
57 private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
59 private Registry registryMock;
61 public MockConfiguration()
63 registryMock = mock( Registry.class );
64 configuration.setArchivaRuntimeConfiguration(new ArchivaRuntimeConfiguration());
65 configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
66 configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
67 configuration.getArchivaRuntimeConfiguration().addChecksumType("md5");
68 RepositoryScanningConfiguration rpsc = new RepositoryScanningConfiguration( );
69 FileType ft = new FileType( );
70 ft.setId( "artifacts" );
71 ArrayList<String> plist = new ArrayList<>( );
72 plist.add( "**/*.jar" );
73 plist.add( "**/*.pom" );
74 plist.add( "**/*.war" );
75 ft.setPatterns( plist );
76 rpsc.addFileType( ft );
77 ArrayList<FileType> ftList = new ArrayList<>( );
79 rpsc.setFileTypes( ftList );
80 configuration.setRepositoryScanning( rpsc );
84 public void addChangeListener( RegistryListener listener )
86 registryListeners.add( listener );
90 public void removeChangeListener( RegistryListener listener )
92 registryListeners.remove( listener );
96 public Configuration getConfiguration()
102 public void save( Configuration configuration )
103 throws RegistryException
109 public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
114 public void triggerChange( String name, String value )
116 for(RegistryListener listener: registryListeners)
120 listener.afterConfigurationChange( registryMock, name, value );
122 catch ( Exception e )
130 public void addListener( ConfigurationListener listener )
132 configListeners.add(listener);
136 public void removeListener( ConfigurationListener listener )
138 configListeners.remove( listener );
142 public boolean isDefaulted()
154 public Locale getDefaultLocale( )
156 return Locale.getDefault();
160 public List<Locale.LanguageRange> getLanguagePriorities( )
162 return Locale.LanguageRange.parse( "en,fr,de" );
166 public Path getAppServerBaseDir() {
167 if (System.getProperties().containsKey("appserver.base")) {
168 return Paths.get(System.getProperty("appserver.base"));
170 return Paths.get("");
176 public Path getRepositoryBaseDir() {
177 return getDataDirectory().resolve("repositories");
181 public Path getRemoteRepositoryBaseDir() {
182 return getDataDirectory().resolve("remotes");
186 public Path getRepositoryGroupBaseDir() {
187 return getDataDirectory().resolve("groups");
191 public Path getDataDirectory() {
192 if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
193 return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
195 return getAppServerBaseDir().resolve("data");
200 public Registry getRegistry( )