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.

TestConfiguration.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package org.apache.archiva.repository.maven.mock.configuration;
  2. import org.apache.archiva.components.registry.Registry;
  3. import org.apache.archiva.components.registry.RegistryException;
  4. import org.apache.archiva.components.registry.RegistryListener;
  5. import org.apache.archiva.configuration.ArchivaConfiguration;
  6. import org.apache.archiva.configuration.Configuration;
  7. import org.apache.archiva.configuration.ConfigurationListener;
  8. import org.apache.archiva.configuration.IndeterminateConfigurationException;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.stereotype.Service;
  11. import java.nio.file.Path;
  12. import java.nio.file.Paths;
  13. import java.util.List;
  14. import java.util.Locale;
  15. /*
  16. * Licensed to the Apache Software Foundation (ASF) under one
  17. * or more contributor license agreements. See the NOTICE file
  18. * distributed with this work for additional information
  19. * regarding copyright ownership. The ASF licenses this file
  20. * to you under the Apache License, Version 2.0 (the
  21. * "License"); you may not use this file except in compliance
  22. * with the License. You may obtain a copy of the License at
  23. *
  24. * http://www.apache.org/licenses/LICENSE-2.0
  25. * Unless required by applicable law or agreed to in writing,
  26. * software distributed under the License is distributed on an
  27. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28. * KIND, either express or implied. See the License for the
  29. * specific language governing permissions and limitations
  30. * under the License.
  31. */
  32. @Service("archivaConfiguration#test")
  33. public class TestConfiguration
  34. implements ArchivaConfiguration
  35. {
  36. private Configuration configuration;
  37. @Override
  38. public Configuration getConfiguration()
  39. {
  40. return configuration;
  41. }
  42. @Override
  43. public void save( Configuration configuration )
  44. throws RegistryException, IndeterminateConfigurationException
  45. {
  46. this.configuration = configuration;
  47. }
  48. @Override
  49. public void save( Configuration configuration, String eventTag ) throws RegistryException, IndeterminateConfigurationException
  50. {
  51. this.configuration = configuration;
  52. }
  53. @Override
  54. public boolean isDefaulted()
  55. {
  56. return false;
  57. }
  58. @Override
  59. public void addListener( ConfigurationListener listener )
  60. {
  61. // no op
  62. }
  63. @Override
  64. public void removeListener( ConfigurationListener listener )
  65. {
  66. // no op
  67. }
  68. @Override
  69. public void addChangeListener( RegistryListener listener )
  70. {
  71. // no op
  72. }
  73. @Override
  74. public void removeChangeListener( RegistryListener listener )
  75. {
  76. // no op
  77. }
  78. @Override
  79. public void reload()
  80. {
  81. // no op
  82. }
  83. @Override
  84. public Locale getDefaultLocale( )
  85. {
  86. return Locale.getDefault();
  87. }
  88. @Override
  89. public List<Locale.LanguageRange> getLanguagePriorities( )
  90. {
  91. return Locale.LanguageRange.parse("en,fr,de");
  92. }
  93. @Override
  94. public Path getAppServerBaseDir() {
  95. if (System.getProperties().containsKey("appserver.base")) {
  96. return Paths.get(System.getProperty("appserver.base"));
  97. } else {
  98. return Paths.get("");
  99. }
  100. }
  101. @Override
  102. public Path getRepositoryBaseDir() {
  103. return getDataDirectory().resolve("");
  104. }
  105. @Override
  106. public Path getRemoteRepositoryBaseDir() {
  107. return getDataDirectory().resolve("remotes");
  108. }
  109. @Override
  110. public Path getRepositoryGroupBaseDir() {
  111. return getDataDirectory().resolve("groups");
  112. }
  113. @Override
  114. public Path getDataDirectory() {
  115. if (configuration!=null && configuration.getArchivaRuntimeConfiguration()!=null &&
  116. StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
  117. return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
  118. } else {
  119. return getAppServerBaseDir().resolve("data");
  120. }
  121. }
  122. @Override
  123. public Registry getRegistry( )
  124. {
  125. return null;
  126. }
  127. }