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 2020/07/31 12:02:22 UTC

[maven-enforcer] branch MENFORCER-338 created (now a1925c9)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MENFORCER-338
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git.


      at a1925c9  update site index with new rule

This branch includes the following new commits:

     new 9e08d26  RequireJavaVendor implemented. Enforces the system to use a specific java vendor.
     new a620432  Changed some text to reflect vendor
     new 056b764  Added @since to rule.
     new a25d721  Change javadoc for RequireJavaVendor.setName to better explain how it works
     new a1925c9  update site index with new rule

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-enforcer] 02/05: Changed some text to reflect vendor

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a620432d6bd49021000cf69e6942c60b37d59328
Author: Tim <ti...@dpgmedia.nl>
AuthorDate: Wed Jul 29 14:00:15 2020 +0200

    Changed some text to reflect vendor
---
 .../main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java  | 2 +-
 .../java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
index 90e95fd..287cb54 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
@@ -24,7 +24,7 @@ import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 
 /**
- * This rule checks that the Java version is allowed.
+ * This rule checks that the Java vendor is allowed.
  *
  * @author Tim Sijstermans
  */
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java
index 921ae7f..a3f0927 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java
@@ -25,7 +25,7 @@ import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.junit.Test;
 
 /**
- * The Class TestRequireJavaVersion.
+ * The Class TestRequireJavaVendor.
  *
  * @author Tim Sijstermans
  */


[maven-enforcer] 01/05: RequireJavaVendor implemented. Enforces the system to use a specific java vendor.

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9e08d262ece27ba4bfc5fe1b23e01ae3f1461402
Author: Tim <ti...@dpgmedia.nl>
AuthorDate: Wed Jul 29 13:54:32 2020 +0200

    RequireJavaVendor implemented. Enforces the system to use a specific java vendor.
---
 .../maven/plugins/enforcer/RequireJavaVendor.java  | 67 ++++++++++++++++++++++
 .../src/site/apt/requireJavaVendor.apt.vm          | 67 ++++++++++++++++++++++
 .../src/site/apt/requireJavaVersion.apt.vm         |  2 +-
 .../plugins/enforcer/TestRequireJavaVendor.java    | 67 ++++++++++++++++++++++
 4 files changed, 202 insertions(+), 1 deletion(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
new file mode 100644
index 0000000..90e95fd
--- /dev/null
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
@@ -0,0 +1,67 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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 org.apache.commons.lang3.SystemUtils;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+
+/**
+ * This rule checks that the Java version is allowed.
+ *
+ * @author Tim Sijstermans
+ */
+public class RequireJavaVendor extends AbstractNonCacheableEnforcerRule
+{
+    private String name;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        if ( !SystemUtils.JAVA_VENDOR.equals( name ) )
+        {
+            String message = getMessage();
+            String error = "Vendor " + SystemUtils.JAVA_VENDOR + " did not match required vendor " + name;
+            StringBuilder sb = new StringBuilder();
+            if ( message != null )
+            {
+                sb.append( message ).append( System.lineSeparator() );
+            }
+
+            sb.append( error );
+
+            throw new EnforcerRuleException( sb.toString() );
+        }
+    }
+
+    /**
+     * Specify the required name. Some examples are:
+     * <ul>
+     * <li><code>AdoptOpenJDK</code> enforces name AdoptOpenJDK </li>
+     * <li><code>Java.net</code> enforces name Amazon </li>
+     * </ul>
+     *
+     * @param name the required name to set
+     */
+    public final void setName( String name )
+    {
+        this.name = name;
+    }
+}
diff --git a/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm b/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm
new file mode 100644
index 0000000..b10bdd2
--- /dev/null
+++ b/enforcer-rules/src/site/apt/requireJavaVendor.apt.vm
@@ -0,0 +1,67 @@
+~~ 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.    
+ 
+  ------
+  Require Java Vendor
+  ------
+  Tim Sijstermans
+  ------
+  July 2020
+  ------
+
+Require Java Vendor
+
+   This rule enforces a certain Java JDK vendor. The rule uses the full vendor name to verify.
+
+   The following parameters are supported by this rule:
+   
+   * message - an optional message to the user if the rule fails.
+   
+   * name - The name of the allowed JDK vendor.
+ 
+   Sample Plugin Configuration:
+   
++---+
+<project>
+  [...]
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>${project.version}</version>
+        <executions>
+          <execution>
+            <id>enforce-java</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <requireJavaVendor>
+                  <name>AdoptOpenJDK</name>
+                </requireJavaVendor>
+              </rules>    
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  [...]
+</project>
++---+
\ No newline at end of file
diff --git a/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm b/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm
index 4022cca..b7a7251 100644
--- a/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm
+++ b/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm
@@ -92,4 +92,4 @@ OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1
 </project>
 +---+
   
