Merge pull request #344
This closes #344
diff --git a/pom.xml b/pom.xml
index 383d5dc..bbe6867 100644
--- a/pom.xml
+++ b/pom.xml
@@ -499,6 +499,21 @@
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.edgent.plugins</groupId>
+ <artifactId>edgent-deployment-filter-maven-plugin</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <id>filter-test-jars</id>
+ <phase>install</phase>
+ <goals>
+ <goal>filter-test-jars</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
<!-- Configure the Site generation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
diff --git a/utils/edgent-deployment-filter-maven-plugin/pom.xml b/utils/edgent-deployment-filter-maven-plugin/pom.xml
new file mode 100644
index 0000000..a3ed058
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/pom.xml
@@ -0,0 +1,156 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>19</version>
+ </parent>
+
+ <groupId>org.apache.edgent.plugins</groupId>
+ <artifactId>edgent-deployment-filter-maven-plugin</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>edgent-deployment-filter-maven-plugin Maven Plugin</name>
+
+ <!-- FIXME change it to the project's website -->
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <goalPrefix>edgent-deployment-filter</goalPrefix>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>run-its</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>mrm-maven-plugin</artifactId>
+ <version>1.1.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>start</goal>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>mrm.distribution.url</propertyName>
+ <repositories>
+ <hostedRepo>
+ <target>${project.build.directory}/maven-repos/remote</target>
+ </hostedRepo>
+ </repositories>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>3.0.1</version>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>install</goal>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <debug>false</debug>
+ <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <postBuildHookScript>verify</postBuildHookScript>
+ <localRepositoryPath>${project.build.directory}/maven-repos/local</localRepositoryPath>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ <goals>
+ <goal>clean</goal>
+ <goal>deploy</goal>
+ </goals>
+ <filterProperties>
+ <mrm.distribution.url>${mrm.distribution.url}</mrm.distribution.url>
+ </filterProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/utils/edgent-deployment-filter-maven-plugin/src/it/settings.xml b/utils/edgent-deployment-filter-maven-plugin/src/it/settings.xml
new file mode 100644
index 0000000..14554cd
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/src/it/settings.xml
@@ -0,0 +1,53 @@
+<?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.
+
+-->
+<settings>
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
diff --git a/utils/edgent-deployment-filter-maven-plugin/src/it/with-plugin/pom.xml b/utils/edgent-deployment-filter-maven-plugin/src/it/with-plugin/pom.xml
new file mode 100644
index 0000000..b59f56f
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/src/it/with-plugin/pom.xml
@@ -0,0 +1,83 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>19</version>
+ </parent>
+
+ <groupId>org.apache.edgent.plugins.it</groupId>
+ <artifactId>with-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <description>A simple IT verifying the basic use case.</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <distributionManagement>
+ <repository>
+ <id>mrm</id>
+ <url>@mrm.distribution.url@</url>
+ </repository>
+ <snapshotRepository>
+ <id>mrm</id>
+ <url>@mrm.distribution.url@</url>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <build>
+ <plugins>
+ <!-- Create a test-jar -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Ensure it's not deployed -->
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>@project.artifactId@</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>filter-test-jars</id>
+ <phase>install</phase>
+ <goals>
+ <goal>filter-test-jars</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/utils/edgent-deployment-filter-maven-plugin/src/it/with-plugin/verify.groovy b/utils/edgent-deployment-filter-maven-plugin/src/it/with-plugin/verify.groovy
new file mode 100644
index 0000000..c376a30
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/src/it/with-plugin/verify.groovy
@@ -0,0 +1,53 @@
+/*
+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.
+*/
+
+import groovy.io.FileType
+
+def jarFile = new File(basedir, "target/with-plugin-1.0-SNAPSHOT.jar")
+def testJarFile = new File(basedir, "target/with-plugin-1.0-SNAPSHOT-tests.jar")
+
+// The jar file should exist
+assert jarFile.exists() && jarFile.isFile()
+
+// The test-jar should also exist
+assert testJarFile.exists() && testJarFile.isFile()
+
+// The local repo should contain the test-jar.
+def jarLocalRepo = new File("target/maven-repos/local/org/apache/edgent/plugins/it/with-plugin/1.0-SNAPSHOT")
+assert jarLocalRepo.exists()
+def foundTestJarInLocal = false
+jarLocalRepo.eachFileRecurse (FileType.FILES) { file ->
+ println file.name
+ if(file.name.endsWith("tests.jar")) {
+ foundTestJarInLocal = true
+ }
+}
+assert foundTestJarInLocal
+
+// The remote repo shouldn't contain it.
+def jarRemoteRepo = new File("target/maven-repos/remote/org/apache/edgent/plugins/it/with-plugin/1.0-SNAPSHOT")
+assert jarRemoteRepo.exists()
+def foundTestJarInRemote = false
+jarRemoteRepo.eachFileRecurse (FileType.FILES) { file ->
+ println file.name
+ if(file.name.endsWith("tests.jar")) {
+ foundTestJarInRemote = true
+ }
+}
+assert !foundTestJarInRemote
diff --git a/utils/edgent-deployment-filter-maven-plugin/src/it/without-plugin/pom.xml b/utils/edgent-deployment-filter-maven-plugin/src/it/without-plugin/pom.xml
new file mode 100644
index 0000000..cea659b
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/src/it/without-plugin/pom.xml
@@ -0,0 +1,67 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>19</version>
+ </parent>
+
+ <groupId>org.apache.edgent.plugins.it</groupId>
+ <artifactId>without-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <description>A simple IT verifying a build without the plugin.</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <distributionManagement>
+ <repository>
+ <id>mrm</id>
+ <url>@mrm.distribution.url@</url>
+ </repository>
+ <snapshotRepository>
+ <id>mrm</id>
+ <url>@mrm.distribution.url@</url>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <build>
+ <plugins>
+ <!-- Create a test-jar -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/utils/edgent-deployment-filter-maven-plugin/src/it/without-plugin/verify.groovy b/utils/edgent-deployment-filter-maven-plugin/src/it/without-plugin/verify.groovy
new file mode 100644
index 0000000..e294108
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/src/it/without-plugin/verify.groovy
@@ -0,0 +1,53 @@
+/*
+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.
+*/
+
+import groovy.io.FileType
+
+def jarFile = new File(basedir, "target/without-plugin-1.0-SNAPSHOT.jar")
+def testJarFile = new File(basedir, "target/without-plugin-1.0-SNAPSHOT-tests.jar")
+
+// The jar file should exist
+assert jarFile.exists() && jarFile.isFile()
+
+// The test-jar should also exist
+assert testJarFile.exists() && testJarFile.isFile()
+
+// The local repo should contain the test-jar.
+def jarLocalRepo = new File("target/maven-repos/local/org/apache/edgent/plugins/it/without-plugin/1.0-SNAPSHOT")
+assert jarLocalRepo.exists()
+def foundTestJarInLocal = false
+jarLocalRepo.eachFileRecurse (FileType.FILES) { file ->
+ println file.name
+ if(file.name.endsWith("tests.jar")) {
+ foundTestJarInLocal = true
+ }
+}
+assert foundTestJarInLocal
+
+// The remote repo should contain it too.
+def jarRemoteRepo = new File("target/maven-repos/remote/org/apache/edgent/plugins/it/without-plugin/1.0-SNAPSHOT")
+assert jarRemoteRepo.exists()
+def foundTestJarInRemote = false
+jarRemoteRepo.eachFileRecurse (FileType.FILES) { file ->
+ println file.name
+ if(file.name.endsWith("tests.jar")) {
+ foundTestJarInRemote = true
+ }
+}
+assert foundTestJarInRemote
diff --git a/utils/edgent-deployment-filter-maven-plugin/src/main/java/org/apache/edgent/plugins/deploymentfilter/FilterTestJarsMojo.java b/utils/edgent-deployment-filter-maven-plugin/src/main/java/org/apache/edgent/plugins/deploymentfilter/FilterTestJarsMojo.java
new file mode 100644
index 0000000..7e90550
--- /dev/null
+++ b/utils/edgent-deployment-filter-maven-plugin/src/main/java/org/apache/edgent/plugins/deploymentfilter/FilterTestJarsMojo.java
@@ -0,0 +1,68 @@
+/*
+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.edgent.plugins.deploymentfilter;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Goal which filters all 'test-jar' artifacts from installation and deployment.
+ * The goal is added to the 'install' phase as this way it is executed after the install plugin,
+ * but before the deploy, which is the phase we don't want the artifact to be handled.
+ */
+@Mojo( name = "filter-test-jars", defaultPhase = LifecyclePhase.INSTALL )
+public class FilterTestJarsMojo
+ extends AbstractMojo
+{
+
+ @Parameter(defaultValue="${project}")
+ private MavenProject project;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ // Find all 'test-jar' artifacts.
+ // (This has to be done in separate loops in order to prevent
+ // concurrent modification exceptions.
+ List<Artifact> toBeRemovedArtifacts = new LinkedList<Artifact>();
+ for(Artifact artifact : project.getAttachedArtifacts()) {
+ if("test-jar".equals(artifact.getType())) {
+ toBeRemovedArtifacts.add(artifact);
+ }
+ }
+
+ // Remove all of them from the list of attached artifacts.
+ if(!toBeRemovedArtifacts.isEmpty()) {
+ for (Artifact toBeRemovedArtifact : toBeRemovedArtifacts) {
+ getLog().info(" - Excluding test-jar artifact " + toBeRemovedArtifact.getArtifactId() +
+ " from deployment.");
+ project.getAttachedArtifacts().remove(toBeRemovedArtifact);
+ }
+ }
+ }
+}