use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testMkdirConcurrencyBug.
@Test
public void testMkdirConcurrencyBug() throws IOException, NoRepositoryConnectorException {
RepositoryConnector connector = factory().newInstance(session, repository);
File artifactFile = TestFileUtils.createTempFile("mkdirsBug0");
File metadataFile = TestFileUtils.createTempFile("mkdirsBug1");
int numTransfers = 2;
ArtifactUpload[] artUps = new ArtifactUpload[numTransfers];
MetadataUpload[] metaUps = new MetadataUpload[numTransfers];
for (int i = 0; i < numTransfers; i++) {
StubArtifact art = new StubArtifact("testGroup", "testArtifact", "", "jar", i + "-test");
StubMetadata meta = new StubMetadata("testGroup", "testArtifact", i + "-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
ArtifactUpload artUp = new ArtifactUpload(art, artifactFile);
MetadataUpload metaUp = new MetadataUpload(meta, metadataFile);
artUps[i] = artUp;
metaUps[i] = metaUp;
}
connector.put(Arrays.asList(artUps), null);
connector.put(null, Arrays.asList(metaUps));
File localRepo = session.getLocalRepository().getBasedir();
StringBuilder localPath = new StringBuilder(localRepo.getAbsolutePath());
for (int i = 0; i < 50; i++) {
localPath.append("/d");
}
ArtifactDownload[] artDowns = new ArtifactDownload[numTransfers];
MetadataDownload[] metaDowns = new MetadataDownload[numTransfers];
for (int m = 0; m < 20; m++) {
for (int i = 0; i < numTransfers; i++) {
File artFile = new File(localPath.toString() + "/a" + i);
File metaFile = new File(localPath.toString() + "/m" + i);
StubArtifact art = new StubArtifact("testGroup", "testArtifact", "", "jar", i + "-test");
StubMetadata meta = new StubMetadata("testGroup", "testArtifact", i + "-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
ArtifactDownload artDown = new ArtifactDownload(art, null, artFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
MetadataDownload metaDown = new MetadataDownload(meta, null, metaFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
artDowns[i] = artDown;
metaDowns[i] = metaDown;
}
connector.get(Arrays.asList(artDowns), Arrays.asList(metaDowns));
for (int j = 0; j < numTransfers; j++) {
ArtifactDownload artDown = artDowns[j];
MetadataDownload metaDown = metaDowns[j];
assertNull("artifact download had exception: " + artDown.getException(), artDown.getException());
assertNull("metadata download had exception: " + metaDown.getException(), metaDown.getException());
assertEquals(State.DONE, artDown.getState());
assertEquals(State.DONE, metaDown.getState());
}
TestFileUtils.delete(localRepo);
}
connector.close();
}
use of org.sonatype.aether.spi.connector.MetadataUpload 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.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class DefaultDeployer method deploy.
private DeployResult deploy(SyncContext syncContext, RepositorySystemSession session, DeployRequest request) throws DeploymentException {
DeployResult result = new DeployResult(request);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
RemoteRepository repository = request.getRepository();
RepositoryConnector connector;
try {
connector = remoteRepositoryManager.getRepositoryConnector(session, repository);
} catch (NoRepositoryConnectorException e) {
throw new DeploymentException("Failed to deploy artifacts/metadata: " + e.getMessage(), e);
}
List<MetadataGenerator> generators = getMetadataGenerators(session, request);
try {
List<ArtifactUpload> artifactUploads = new ArrayList<ArtifactUpload>();
List<MetadataUpload> metadataUploads = new ArrayList<MetadataUpload>();
IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
EventCatapult catapult = new EventCatapult(session, trace, repository, repositoryEventDispatcher);
List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (int i = 0; i < artifacts.size(); i++) {
Artifact artifact = artifacts.get(i);
for (MetadataGenerator generator : generators) {
artifact = generator.transformArtifact(artifact);
}
artifacts.set(i, artifact);
artifactUploads.add(new ArtifactUploadEx(artifact, artifact.getFile(), catapult));
}
connector.put(artifactUploads, null);
for (ArtifactUpload upload : artifactUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy artifacts: " + upload.getException().getMessage(), upload.getException());
}
result.addArtifact(upload.getArtifact());
}
metadatas = Utils.finishMetadata(generators, artifacts);
syncContext.acquire(null, metadatas);
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (Metadata metadata : request.getMetadata()) {
if (!processedMetadata.containsKey(metadata)) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
}
connector.put(null, metadataUploads);
for (MetadataUpload upload : metadataUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy metadata: " + upload.getException().getMessage(), upload.getException());
}
result.addMetadata(upload.getMetadata());
}
} finally {
connector.close();
}
return result;
}
use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class PutTest method testMetadataUpload.
@Test
public void testMetadataUpload() throws Exception {
String content = "metadata";
addExpectation("gid/aid/version/maven-metadata.xml", content);
addExpectation("gid/aid/version/maven-metadata.xml.sha1", sha1(content));
addExpectation("gid/aid/version/maven-metadata.xml.md5", md5(content));
Metadata metadata = metadata(content);
List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
connector().put(null, uploads);
assertExpectations();
}
use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class PutTest method testCloseAfterMetadataUpload.
@Test
public void testCloseAfterMetadataUpload() throws Exception {
Metadata metadata = metadata("metadata");
List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
connector().put(null, uploads);
connector().close();
}
Aggregations