You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MockConfiguration.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package org.apache.archiva.metadata.repository.storage.maven2.conf;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  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
  18. * under the License.
  19. */
  20. import org.apache.archiva.configuration.ArchivaConfiguration;
  21. import org.apache.archiva.configuration.ArchivaRuntimeConfiguration;
  22. import org.apache.archiva.configuration.Configuration;
  23. import org.apache.archiva.configuration.ConfigurationListener;
  24. import org.apache.archiva.redback.components.registry.Registry;
  25. import org.apache.archiva.redback.components.registry.RegistryException;
  26. import org.apache.archiva.redback.components.registry.RegistryListener;
  27. import org.apache.commons.lang.StringUtils;
  28. import org.easymock.IMocksControl;
  29. import org.springframework.stereotype.Service;
  30. import java.nio.file.Path;
  31. import java.nio.file.Paths;
  32. import java.util.HashSet;
  33. import java.util.List;
  34. import java.util.Locale;
  35. import java.util.Set;
  36. import static org.easymock.EasyMock.createNiceControl;
  37. /**
  38. * MockConfiguration
  39. *
  40. *
  41. */
  42. @Service("archivaConfiguration#mock")
  43. public class MockConfiguration
  44. implements ArchivaConfiguration
  45. {
  46. private Configuration configuration = new Configuration();
  47. private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
  48. private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
  49. private IMocksControl registryControl;
  50. private Registry registryMock;
  51. public MockConfiguration()
  52. {
  53. registryControl = createNiceControl();
  54. registryMock = registryControl.createMock( Registry.class );
  55. configuration.setArchivaRuntimeConfiguration(new ArchivaRuntimeConfiguration());
  56. configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
  57. configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
  58. configuration.getArchivaRuntimeConfiguration().addChecksumType("md5");
  59. }
  60. @Override
  61. public void addChangeListener( RegistryListener listener )
  62. {
  63. registryListeners.add( listener );
  64. }
  65. @Override
  66. public void removeChangeListener( RegistryListener listener )
  67. {
  68. registryListeners.remove( listener );
  69. }
  70. @Override
  71. public Configuration getConfiguration()
  72. {
  73. return configuration;
  74. }
  75. @Override
  76. public void save( Configuration configuration )
  77. throws RegistryException
  78. {
  79. /* do nothing */
  80. }
  81. public void triggerChange( String name, String value )
  82. {
  83. for(RegistryListener listener: registryListeners)
  84. {
  85. try
  86. {
  87. listener.afterConfigurationChange( registryMock, name, value );
  88. }
  89. catch ( Exception e )
  90. {
  91. e.printStackTrace();
  92. }
  93. }
  94. }
  95. @Override
  96. public void addListener( ConfigurationListener listener )
  97. {
  98. configListeners.add(listener);
  99. }
  100. @Override
  101. public void removeListener( ConfigurationListener listener )
  102. {
  103. configListeners.remove( listener );
  104. }
  105. @Override
  106. public boolean isDefaulted()
  107. {
  108. return false;
  109. }
  110. @Override
  111. public void reload()
  112. {
  113. // no op
  114. }
  115. @Override
  116. public Locale getDefaultLocale( )
  117. {
  118. return Locale.getDefault();
  119. }
  120. @Override
  121. public List<Locale.LanguageRange> getLanguagePriorities( )
  122. {
  123. return Locale.LanguageRange.parse( "en,fr,de" );
  124. }
  125. @Override
  126. public Path getAppServerBaseDir() {
  127. if (System.getProperties().containsKey("appserver.base")) {
  128. return Paths.get(System.getProperty("appserver.base"));
  129. } else {
  130. return Paths.get("");
  131. }
  132. }
  133. @Override
  134. public Path getRepositoryBaseDir() {
  135. return getDataDirectory().resolve("repositories");
  136. }
  137. @Override
  138. public Path getRemoteRepositoryBaseDir() {
  139. return getDataDirectory().resolve("remotes");
  140. }
  141. @Override
  142. public Path getRepositoryGroupBaseDir() {
  143. return getDataDirectory().resolve("groups");
  144. }
  145. @Override
  146. public Path getDataDirectory() {
  147. if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
  148. return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
  149. } else {
  150. return getAppServerBaseDir().resolve("data");
  151. }
  152. }
  153. }