diff options
Diffstat (limited to 'bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis')
11 files changed, 33 insertions, 16 deletions
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java index 4fd8e936f3d..95beaf3c82a 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -18,24 +18,31 @@ import java.util.Optional; * * @author Tony Vaagenes * @author ollivir + * @author gjoranv */ public class Analyze { + public enum JdkVersionCheck { + ENABLED, + DISABLED + } + + static ClassFileMetaData analyzeClass(File classFile) { - return analyzeClass(classFile, null); + return analyzeClass(classFile, JdkVersionCheck.DISABLED, null); } - public static ClassFileMetaData analyzeClass(File classFile, ArtifactVersion artifactVersion) { + public static ClassFileMetaData analyzeClass(File classFile, JdkVersionCheck jdkVersionCheck, ArtifactVersion artifactVersion) { try { - return analyzeClass(new FileInputStream(classFile), artifactVersion); + return analyzeClass(new FileInputStream(classFile), jdkVersionCheck, artifactVersion); } catch (Exception e) { throw new RuntimeException("An error occurred when analyzing " + classFile.getPath(), e); } } - public static ClassFileMetaData analyzeClass(InputStream inputStream, ArtifactVersion artifactVersion) { + public static ClassFileMetaData analyzeClass(InputStream inputStream, JdkVersionCheck jdkVersionCheck, ArtifactVersion artifactVersion) { try { - AnalyzeClassVisitor visitor = new AnalyzeClassVisitor(artifactVersion); + AnalyzeClassVisitor visitor = new AnalyzeClassVisitor(artifactVersion, jdkVersionCheck); new ClassReader(inputStream).accept(visitor, ClassReader.SKIP_DEBUG); return visitor.result(); } catch (IOException e) { diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java index 310527e9254..6b8f3f6ba12 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java @@ -1,7 +1,8 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import com.yahoo.api.annotations.PublicApi; +import com.yahoo.container.plugin.classanalysis.Analyze.JdkVersionCheck; import com.yahoo.osgi.annotation.ExportPackage; import com.yahoo.osgi.annotation.Version; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -23,6 +24,7 @@ import java.util.Set; * * @author Tony Vaagenes * @author ollivir + * @author gjoranv */ class AnalyzeClassVisitor extends ClassVisitor implements ImportCollector { @@ -32,10 +34,12 @@ class AnalyzeClassVisitor extends ClassVisitor implements ImportCollector { private boolean isPublicApi = false; private final Optional<ArtifactVersion> defaultExportPackageVersion; + private final JdkVersionCheck jdkVersionCheck; - AnalyzeClassVisitor(ArtifactVersion defaultExportPackageVersion) { + AnalyzeClassVisitor(ArtifactVersion defaultExportPackageVersion, JdkVersionCheck jdkVersionCheck) { super(Opcodes.ASM9); this.defaultExportPackageVersion = Optional.ofNullable(defaultExportPackageVersion); + this.jdkVersionCheck = jdkVersionCheck; } @Override @@ -73,6 +77,11 @@ class AnalyzeClassVisitor extends ClassVisitor implements ImportCollector { this.name = Analyze.internalNameToClassName(name) .orElseThrow(() -> new RuntimeException("Unable to resolve class name for " + name)); + if (version > Opcodes.V17 && jdkVersionCheck == JdkVersionCheck.ENABLED) { + var jdkVersion = version - 44; + throw new RuntimeException("Class " + name + " is compiled for Java version " + jdkVersion + ", but only Java 17 is supported"); + } + addImportWithInternalName(superName); Arrays.asList(interfaces).forEach(this::addImportWithInternalName); diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeFieldVisitor.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeFieldVisitor.java index 87a2b2eb941..d7553b6e272 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeFieldVisitor.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeFieldVisitor.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import org.objectweb.asm.AnnotationVisitor; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodVisitor.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodVisitor.java index cdf6e93abda..788fa346a37 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodVisitor.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodVisitor.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import org.objectweb.asm.AnnotationVisitor; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeSignatureVisitor.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeSignatureVisitor.java index deb08ee21fa..35103fb1213 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeSignatureVisitor.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeSignatureVisitor.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import org.objectweb.asm.Opcodes; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ClassFileMetaData.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ClassFileMetaData.java index 7e2f59c1e4d..75840e95179 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ClassFileMetaData.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ClassFileMetaData.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import java.util.Optional; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ExportPackageAnnotation.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ExportPackageAnnotation.java index 517a59a5a06..fb76b9832ec 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ExportPackageAnnotation.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ExportPackageAnnotation.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import java.util.Objects; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ImportCollector.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ImportCollector.java index e341ef1a80f..00be2022e30 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ImportCollector.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/ImportCollector.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import org.objectweb.asm.Type; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageInfo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageInfo.java index 7b665d67931..d487e2b24d6 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageInfo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageInfo.java @@ -1,3 +1,4 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import java.util.Optional; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java index 699736195cf..c376e4cd6cb 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import com.google.common.collect.Sets; diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Packages.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Packages.java index 7677c55ea86..b044ad4fbd9 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Packages.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Packages.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.plugin.classanalysis; import com.yahoo.container.plugin.osgi.ImportPackages; |