Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

BasicRepositoryGroup.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package org.apache.archiva.repository.base.group;
  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.common.filelock.DefaultFileLockManager;
  20. import org.apache.archiva.common.filelock.FileLockManager;
  21. import org.apache.archiva.repository.EditableRepositoryGroup;
  22. import org.apache.archiva.repository.ManagedRepository;
  23. import org.apache.archiva.repository.ReleaseScheme;
  24. import org.apache.archiva.repository.RepositoryCapabilities;
  25. import org.apache.archiva.repository.RepositoryGroup;
  26. import org.apache.archiva.repository.RepositoryState;
  27. import org.apache.archiva.repository.RepositoryType;
  28. import org.apache.archiva.repository.StandardCapabilities;
  29. import org.apache.archiva.repository.base.AbstractRepository;
  30. import org.apache.archiva.repository.base.managed.BasicManagedRepository;
  31. import org.apache.archiva.repository.features.IndexCreationFeature;
  32. import org.apache.archiva.repository.storage.RepositoryStorage;
  33. import org.apache.archiva.repository.storage.fs.FilesystemStorage;
  34. import org.slf4j.Logger;
  35. import org.slf4j.LoggerFactory;
  36. import java.io.IOException;
  37. import java.nio.file.Path;
  38. import java.util.ArrayList;
  39. import java.util.List;
  40. /**
  41. * @author Martin Stockhammer <martin_s@apache.org>
  42. */
  43. public class BasicRepositoryGroup extends AbstractRepository implements EditableRepositoryGroup
  44. {
  45. private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
  46. new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
  47. new String[] {},
  48. new String[] {},
  49. new String[] {IndexCreationFeature.class.getName()},
  50. false,
  51. false,
  52. false,
  53. false,
  54. false
  55. );
  56. private int mergedIndexTtl = 0;
  57. private boolean hasIndex = false;
  58. private final Logger log = LoggerFactory.getLogger(BasicRepositoryGroup.class);
  59. private List<ManagedRepository> repositories = new ArrayList<>( );
  60. public BasicRepositoryGroup( String id, String name, RepositoryStorage repositoryStorage )
  61. {
  62. super( RepositoryType.MAVEN, id, name, repositoryStorage );
  63. IndexCreationFeature feature = new IndexCreationFeature( this, null );
  64. feature.setLocalIndexPath( repositoryStorage.getRoot( ).resolve(".indexer") );
  65. feature.setLocalPackedIndexPath( repositoryStorage.getRoot( ).resolve(".index") );
  66. addFeature( feature );
  67. setLastState( RepositoryState.CREATED );
  68. }
  69. @Override
  70. public List<ManagedRepository> getRepositories( )
  71. {
  72. return repositories;
  73. }
  74. @Override
  75. public boolean contains( ManagedRepository repository )
  76. {
  77. return repositories.contains( repository );
  78. }
  79. @Override
  80. public boolean contains( String id )
  81. {
  82. return repositories.stream( ).anyMatch( v -> id.equals( v.getId( ) ) );
  83. }
  84. @Override
  85. public int getMergedIndexTTL( )
  86. {
  87. return mergedIndexTtl;
  88. }
  89. @Override
  90. public boolean hasIndex( )
  91. {
  92. return hasIndex;
  93. }
  94. @Override
  95. public RepositoryCapabilities getCapabilities( )
  96. {
  97. return CAPABILITIES;
  98. }
  99. @Override
  100. public void clearRepositories( )
  101. {
  102. this.repositories.clear( );
  103. }
  104. @Override
  105. public void setRepositories( List<ManagedRepository> repositories )
  106. {
  107. this.repositories.clear();
  108. this.repositories.addAll( repositories );
  109. }
  110. @Override
  111. public void addRepository( ManagedRepository repository )
  112. {
  113. if ( !this.repositories.contains( repository ) )
  114. {
  115. this.repositories.add( repository );
  116. }
  117. }
  118. @Override
  119. public void addRepository( int index, ManagedRepository repository )
  120. {
  121. if (!this.repositories.contains( repository )) {
  122. this.repositories.add( index, repository );
  123. }
  124. }
  125. @Override
  126. public boolean removeRepository( ManagedRepository repository )
  127. {
  128. return this.repositories.remove( repository );
  129. }
  130. @Override
  131. public ManagedRepository removeRepository( String repoId )
  132. {
  133. for (ManagedRepository repo : this.repositories) {
  134. if (repoId.equals( repo.getId() )) {
  135. this.repositories.remove( repo );
  136. return repo;
  137. }
  138. }
  139. return null;
  140. }
  141. @Override
  142. public void setMergedIndexTTL( int timeInSeconds )
  143. {
  144. this.mergedIndexTtl = timeInSeconds;
  145. }
  146. /**
  147. * Creates a filesystem based repository instance. The path is built by basePath/repository-id
  148. *
  149. * @param id The repository id
  150. * @param name The name of the repository
  151. * @param repositoryPath The path to the repository
  152. * @return The repository instance
  153. * @throws IOException
  154. */
  155. public static BasicRepositoryGroup newFilesystemInstance( String id, String name, Path repositoryPath) throws IOException {
  156. FileLockManager lockManager = new DefaultFileLockManager();
  157. FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
  158. return new BasicRepositoryGroup(id, name, storage);
  159. }
  160. }