Skip to content

Commit

Permalink
Fix checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Dec 17, 2024
1 parent bccd0d2 commit 7749ff3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 23 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
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 7749ff3

Please sign in to comment.