Author: andham
Date: Fri Feb 22 08:56:29 2013
New Revision: 1448947

URL: http://svn.apache.org/r1448947
Log:
Made class more Java 5 (switched to enum)

Modified:
    
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/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=1448947&r1=1448946&r2=1448947&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
 Fri Feb 22 08:56:29 2013
@@ -36,57 +36,36 @@ import org.codehaus.plexus.util.StringUt
 class InvokerProperties
 {
 
-    /**
-     * The invoker properties being wrapped, never <code>null</code>.
-     */
-    private final Properties properties;
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String PROJECT = "invoker.project";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String GOALS = "invoker.goals";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String PROFILES = "invoker.profiles";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String MAVEN_OPTS = "invoker.mavenOpts";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String FAILURE_BEHAVIOR = "invoker.failureBehavior";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String NON_RECURSIVE = "invoker.nonRecursive";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String OFFLINE = "invoker.offline";
-
-    /**
-     * The constant for the invoker property.
-     */
-    private static final String SYSTEM_PROPERTIES_FILE = 
"invoker.systemPropertiesFile";
+    private enum InvocationProperty
+    {
+        PROJECT( "invoker.project" ),
+        GOALS( "invoker.goals" ),
+        PROFILES( "invoker.profiles" ),
+        MAVEN_OPTS ( "invoker.mavenOpts" ),
+        FAILURE_BEHAVIOR( "invoker.failureBehavior" ),
+        NON_RECURSIVE( "invoker.nonRecursive" ),
+        OFFLINE( "invoker.offline" ),
+        SYSTEM_PROPERTIES_FILE( "invoker.systemPropertiesFile" ),
+        DEBUG( "invoker.debug" );
+        
+        private final String key;
+        
+        private InvocationProperty(final String s)
+        {
+            this.key = s;
+        }
 
+        @Override
+        public String toString() {
+            return key;
+        }
+    }
     
     /**
-     * The constant for the invoker property.
+     * The invoker properties being wrapped.
      */
-    private static final String DEBUG = "invoker.debug";
-    
+    private final Properties properties;
+
     /**
      * Creates a new facade for the specified invoker properties. The 
properties will not be copied, so any changes to
      * them will be reflected by the facade.
@@ -167,11 +146,9 @@ class InvokerProperties
      */
     public boolean isInvocationDefined( int index )
     {
-        String[] keys =
-            { PROJECT, GOALS, PROFILES, MAVEN_OPTS, FAILURE_BEHAVIOR, 
NON_RECURSIVE, OFFLINE, SYSTEM_PROPERTIES_FILE, DEBUG };
-        for ( int i = 0; i < keys.length; i++ )
+        for ( InvocationProperty prop : InvocationProperty.values() )
         {
-            if ( properties.getProperty( keys[i] + '.' + index ) != null )
+            if ( properties.getProperty( prop.toString() + '.' + index ) != 
null )
             {
                 return true;
             }
@@ -188,7 +165,7 @@ class InvokerProperties
      */
     public void configureInvocation( InvocationRequest request, int index )
     {
-        String project = get( PROJECT, index );
+        String project = get( InvocationProperty.PROJECT, index );
         if ( project != null )
         {
             File file = new File( request.getBaseDirectory(), project );
@@ -204,43 +181,43 @@ class InvokerProperties
             }
         }
 
-        String goals = get( GOALS, index );
+        String goals = get( InvocationProperty.GOALS, index );
         if ( goals != null )
         {
             request.setGoals( new ArrayList<String>( Arrays.asList( 
StringUtils.split( goals, ", \t\n\r\f" ) ) ) );
         }
 
-        String profiles = get( PROFILES, index );
+        String profiles = get( InvocationProperty.PROFILES, index );
         if ( profiles != null )
         {
             request.setProfiles( new ArrayList<String>( Arrays.asList( 
StringUtils.split( profiles, ", \t\n\r\f" ) ) ) );
         }
 
-        String mvnOpts = get( MAVEN_OPTS, index );
+        String mvnOpts = get( InvocationProperty.MAVEN_OPTS, index );
         if ( mvnOpts != null )
         {
             request.setMavenOpts( mvnOpts );
         }
 
-        String failureBehavior = get( FAILURE_BEHAVIOR, index );
+        String failureBehavior = get( InvocationProperty.FAILURE_BEHAVIOR, 
index );
         if ( failureBehavior != null )
         {
             request.setFailureBehavior( failureBehavior );
         }
 
-        String nonRecursive = get( NON_RECURSIVE, index );
+        String nonRecursive = get( InvocationProperty.NON_RECURSIVE, index );
         if ( nonRecursive != null )
         {
             request.setRecursive( !Boolean.valueOf( nonRecursive 
).booleanValue() );
         }
 
-        String offline = get( OFFLINE, index );
+        String offline = get( InvocationProperty.OFFLINE, index );
         if ( offline != null )
         {
             request.setOffline( Boolean.valueOf( offline ).booleanValue() );
         }
         
-        String debug = get( DEBUG, index );
+        String debug = get( InvocationProperty.DEBUG, index );
         if ( debug != null )
         {
             request.setDebug( Boolean.valueOf( debug ).booleanValue() );    
@@ -262,14 +239,14 @@ class InvokerProperties
     }
 
     /**
-     * Gets the path to the properties file used to set the system properties 
for the specified execution.
+     * Gets the path to the properties file used to set the system properties 
for the specified invocation.
      * 
      * @param index The index of the invocation for which to check the exit 
code, must not be negative.
      * @return The path to the properties file or <code>null</code> if not set.
      */
     public String getSystemPropertiesFile( int index )
     {
-        return get( SYSTEM_PROPERTIES_FILE, index );
+        return get( InvocationProperty.SYSTEM_PROPERTIES_FILE, index );
     }
 
     /**
@@ -297,4 +274,8 @@ class InvokerProperties
         return value;
     }
 
+    private String get( InvocationProperty prop, int index )
+    {
+        return get( prop.toString(), index);
+    }
 }

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=1448947&r1=1448946&r2=1448947&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
 Fri Feb 22 08:56:29 2013
@@ -1,22 +1,13 @@
 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.
+ * 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.io.File;
@@ -62,6 +53,17 @@ public class InvokerPropertiesTest
         assertEquals( "value", facade.get( "key", 2 ) );
     }
 
+    public void testGetJobName()
+        throws Exception
+    {
+        Properties props = new Properties();
+        final String jobName = "Build Job name";
+        props.put( "invoker.name", jobName );
+        InvokerProperties facade = new InvokerProperties( props );
+
+        assertEquals( jobName, facade.getJobName() );
+    }
+
     public void testIsExpectedResult()
         throws Exception
     {
@@ -251,4 +253,20 @@ public class InvokerPropertiesTest
         assertFalse( request.isOffline() );
     }
 
+    public void testIsInvocationDefined()
+        throws Exception
+    {
+        Properties props = new Properties();
+        InvokerProperties facade = new InvokerProperties( props );
+        
+        assertFalse( facade.isInvocationDefined( 1 ));
+        
+        props.setProperty( "invoker.goals", "install" );
+        assertFalse( facade.isInvocationDefined( 1 ));
+
+        props.setProperty( "invoker.goals.2", "install" );
+        assertFalse( facade.isInvocationDefined( 1 ));
+        assertTrue( facade.isInvocationDefined( 2 ));
+        assertFalse( facade.isInvocationDefined( 3 ));
+    }
 }


Reply via email to