You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2021/01/11 11:13:28 UTC

[sling-slingfeature-maven-plugin] branch issues/SLING-10052 created (now a03f976)

This is an automated email from the ASF dual-hosted git repository.

pauls pushed a change to branch issues/SLING-10052
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git.


      at a03f976  SLING-10052: Cache artifact resolution per project

This branch includes the following new commits:

     new a03f976  SLING-10052: Cache artifact resolution per project

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-slingfeature-maven-plugin] 01/01: SLING-10052: Cache artifact resolution per project

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch issues/SLING-10052
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit a03f9769236450ad0017dffabe544b1e0013ba0c
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Mon Jan 11 12:13:12 2021 +0100

    SLING-10052: Cache artifact resolution per project
---
 .../apache/sling/feature/maven/ProjectHelper.java  | 62 +++++++++++++---------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
index b710190..ed98bc2 100644
--- a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
+++ b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 import org.apache.maven.artifact.Artifact;
@@ -73,6 +74,9 @@ public abstract class ProjectHelper {
     /** Default metadata */
     private static final String METADATA_KEY = Feature.class.getName() + "/metadata";
 
+    /** Artifact cache */
+    private static final String ARTIFACT_CACHE = Artifact.class.getName() + "/cache";
+
     private static void store(final MavenProject project, final String key, final Map<String, Feature> features) {
         if ( features != null && !features.isEmpty()) {
             project.setContextValue(key, features.size());
@@ -317,37 +321,47 @@ public abstract class ProjectHelper {
             final ArtifactHandlerManager artifactHandlerManager,
             final ArtifactResolver resolver,
             final ArtifactId id) {
-        Artifact result = findArtifact(id, project.getAttachedArtifacts());
+        @SuppressWarnings("unchecked")
+        Map<String, Artifact> cache = (Map<String, Artifact>) project.getContextValue(ARTIFACT_CACHE);
+        if ( cache == null ) {
+            cache = new ConcurrentHashMap<>();
+            project.setContextValue(ARTIFACT_CACHE, cache);
+        }
+        Artifact result = cache.get(id.toMvnId());
         if ( result == null ) {
-            result = findArtifact(id, project.getDependencyArtifacts());
+            result = findArtifact(id, project.getAttachedArtifacts());
             if ( result == null ) {
-                if ( isLocalProjectArtifact(project, id)) {
-                    for(final Map.Entry<String, Feature> entry : getFeatures(project).entrySet()) {
-                        if ( entry.getValue().getId().equals(id)) {
-                            final Artifact artifact = new DefaultArtifact(id.getGroupId(), id.getArtifactId(), id.getVersion(), Artifact.SCOPE_PROVIDED, id.getType(), id.getClassifier(), null);
-                            artifact.setFile(createTmpFeatureFile(project, entry.getValue()));
-
-                            result = artifact;
-                            break;
+                result = findArtifact(id, project.getDependencyArtifacts());
+                if ( result == null ) {
+                    if ( isLocalProjectArtifact(project, id)) {
+                        for(final Map.Entry<String, Feature> entry : getFeatures(project).entrySet()) {
+                            if ( entry.getValue().getId().equals(id)) {
+                                final Artifact artifact = new DefaultArtifact(id.getGroupId(), id.getArtifactId(), id.getVersion(), Artifact.SCOPE_PROVIDED, id.getType(), id.getClassifier(), null);
+                                artifact.setFile(createTmpFeatureFile(project, entry.getValue()));
+
+                                result = artifact;
+                                break;
+                            }
                         }
                     }
-                }
-                if ( result == null ) {
-                    final Artifact prjArtifact = new DefaultArtifact(id.getGroupId(),
-                            id.getArtifactId(),
-                            VersionRange.createFromVersion(id.getVersion()),
-                            Artifact.SCOPE_PROVIDED,
-                            id.getType(),
-                            id.getClassifier(),
-                            artifactHandlerManager.getArtifactHandler(id.getType()));
-                    try {
-                        resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
-                    } catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
-                        throw new RuntimeException("Unable to get artifact for " + id.toMvnId(), e);
+                    if ( result == null ) {
+                        final Artifact prjArtifact = new DefaultArtifact(id.getGroupId(),
+                                id.getArtifactId(),
+                                VersionRange.createFromVersion(id.getVersion()),
+                                Artifact.SCOPE_PROVIDED,
+                                id.getType(),
+                                id.getClassifier(),
+                                artifactHandlerManager.getArtifactHandler(id.getType()));
+                        try {
+                            resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
+                        } catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
+                            throw new RuntimeException("Unable to get artifact for " + id.toMvnId(), e);
+                        }
+                        result = prjArtifact;
                     }
-                    result = prjArtifact;
                 }
             }
+            cache.put(id.toMvnId(), result);
         }
 
         return result;