From 228f804eedd9168941993863b27eec55673a5198 Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Fri, 14 Aug 2026 15:32:38 +0200 Subject: [PATCH] Cleaned up some issues in the maven code While reviewing the side-effect of case sensitive file systems I came across some issues that we should fix first --- src/org/rascalmpl/util/maven/Artifact.java | 2 +- .../util/maven/BaseRepositoryDownloader.java | 18 +++++++++--------- .../util/maven/MavenProxySelector.java | 2 +- .../rascalmpl/util/maven/SimpleResolver.java | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/org/rascalmpl/util/maven/Artifact.java b/src/org/rascalmpl/util/maven/Artifact.java index 473371f41b0..ad212ed40b3 100644 --- a/src/org/rascalmpl/util/maven/Artifact.java +++ b/src/org/rascalmpl/util/maven/Artifact.java @@ -187,7 +187,7 @@ public boolean equals(Object obj) { /** * The state of the resolver. It contains the artifact and the transitive set of exclusions. */ - static private class ResolveState { + private static class ResolveState { private final Artifact artifact; private final Set exclusions; diff --git a/src/org/rascalmpl/util/maven/BaseRepositoryDownloader.java b/src/org/rascalmpl/util/maven/BaseRepositoryDownloader.java index eccbd04582b..72fe5c64380 100644 --- a/src/org/rascalmpl/util/maven/BaseRepositoryDownloader.java +++ b/src/org/rascalmpl/util/maven/BaseRepositoryDownloader.java @@ -48,12 +48,12 @@ * keep track of when the last download has taken place. If this is less than 12 * hours ago, the cached version is used. Otherwise the file is downloaded again. */ -abstract public class BaseRepositoryDownloader implements RepositoryDownloader { +public abstract class BaseRepositoryDownloader implements RepositoryDownloader { private static final String PROP_LAST_UPDATED = "lastUpdated"; private static final long MAX_INFO_AGE = 1000 * 60 * 60 * 12; // 12 hours private final Repo repo; - public BaseRepositoryDownloader(Repo repo) { + protected BaseRepositoryDownloader(Repo repo) { this.repo = repo; } @@ -86,9 +86,9 @@ protected void ensureTargetDirectoryExists(Path target) throws IOException { String infoFilename = fileName.substring(0, dotIndex) + "-info.properties"; Path infoPath = target.resolveSibling(infoFilename); if (Files.exists(infoPath)) { - Properties info = new Properties(); - try { - info.load(Files.newBufferedReader(infoPath)); + try (var infoFile = Files.newBufferedReader(infoPath)) { + Properties info = new Properties(); + info.load(infoFile); long lastUpdated = Long.parseLong(info.getProperty(PROP_LAST_UPDATED, "0")); if (System.currentTimeMillis() - lastUpdated < MAX_INFO_AGE) { // If the info file is recent enough, read metadata from local repo @@ -108,10 +108,10 @@ protected void ensureTargetDirectoryExists(Path target) throws IOException { } // Update the info file with the current timestamp - Properties info = new Properties(); - info.setProperty(PROP_LAST_UPDATED, String.valueOf(System.currentTimeMillis())); - try { - info.store(Files.newBufferedWriter(infoPath), "Metadata info for " + fileName); + try (var infoFile = Files.newBufferedWriter(infoPath)) { + Properties info = new Properties(); + info.setProperty(PROP_LAST_UPDATED, String.valueOf(System.currentTimeMillis())); + info.store(infoFile, "Metadata info for " + fileName); } catch (IOException e) { // Too bad, we cannot store the info file so caching will be disabled. diff --git a/src/org/rascalmpl/util/maven/MavenProxySelector.java b/src/org/rascalmpl/util/maven/MavenProxySelector.java index 13b22fd7509..e7fc08a37b6 100644 --- a/src/org/rascalmpl/util/maven/MavenProxySelector.java +++ b/src/org/rascalmpl/util/maven/MavenProxySelector.java @@ -82,7 +82,7 @@ public MavenProxySelector(List mavenProxies, List messages) { continue; } java.net.Proxy.Type type = - mavenProxy.getProtocol() == "socks5" ? java.net.Proxy.Type.SOCKS : java.net.Proxy.Type.HTTP; + mavenProxy.getProtocol().equals("socks5") ? java.net.Proxy.Type.SOCKS : java.net.Proxy.Type.HTTP; java.net.Proxy proxy = new java.net.Proxy(type, new InetSocketAddress(mavenProxy.getHost(), mavenProxy.getPort())); filteredProxies.add(new FilteredProxy(proxy, mavenProxy.getNonProxyHosts())); diff --git a/src/org/rascalmpl/util/maven/SimpleResolver.java b/src/org/rascalmpl/util/maven/SimpleResolver.java index c1acce82845..d9443654ded 100644 --- a/src/org/rascalmpl/util/maven/SimpleResolver.java +++ b/src/org/rascalmpl/util/maven/SimpleResolver.java @@ -66,7 +66,7 @@ public static SimpleResolver createRootResolver(Path rootRepository, HttpClient } } - private static RepositoryDownloaderFactory downloaderFactory; + private final RepositoryDownloaderFactory downloaderFactory; private final List availableRepostories = new ArrayList<>(); private final Path rootRepository; @@ -166,11 +166,11 @@ public String findLatestMatchingVersion(String groupId, String artifactId, Strin try { VersionRange versionRange = VersionRange.createFromVersionSpec(versionSpec); return metadata.getVersioning().getVersions().stream() - .map(version -> new DefaultArtifactVersion(version)) - .filter(version -> versionRange.containsVersion(version)) - .max((v1, v2) -> v1.compareTo(v2)) + .map(DefaultArtifactVersion::new) + .filter(versionRange::containsVersion) + .max(Comparable::compareTo) .orElseThrow(() -> new UnresolvableModelException("No version found in range", groupId, artifactId, versionSpec)) - .toString(); + .toString(); } catch (InvalidVersionSpecificationException e) { throw new UnresolvableModelException("Invalid version range specification", groupId, artifactId, versionSpec, e); } @@ -211,7 +211,7 @@ public void addRepository(Repository repository, boolean replace) throws Invalid this.availableRepostories.removeIf(r -> r.getRepo().getId().equals(repository.getId())); } Mirror mirror = mirrors.get(repository.getId()); - Repo repo = mirror == null ? new Repo(repository) : new MirrorRepo(mirror,repository); + Repo repo = mirror == null ? new Repo(repository) : new MirrorRepo(mirror,repository); this.availableRepostories.add(downloaderFactory.createDownloader(repo, servers.get(repo.getId()))); }