slawekjaranowski commented on code in PR #968:
URL: https://github.com/apache/maven-enforcer/pull/968#discussion_r2990192250


##########
enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/EnforceBytecodeVersion.java:
##########
@@ -0,0 +1,613 @@
+/*
+ * 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.
+ */
+package org.apache.maven.enforcer.rules.dependency;
+
+/*
+ * 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 javax.inject.Inject;
+import javax.inject.Named;
+
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Predicate;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.enforcer.rule.api.EnforcerLogger;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule;
+import org.apache.maven.enforcer.rules.utils.ArtifactMatcher;
+import org.apache.maven.enforcer.rules.utils.ArtifactUtils;
+import org.apache.maven.execution.MavenSession;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
+import org.eclipse.aether.graph.DependencyVisitor;
+import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor;
+import org.eclipse.sisu.Priority;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Enforcer rule that will check the bytecode version of each class of each 
dependency.
+ *
+ * @see <a 
href="http://en.wikipedia.org/wiki/Java_class_file#General_layout";>Java class 
file general layout</a>
+ * @since 3.6.3
+ */
+@Priority(10) // if both mojohaus and this one are present, this prevails
+@Named("enforceBytecodeVersion")
+public class EnforceBytecodeVersion extends AbstractStandardEnforcerRule {
+    /**
+     * Default ignores when validating against jdk < 9 because 
<code>module-info.class</code> will always have level 1.9.
+     */
+    private static final String[] DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9 = 
{"module-info"};
+
+    private static final Pattern MULTI_RELEASE = 
Pattern.compile("META-INF/versions/(\\d+)/.*");
+
+    private static final Map<String, Integer> 
JDK_TO_MAJOR_VERSION_NUMBER_MAPPING = new LinkedHashMap<>();
+
+    static {
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.1", 45);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.2", 46);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.3", 47);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.4", 48);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.5", 49);
+        // Java6
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.6", 50);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("6", 50);
+        // Java7
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.7", 51);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("7", 51);
+        // Java8
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("8", 52);
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("1.8", 52);
+        // Java9
+        JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.put("9", 53);

Review Comment:
   Maps for jdk version > 52 is not requred, it will be computed
   please look at methods `renderVersion` , `decodeMajorVersion`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to