Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -38,7 +41,6 @@
import org.eclipse.aether.impl.VersionResolver;
import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager;
import org.eclipse.aether.internal.impl.filter.Filters;
import org.eclipse.aether.internal.test.util.TestFileUtils;
import org.eclipse.aether.internal.test.util.TestLocalRepositoryManager;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.metadata.Metadata;
Expand Down Expand Up @@ -67,9 +69,9 @@
import org.eclipse.aether.transfer.ArtifactNotFoundException;
import org.eclipse.aether.transfer.ArtifactTransferException;
import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -92,6 +94,9 @@ public class DefaultArtifactResolverTest {

private DefaultRemoteRepositoryFilterManager remoteRepositoryFilterManager;

@TempDir
private Path tempPath;

@BeforeEach
void setup() {
remoteRepositoryFilterSources = new HashMap<>();
Expand Down Expand Up @@ -125,18 +130,12 @@ private DefaultArtifactResolver setupArtifactResolver(
remoteRepositoryFilterManager);
}

@AfterEach
void teardown() throws Exception {
if (session.getLocalRepository() != null) {
TestFileUtils.deleteFile(session.getLocalRepository().getBasedir());
}
}

@Test
void testResolveLocalArtifactSuccessful() throws IOException, ArtifactResolutionException {
File tmpFile = TestFileUtils.createTempFile("tmp");
Map<String, String> properties = new HashMap<>();
properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
properties.put(
ArtifactProperties.LOCAL_PATH,
Files.createTempFile(tempPath, "", "").toAbsolutePath().toString());
artifact = artifact.setProperties(properties);

ArtifactRequest request = new ArtifactRequest(artifact, null, "");
Expand All @@ -153,12 +152,12 @@ void testResolveLocalArtifactSuccessful() throws IOException, ArtifactResolution

@Test
void testResolveLocalArtifactUnsuccessful() throws IOException {
File tmpFile = TestFileUtils.createTempFile("tmp");
Path testPath = Files.createTempFile(tempPath, "", "").toAbsolutePath();
Map<String, String> properties = new HashMap<>();
properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
properties.put(ArtifactProperties.LOCAL_PATH, testPath.toString());
artifact = artifact.setProperties(properties);

tmpFile.delete();
Files.deleteIfExists(testPath);

ArtifactRequest request = new ArtifactRequest(artifact, null, "");

Expand Down Expand Up @@ -393,8 +392,9 @@ public void get(
connector.assertSeenExpected();
}

TestFileUtils.writeString(
new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact2)), "artifact");
Files.write(
new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact2)).toPath(),
"artifact".getBytes(StandardCharsets.UTF_8));
lrm.setArtifactAvailability(artifact2, false);

DefaultUpdateCheckManagerTest.resetSessionData(session);
Expand Down Expand Up @@ -427,7 +427,9 @@ public List<String> findVersions(Artifact artifact) {

public File findArtifact(Artifact artifact) {
try {
return TestFileUtils.createTempFile(artifact.toString());
Path path = Files.createTempFile(tempPath, "", "");
Files.write(path, artifact.toString().getBytes(StandardCharsets.UTF_8));
return path.toFile();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
Expand All @@ -445,7 +447,9 @@ public File findArtifact(Artifact artifact) {
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());

assertEquals(resolved.toString(), TestFileUtils.readString(resolved.getFile()));
assertEquals(
resolved.toString(),
new String(Files.readAllBytes(resolved.getFile().toPath()), StandardCharsets.UTF_8));

resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
Expand Down Expand Up @@ -494,10 +498,10 @@ public File findArtifact(Artifact artifact) {
void testRepositoryEventsSuccessfulLocal() throws ArtifactResolutionException, IOException {
RecordingRepositoryListener listener = new RecordingRepositoryListener();
session.setRepositoryListener(listener);

File tmpFile = TestFileUtils.createTempFile("tmp");
Map<String, String> properties = new HashMap<>();
properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
properties.put(
ArtifactProperties.LOCAL_PATH,
Files.createTempFile(tempPath, "", "").toAbsolutePath().toString());
artifact = artifact.setProperties(properties);

ArtifactRequest request = new ArtifactRequest(artifact, null, "");
Expand Down Expand Up @@ -731,7 +735,7 @@ public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRe
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(true);
try {
result.setFile(TestFileUtils.createTempFile(""));
result.setFile(Files.createTempFile(tempPath, "", "").toFile());
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -743,7 +747,7 @@ public void add(RepositorySystemSession session, LocalArtifactRegistration reque
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
try {
result.setFile(TestFileUtils.createTempFile(""));
result.setFile(Files.createTempFile(tempPath, "", "").toFile());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -772,7 +776,7 @@ void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() throws Arti
session.setLocalRepositoryManager(new LocalRepositoryManager() {

public LocalRepository getRepository() {
return new LocalRepository(new File(""));
return new LocalRepository(tempPath.toFile());
}

public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
Expand All @@ -796,7 +800,7 @@ public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRe
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(false);
try {
result.setFile(TestFileUtils.createTempFile(""));
result.setFile(Files.createTempFile(tempPath, "", "").toFile());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -841,7 +845,7 @@ void testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository() t
session.setLocalRepositoryManager(new LocalRepositoryManager() {

public LocalRepository getRepository() {
return new LocalRepository(new File(""));
return new LocalRepository(tempPath.toFile());
}

public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
Expand All @@ -865,7 +869,7 @@ public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRe
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(false);
try {
result.setFile(TestFileUtils.createTempFile(""));
result.setFile(Files.createTempFile(tempPath, "", "").toFile());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down