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.

MavenManagedRepository.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package org.apache.archiva.repository.maven2;
  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.common.utils.PathUtil;
  21. import org.apache.archiva.repository.*;
  22. import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo;
  23. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  24. import org.apache.archiva.repository.features.IndexCreationFeature;
  25. import org.apache.archiva.repository.features.RepositoryFeature;
  26. import org.apache.archiva.repository.features.StagingRepositoryFeature;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;
  29. import java.io.IOException;
  30. import java.net.URI;
  31. import java.nio.file.Files;
  32. import java.nio.file.Path;
  33. import java.util.Locale;
  34. import java.util.function.Function;
  35. /**
  36. * Maven2 managed repository implementation.
  37. */
  38. public class MavenManagedRepository extends AbstractManagedRepository
  39. {
  40. private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class );
  41. public static final String DEFAULT_LAYOUT = "default";
  42. public static final String LEGACY_LAYOUT = "legacy";
  43. private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
  44. private IndexCreationFeature indexCreationFeature;
  45. private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
  46. private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
  47. new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
  48. new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT},
  49. new String[] {},
  50. new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(),
  51. StagingRepositoryFeature.class.getName()},
  52. true,
  53. true,
  54. true,
  55. true,
  56. false
  57. );
  58. public MavenManagedRepository( String id, String name, Path basePath )
  59. {
  60. super( RepositoryType.MAVEN, id, name, basePath);
  61. this.indexCreationFeature = new IndexCreationFeature(this, this);
  62. }
  63. public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath )
  64. {
  65. super( primaryLocale, RepositoryType.MAVEN, id, name, basePath );
  66. }
  67. @Override
  68. public RepositoryCapabilities getCapabilities( )
  69. {
  70. return CAPABILITIES;
  71. }
  72. @SuppressWarnings( "unchecked" )
  73. @Override
  74. public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
  75. {
  76. if (ArtifactCleanupFeature.class.equals( clazz ))
  77. {
  78. return (RepositoryFeature<T>) artifactCleanupFeature;
  79. } else if (IndexCreationFeature.class.equals(clazz)) {
  80. return (RepositoryFeature<T>) indexCreationFeature;
  81. } else if (StagingRepositoryFeature.class.equals(clazz)) {
  82. return (RepositoryFeature<T>) stagingRepositoryFeature;
  83. } else {
  84. throw new UnsupportedFeatureException( );
  85. }
  86. }
  87. @Override
  88. public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
  89. {
  90. if (ArtifactCleanupFeature.class.equals(clazz) ||
  91. IndexCreationFeature.class.equals(clazz) ||
  92. StagingRepositoryFeature.class.equals(clazz)) {
  93. return true;
  94. }
  95. return false;
  96. }
  97. @Override
  98. public boolean hasIndex( )
  99. {
  100. return indexCreationFeature.hasIndex();
  101. }
  102. @Override
  103. public void setLocation( URI location )
  104. {
  105. super.setLocation( location );
  106. Path newLoc = PathUtil.getPathFromUri( location );
  107. if (!Files.exists( newLoc )) {
  108. try
  109. {
  110. Files.createDirectories( newLoc );
  111. }
  112. catch ( IOException e )
  113. {
  114. log.error("Could not create directory {}",location, e);
  115. }
  116. }
  117. }
  118. @Override
  119. public RepositoryRequestInfo getRequestInfo() {
  120. return new MavenRepositoryRequestInfo(this);
  121. }
  122. }