Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/org/rascalmpl/util/maven/Artifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<WithoutVersion> exclusions;

Expand Down
18 changes: 9 additions & 9 deletions src/org/rascalmpl/util/maven/BaseRepositoryDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/util/maven/MavenProxySelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public MavenProxySelector(List<Proxy> mavenProxies, List<IValue> 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()));
Expand Down
12 changes: 6 additions & 6 deletions src/org/rascalmpl/util/maven/SimpleResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static SimpleResolver createRootResolver(Path rootRepository, HttpClient
}
}

private static RepositoryDownloaderFactory downloaderFactory;
private final RepositoryDownloaderFactory downloaderFactory;

private final List<RepositoryDownloader> availableRepostories = new ArrayList<>();
private final Path rootRepository;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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())));
}

Expand Down
Loading