Author: rfscholte
Date: Sat Aug 15 14:55:37 2015
New Revision: 1696053
URL: http://svn.apache.org/r1696053
Log:
[MINVOKER-193] Ensure that setupProjects are always executed first when using
-Dinvoker.test
Introduce BuildJobComparator
Added:
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/BuildJobComparator.java
maven/plugins/branches/m-invoker-p-3.0/src/test/java/org/apache/maven/plugin/invoker/BuildJobComparatorTest.java
Modified:
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
Modified:
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=1696053&r1=1696052&r2=1696053&view=diff
==============================================================================
---
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
(original)
+++
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
Sat Aug 15 14:55:37 2015
@@ -1976,6 +1976,8 @@ public abstract class AbstractInvokerMoj
// it would be nice if we could figure out what types these are...
but perhaps
// not necessary for the -Dinvoker.test=xxx t
buildJobs = scanProjectsDirectory( includes, excludes,
BuildJob.Type.DIRECT );
+
+ Arrays.sort( buildJobs, new BuildJobComparator( setupIncludes ) );
}
else
{
Added:
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/BuildJobComparator.java
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/BuildJobComparator.java?rev=1696053&view=auto
==============================================================================
---
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/BuildJobComparator.java
(added)
+++
maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/BuildJobComparator.java
Sat Aug 15 14:55:37 2015
@@ -0,0 +1,73 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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 java.util.Comparator;
+import java.util.List;
+
+import org.apache.maven.plugin.invoker.model.BuildJob;
+import org.codehaus.plexus.util.MatchPatterns;
+
+/**
+ * Ensures that setupProjects are always the first
+ *
+ * @author Robert Scholte
+ * @since 3.0
+ */
+public class BuildJobComparator
+ implements Comparator<BuildJob>
+{
+ private List<String> setupIncludes;
+
+ public BuildJobComparator( List<String> setupIncludes )
+ {
+ this.setupIncludes = setupIncludes;
+ }
+
+ @Override
+ public int compare( BuildJob job1, BuildJob job2 )
+ {
+ MatchPatterns setupPatterns = MatchPatterns.from( setupIncludes );
+
+ if ( setupPatterns.matches( job1.getProject(), true ) )
+ {
+ if ( setupPatterns.matches( job2.getProject(), true ) )
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else
+ {
+ if ( setupPatterns.matches( job2.getProject(), true ) )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+
+}
Added:
maven/plugins/branches/m-invoker-p-3.0/src/test/java/org/apache/maven/plugin/invoker/BuildJobComparatorTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/m-invoker-p-3.0/src/test/java/org/apache/maven/plugin/invoker/BuildJobComparatorTest.java?rev=1696053&view=auto
==============================================================================
---
maven/plugins/branches/m-invoker-p-3.0/src/test/java/org/apache/maven/plugin/invoker/BuildJobComparatorTest.java
(added)
+++
maven/plugins/branches/m-invoker-p-3.0/src/test/java/org/apache/maven/plugin/invoker/BuildJobComparatorTest.java
Sat Aug 15 14:55:37 2015
@@ -0,0 +1,57 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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 java.util.Arrays;
+import java.util.Collections;
+
+import org.apache.maven.plugin.invoker.model.BuildJob;
+
+import junit.framework.TestCase;
+
+public class BuildJobComparatorTest
+ extends TestCase
+{
+
+ private BuildJobComparator comparator = new BuildJobComparator(
Collections.singletonList( "setup*/pom.xml" ) );
+
+ public void testComparator()
+ {
+ BuildJob setup = new BuildJob( "setup/pom.xml", BuildJob.Type.DIRECT );
+ BuildJob setup2 = new BuildJob( "setup2/pom.xml", BuildJob.Type.DIRECT
);
+ BuildJob normal = new BuildJob( "normal/pom.xml", BuildJob.Type.DIRECT
);
+ BuildJob normal2 = new BuildJob( "normal2/pom.xml",
BuildJob.Type.DIRECT );
+
+ assertEquals( 0, comparator.compare( setup, setup2 ) );
+ assertEquals( 0, comparator.compare( normal, normal2 ) );
+
+ assertEquals( -1, comparator.compare( setup, normal ) );
+ assertEquals( 1, comparator.compare( normal, setup ) );
+
+ BuildJob[] jobs = new BuildJob[] { normal, setup, normal2, setup2 };
+ Arrays.sort( jobs, comparator );
+
+ assertEquals( setup, jobs[0] );
+ assertEquals( setup2, jobs[1] );
+ assertEquals( normal, jobs[2] );
+ assertEquals( normal2, jobs[3] );
+ }
+
+}