use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class DefaultUpdateCheckManagerTest method testCheckArtifactNotFoundInRepoCachingDisabled.
@Test
public void testCheckArtifactNotFoundInRepoCachingDisabled() throws Exception {
artifact.getFile().delete();
session.setNotFoundCachingEnabled(false);
UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
check.setException(new ArtifactNotFoundException(artifact, repository));
manager.touchArtifact(session, check);
resetSessionData(session);
// ! file.exists && ! updateRequired -> artifact not found in remote repo
check = newArtifactCheck().setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
manager.checkArtifact(session, check);
assertEquals(true, check.isRequired());
assertNull(check.getException());
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testTransferZeroBytesFile.
/**
* See https://issues.sonatype.org/browse/AETHER-8
*/
@Test
public void testTransferZeroBytesFile() throws IOException, NoRepositoryConnectorException {
File emptyFile = TestFileUtils.createTempFile("");
Artifact artifact = new StubArtifact("gid:aid:ext:ver");
ArtifactUpload upA = new ArtifactUpload(artifact, emptyFile);
File dir = TestFileUtils.createTempDir("con-test");
File downAFile = new File(dir, "downA.file");
downAFile.deleteOnExit();
ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload upM = new MetadataUpload(metadata, emptyFile);
File downMFile = new File(dir, "downM.file");
downMFile.deleteOnExit();
MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
RepositoryConnector connector = factory().newInstance(session, repository);
connector.put(Arrays.asList(upA), Arrays.asList(upM));
connector.get(Arrays.asList(downA), Arrays.asList(downM));
assertNull(String.valueOf(upA.getException()), upA.getException());
assertNull(String.valueOf(upM.getException()), upM.getException());
assertNull(String.valueOf(downA.getException()), downA.getException());
assertNull(String.valueOf(downM.getException()), downM.getException());
assertEquals(0, downAFile.length());
assertEquals(0, downMFile.length());
connector.close();
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class ConnectorTestUtils method createTransfers.
/**
* Creates transfer objects according to the given class. If the file parameter is {@code null}, a new temporary
* file will be created for downloads. Uploads will just use the parameter as it is.
*/
public static <T extends Transfer> List<T> createTransfers(Class<T> cls, int count, File file) {
ArrayList<T> ret = new ArrayList<T>();
Object item;
if (ArtifactTransfer.class.isAssignableFrom(cls)) {
item = new StubArtifact("testGroup", "testArtifact", "sources", "jar", "will be replaced");
} else {
item = new StubMetadata("testGroup", "testArtifact", "will be replaced", "jar", Metadata.Nature.RELEASE_OR_SNAPSHOT, file);
}
for (int i = 0; i < count; i++) {
String context = null;
String checksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
Object obj = null;
if (cls.isAssignableFrom(ArtifactUpload.class)) {
Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
obj = new ArtifactUpload(artifact, file);
} else if (cls.isAssignableFrom(ArtifactDownload.class)) {
try {
Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
obj = new ArtifactDownload(artifact, context, safeFile(file), checksumPolicy);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if (cls.isAssignableFrom(MetadataUpload.class)) {
Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
obj = new MetadataUpload(metadata, file);
} else if (cls.isAssignableFrom(MetadataDownload.class)) {
try {
Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
obj = new MetadataDownload(metadata, context, safeFile(file), checksumPolicy);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
ret.add(cls.cast(obj));
}
return ret;
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class RecordingRepositoryConnector method get.
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
try {
if (artifactDownloads != null) {
for (ArtifactDownload artifactDownload : artifactDownloads) {
artifactDownload.setState(State.ACTIVE);
Artifact artifact = artifactDownload.getArtifact();
this.actualGet.add(artifact);
TestFileUtils.write(artifact.toString(), artifactDownload.getFile());
artifactDownload.setState(State.DONE);
}
}
if (metadataDownloads != null) {
for (MetadataDownload metadataDownload : metadataDownloads) {
metadataDownload.setState(State.ACTIVE);
Metadata metadata = metadataDownload.getMetadata();
this.actualGetMD.add(metadata);
TestFileUtils.write(metadata.toString(), metadataDownload.getFile());
metadataDownload.setState(State.DONE);
}
}
} catch (IOException e) {
throw new IllegalStateException("Cannot create temporary file", e);
}
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class SimpleLocalRepositoryManagerTest method testGetPathForLocalArtifact.
@Test
public void testGetPathForLocalArtifact() throws Exception {
Artifact artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-SNAPSHOT");
assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact(artifact));
artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-20110329.221805-4");
assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact(artifact));
artifact = new DefaultArtifact("g.i.d", "a.i.d", "", "", "1.0-SNAPSHOT");
assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT", manager.getPathForLocalArtifact(artifact));
}
Aggregations