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.

ArtifactUtil.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package org.apache.archiva.repository.content;
  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.ArtifactReference;
  21. import org.apache.archiva.repository.ManagedRepository;
  22. import org.apache.archiva.repository.ManagedRepositoryContent;
  23. import org.apache.archiva.repository.RepositoryContentFactory;
  24. import org.apache.archiva.repository.RepositoryException;
  25. import org.apache.archiva.repository.storage.StorageAsset;
  26. import org.springframework.stereotype.Service;
  27. import javax.inject.Inject;
  28. import java.nio.file.Path;
  29. import java.nio.file.Paths;
  30. /**
  31. * Utility class that gives information about the physical location of artifacts.
  32. */
  33. @Service( "ArtifactUtil#default" )
  34. public class ArtifactUtil {
  35. @Inject
  36. RepositoryContentFactory repositoryContentFactory;
  37. /**
  38. * Returns the physical location of a given artifact in the repository. There is no check for the
  39. * existence of the returned file.
  40. *
  41. * @param repository The repository, where the artifact is stored.
  42. * @param artifactReference The artifact reference.
  43. * @return The absolute path to the artifact.
  44. * @throws RepositoryException
  45. */
  46. public Path getArtifactPath(ManagedRepository repository, ArtifactReference artifactReference) throws RepositoryException {
  47. final ManagedRepositoryContent content = repositoryContentFactory.getManagedRepositoryContent(repository);
  48. final String artifactPath = content.toPath( artifactReference );
  49. return Paths.get(repository.getLocation()).resolve(artifactPath);
  50. }
  51. /**
  52. * Returns the physical location of a given artifact in the repository. There is no check for the
  53. * existence of the returned file.
  54. *
  55. * @param repository The repository, where the artifact is stored.
  56. * @param artifactReference The artifact reference.
  57. * @return The asset representation of the artifact.
  58. * @throws RepositoryException
  59. */
  60. public StorageAsset getArtifactAsset(ManagedRepository repository, ArtifactReference artifactReference) throws RepositoryException {
  61. final ManagedRepositoryContent content = repositoryContentFactory.getManagedRepositoryContent(repository);
  62. final String artifactPath = content.toPath( artifactReference );
  63. return repository.getAsset(artifactPath);
  64. }
  65. }