You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2019/05/04 19:19:12 UTC
[archiva] 01/05: Adding utility for artifact path handling
This is an automated email from the ASF dual-hosted git repository.
martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git
commit a3c149327e470c0391b9807545651de38c50e728
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Sat May 4 10:48:48 2019 +0200
Adding utility for artifact path handling
---
.../archiva/repository/content/ArtifactUtil.java | 56 ++++++++++++++++++++++
.../src/main/resources/META-INF/spring-context.xml | 2 +-
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactUtil.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactUtil.java
new file mode 100644
index 0000000..7755b53
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactUtil.java
@@ -0,0 +1,56 @@
+package org.apache.archiva.repository.content;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryContentFactory;
+import org.apache.archiva.repository.RepositoryException;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Utility class that gives information about the physical location of artifacts.
+ */
+@Service( "ArtifactUtil#default" )
+public class ArtifactUtil {
+
+ @Inject
+ RepositoryContentFactory repositoryContentFactory;
+
+ /**
+ * Returns the physical location of a given artifact in the repository. There is no check for the
+ * existence of the returned file.
+ *
+ * @param repository The repository, where the artifact is stored.
+ * @param artifactReference The artifact reference.
+ * @return The absolute path to the artifact.
+ * @throws RepositoryException
+ */
+ public Path getArtifactPath(ManagedRepository repository, ArtifactReference artifactReference) throws RepositoryException {
+ final ManagedRepositoryContent content = repositoryContentFactory.getManagedRepositoryContent(repository);
+ final String artifactPath = content.toPath( artifactReference );
+ return Paths.get(repository.getLocation()).resolve(artifactPath);
+ }
+
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/main/resources/META-INF/spring-context.xml
index ec80225..f411ade 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/resources/META-INF/spring-context.xml
@@ -28,6 +28,6 @@
default-lazy-init="true">
<context:annotation-config/>
- <context:component-scan base-package="org.apache.archiva.repository"/>
+ <context:component-scan base-package="org.apache.archiva.repository,org.apache.archiva.repository.content"/>
</beans>
\ No newline at end of file