Skip to content

Commit

Permalink
other attempt to fix ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-br committed Jun 9, 2021
1 parent ccd6e0b commit 4af820d
Showing 1 changed file with 32 additions and 43 deletions.
75 changes: 32 additions & 43 deletions src/main/java/net/flintmc/gradle/maven/MavenArtifactDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -59,10 +60,8 @@ public MavenArtifactDownloader() {
*
* @param source The repository to add
*/
public void addSource(ReadableMavenRepository source) {
synchronized (this.sources) {
this.sources.add(source);
}
public synchronized void addSource(ReadableMavenRepository source) {
this.sources.add(source);
}

/**
Expand All @@ -71,21 +70,17 @@ public void addSource(ReadableMavenRepository source) {
* @param source The repository to check if it exists as a source
* @return {@code true} if this downloader has the give repository as a source, {@code false} otherwise
*/
public boolean hasSource(ReadableMavenRepository source) {
synchronized (this.sources) {
return this.sources.contains(source);
}
public synchronized boolean hasSource(ReadableMavenRepository source) {
return this.sources.contains(source);
}

/**
* Removes the given repository as a source.
*
* @param source The repository to remove
*/
public void removeSource(ReadableMavenRepository source) {
synchronized (this.sources) {
this.sources.remove(source);
}
public synchronized void removeSource(ReadableMavenRepository source) {
this.sources.remove(source);
}

/**
Expand All @@ -97,7 +92,7 @@ public void removeSource(ReadableMavenRepository source) {
* @throws IOException If an I/O error occurs while installing the artifact or one if its dependencies
* @throws MavenResolveException If the artifact or one of its dependencies can't be resolved
*/
public void installAll(MavenArtifact artifact, SimpleMavenRepository target, boolean installIfNotExists)
public synchronized void installAll(MavenArtifact artifact, SimpleMavenRepository target, boolean installIfNotExists)
throws IOException, MavenResolveException {
// Get the local POM path
Path localPomPath = target.getPomPath(artifact);
Expand Down Expand Up @@ -218,19 +213,17 @@ private boolean shouldSkip(MavenDependency dependency) {
* @return An input stream from which the artifact can be read, or {@code null} if not found in the sources
* @throws IOException If an I/O error occurs while opening the stream
*/
public InputStream findArtifactStream(MavenArtifact artifact) throws IOException {
synchronized (this.sources) {
for (ReadableMavenRepository source : sources) {
InputStream stream;
if ((stream = source.getArtifactStream(artifact)) != null) {
// Found the requested artifact
return stream;
}
public synchronized InputStream findArtifactStream(MavenArtifact artifact) throws IOException {
for (ReadableMavenRepository source : sources) {
InputStream stream;
if ((stream = source.getArtifactStream(artifact)) != null) {
// Found the requested artifact
return stream;
}

// Artifact has not been found in any source
return null;
}

// Artifact has not been found in any source
return null;
}

/**
Expand All @@ -240,18 +233,16 @@ public InputStream findArtifactStream(MavenArtifact artifact) throws IOException
* @return The found URI, or {@code null}, if not found in the sources
* @throws IOException If an I/O error occurs while checking for the artifact
*/
public Pair<ReadableMavenRepository, URI> findArtifactURI(MavenArtifact artifact) throws IOException {
synchronized (this.sources) {
for (ReadableMavenRepository source : sources) {
URI uri = source.getArtifactURI(artifact);
if (uri != null) {
return new Pair<>(source, uri);
}
public synchronized Pair<ReadableMavenRepository, URI> findArtifactURI(MavenArtifact artifact) throws IOException {
for (ReadableMavenRepository source : sources) {
URI uri = source.getArtifactURI(artifact);
if (uri != null) {
return new Pair<>(source, uri);
}

// Artifact has not been found in any source
return null;
}

// Artifact has not been found in any source
return null;
}

/**
Expand All @@ -262,13 +253,11 @@ public Pair<ReadableMavenRepository, URI> findArtifactURI(MavenArtifact artifact
* @throws IOException If an I/O error occurs while trying to read a POM
*/
private MavenPom findPom(MavenArtifact artifact) throws IOException {
synchronized (this.sources) {
for (ReadableMavenRepository source : sources) {
MavenPom pom;
if ((pom = source.getArtifactPom(artifact)) != null) {
// Found the requested POM
return pom;
}
for (ReadableMavenRepository source : sources) {
MavenPom pom;
if ((pom = source.getArtifactPom(artifact)) != null) {
// Found the requested POM
return pom;
}
}

Expand All @@ -285,7 +274,7 @@ private MavenPom findPom(MavenArtifact artifact) throws IOException {
* @throws IOException If an I/O error occurs while installing the artifact
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean installArtifact(MavenArtifact artifact, SimpleMavenRepository target) throws IOException {
public synchronized boolean installArtifact(MavenArtifact artifact, SimpleMavenRepository target) throws IOException {
try (InputStream stream = findArtifactStream(artifact)) {
// Try to find the given artifact
if (stream != null) {
Expand All @@ -299,7 +288,7 @@ public boolean installArtifact(MavenArtifact artifact, SimpleMavenRepository tar
LOGGER.lifecycle("Installing artifact {}", formatArtifact(artifact));

// Copy the artifact to the local path
Files.copy(stream, targetPath);
Files.copy(stream, targetPath, StandardCopyOption.REPLACE_EXISTING);
return true;
} else {
return false;
Expand Down

0 comments on commit 4af820d

Please sign in to comment.