diff --git a/common/utils/src/main/java/org/graalvm/buildtools/agent/AgentConfiguration.java b/common/utils/src/main/java/org/graalvm/buildtools/agent/AgentConfiguration.java index 4ed13d01..1299d358 100644 --- a/common/utils/src/main/java/org/graalvm/buildtools/agent/AgentConfiguration.java +++ b/common/utils/src/main/java/org/graalvm/buildtools/agent/AgentConfiguration.java @@ -43,7 +43,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.Serializable; -import java.nio.file.*; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -152,7 +155,7 @@ private void addDefaultAccessFilter() { return; } - try(InputStream accessFilterData = AgentConfiguration.class.getResourceAsStream(DEFAULT_ACCESS_FILTER_FILE_LOCATION)) { + try (InputStream accessFilterData = AgentConfiguration.class.getResourceAsStream(DEFAULT_ACCESS_FILTER_FILE_LOCATION)) { if (accessFilterData == null) { throw new IOException("Cannot access data from: " + DEFAULT_ACCESS_FILTER_FILE_LOCATION); } @@ -177,7 +180,7 @@ private void addDefaultAccessFilter() { accessFilterFiles.add(accessFilterFile.toString()); } catch (IOException e) { - throw new RuntimeException("Cannot add default access-filter.json" ,e); + throw new RuntimeException("Cannot add default access-filter.json", e); } } diff --git a/common/utils/src/main/java/org/graalvm/buildtools/utils/ExponentialBackoff.java b/common/utils/src/main/java/org/graalvm/buildtools/utils/ExponentialBackoff.java index bdb4dba5..d44ab320 100644 --- a/common/utils/src/main/java/org/graalvm/buildtools/utils/ExponentialBackoff.java +++ b/common/utils/src/main/java/org/graalvm/buildtools/utils/ExponentialBackoff.java @@ -1,17 +1,42 @@ /* - * Copyright 2003-2021 the original author or authors. + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Licensed 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 + * The Universal Permissive License (UPL), Version 1.0 * - * https://www.apache.org/licenses/LICENSE-2.0 + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both * - * 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. + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ package org.graalvm.buildtools.utils; @@ -51,6 +76,7 @@ public static ExponentialBackoff get() { /** * The maximum number of retries. * + * @param maxRetries the maximum number of retries * @return an exponential backoff with the specified number of retries */ public ExponentialBackoff withMaxRetries(int maxRetries) { diff --git a/common/utils/src/test/java/org/graalvm/buildtools/utils/ExponentialBackoffTest.java b/common/utils/src/test/java/org/graalvm/buildtools/utils/ExponentialBackoffTest.java index ded4212e..c03c68d2 100644 --- a/common/utils/src/test/java/org/graalvm/buildtools/utils/ExponentialBackoffTest.java +++ b/common/utils/src/test/java/org/graalvm/buildtools/utils/ExponentialBackoffTest.java @@ -1,17 +1,42 @@ /* - * Copyright 2024 the original author or authors. + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Licensed 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 + * The Universal Permissive License (UPL), Version 1.0 * - * https://www.apache.org/licenses/LICENSE-2.0 + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both * - * 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. + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ package org.graalvm.buildtools.utils; diff --git a/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java b/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java index 713274a4..8ed151ef 100644 --- a/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java +++ b/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java @@ -65,11 +65,11 @@ void invalidRequiredVersion() { @Test void checkGraalVMCEVersion() { - String graalVMCE_22_3 = "GraalVM 22.3.0 Java 17 CE (Java Version 17.0.5+8-jvmci-22.3-b08)"; - NativeImageUtils.checkVersion("22", graalVMCE_22_3); - NativeImageUtils.checkVersion("22.3", graalVMCE_22_3); - NativeImageUtils.checkVersion("22.3.0", graalVMCE_22_3); - Assertions.assertEquals(17, NativeImageUtils.getMajorJDKVersion(graalVMCE_22_3)); + String graalVMCE223 = "GraalVM 22.3.0 Java 17 CE (Java Version 17.0.5+8-jvmci-22.3-b08)"; + NativeImageUtils.checkVersion("22", graalVMCE223); + NativeImageUtils.checkVersion("22.3", graalVMCE223); + NativeImageUtils.checkVersion("22.3.0", graalVMCE223); + Assertions.assertEquals(17, NativeImageUtils.getMajorJDKVersion(graalVMCE223)); String graalVMCEForJDK17 = "native-image 17.0.7 2023-04-18\nGraalVM Runtime Environment GraalVM CE 17.0.7+4.1 (build 17.0.7+4-jvmci-23.0-b10)\nSubstrate VM GraalVM CE 17.0.7+4.1 (build 17.0.7+4, serial gc)"; NativeImageUtils.checkVersion("22.3.0", graalVMCEForJDK17); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java index e4ff2d8e..e2d84193 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java @@ -56,12 +56,28 @@ import org.graalvm.buildtools.utils.SharedConstants; import javax.inject.Inject; -import java.io.*; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; -import java.nio.file.*; -import java.util.*; +import java.nio.file.FileSystemAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -252,7 +268,7 @@ protected List getBuildArgs() throws MojoExecutionException { static List processBuildArgs(List buildArgs) { var result = new ArrayList(); for (String buildArg : buildArgs) { - if(buildArg.startsWith("\\Q") || buildArg.startsWith("-H:ConfigurationFileDirectories")) { + if (buildArg.startsWith("\\Q") || buildArg.startsWith("-H:ConfigurationFileDirectories")) { result.add(buildArg); } else { result.addAll(Arrays.asList(buildArg.split("\\s+", 2))); @@ -439,7 +455,7 @@ protected void checkRequiredVersionIfNeeded() throws MojoExecutionException { NativeImageUtils.checkVersion(requiredVersion, getVersionInformation(logger)); } - static protected boolean isOracleGraalVM(Logger logger) throws MojoExecutionException { + protected static boolean isOracleGraalVM(Logger logger) throws MojoExecutionException { return getVersionInformation(logger).contains(ORACLE_GRAALVM_IDENTIFIER); } @@ -449,7 +465,7 @@ static protected boolean isOracleGraalVM(Logger logger) throws MojoExecutionExce * @return the output as a string joined by "\n". * @throws MojoExecutionException when any errors occurred. */ - static protected String getVersionInformation(Logger logger) throws MojoExecutionException { + protected static String getVersionInformation(Logger logger) throws MojoExecutionException { if (nativeImageVersionInformation != null) { return nativeImageVersionInformation; } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java index d9111734..904a7051 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java @@ -102,7 +102,7 @@ public void execute() throws MojoExecutionException { return; } - if(skipNativeBuildForPom && project.getPackaging().equals("pom")) { + if (skipNativeBuildForPom && project.getPackaging().equals("pom")) { logger.info("Skipping native-image generation (parameter 'skipNativeBuildForPom' is true)."); return; } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactAdapterResolver.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactAdapterResolver.java index 414cc0f0..ae3f5764 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactAdapterResolver.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactAdapterResolver.java @@ -44,9 +44,20 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.shared.utils.xml.Xpp3Dom; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.DirectoryStream; import java.nio.file.FileSystem; -import java.nio.file.*; +import java.nio.file.FileSystemAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.HashSet; import java.util.Optional; @@ -136,7 +147,7 @@ Optional populateWithAdditionalFields(Path jarPath, ArtifactAda artifact.setPackageNames(packageNames); artifact.setJarPath(shadedJarPath.toUri()); return Optional.of(artifact); - } + } return Optional.empty(); } @@ -238,6 +249,7 @@ private static Optional getMetaInfArtifactPath(FileSystem jarFileSystem, A return Optional.of(path); } + // Checkstyle: stop /** * Finds the paths to the directories containing the class files for the {@param artifact} inside the jar. * For example, if {@param artifact} represents commons-validator and the content of a fat jar looks like this: @@ -280,6 +292,7 @@ private static Optional getMetaInfArtifactPath(FileSystem jarFileSystem, A * @return A list of paths containing the class files for the artifact. * @throws IOException if an error occurs while reading the JAR. */ + // Checkstyle: resume private Optional> resolveArtifactClassFileDirectories(FileSystem jarFileSystem, Path jarPath, ArtifactAdapter artifact) throws IOException { if (pathToClassFilesDirectories.isEmpty()) { Set potentialDirectories = resolveDirectoriesContainingClassFiles(jarFileSystem.getPath("/")); @@ -371,7 +384,9 @@ private Optional findTopClassDirectory(Path rootPath, String qualifiedName */ private Optional tryResolveUsingGAVCoordinates(Path rootPath, ArtifactAdapter artifact) throws IOException { Optional resolvedPath = resolveGAVCoordinates(rootPath, artifact, true); - if (resolvedPath.isPresent()) return resolvedPath; + if (resolvedPath.isPresent()) { + return resolvedPath; + } return resolveGAVCoordinates(rootPath, artifact, false); } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactToPackageNameResolver.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactToPackageNameResolver.java index 9ae7a69d..e466334f 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactToPackageNameResolver.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/ArtifactToPackageNameResolver.java @@ -53,7 +53,11 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; final class ArtifactToPackageNameResolver { diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/FileWalkerUtility.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/FileWalkerUtility.java index bee96478..019f4c29 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/FileWalkerUtility.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/FileWalkerUtility.java @@ -42,7 +42,12 @@ import java.io.File; import java.io.IOException; -import java.nio.file.*; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystem; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.HashSet; import java.util.Optional; diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java index 28ad8cb8..41bde40e 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java @@ -62,7 +62,16 @@ import static org.graalvm.buildtools.maven.NativeCompileNoForkMojo.AUGMENTED_SBOM_PARAM_NAME; import static org.graalvm.buildtools.utils.NativeImageUtils.ORACLE_GRAALVM_IDENTIFIER; -import static org.twdata.maven.mojoexecutor.MojoExecutor.*; +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.element; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.name; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; /** * Generates a Software Bill of Materials (SBOM) that is augmented and refined by Native Image. This feature is only @@ -83,7 +92,7 @@ * * Great Baseline: Produces an industry-standard SBOM at minimum. * * Enhanced Accuracy: Native Image augments and refines the SBOM, potentially significantly improving its accuracy. */ -final public class SBOMGenerator { +public final class SBOMGenerator { public static final int requiredNativeImageVersion = 24; private final MavenProject mavenProject;