You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/02/25 11:22:33 UTC

[maven-invoker-plugin] branch MINVOKER-328 created (now 79289f4)

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

sjaranowski pushed a change to branch MINVOKER-328
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git


      at 79289f4  [MINVOKER-328] Skip install artifacts with the same source and target path

This branch includes the following new commits:

     new 79289f4  [MINVOKER-328] Skip install artifacts with the same source and target path

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.



[maven-invoker-plugin] 01/01: [MINVOKER-328] Skip install artifacts with the same source and target path

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

sjaranowski pushed a commit to branch MINVOKER-328
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git

commit 79289f492a45f8309bca20c67e9ec132abc909b9
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Feb 25 12:22:13 2023 +0100

    [MINVOKER-328] Skip install artifacts with the same source and target path
    
    When user not specified localRepositoryPath
    we can not reinstall artifact with the same source and target path
---
 .../invoker.properties                             | 18 +++++++
 src/it/MINVOKER-328_install-default/pom.xml        | 63 ++++++++++++++++++++++
 src/it/MINVOKER-328_install-default/verify.groovy  | 20 +++++++
 .../apache/maven/plugins/invoker/InstallMojo.java  | 28 +++++++++-
 4 files changed, 127 insertions(+), 2 deletions(-)

diff --git a/src/it/MINVOKER-328_install-default/invoker.properties b/src/it/MINVOKER-328_install-default/invoker.properties
new file mode 100644
index 0000000..353946b
--- /dev/null
+++ b/src/it/MINVOKER-328_install-default/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = verify
diff --git a/src/it/MINVOKER-328_install-default/pom.xml b/src/it/MINVOKER-328_install-default/pom.xml
new file mode 100644
index 0000000..8b2718b
--- /dev/null
+++ b/src/it/MINVOKER-328_install-default/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>minvoker328</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <url>https://issues.apache.org/jira/browse/MINVOKER-328</url>
+  <description>install with default configuration</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.36</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>install</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/MINVOKER-328_install-default/verify.groovy b/src/it/MINVOKER-328_install-default/verify.groovy
new file mode 100644
index 0000000..144091e
--- /dev/null
+++ b/src/it/MINVOKER-328_install-default/verify.groovy
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+File buildLog = new File(basedir, 'build.log')
+assert buildLog.text.contains('[DEBUG] Skip install the same target')
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
index 8c2000d..5f0edfb 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
@@ -19,12 +19,15 @@
 package org.apache.maven.plugins.invoker;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -356,6 +359,10 @@ public class InstallMojo extends AbstractMojo {
      */
     private void installArtifacts(Collection<Artifact> resolvedArtifacts) throws InstallationException {
 
+        RepositorySystemSession systemSessionForLocalRepo = createSystemSessionForLocalRepo();
+        // remove artifacts with tha same target and source file
+        resolvedArtifacts.removeIf(a -> hasTheSamePathAsTarget(a, systemSessionForLocalRepo));
+
         // we can have on dependency two artifacts with the same groupId:artifactId
         // with different version, in such case when we install both in one request
         // metadata will contain only one version
@@ -366,8 +373,6 @@ public class InstallMojo extends AbstractMojo {
                         LinkedHashMap::new,
                         Collectors.toList()));
 
-        RepositorySystemSession systemSessionForLocalRepo = createSystemSessionForLocalRepo();
-
         for (List<Artifact> artifacts : collect.values()) {
             InstallRequest request = new InstallRequest();
             request.setArtifacts(artifacts);
@@ -375,6 +380,25 @@ public class InstallMojo extends AbstractMojo {
         }
     }
 
+    private boolean hasTheSamePathAsTarget(Artifact artifact, RepositorySystemSession systemSession) {
+        try {
+            LocalRepositoryManager lrm = systemSession.getLocalRepositoryManager();
+            File targetBasedir = lrm.getRepository().getBasedir();
+            if (targetBasedir == null) {
+                return false;
+            }
+            File targetFile = new File(targetBasedir, lrm.getPathForLocalArtifact(artifact)).getCanonicalFile();
+            File sourceFile = artifact.getFile().getCanonicalFile();
+            if (Objects.equals(targetFile, sourceFile)) {
+                getLog().debug("Skip install the same target " + sourceFile);
+                return true;
+            }
+            return false;
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+
     /**
      * Create a new {@link  RepositorySystemSession} connected with local repo.
      */