Skip to content

Commit

Permalink
Merge pull request #657 from graalvm/fix-checkstyle
Browse files Browse the repository at this point in the history
Fix checkstyle errors
  • Loading branch information
vjovanov authored Dec 17, 2024
2 parents 355efa0 + 7749ff3 commit e05d314
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -252,7 +268,7 @@ protected List<String> getBuildArgs() throws MojoExecutionException {
static List<String> processBuildArgs(List<String> buildArgs) {
var result = new ArrayList<String>();
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)));
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,7 +147,7 @@ Optional<ArtifactAdapter> populateWithAdditionalFields(Path jarPath, ArtifactAda
artifact.setPackageNames(packageNames);
artifact.setJarPath(shadedJarPath.toUri());
return Optional.of(artifact);
}
}
return Optional.empty();
}

Expand Down Expand Up @@ -238,6 +249,7 @@ private static Optional<Path> 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:
Expand Down Expand Up @@ -280,6 +292,7 @@ private static Optional<Path> 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<Set<Path>> resolveArtifactClassFileDirectories(FileSystem jarFileSystem, Path jarPath, ArtifactAdapter artifact) throws IOException {
if (pathToClassFilesDirectories.isEmpty()) {
Set<Path> potentialDirectories = resolveDirectoriesContainingClassFiles(jarFileSystem.getPath("/"));
Expand Down Expand Up @@ -371,7 +384,9 @@ private Optional<Path> findTopClassDirectory(Path rootPath, String qualifiedName
*/
private Optional<Path> tryResolveUsingGAVCoordinates(Path rootPath, ArtifactAdapter artifact) throws IOException {
Optional<Path> resolvedPath = resolveGAVCoordinates(rootPath, artifact, true);
if (resolvedPath.isPresent()) return resolvedPath;
if (resolvedPath.isPresent()) {
return resolvedPath;
}
return resolveGAVCoordinates(rootPath, artifact, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit e05d314

Please sign in to comment.