maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject [maven-enforcer] 01/01: Removed the need for powermock. - Changed the implementation
Date Sat, 17 Feb 2018 16:07:35 GMT
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch MENFORCER-288
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit 50eef70265436ea44915020fefe1362afbd53c74
Author: Karl Heinz Marbaise <khmarbaise@apache.org>
AuthorDate: Mon Feb 12 22:43:14 2018 +0100

    Removed the need for powermock.
     - Changed the implementation
---
 enforcer-rules/pom.xml                             | 10 --------
 .../maven/plugins/enforcer/RequireJavaVersion.java | 10 ++++++--
 ...VesionTest.java => RequireJavaVersionTest.java} | 27 +++++++---------------
 pom.xml                                            | 16 +------------
 4 files changed, 17 insertions(+), 46 deletions(-)

diff --git a/enforcer-rules/pom.xml b/enforcer-rules/pom.xml
index 7e92e2b..41e59c8 100644
--- a/enforcer-rules/pom.xml
+++ b/enforcer-rules/pom.xml
@@ -99,16 +99,6 @@
       <artifactId>assertj-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-module-junit4</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-api-mockito2</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>
diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java
b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java
index 4ef046d..1990c3b 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java
@@ -23,7 +23,6 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.commons.lang3.SystemUtils;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
@@ -40,11 +39,13 @@ import org.codehaus.plexus.util.StringUtils;
 public class RequireJavaVersion
     extends AbstractVersionEnforcer
 {
+    private boolean jep322Version = false;
+
     @Override
     public void execute( EnforcerRuleHelper helper )
         throws EnforcerRuleException
     {
-        String javaVersion = SystemUtils.JAVA_VERSION;
+        String javaVersion = System.getProperty( "java.version" );
         Log log = helper.getLog();
 
         log.debug( "Detected Java String: '" + javaVersion + "'" );
@@ -60,6 +61,11 @@ public class RequireJavaVersion
         enforceVersion( helper.getLog(), "JDK", getVersion(), detectedJdkVersion );
     }
 
+    // http://openjdk.java.net/jeps/322
+    // RegEx from JEP322: [1-9][0-9]*((\.0)*\.[1-9][0-9]*)*
+    // $FEATURE.$INTERIM.$UPDATE.$PATCH
+    //
+
     /**
      * Converts a jdk string from 1.5.0-11b12 to a single 3 digit version like 1.5.0-11
      *
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVesionTest.java
b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVersionTest.java
similarity index 76%
rename from enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVesionTest.java
rename to enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVersionTest.java
index 4439744..15c62e7 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVesionTest.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVersionTest.java
@@ -22,7 +22,6 @@ package org.apache.maven.plugins.enforcer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import org.apache.commons.lang3.SystemUtils;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.logging.Log;
@@ -30,19 +29,13 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
 
 /**
  * The Class RequireJavaVersionTest
  *
  * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
  */
-@RunWith( PowerMockRunner.class )
-@PrepareForTest( { SystemUtils.class } )
-public class RequireJavaVesionTest
+public class RequireJavaVersionTest
 {
 
     private EnforcerRuleHelper helper;
@@ -52,11 +45,12 @@ public class RequireJavaVesionTest
     @Before
     public void before()
     {
+        System.clearProperty( "java.version" );
 
         helper = mock( EnforcerRuleHelper.class );
-
         Log log = mock( Log.class );
         when( helper.getLog() ).thenReturn( log );
+        rule = new RequireJavaVersion();
 
     }
 
@@ -67,9 +61,7 @@ public class RequireJavaVesionTest
     public void first()
         throws EnforcerRuleException
     {
-        Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "1.4" );
-
-        rule = new RequireJavaVersion();
+        System.setProperty( "java.version", "1.4" );
         rule.setVersion( "1.5" );
 
         exception.expect( EnforcerRuleException.class );
@@ -81,9 +73,8 @@ public class RequireJavaVesionTest
     public void second()
         throws EnforcerRuleException
     {
-        Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "1.8" );
+        System.setProperty( "java.version", "1.8" );
 
-        rule = new RequireJavaVersion();
         rule.setVersion( "1.9" );
         exception.expect( EnforcerRuleException.class );
         exception.expectMessage( "Detected JDK Version: 1.8 is not in the allowed range 1.9."
);
@@ -94,9 +85,8 @@ public class RequireJavaVesionTest
     public void third()
         throws EnforcerRuleException
     {
-        Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "9.0.4" );
+        System.setProperty( "java.version", "9.0.4" );
 
-        rule = new RequireJavaVersion();
         rule.setVersion( "9.0.5" );
         exception.expect( EnforcerRuleException.class );
         exception.expectMessage( "Detected JDK Version: 9.0.4 is not in the allowed range
9.0.5." );
@@ -107,12 +97,11 @@ public class RequireJavaVesionTest
     public void forth()
         throws EnforcerRuleException
     {
-        Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "1.8.0_b192" );
+        System.setProperty( "java.version", "1.8.0_b192" );
 
-        rule = new RequireJavaVersion();
         rule.setVersion( "8" );
         exception.expect( EnforcerRuleException.class );
-        exception.expectMessage( "Detected JDK Version: 9.0.4 is not in the allowed range
9.0.5." );
+        exception.expectMessage( "Detected JDK Version: 1.8.0-192 is not in the allowed range
8." );
         rule.execute( helper );
     }
 
diff --git a/pom.xml b/pom.xml
index 92f314f..b02a1a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,6 @@
   <properties>
     <maven.version>3.0</maven.version>
     <maven.site.path>enforcer-archives/enforcer-LATEST</maven.site.path>
-    <powermock.version>1.7.1</powermock.version>
   </properties>
 
   <dependencyManagement>
@@ -131,22 +130,9 @@
         <scope>test</scope>
       </dependency>
       <dependency>
-        <groupId>org.powermock</groupId>
-        <artifactId>powermock-module-junit4</artifactId>
-        <version>${powermock.version}</version>
-        <scope>test</scope>
-      </dependency>
-      <dependency>
-        <groupId>org.powermock</groupId>
-        <artifactId>powermock-api-mockito2</artifactId>
-        <version>${powermock.version}</version>
-        <scope>test</scope>
-      </dependency>
-
-      <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-lang3</artifactId>
-        <version>3.7</version> <!-- commons-lang3 >= 3.6 require at least
Java 7 -->
+        <version>3.5</version> <!-- commons-lang3 >= 3.6 require at least
Java 7 -->
       </dependency>
       <dependency>
         <groupId>commons-codec</groupId>

-- 
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.

Mime
View raw message