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 5b82ce1b71fb0679a7fd93c0ab7d0ae3f74bd873 Author: Konrad Windszus <[email protected]> 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 | 15 ++++++-- .../slingstart/DependencyLifecycleParticipant.java | 44 +++++++++++++++++++--- src/main/resources/project.properties | 19 ++++++++++ 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 1910445..d5355dd 100644 --- a/pom.xml +++ b/pom.xml @@ -11,14 +11,15 @@ 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/maven-v4_0_0.xsd"> +<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.sling</groupId> <artifactId>sling</artifactId> <version>30</version> - <relativePath /> + <relativePath/> </parent> <artifactId>slingstart-maven-plugin</artifactId> @@ -41,8 +42,8 @@ <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git</developerConnection> <url>https://gitbox.apache.org/repos/asf?p=sling-slingstart-maven-plugin.git</url> - <tag>HEAD</tag> - </scm> + <tag>HEAD</tag> + </scm> <!-- Support for publishing the mvn site. --> <distributionManagement> @@ -128,6 +129,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 "[email protected]" <[email protected]>.
