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.

RemoteDefaultRepositoryContent.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package org.apache.archiva.repository.content.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.metadata.repository.storage.maven2.ArtifactMappingProvider;
  21. import org.apache.archiva.model.ArtifactReference;
  22. import org.apache.archiva.model.RepositoryURL;
  23. import org.apache.archiva.repository.LayoutException;
  24. import org.apache.archiva.repository.RemoteRepository;
  25. import org.apache.archiva.repository.RemoteRepositoryContent;
  26. import java.util.List;
  27. /**
  28. * RemoteDefaultRepositoryContent
  29. */
  30. public class RemoteDefaultRepositoryContent
  31. extends AbstractDefaultRepositoryContent
  32. implements RemoteRepositoryContent
  33. {
  34. private RemoteRepository repository;
  35. public RemoteDefaultRepositoryContent( List<? extends ArtifactMappingProvider> artifactMappingProviders ) {
  36. super(artifactMappingProviders);
  37. }
  38. @Override
  39. public String getId( )
  40. {
  41. return repository.getId( );
  42. }
  43. @Override
  44. public RemoteRepository getRepository( )
  45. {
  46. return repository;
  47. }
  48. @Override
  49. public RepositoryURL getURL( )
  50. {
  51. try
  52. {
  53. return new RepositoryURL( repository.getLocation( ).toString( ) );
  54. }
  55. catch ( Exception e )
  56. {
  57. log.error( "Could not convert location url {}", repository.getLocation( ) );
  58. return new RepositoryURL( "" );
  59. }
  60. }
  61. @Override
  62. public void setRepository( RemoteRepository repository )
  63. {
  64. this.repository = repository;
  65. }
  66. /**
  67. * Convert a path to an artifact reference.
  68. *
  69. * @param path the path to convert. (relative or full url path)
  70. * @throws LayoutException if the path cannot be converted to an artifact reference.
  71. */
  72. @Override
  73. public ArtifactReference toArtifactReference( String path )
  74. throws LayoutException
  75. {
  76. if ( ( path != null ) && repository.getLocation()!=null && path.startsWith( repository.getLocation().toString() ) )
  77. {
  78. return super.toArtifactReference( path.substring( repository.getLocation().toString().length( ) ) );
  79. }
  80. return super.toArtifactReference( path );
  81. }
  82. @Override
  83. public RepositoryURL toURL( ArtifactReference reference )
  84. {
  85. String url = repository.getLocation( ) + toPath( reference );
  86. return new RepositoryURL( url );
  87. }
  88. }