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.

AbstractLegacyRepositoryContent.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package org.apache.archiva.repository.content.legacy;
  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.model.ArchivaArtifact;
  21. import org.apache.archiva.model.ArtifactReference;
  22. import org.apache.archiva.repository.content.PathParser;
  23. import org.apache.archiva.repository.content.maven2.ArtifactExtensionMapping;
  24. import org.apache.archiva.repository.layout.LayoutException;
  25. import org.apache.commons.lang.StringUtils;
  26. import javax.inject.Inject;
  27. import javax.inject.Named;
  28. import java.util.HashMap;
  29. import java.util.Map;
  30. /**
  31. * AbstractLegacyRepositoryContent
  32. *
  33. *
  34. */
  35. public abstract class AbstractLegacyRepositoryContent
  36. {
  37. private static final String PATH_SEPARATOR = "/";
  38. private static final Map<String, String> typeToDirectoryMap;
  39. static
  40. {
  41. typeToDirectoryMap = new HashMap<>( 5 );
  42. typeToDirectoryMap.put( "ejb-client", "ejb" );
  43. typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" );
  44. typeToDirectoryMap.put( "distribution-tgz", "distribution" );
  45. typeToDirectoryMap.put( "distribution-zip", "distribution" );
  46. typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
  47. }
  48. /**
  49. *
  50. */
  51. @Inject
  52. @Named( value = "pathParser#legacy" )
  53. private PathParser legacyPathParser;
  54. public ArtifactReference toArtifactReference( String path )
  55. throws LayoutException
  56. {
  57. return legacyPathParser.toArtifactReference( path );
  58. }
  59. public String toPath( ArchivaArtifact reference )
  60. {
  61. if ( reference == null )
  62. {
  63. throw new IllegalArgumentException( "Artifact reference cannot be null" );
  64. }
  65. return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
  66. reference.getClassifier(), reference.getType() );
  67. }
  68. public String toPath( ArtifactReference reference )
  69. {
  70. if ( reference == null )
  71. {
  72. throw new IllegalArgumentException( "Artifact reference cannot be null" );
  73. }
  74. return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
  75. reference.getClassifier(), reference.getType() );
  76. }
  77. private String toPath( String groupId, String artifactId, String version, String classifier, String type )
  78. {
  79. StringBuilder path = new StringBuilder();
  80. path.append( groupId ).append( PATH_SEPARATOR );
  81. path.append( getDirectory( type ) ).append( PATH_SEPARATOR );
  82. if ( version != null )
  83. {
  84. path.append( artifactId ).append( '-' ).append( version );
  85. if ( StringUtils.isNotBlank( classifier ) )
  86. {
  87. path.append( '-' ).append( classifier );
  88. }
  89. path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
  90. }
  91. return path.toString();
  92. }
  93. private String getDirectory( String type )
  94. {
  95. String dirname = typeToDirectoryMap.get( type );
  96. if ( dirname != null )
  97. {
  98. return dirname + "s";
  99. }
  100. // Default process.
  101. return type + "s";
  102. }
  103. public void setLegacyPathParser( PathParser parser )
  104. {
  105. this.legacyPathParser = parser;
  106. }
  107. }