Skip to content

Commit

Permalink
Upgrade to Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Nov 7, 2024
1 parent 2ad8d04 commit 0674e95
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macOS-latest, windows-latest ]
java: [ "11", "17", "21" ]
java: [ "17", "21", "22" ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
11 changes: 11 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} -javaagent:${com.ginsberg:junit5-system-exit:jar}</argLine>
<systemPropertyVariables>
<org.jboss.byteman.contrib.bmunit.agent.inhibit>true</org.jboss.byteman.contrib.bmunit.agent.inhibit>
<org.jboss.byteman.contrib.bmunit.agent.port>9091</org.jboss.byteman.contrib.bmunit.agent.port>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 changes: 1 addition & 4 deletions cli/src/main/java/org/jboss/pnc/build/finder/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,7 @@ public Void call() {
for (LocalFile filename : entry.getValue()) {
newMap.put(
new Checksum(checksumType, entry.getKey(), filename),
entry.getValue()
.stream()
.map(LocalFile::getFilename)
.collect(Collectors.toUnmodifiableList()));
entry.getValue().stream().map(LocalFile::getFilename).toList());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.jboss.pnc.build.finder.core.TestUtils;
import org.jboss.pnc.build.finder.core.Utils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.io.TempDir;
import org.junitpioneer.jupiter.StdIo;
import org.junitpioneer.jupiter.StdOut;
Expand All @@ -54,7 +52,6 @@ private static ParseResult parseCommandLine(Object command, String[] args) {
@ExpectSystemExitWithStatus(0)
@StdIo
@Test
@DisabledForJreRange(min = JRE.JAVA_18)
void testHelp(StdOut out) {
String[] args = { "--help" };

Expand All @@ -70,7 +67,6 @@ void testHelp(StdOut out) {
@ExpectSystemExitWithStatus(0)
@StdIo
@Test
@DisabledForJreRange(min = JRE.JAVA_18)
void testVersion(StdOut out) {
String[] args = { "--version" };
ParseResult parseResult = parseCommandLine(new Main(), args);
Expand Down Expand Up @@ -170,7 +166,6 @@ void testParsing(@TempDir File folder) throws IOException {
@ExpectSystemExitWithStatus(0)
@StdIo
@Test
@DisabledForJreRange(min = JRE.JAVA_18)
void testConfig(@TempDir File folder, StdOut out) throws IOException {
File configFile = TestUtils.loadFile("config.json");
File inputFile = TestUtils.loadFile("nested.war");
Expand Down Expand Up @@ -210,7 +205,6 @@ void testConfig(@TempDir File folder, StdOut out) throws IOException {
@ExpectSystemExitWithStatus(0)
@StdIo
@Test
@DisabledForJreRange(min = JRE.JAVA_18)
void testDebug(@TempDir File folder, StdOut out) throws IOException {
File configFile = TestUtils.loadFile("config.json");
File inputFile = TestUtils.loadFile("nested.war");
Expand Down Expand Up @@ -267,7 +261,6 @@ void testDebug(@TempDir File folder, StdOut out) throws IOException {
@ExpectSystemExitWithStatus(0)
@StdIo
@Test
@DisabledForJreRange(min = JRE.JAVA_18)
void testQuiet(@TempDir File folder, StdOut out) throws IOException {
File configFile = TestUtils.loadFile("config.json");
File inputFile = TestUtils.loadFile("nested.war");
Expand Down
42 changes: 16 additions & 26 deletions core/src/main/java/org/jboss/pnc/build/finder/core/BuildFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,12 @@ private void handleRPMs(Collection<Entry<Checksum, Collection<String>>> rpmEntri
.map(KojiRpmInfo::getBuildId)
.filter(Objects::nonNull)
.map(KojiIdOrName::getFor)
.collect(Collectors.toUnmodifiableList());
.toList();
Future<List<KojiBuildInfo>> futureRpmBuildInfos = pool.submit(() -> session.getBuild(rpmBuildIds));
Future<List<List<KojiTagInfo>>> futureRpmTagInfos = pool.submit(() -> session.listTags(rpmBuildIds));
Future<List<List<KojiRpmInfo>>> futureRpmRpmInfos = pool.submit(() -> session.listBuildRPMs(rpmBuildIds));
List<KojiBuildInfo> rpmBuildInfos = futureRpmBuildInfos.get();
List<Integer> taskIds = rpmBuildInfos.stream()
.map(KojiBuildInfo::getTaskId)
.filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableList());
List<Integer> taskIds = rpmBuildInfos.stream().map(KojiBuildInfo::getTaskId).filter(Objects::nonNull).toList();
int taskIdsSize = taskIds.size();
List<KojiTaskInfo> rpmTaskInfos = null;
Future<List<KojiTaskInfo>> futureRpmTaskInfos = null;
Expand Down Expand Up @@ -439,7 +436,7 @@ private KojiBuild findBestBuildFromCandidates(List<KojiBuild> candidates, List<K
List<Integer> candidateIds = candidates.stream()
.map(KojiBuild::getBuildInfo)
.map(KojiBuildInfo::getId)
.collect(Collectors.toUnmodifiableList());
.toList();

LOGGER.debug("Found {} builds containing archive with checksum {}: {}", candidatesSize, checksum, candidateIds);

Expand All @@ -461,7 +458,7 @@ private KojiBuild findBestBuildFromCandidates(List<KojiBuild> candidates, List<K
List<KojiBuild> cachedBuilds = candidateIds.stream()
.map(id -> builds.get(new BuildSystemInteger(id, BuildSystem.koji)))
.filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableList());
.toList();

if (!cachedBuilds.isEmpty()) {
KojiBuild build = cachedBuilds.get(cachedBuilds.size() - 1);
Expand All @@ -473,13 +470,13 @@ private KojiBuild findBestBuildFromCandidates(List<KojiBuild> candidates, List<K

List<KojiBuild> completedBuilds = candidates.stream()
.filter(build -> build.getBuildInfo().getBuildState() == KojiBuildState.COMPLETE)
.collect(Collectors.toUnmodifiableList());
.toList();
List<KojiBuild> completedTaggedBuilds = completedBuilds.stream()
.filter(build -> build.getTags() != null && !build.getTags().isEmpty())
.collect(Collectors.toUnmodifiableList());
.toList();
List<KojiBuild> completedTaggedBuiltBuilds = completedTaggedBuilds.stream()
.filter(build -> !build.isImport())
.collect(Collectors.toUnmodifiableList());
.toList();

if (!completedTaggedBuiltBuilds.isEmpty()) {
KojiBuild build = completedTaggedBuiltBuilds.get(completedTaggedBuiltBuilds.size() - 1);
Expand Down Expand Up @@ -530,7 +527,7 @@ private KojiBuild findBestBuildFromCandidates(List<KojiBuild> candidates, List<K
* are separated by "!/") until a local archive is matched.
*
* @param filename the filename
* @return the parent of the file name (separated by "!/"")
* @return the parent of the file name (separated by &quot;!/&quot;)
*/
private Optional<String> handleNotFoundFile(String filename) {
LOGGER.debug("Handle not found file: {}", filename);
Expand Down Expand Up @@ -581,7 +578,7 @@ private Optional<String> handleNotFoundFile(String filename) {
* using a particular checksum type, but then was found later using another checksum type.
*
* @param filename the filename
* @return the parent of the file name (separated by "!/"")
* @return the parent of the file name (separated by &quot;!/&quot;)
*/
private Optional<String> handleFoundFile(String filename) {
LOGGER.debug("Handle found file: {}", filename);
Expand Down Expand Up @@ -688,10 +685,7 @@ public Map<BuildSystemInteger, KojiBuild> findBuilds(Map<Checksum, Collection<St
LOGGER.debug(
"Checksum {} cached with build ids {}",
green(checksum),
green(
cacheArchiveInfos.stream()
.map(KojiArchiveInfo::getBuildId)
.collect(Collectors.toUnmodifiableList())));
green(cacheArchiveInfos.stream().map(KojiArchiveInfo::getBuildId).toList()));
cachedChecksums.add(entry);
cachedArchiveInfos.add(cacheArchiveInfos);
}
Expand Down Expand Up @@ -768,9 +762,7 @@ public Map<BuildSystemInteger, KojiBuild> findBuilds(Map<Checksum, Collection<St
}
}

List<KojiArchiveInfo> archivesToEnrich = archives.stream()
.flatMap(List::stream)
.collect(Collectors.toUnmodifiableList());
List<KojiArchiveInfo> archivesToEnrich = archives.stream().flatMap(List::stream).toList();

session.enrichArchiveTypeInfo(archivesToEnrich);

Expand Down Expand Up @@ -857,9 +849,7 @@ public Map<BuildSystemInteger, KojiBuild> findBuilds(Map<Checksum, Collection<St
* build. 3- find all the KojiTagInfo associated with each build.
*/
if (!buildIds.isEmpty()) {
List<KojiIdOrName> idsOrNames = buildIds.stream()
.map(KojiIdOrName::getFor)
.collect(Collectors.toUnmodifiableList());
List<KojiIdOrName> idsOrNames = buildIds.stream().map(KojiIdOrName::getFor).toList();
Future<List<KojiBuildInfo>> futureArchiveBuilds = pool.submit(() -> session.getBuild(idsOrNames));
Future<List<List<KojiTagInfo>>> futureTagInfos = pool.submit(() -> session.listTags(idsOrNames));
List<KojiArchiveQuery> queries = new ArrayList<>(buildIdsSize);
Expand Down Expand Up @@ -1222,7 +1212,7 @@ private static List<KojiBuild> getKojiBuildsForArchives(
Set<Integer> buildIds = archiveInfos.stream()
.map(KojiArchiveInfo::getBuildId)
.collect(Collectors.toCollection(HashSet::new));
return buildIds.stream().map(allBuilds::get).collect(Collectors.toUnmodifiableList());
return buildIds.stream().map(allBuilds::get).toList();
}

public Map<Checksum, Collection<String>> getFoundChecksums() {
Expand Down Expand Up @@ -1402,7 +1392,7 @@ public Map<BuildSystemInteger, KojiBuild> call() throws KojiClientException {
.map(LicenseInfo::getSpdxLicenseId)
.sorted()
.distinct()
.collect(Collectors.toUnmodifiableList());
.toList();

if (LOGGER.isInfoEnabled()) {
LOGGER.info(
Expand All @@ -1415,7 +1405,7 @@ public Map<BuildSystemInteger, KojiBuild> call() throws KojiClientException {
kojiBuild -> kojiBuild.getArchives()
.stream()
.anyMatch(kojiLocalArchive -> !kojiLocalArchive.getLicenses().isEmpty()))
.collect(Collectors.toUnmodifiableList());
.toList();
int numBuildsWithLicenses = buildsWithLicenses.size();
LOGGER.info(
"{} / {} = {}% of builds have license information",
Expand All @@ -1426,7 +1416,7 @@ public Map<BuildSystemInteger, KojiBuild> call() throws KojiClientException {
List<KojiLocalArchive> archives = allBuilds.values()
.stream()
.flatMap(kojiBuild -> kojiBuild.getArchives().stream())
.collect(Collectors.toUnmodifiableList());
.toList();
int numArchives = archives.size();
long numArchivesWithLicenses = archives.stream()
.filter(kojiLocalArchive -> !kojiLocalArchive.getLicenses().isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.zip.ZipOutputStream;

import org.apache.commons.codec.binary.Hex;
Expand Down Expand Up @@ -348,10 +347,7 @@ private static List<String> getArchiveExtensionsFromKoji(BuildConfig config, Cli
throws KojiClientException {
Map<String, KojiArchiveType> allArchiveTypesMap = session.getArchiveTypeMap();

List<String> allArchiveTypes = allArchiveTypesMap.values()
.stream()
.map(KojiArchiveType::getName)
.collect(Collectors.toUnmodifiableList());
List<String> allArchiveTypes = allArchiveTypesMap.values().stream().map(KojiArchiveType::getName).toList();
List<String> archiveTypes = config.getArchiveTypes();
List<String> archiveTypesToCheck;

Expand All @@ -365,9 +361,7 @@ private static List<String> getArchiveExtensionsFromKoji(BuildConfig config, Cli
String.join(", ", archiveTypes));
}

archiveTypesToCheck = archiveTypes.stream()
.filter(allArchiveTypesMap::containsKey)
.collect(Collectors.toUnmodifiableList());
archiveTypesToCheck = archiveTypes.stream().filter(allArchiveTypesMap::containsKey).toList();

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
Expand All @@ -387,7 +381,7 @@ private static List<String> getArchiveExtensionsFromKoji(BuildConfig config, Cli
.stream()
.map(KojiArchiveType::getExtensions)
.flatMap(List::stream)
.collect(Collectors.toUnmodifiableList());
.toList();
List<String> extensions = config.getArchiveExtensions();
List<String> extensionsToCheck;

Expand All @@ -399,9 +393,7 @@ private static List<String> getArchiveExtensionsFromKoji(BuildConfig config, Cli
String.join(", ", extensions));
}

extensionsToCheck = extensions.stream()
.filter(allArchiveExtensions::contains)
.collect(Collectors.toUnmodifiableList());
extensionsToCheck = extensions.stream().filter(allArchiveExtensions::contains).toList();

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.Serial;
import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -34,7 +35,6 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -55,6 +55,7 @@
public class Checksum implements Comparable<Checksum>, Serializable {
private static final Logger LOGGER = LoggerFactory.getLogger(Checksum.class);

@Serial
private static final long serialVersionUID = -7347509034711302799L;

private static final int BUFFER_SIZE = 1024;
Expand Down Expand Up @@ -256,9 +257,7 @@ public static Set<Checksum> checksum(FileObject fo, Collection<ChecksumType> che
}

static Optional<Checksum> findByType(Collection<Checksum> checksums, ChecksumType type) {
List<Checksum> list = checksums.stream()
.filter(checksum -> checksum.getType() == type)
.collect(Collectors.toUnmodifiableList());
List<Checksum> list = checksums.stream().filter(checksum -> checksum.getType() == type).toList();
Checksum checksum = null;

if (!list.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public Map<ChecksumType, MultiValuedMap<String, LocalFile>> checksumFiles() thro
.stream()
.flatMap(Collection::stream)
.map(LicenseInfo::getSpdxLicenseId)
.collect(Collectors.toUnmodifiableList());
.toList();
Set<String> uniqueLicenses = new TreeSet<>(totalLicenses);
Map<String, Long> licenseCountMap = totalLicenses.stream().collect(groupingBy(identity(), counting()));
String licenseCounts = licenseCountMap.entrySet()
Expand Down Expand Up @@ -497,11 +497,10 @@ private void listArchive(FileObject fo) {
private static String getMessage(Throwable t) {
StringBuilder sb = new StringBuilder(32);

if (t instanceof java.nio.file.FileSystemException) {
java.nio.file.FileSystemException fse = (java.nio.file.FileSystemException) t;
if (t instanceof java.nio.file.FileSystemException fse) {

if (fse instanceof DirectoryNotEmptyException) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append(": ");
}

Expand Down Expand Up @@ -667,7 +666,7 @@ private List<LicenseInfo> addLicensesFromJar(FileObject jar, List<FileObject> lo
.map(localFile -> addLicensesFromJar(jar, localFile))
.filter(not(Collection::isEmpty))
.flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableList());
.toList();
}

private List<LicenseInfo> addLicensesFromJar(FileObject jar, FileObject localFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.vfs2.FileContent;
import org.apache.commons.vfs2.FileObject;
Expand Down Expand Up @@ -149,10 +148,7 @@ public static String getGAV(MavenProject project) {
* @return the list of Maven projects (may be empty)
*/
public static List<LicenseInfo> getLicenses(MavenProject project, LicenseSource source) {
return project.getLicenses()
.stream()
.map(license -> new LicenseInfo(license, source))
.collect(Collectors.toUnmodifiableList());
return project.getLicenses().stream().map(license -> new LicenseInfo(license, source)).toList();
}

/**
Expand Down
Loading

0 comments on commit 0674e95

Please sign in to comment.