You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ks...@apache.org on 2015/09/19 11:11:31 UTC
svn commit: r1703964 - in
/servicemix/maven-plugins/trunk/depends-maven-plugin: ./ resources/
resources/META-INF/ resources/META-INF/m2e/
src/main/java/org/apache/servicemix/tooling/depends/
Author: ksobkowiak
Date: Sat Sep 19 09:11:31 2015
New Revision: 1703964
URL: http://svn.apache.org/viewvc?rev=1703964&view=rev
Log:
SM-2669: Support depends-maven-plugin in m2e
Thanks to Christian Schneider for the patch!!!
Added:
servicemix/maven-plugins/trunk/depends-maven-plugin/resources/
servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/
servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/m2e/
servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/DependencyComparator.java
Modified:
servicemix/maven-plugins/trunk/depends-maven-plugin/pom.xml
servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/GenerateDependsFileMojo.java
Modified: servicemix/maven-plugins/trunk/depends-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/trunk/depends-maven-plugin/pom.xml?rev=1703964&r1=1703963&r2=1703964&view=diff
==============================================================================
--- servicemix/maven-plugins/trunk/depends-maven-plugin/pom.xml (original)
+++ servicemix/maven-plugins/trunk/depends-maven-plugin/pom.xml Sat Sep 19 09:11:31 2015
@@ -1,42 +1,31 @@
-<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">
- <!--
-
- 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.
- -->
+ <!-- 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. -->
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.servicemix.tooling</groupId>
- <artifactId>maven-plugins-pom</artifactId>
- <version>3</version>
- <relativePath>../maven-plugins-pom/pom.xml</relativePath>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>maven-plugins-pom</artifactId>
+ <version>3</version>
+ <relativePath>../maven-plugins-pom/pom.xml</relativePath>
</parent>
- <groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.3-SNAPSHOT</version>
<name>Apache ServiceMix :: Plugins :: Maven2 Depends Plugin</name>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/servicemix/maven-plugins/depends-maven-plugin/trunk</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/servicemix/maven-plugins/depends-maven-plugin/trunk</developerConnection>
- <url>http://svn.apache.org/viewcvs.cgi/servicemix/maven-plugins/depends-maven-plugin/trunk</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/servicemix/maven-plugins/trunk/depends-maven-plugin</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/servicemix/maven-plugins/trunk/depends-maven-plugin</developerConnection>
+ <url>http://svn.apache.org/viewcvs.cgi/servicemix/maven-plugins/trunk/depends-maven-plugin</url>
</scm>
<dependencies>
@@ -50,6 +39,16 @@
<artifactId>maven-project</artifactId>
<version>2.0.9</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.plexus</groupId>
+ <artifactId>plexus-build-api</artifactId>
+ <version>0.0.7</version>
+ </dependency>
</dependencies>
</project>
Added: servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/m2e/lifecycle-mapping-metadata.xml?rev=1703964&view=auto
==============================================================================
--- servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/m2e/lifecycle-mapping-metadata.xml (added)
+++ servicemix/maven-plugins/trunk/depends-maven-plugin/resources/META-INF/m2e/lifecycle-mapping-metadata.xml Sat Sep 19 09:11:31 2015
@@ -0,0 +1,35 @@
+<?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.
+-->
+<lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <execute>
+ <runOnIncremental>true</runOnIncremental>
+ </execute>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+</lifecycleMappingMetadata>
\ No newline at end of file
Added: servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/DependencyComparator.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/DependencyComparator.java?rev=1703964&view=auto
==============================================================================
--- servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/DependencyComparator.java (added)
+++ servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/DependencyComparator.java Sat Sep 19 09:11:31 2015
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.tooling.depends;
+
+import java.util.Comparator;
+
+import org.apache.maven.model.Dependency;
+
+final class DependencyComparator implements Comparator<Dependency> {
+ public int compare(Dependency o1, Dependency o2) {
+ int result = o1.getGroupId().compareTo( o2.getGroupId() );
+ if ( result == 0 ) {
+ result = o1.getArtifactId().compareTo( o2.getArtifactId() );
+ if ( result == 0 ) {
+ result = o1.getType().compareTo( o2.getType() );
+ if ( result == 0 ) {
+ if ( o1.getClassifier() == null ) {
+ if ( o2.getClassifier() != null ) {
+ result = 1;
+ }
+ } else {
+ if ( o2.getClassifier() != null ) {
+ result = o1.getClassifier().compareTo( o2.getClassifier() );
+ } else {
+ result = -1;
+ }
+ }
+ if ( result == 0 ) {
+ // We don't consider the version range in the comparison, just the resolved version
+ result = o1.getVersion().compareTo( o2.getVersion() );
+ }
+ }
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Modified: servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/GenerateDependsFileMojo.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/GenerateDependsFileMojo.java?rev=1703964&r1=1703963&r2=1703964&view=diff
==============================================================================
--- servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/GenerateDependsFileMojo.java (original)
+++ servicemix/maven-plugins/trunk/depends-maven-plugin/src/main/java/org/apache/servicemix/tooling/depends/GenerateDependsFileMojo.java Sat Sep 19 09:11:31 2015
@@ -17,15 +17,12 @@
package org.apache.servicemix.tooling.depends;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -41,6 +38,7 @@ import org.apache.maven.plugin.AbstractM
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.sonatype.plexus.build.incremental.BuildContext;
/**
* Generates the dependencies properties file
@@ -78,7 +76,7 @@ public class GenerateDependsFileMojo ext
*/
private File outputFile;
-
+
/**
* @parameter default-value="${localRepository}"
*/
@@ -106,72 +104,55 @@ public class GenerateDependsFileMojo ext
*/
protected ArtifactFactory factory;
+ /**
+ * @component
+ */
+ private BuildContext buildContext;
+
public void execute() throws MojoExecutionException, MojoFailureException {
+ if (buildContext.hasDelta("pom.xml")) {
+ List<Dependency> dependencies = getDependencies();
+ writeDependencies(dependencies);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<Dependency> getDependencies() {
+ List<Dependency> dependencies;
+ if (!recursive) {
+ dependencies = project.getDependencies();
+ } else {
+ Set<Artifact> artifacts = project.getArtifacts();
+ dependencies = new ArrayList<Dependency>();
+ for (Artifact a : artifacts) {
+ Dependency dep = new Dependency();
+ dep.setGroupId(a.getGroupId());
+ dep.setArtifactId(a.getArtifactId());
+ dep.setVersion(a.getBaseVersion());
+ dep.setClassifier(a.getClassifier());
+ dep.setType(a.getType());
+ dep.setScope(a.getScope());
+ dependencies.add(dep);
+ }
+ }
+ Collections.sort(dependencies, new DependencyComparator());
+ return dependencies;
+ }
+
+
+ private void writeDependencies(List<Dependency> dependencies) throws MojoExecutionException {
OutputStream out = null;
try {
outputFile.getParentFile().mkdirs();
- out = new FileOutputStream(outputFile);
+ out = buildContext.newFileOutputStream(outputFile);
PrintStream printer = new PrintStream(out);
-
- List<Dependency> dependencies;
- if (!recursive) {
- dependencies = project.getDependencies();
- } else {
- Set<Artifact> artifacts = project.getArtifacts();
- dependencies = new ArrayList<Dependency>();
- for (Artifact a : artifacts) {
- Dependency dep = new Dependency();
- dep.setGroupId(a.getGroupId());
- dep.setArtifactId(a.getArtifactId());
- dep.setVersion(a.getBaseVersion());
- dep.setClassifier(a.getClassifier());
- dep.setType(a.getType());
- dep.setScope(a.getScope());
- dependencies.add(dep);
- }
- }
- Collections.sort(dependencies, new Comparator<Dependency>() {
- public int compare(Dependency o1, Dependency o2) {
- int result = o1.getGroupId().compareTo( o2.getGroupId() );
- if ( result == 0 ) {
- result = o1.getArtifactId().compareTo( o2.getArtifactId() );
- if ( result == 0 ) {
- result = o1.getType().compareTo( o2.getType() );
- if ( result == 0 ) {
- if ( o1.getClassifier() == null ) {
- if ( o2.getClassifier() != null ) {
- result = 1;
- }
- } else {
- if ( o2.getClassifier() != null ) {
- result = o1.getClassifier().compareTo( o2.getClassifier() );
- } else {
- result = -1;
- }
- }
- if ( result == 0 ) {
- // We don't consider the version range in the comparison, just the resolved version
- result = o1.getVersion().compareTo( o2.getVersion() );
- }
- }
- }
- }
- return result;
- }
- });
populateProperties(printer, dependencies);
getLog().info("Created: " + outputFile);
} catch (Exception e) {
throw new MojoExecutionException(
"Unable to create dependencies file: " + e, e);
} finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- getLog().info("Failed to close: " + outputFile + ". Reason: " + e, e);
- }
- }
+ safeClose(out);
}
}
@@ -188,10 +169,7 @@ public class GenerateDependsFileMojo ext
out.println("# dependencies");
out.println();
- Iterator iterator = dependencies.iterator();
-
- while (iterator.hasNext()) {
- Dependency dependency = (Dependency) iterator.next();
+ for (Dependency dependency : dependencies) {
String prefix = dependency.getGroupId() + SEPARATOR + dependency.getArtifactId() + SEPARATOR;
out.println(prefix + "version = " + dependency.getVersion());
String classifier = dependency.getClassifier();
@@ -205,5 +183,15 @@ public class GenerateDependsFileMojo ext
getLog().debug("Dependency: " + dependency + " classifier: " + classifier + " type: " + dependency.getType());
}
}
+
+ private void safeClose(OutputStream out) {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ getLog().info("Failed to close: " + outputFile + ". Reason: " + e, e);
+ }
+ }
+ }
}
\ No newline at end of file