-  If you would like to enforce a certain vendor string for the JDK, you would use the {{{./requireProperty.html}RequireProperty}} rule, and check the java.vendor property with a regular expression.
+  If you would like to enforce a certain vendor string for the JDK, you would use the {{{./requireJavaVendor.html}RequireJavaVendor}} rule
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java
new file mode 100644
index 0000000..921ae7f
--- /dev/null
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVendor.java
@@ -0,0 +1,67 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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 org.apache.commons.lang3.SystemUtils;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.junit.Test;
+
+/**
+ * The Class TestRequireJavaVersion.
+ *
+ * @author Tim Sijstermans
+ */
+public class TestRequireJavaVendor
+{
+
+    /**
+     * Test Rule: Success case
+     *
+     * @throws EnforcerRuleException the enforcer rule exception
+     */
+    @Test
+    public void settingTheRequiredJavaVendorToSystemVendorShouldNotFail() throws EnforcerRuleException
+    {
+        RequireJavaVendor underTest = new RequireJavaVendor();
+        // Set the required vendor to the current system vendor
+        underTest.setName( SystemUtils.JAVA_VENDOR );
+        final EnforcerRuleHelper helper = EnforcerTestUtils.getHelper();
+        underTest.execute( helper );
+        // No assert and no expected exception because this test should not fail
+    }
+
+    /**
+     * Test rule: Failing case
+     *
+     * @throws EnforcerRuleException the enforcer rule exception
+     */
+    @Test( expected = EnforcerRuleException.class )
+    public void excludingTheCurrentVendorShouldFail() throws EnforcerRuleException
+    {
+
+        RequireJavaVendor underTest = new RequireJavaVendor();
+        // Set the required vendor to something nonsensical
+        underTest.setName( "..." + SystemUtils.JAVA_VENDOR );
+        final EnforcerRuleHelper helper = EnforcerTestUtils.getHelper();
+        underTest.execute( helper );
+        // expect EnforcerRuleException to happen
+    }
+}
\ No newline at end of file


[maven-enforcer] 05/05: update site index with new rule

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a1925c99a407c4552fe067aaeb9694d8832831b5
Author: Tim <ti...@dpgmedia.nl>
AuthorDate: Fri Jul 31 11:53:43 2020 +0200

    update site index with new rule
---
 enforcer-rules/src/site/apt/index.apt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/enforcer-rules/src/site/apt/index.apt b/enforcer-rules/src/site/apt/index.apt
index fe43cc9..6a88480 100644
--- a/enforcer-rules/src/site/apt/index.apt
+++ b/enforcer-rules/src/site/apt/index.apt
@@ -61,6 +61,8 @@ Built-In Rules
 
   * {{{./requireFilesSize.html}requireFilesSize}} - enforces that the list of files exists and is within a certain size range.
 
+  * {{{./requireJavaVendor.html}requireJavaVendor}} - enforces the JDK vendor.
+
   * {{{./requireJavaVersion.html}requireJavaVersion}} - enforces the JDK version.
 
   * {{{./requireMavenVersion.html}requireMavenVersion}} - enforces the Maven version.


[maven-enforcer] 04/05: Change javadoc for RequireJavaVendor.setName to better explain how it works

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a25d721ab05465270300634e12ea0c25799c3869
Author: Tim <ti...@dpgmedia.nl>
AuthorDate: Fri Jul 31 11:51:18 2020 +0200

    Change javadoc for RequireJavaVendor.setName to better explain how it works
---
 .../java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java   | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
index f3f297a..5d2444e 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
@@ -54,9 +54,11 @@ public class RequireJavaVendor extends AbstractNonCacheableEnforcerRule
 
     /**
      * Specify the required name. Some examples are:
+     * Name should be an exact match of the System Property java.vendor, which you can also see with mvn --version
+     *
      * <ul>
-     * <li><code>AdoptOpenJDK</code> enforces name AdoptOpenJDK </li>
-     * <li><code>Java.net</code> enforces name Amazon </li>
+     * <li><code>AdoptOpenJDK</code> enforces vendor name AdoptOpenJDK </li>
+     * <li><code>Amazon</code> enforces vendor name Amazon </li>
      * </ul>
      *
      * @param name the required name to set


[maven-enforcer] 03/05: Added @since to rule.

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 056b76420d57d1e6ea60f1ec9cf347a8d50a624f
Author: Tim <ti...@dpgmedia.nl>
AuthorDate: Wed Jul 29 14:26:51 2020 +0200

    Added @since to rule.
---
 .../main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
index 287cb54..f3f297a 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
@@ -27,6 +27,7 @@ import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
  * This rule checks that the Java vendor is allowed.
  *
  * @author Tim Sijstermans
+ * @since 3.0.0
  */
 public class RequireJavaVendor extends AbstractNonCacheableEnforcerRule
 {