use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class PromotionValidationTools method readLocalPom.
public MavenPomView readLocalPom(final String path, final ValidationRequest request) throws IndyWorkflowException, GalleyMavenException {
ArtifactRef artifactRef = getArtifact(path);
if (artifactRef == null) {
throw new IndyWorkflowException("Invalid artifact path: %s. Could not parse ArtifactRef from path.", path);
}
Transfer transfer = retrieve(request.getSourceRepository(), path);
return pomReader.readLocalPom(artifactRef.asProjectVersionRef(), transfer, MavenPomView.ALL_PROFILES);
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class PromotionManagerTest method rollback_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback.
@Test
public void rollback_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback() throws Exception {
final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final String first = "/first/path";
final String second = "/second/path";
contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(2));
assertThat(result.getError(), nullValue());
result = manager.rollbackPathsPromote(result);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
pending = result.getPendingPaths();
assertThat(pending, notNullValue());
assertThat(pending.size(), equalTo(2));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, first);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(target, second);
assertThat(ref.exists(), equalTo(false));
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class PromotionManagerTest method promoteAllByPath_CollidingPaths_VerifySecondSkipped.
/**
* On collision, the promotion manager should skip the second file to be promoted (instead of overwriting the
* existing one). This assumes no overwrite attribute is available for setting in the promotion request (or that
* it is available but isn't set...and defaults to false).
* @throws Exception
*/
@Test
public void promoteAllByPath_CollidingPaths_VerifySecondSkipped() throws Exception {
final HostedRepository source1 = new HostedRepository(MAVEN_PKG_KEY, "source1");
final HostedRepository source2 = new HostedRepository(MAVEN_PKG_KEY, "source2");
storeManager.storeArtifactStore(source1, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
storeManager.storeArtifactStore(source2, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
String originalString = "This is a test";
final String path = "/path/path";
contentManager.store(source1, path, new ByteArrayInputStream(originalString.getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source2, path, new ByteArrayInputStream("This is another test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source1.getKey(), target.getKey(), path), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source1.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
Set<String> skipped = result.getSkippedPaths();
assertThat(skipped == null || skipped.isEmpty(), equalTo(true));
Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(1));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, path);
assertThat(ref.exists(), equalTo(true));
try (InputStream in = ref.openInputStream()) {
String value = IOUtils.toString(in);
assertThat(value, equalTo(originalString));
}
result = manager.promotePaths(new PathsPromoteRequest(source1.getKey(), target.getKey(), path), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source1.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
skipped = result.getSkippedPaths();
assertThat(skipped, notNullValue());
assertThat(skipped.size(), equalTo(1));
completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
assertThat(result.getError(), nullValue());
ref = downloadManager.getStorageReference(target, path);
assertThat(ref.exists(), equalTo(true));
try (InputStream in = ref.openInputStream()) {
String value = IOUtils.toString(in);
assertThat(value, equalTo(originalString));
}
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class MavenMetadataMergerTest method mergeWhenOneTransferIsMissing.
@Test
public void mergeWhenOneTransferIsMissing() throws Exception {
String path = "org/foo/bar/maven-metadata.xml";
HostedRepository h1 = new HostedRepository("test-hosted-1");
HostedRepository h2 = new HostedRepository("test-hosted-2");
Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
initTestData(t1, VERSION_META + "simple-1.xml");
Transfer t2 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h2), path));
Group g = new Group("test-group", h1.getKey(), h2.getKey());
List<Transfer> sources = Arrays.asList(t1, t2);
byte[] output = new MavenMetadataMerger(Collections.emptyList()).merge(sources, g, path);
Metadata merged = new MetadataXpp3Reader().read(new ByteArrayInputStream(output));
assertThat(merged.getGroupId(), equalTo("org.foo"));
assertThat(merged.getArtifactId(), equalTo("bar"));
Versioning versioning = merged.getVersioning();
assertThat(versioning, notNullValue());
List<String> versions = versioning.getVersions();
assertThat(versions, notNullValue());
assertThat(versions.size(), equalTo(1));
assertThat(versioning.getRelease(), equalTo("1.0"));
assertThat(versioning.getLatest(), equalTo("1.0"));
int idx = 0;
assertThat(versions.get(idx), equalTo("1.0"));
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class MavenMetadataMergerTest method mergeWhenOneTransferIsInvalidXml.
@Test
public void mergeWhenOneTransferIsInvalidXml() throws Exception {
String path = "org/foo/bar/maven-metadata.xml";
HostedRepository h1 = new HostedRepository("test-hosted-1");
HostedRepository h2 = new HostedRepository("test-hosted-2");
Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
initTestData(t1, VERSION_META + "simple-1.xml");
Transfer t2 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h2), path));
initTestData(t2, VERSION_META + "invalid.xml");
Group g = new Group("test-group", h1.getKey(), h2.getKey());
List<Transfer> sources = Arrays.asList(t1, t2);
byte[] output = new MavenMetadataMerger(Collections.emptyList()).merge(sources, g, path);
Metadata merged = new MetadataXpp3Reader().read(new ByteArrayInputStream(output));
assertThat(merged.getGroupId(), equalTo("org.foo"));
assertThat(merged.getArtifactId(), equalTo("bar"));
Versioning versioning = merged.getVersioning();
assertThat(versioning, notNullValue());
List<String> versions = versioning.getVersions();
assertThat(versions, notNullValue());
assertThat(versions.size(), equalTo(1));
assertThat(versioning.getRelease(), equalTo("1.0"));
assertThat(versioning.getLatest(), equalTo("1.0"));
int idx = 0;
assertThat(versions.get(idx), equalTo("1.0"));
}
Aggregations