You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2017/01/17 20:20:02 UTC
svn commit: r1779250 - in /maven/plugins/trunk/maven-invoker-plugin: ./
src/main/java/org/apache/maven/plugin/invoker/
src/test/java/org/apache/maven/plugin/invoker/
Author: rfscholte
Date: Tue Jan 17 20:20:02 2017
New Revision: 1779250
URL: http://svn.apache.org/viewvc?rev=1779250&view=rev
Log:
[MINVOKER-214] Allow indexed maven.version and os.familiy in invoker.properties
Added:
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/Selector.java
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/SelectorTest.java
Modified:
maven/plugins/trunk/maven-invoker-plugin/pom.xml
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerPropertiesTest.java
Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=1779250&r1=1779249&r2=1779250&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Tue Jan 17 20:20:02 2017
@@ -213,7 +213,7 @@ under the License.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=1779250&r1=1779249&r2=1779250&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java Tue Jan 17 20:20:02 2017
@@ -107,13 +107,6 @@ import static org.apache.maven.shared.ut
public abstract class AbstractInvokerMojo
extends AbstractMojo
{
-
- private static final int SELECTOR_MAVENVERSION = 1;
-
- private static final int SELECTOR_JREVERSION = 2;
-
- private static final int SELECTOR_OSFAMILY = 4;
-
/**
* Flag used to suppress certain invocations. This is useful in tailoring the build using profiles.
*
@@ -504,7 +497,7 @@ public abstract class AbstractInvokerMoj
* # A comma separated list of JRE versions on which this build job should be run.
* # Since plugin version 1.4
* invoker.java.version = 1.4+, !1.4.1, 1.7-
- *
+ *
* # A comma separated list of OS families on which this build job should be run.
* # Since plugin version 1.4
* invoker.os.family = !windows, unix, mac
@@ -512,7 +505,16 @@ public abstract class AbstractInvokerMoj
* # A comma separated list of Maven versions on which this build should be run.
* # Since plugin version 1.5
* invoker.maven.version = 2.0.10+, !2.1.0, !2.2.0
- *
+ *
+ * # For java.version, maven.version and os.family it is possible to define multiple selectors.
+ * # If one of the indexed selectors matches, the test is executed.
+ * # With the invoker.x.y equivalents you can specify global matchers.
+ * selector.1.java.version = 1.8+
+ * selector.1.maven.version = 3.2.5+
+ * selector.1.os.family = !windows
+ * selector.2.maven.version = 3.0+
+ * selector.3.java.version = 9+
+ *
* # A boolean value controlling the debug logging level of Maven, , defaults to "false"
* # Since plugin version 1.8
* invoker.debug = true
@@ -1533,25 +1535,32 @@ public abstract class AbstractInvokerMoj
buildJob.setResult( BuildJob.Result.SKIPPED );
StringBuilder message = new StringBuilder();
- if ( ( selection & SELECTOR_MAVENVERSION ) != 0 )
+ if ( selection == Selector.SELECTOR_MULTI )
{
- message.append( "Maven version" );
+ message.append( "non-matching selectors" );
}
- if ( ( selection & SELECTOR_JREVERSION ) != 0 )
+ else
{
- if ( message.length() > 0 )
+ if ( ( selection & Selector.SELECTOR_MAVENVERSION ) != 0 )
{
- message.append( ", " );
+ message.append( "Maven version" );
}
- message.append( "JRE version" );
- }
- if ( ( selection & SELECTOR_OSFAMILY ) != 0 )
- {
- if ( message.length() > 0 )
+ if ( ( selection & Selector.SELECTOR_JREVERSION ) != 0 )
{
- message.append( ", " );
+ if ( message.length() > 0 )
+ {
+ message.append( ", " );
+ }
+ message.append( "JRE version" );
+ }
+ if ( ( selection & Selector.SELECTOR_OSFAMILY ) != 0 )
+ {
+ if ( message.length() > 0 )
+ {
+ message.append( ", " );
+ }
+ message.append( "OS" );
}
- message.append( "OS" );
}
if ( !suppressSummaries )
@@ -1615,23 +1624,7 @@ public abstract class AbstractInvokerMoj
*/
private int getSelection( InvokerProperties invokerProperties, CharSequence actualJreVersion )
{
- int selection = 0;
- if ( !SelectorUtils.isMavenVersion( invokerProperties.getMavenVersion(), actualMavenVersion ) )
- {
- selection |= SELECTOR_MAVENVERSION;
- }
-
- if ( !SelectorUtils.isJreVersion( invokerProperties.getJreVersion(), actualJreVersion.toString() ) )
- {
- selection |= SELECTOR_JREVERSION;
- }
-
- if ( !SelectorUtils.isOsFamily( invokerProperties.getOsFamily() ) )
- {
- selection |= SELECTOR_OSFAMILY;
- }
-
- return selection;
+ return new Selector( actualMavenVersion, actualJreVersion.toString() ).getSelection( invokerProperties );
}
/**
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java?rev=1779250&r1=1779249&r2=1779250&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerProperties.java Tue Jan 17 20:20:02 2017
@@ -36,6 +36,7 @@ import org.codehaus.plexus.util.StringUt
*/
class InvokerProperties
{
+ private static final String SELECTOR_PREFIX = "selector.";
private enum InvocationProperty
{
@@ -62,6 +63,26 @@ class InvokerProperties
return key;
}
}
+
+ private enum SelectorProperty
+ {
+ JAVA_VERSION( ".java.version" ),
+ MAVEN_VERSION( ".maven.version" ),
+ OS_FAMLY( ".os.family" );
+
+ private final String suffix;
+
+ private SelectorProperty( String suffix )
+ {
+ this.suffix = suffix;
+ }
+
+ @Override
+ public String toString()
+ {
+ return suffix;
+ }
+ }
/**
* The invoker properties being wrapped.
@@ -120,6 +141,17 @@ class InvokerProperties
}
/**
+ * Gets the specification of JRE versions on which this build job should be run.
+ *
+ * @return The specification of JRE versions or an empty string if not set.
+ */
+ public String getJreVersion( int index )
+ {
+ return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.JAVA_VERSION.suffix,
+ getJreVersion() );
+ }
+
+ /**
* Gets the specification of Maven versions on which this build job should be run.
*
* @return The specification of Maven versions on which this build job should be run.
@@ -129,6 +161,18 @@ class InvokerProperties
{
return this.properties.getProperty( "invoker.maven.version", "" );
}
+
+ /**
+ *
+ * @param index the selector index
+ * @return The specification of Maven versions on which this build job should be run.
+ * @since 3.0.0
+ */
+ public String getMavenVersion( int index )
+ {
+ return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.MAVEN_VERSION.suffix,
+ getMavenVersion() );
+ }
/**
* Gets the specification of OS families on which this build job should be run.
@@ -139,6 +183,20 @@ class InvokerProperties
{
return this.properties.getProperty( "invoker.os.family", "" );
}
+
+ /**
+ * Gets the specification of OS families on which this build job should be run.
+ *
+ * @param index the selector index
+ * @return The specification of OS families or an empty string if not set.
+ * @since 3.0.0
+ */
+ public String getOsFamily( int index )
+ {
+ return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.OS_FAMLY.suffix,
+ getOsFamily() );
+ }
+
/**
* Determines whether these invoker properties contain a build definition for the specified invocation index.
@@ -154,6 +212,25 @@ class InvokerProperties
{
return true;
}
+ }
+ return false;
+ }
+
+ /**
+ * Determines whether these invoker properties contain a build definition for the specified selector index.
+ *
+ * @param index the index
+ * @return <code>true</code> if the selector with the specified index is defined, <code>false</code> otherwise.
+ * @since 3.0.0
+ */
+ public boolean isSelectorDefined( int index )
+ {
+ for ( SelectorProperty prop : SelectorProperty.values() )
+ {
+ if ( properties.getProperty( SELECTOR_PREFIX + index + prop.suffix ) != null )
+ {
+ return true;
+ }
}
return false;
}
Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/Selector.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/Selector.java?rev=1779250&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/Selector.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/Selector.java Tue Jan 17 20:20:02 2017
@@ -0,0 +1,113 @@
+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.
+ */
+
+/**
+ *
+ * @author Robert Scholte
+ *
+ */
+class Selector
+{
+ static final int SELECTOR_MAVENVERSION = 1;
+
+ static final int SELECTOR_JREVERSION = 2;
+
+ static final int SELECTOR_OSFAMILY = 4;
+
+ static final int SELECTOR_MULTI = 8;
+
+ private final String actualMavenVersion;
+
+ private final String actualJavaVersion;
+
+ public Selector( String actualMavenVersion, String actualJavaVersion )
+ {
+ this.actualMavenVersion = actualMavenVersion;
+ this.actualJavaVersion = actualJavaVersion;
+ }
+
+ public int getSelection( InvokerProperties invokerProperties )
+ {
+ if ( !invokerProperties.isSelectorDefined( 1 ) )
+ {
+ return getGlobal( invokerProperties );
+ }
+
+ for ( int selectorIndex = 1;; selectorIndex++ )
+ {
+ if ( selectorIndex > 1 && !invokerProperties.isSelectorDefined( selectorIndex ) )
+ {
+ break;
+ }
+
+ int selection = 0;
+ if ( !SelectorUtils.isMavenVersion( invokerProperties.getMavenVersion( selectorIndex ),
+ actualMavenVersion ) )
+ {
+ selection |= SELECTOR_MAVENVERSION;
+ }
+
+ if ( !SelectorUtils.isJreVersion( invokerProperties.getJreVersion( selectorIndex ), actualJavaVersion ) )
+ {
+ selection |= SELECTOR_JREVERSION;
+ }
+
+ if ( !SelectorUtils.isOsFamily( invokerProperties.getOsFamily( selectorIndex ) ) )
+ {
+ selection |= SELECTOR_OSFAMILY;
+ }
+
+ if ( selection == 0 )
+ {
+ return 0;
+ }
+ }
+ return SELECTOR_MULTI;
+ }
+
+ /**
+ * Determines whether selector conditions of the specified invoker properties match the current environment.
+ *
+ * @param invokerProperties The invoker properties to check, must not be <code>null</code>.
+ * @return <code>0</code> if the job corresponding to the properties should be run, otherwise a bitwise value
+ * representing the reason why it should be skipped.
+ */
+ private int getGlobal( InvokerProperties invokerProperties )
+ {
+ int selection = 0;
+ if ( !SelectorUtils.isMavenVersion( invokerProperties.getMavenVersion(), actualMavenVersion ) )
+ {
+ selection |= SELECTOR_MAVENVERSION;
+ }
+
+ if ( !SelectorUtils.isJreVersion( invokerProperties.getJreVersion(), actualJavaVersion.toString() ) )
+ {
+ selection |= SELECTOR_JREVERSION;
+ }
+
+ if ( !SelectorUtils.isOsFamily( invokerProperties.getOsFamily() ) )
+ {
+ selection |= SELECTOR_OSFAMILY;
+ }
+
+ return selection;
+ }
+}
Modified: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerPropertiesTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerPropertiesTest.java?rev=1779250&r1=1779249&r2=1779250&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerPropertiesTest.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerPropertiesTest.java Tue Jan 17 20:20:02 2017
@@ -269,4 +269,26 @@ public class InvokerPropertiesTest
assertTrue( facade.isInvocationDefined( 2 ) );
assertFalse( facade.isInvocationDefined( 3 ) );
}
+
+ public void testIsSelectedDefined()
+ {
+ Properties props = new Properties();
+ InvokerProperties facade = new InvokerProperties( props );
+
+ assertFalse( facade.isSelectorDefined( 1 ) );
+
+ props.setProperty( "invoker.java.version", "1.6+" );
+ props.setProperty( "invoker.maven.version", "3.0+" );
+ props.setProperty( "invoker.os.family", "windows" );
+ assertFalse( facade.isSelectorDefined( 1 ) );
+
+ props.setProperty( "selector.2.java.version", "1.6+" );
+ props.setProperty( "selector.3.maven.version", "3.0+" );
+ props.setProperty( "selector.4.os.family", "windows" );
+ assertFalse( facade.isSelectorDefined( 1 ) );
+ assertTrue( facade.isSelectorDefined( 2 ) );
+ assertTrue( facade.isSelectorDefined( 3 ) );
+ assertTrue( facade.isSelectorDefined( 4 ) );
+ assertFalse( facade.isSelectorDefined( 5 ) );
+ }
}
Added: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/SelectorTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/SelectorTest.java?rev=1779250&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/SelectorTest.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/SelectorTest.java Tue Jan 17 20:20:02 2017
@@ -0,0 +1,78 @@
+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 static org.junit.Assert.assertEquals;
+import java.util.Properties;
+
+import org.junit.Test;
+
+public class SelectorTest
+{
+ @Test
+ public void testGlobalMatch()
+ {
+ Selector selector = new Selector( "3.2.5", "1.7" );
+
+ Properties props = new Properties();
+ props.setProperty( "invoker.maven.version", "3.0+" );
+ InvokerProperties invokerProperties = new InvokerProperties( props );
+ assertEquals( 0, selector.getSelection( invokerProperties ) );
+ }
+
+ @Test
+ public void testSelectorMatch()
+ {
+ Selector selector = new Selector( "3.2.5", "1.7" );
+
+ Properties props = new Properties();
+ props.setProperty( "selector.1.maven.version", "3.0+" );
+ InvokerProperties invokerProperties = new InvokerProperties( props );
+ assertEquals( 0, selector.getSelection( invokerProperties ) );
+
+ props.setProperty( "selector.1.maven.version", "3.3.1+" );
+ assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
+ }
+
+ @Test
+ public void testSelectorWithGlobalMatch()
+ {
+ Selector selector = new Selector( "3.2.5", "1.7" );
+
+ Properties props = new Properties();
+ // invoker.maven.version is used by all selectors
+ props.setProperty( "invoker.maven.version", "3.0+" );
+ props.setProperty( "selector.1.java.version", "1.4+" );
+ props.setProperty( "selector.2.os.family", "myos" );
+ InvokerProperties invokerProperties = new InvokerProperties( props );
+ assertEquals( 0, selector.getSelection( invokerProperties ) );
+
+ props.setProperty( "invoker.maven.version", "3.3.1+" );
+ assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
+
+ props.setProperty( "invoker.maven.version", "3.0+" );
+ props.setProperty( "selector.1.maven.version", "3.3.1+" );
+ assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
+
+ props.setProperty( "selector.2.os.family", "!myos" );
+ assertEquals( 0, selector.getSelection( invokerProperties ) );
+ }
+
+}