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.

StubConfiguration.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package org.apache.archiva.repository.maven.mock.configuration;
  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. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import org.apache.archiva.components.registry.Registry;
  20. import org.apache.archiva.components.registry.RegistryException;
  21. import org.apache.archiva.components.registry.RegistryListener;
  22. import org.apache.archiva.configuration.ArchivaConfiguration;
  23. import org.apache.archiva.configuration.Configuration;
  24. import org.apache.archiva.configuration.ConfigurationListener;
  25. import org.apache.archiva.configuration.IndeterminateConfigurationException;
  26. import org.apache.archiva.configuration.RepositoryScanningConfiguration;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.springframework.stereotype.Service;
  29. import java.nio.file.Path;
  30. import java.nio.file.Paths;
  31. import java.util.List;
  32. import java.util.Locale;
  33. @Service("archivaConfiguration#mocked")
  34. public class StubConfiguration
  35. implements ArchivaConfiguration
  36. {
  37. private Configuration configuration = new Configuration();
  38. StubConfiguration() {
  39. configuration.setRepositoryScanning( new RepositoryScanningConfiguration() );
  40. }
  41. @Override
  42. public Configuration getConfiguration()
  43. {
  44. return configuration;
  45. }
  46. @Override
  47. public void save( Configuration configuration )
  48. throws RegistryException, IndeterminateConfigurationException
  49. {
  50. this.configuration = configuration;
  51. }
  52. @Override
  53. public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
  54. {
  55. this.configuration = configuration;
  56. }
  57. @Override
  58. public boolean isDefaulted()
  59. {
  60. return false;
  61. }
  62. @Override
  63. public void addListener( ConfigurationListener listener )
  64. {
  65. // throw new UnsupportedOperationException();
  66. }
  67. @Override
  68. public void removeListener( ConfigurationListener listener )
  69. {
  70. throw new UnsupportedOperationException();
  71. }
  72. @Override
  73. public void addChangeListener( RegistryListener listener )
  74. {
  75. // throw new UnsupportedOperationException();
  76. }
  77. @Override
  78. public void removeChangeListener( RegistryListener listener )
  79. {
  80. throw new UnsupportedOperationException();
  81. }
  82. @Override
  83. public void reload()
  84. {
  85. // no op
  86. }
  87. @Override
  88. public Locale getDefaultLocale( )
  89. {
  90. return Locale.getDefault();
  91. }
  92. @Override
  93. public List<Locale.LanguageRange> getLanguagePriorities( )
  94. {
  95. return Locale.LanguageRange.parse( "en,fr,de" );
  96. }
  97. @Override
  98. public Path getAppServerBaseDir() {
  99. if (System.getProperties().containsKey("appserver.base")) {
  100. return Paths.get(System.getProperty("appserver.base"));
  101. } else {
  102. return Paths.get("");
  103. }
  104. }
  105. @Override
  106. public Path getRepositoryBaseDir() {
  107. return getDataDirectory().resolve("repositories");
  108. }
  109. @Override
  110. public Path getRemoteRepositoryBaseDir() {
  111. return getDataDirectory().resolve("remotes");
  112. }
  113. @Override
  114. public Path getRepositoryGroupBaseDir( )
  115. {
  116. return getDataDirectory().resolve("group");
  117. }
  118. @Override
  119. public Path getDataDirectory() {
  120. if (configuration!=null && configuration.getArchivaRuntimeConfiguration()!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
  121. Path dataDir = Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
  122. if (dataDir.isAbsolute()) {
  123. return dataDir;
  124. } else {
  125. return getAppServerBaseDir().resolve(dataDir);
  126. }
  127. } else {
  128. return getAppServerBaseDir().resolve("data");
  129. }
  130. }
  131. @Override
  132. public Registry getRegistry( )
  133. {
  134. return null;
  135. }
  136. }