You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2017/12/27 19:02:15 UTC

[sling-slingstart-maven-plugin] branch bugfix/SLING-7334-separate-dependency-lifecycle-participant updated (5b82ce1 -> 29c66bc)

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

kwin pushed a change to branch bugfix/SLING-7334-separate-dependency-lifecycle-participant
in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git.


    omit 5b82ce1  SLING-7334 only consider Maven modules leveraging the same version of the s-m-p in the DependencyLifecycleParticipant
     new 29c66bc  SLING-7334 only consider Maven modules leveraging the same version of the s-m-p in the DependencyLifecycleParticipant

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5b82ce1)
            \
             N -- N -- N   refs/heads/bugfix/SLING-7334-separate-dependency-lifecycle-participant (29c66bc)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 pom.xml | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-slingstart-maven-plugin] 01/01: SLING-7334 only consider Maven modules leveraging the same version of the s-m-p in the DependencyLifecycleParticipant

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

kwin pushed a commit to branch bugfix/SLING-7334-separate-dependency-lifecycle-participant
in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git

commit 29c66bc2c25ea85328b221d09db3412cbf662f43
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Dec 27 19:59:56 2017 +0100

    SLING-7334 only consider Maven modules leveraging the same version of
    the s-m-p in the DependencyLifecycleParticipant
---
 pom.xml                                            |  6 +++
 .../slingstart/DependencyLifecycleParticipant.java | 44 +++++++++++++++++++---
 src/main/resources/project.properties              | 19 ++++++++++
 3 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1910445..3362bcc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,6 +128,12 @@
                 </configuration>
             </plugin>
         </plugins>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
     </build>
 
     <dependencies>
diff --git a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
index 7335f9f..1efa58c 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
@@ -16,6 +16,10 @@
  */
 package org.apache.sling.maven.slingstart;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
 import org.apache.maven.AbstractMavenLifecycleParticipant;
 import org.apache.maven.MavenExecutionException;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -61,20 +65,48 @@ public class DependencyLifecycleParticipant extends AbstractMavenLifecyclePartic
         env.logger = logger;
         env.session = session;
 
-        logger.debug("Searching for project leveraging plugin '" + PLUGIN_ID + "'...");
+        final String version;
+        try {
+            version = getCurrentPluginVersion();
+        } catch (IOException e) {
+            throw new MavenExecutionException("Could not retrieve extensions version", e);
+        }
+        logger.debug("Searching for projects leveraging plugin '" + PLUGIN_ID + "' in version "+ version + "...");
 
         for (final MavenProject project : session.getProjects()) {
             // consider all projects where this plugin is configured
             Plugin plugin = project.getPlugin(PLUGIN_ID);
             if (plugin != null) {
-                logger.debug("Found project " + project + " leveraging " + PLUGIN_ID +".");
-                final ProjectInfo info = new ProjectInfo();
-                info.plugin = plugin;
-                info.project = project;
-                env.modelProjects.put(project.getGroupId() + ":" + project.getArtifactId(), info);
+                if (version.equals(plugin.getVersion())) {
+                    logger.debug("Found project " + project + " leveraging " + PLUGIN_ID +" in version "+ version + ".");
+                    final ProjectInfo info = new ProjectInfo();
+                    info.plugin = plugin;
+                    info.project = project;
+                    env.modelProjects.put(project.getGroupId() + ":" + project.getArtifactId(), info);
+                } else {
+                    logger.debug("Skipping project " + project + " leveraging " + PLUGIN_ID +" in another version "+ project.getVersion() + ".");
+                }
             }
         }
 
         new ModelPreprocessor().addDependencies(env);
     }
+    
+    /**
+     * Retrieves the version of the encapsulating Mojo by evaluating a properties file loaded via the extension classloader
+     * @throws IOException 
+     * @see <a href="https://stackoverflow.com/a/3697482/5155923">Stackoverflow: Retrieve version from maven pom.xml in code</a>
+     * @see <a href="http://takari.io/book/91-maven-classloading.html#build-extension-classloaders">Maven Extension Classloaders</a>
+     */
+    private static final String getCurrentPluginVersion() throws IOException {
+        
+        try (InputStream inputStream = DependencyLifecycleParticipant.class.getResourceAsStream("/project.properties")) {
+            if (inputStream == null) {
+                throw new IllegalStateException("Could not find 'project.properties' via classloader '" + DependencyLifecycleParticipant.class.getClassLoader() + "'");
+            }
+            final Properties properties = new Properties();
+            properties.load(inputStream);
+            return properties.getProperty("version");
+        }
+    }
 }
diff --git a/src/main/resources/project.properties b/src/main/resources/project.properties
new file mode 100644
index 0000000..b3fa73c
--- /dev/null
+++ b/src/main/resources/project.properties
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+version=${project.version}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.