use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class PromotionValidationTools method readPom.
public MavenPomView readPom(final String path, final ValidationRequest request, final StoreKey... extraLocations) throws IndyWorkflowException, GalleyMavenException, IndyDataException {
ArtifactRef artifactRef = getArtifact(path);
if (artifactRef == null) {
return null;
}
Transfer transfer = retrieve(request.getSourceRepository(), path);
List<Location> locations = new ArrayList<>(extraLocations.length + 1);
locations.add(transfer.getLocation());
addLocations(locations, extraLocations);
return pomReader.read(artifactRef.asProjectVersionRef(), transfer, locations, MavenPomView.ALL_PROFILES);
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class PromotionManagerTest method rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource.
@Test
public void rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource() 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()).setPurgeSource(true), 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));
ref = downloadManager.getStorageReference(source, first);
assertThat(ref.exists(), equalTo(true));
ref = downloadManager.getStorageReference(source, second);
assertThat(ref.exists(), equalTo(true));
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class RelateContentGenerator method generateFileContent.
@Override
public Transfer generateFileContent(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
if (!config.isEnabled()) {
logger.debug("Relate Add-on is not enabled.");
return null;
}
logger.info("Generate .rel for: {}/{}", store.getKey(), path);
if (!canProcess(path)) {
logger.debug("Not a .rel request");
return null;
}
logger.debug("Check for POM matching: {}", path);
String pomPath = path.substring(0, path.length() - REL_SUFFIX.length());
if (!pomPath.endsWith(POM_SUFFIX)) {
logger.debug("Not a POM {}", pomPath);
return null;
}
Transfer pomTransfer = fileManager.getTransfer(store, path);
if (!exists(pomTransfer)) {
ThreadContext threadContext = ThreadContext.getContext(true);
threadContext.put(REL_DIRECT_GENERATING, true);
pomTransfer = downloadManager.retrieve(store, pomPath, eventMetadata);
if (!exists(pomTransfer)) {
logger.debug("POM not exists for request {}", pomPath);
return null;
}
}
Transfer result = relateGenerationManager.generateRelationshipFile(pomTransfer, TransferOperation.DOWNLOAD);
if (result != null) {
Transfer meta = result.getSiblingMeta(HttpExchangeMetadata.FILE_EXTENSION);
try {
// delete *.rel.http-metadata.json, which is created unnecessarily during the unsuccessful get request
meta.delete();
// TODO: If mark .rel as generated in SpecialPathManager, should be able to avoid creating the meta file in the first place...
} catch (IOException e) {
logger.debug("Delete meta {} failed", meta, e);
}
}
// Finally, pass the Transfer back.
return result;
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class RelateGenerationManager method generateRelationshipFile.
/**
* Generate relationship file for pom transfer.
* @param transfer
* @param op
* @return transfer pointing to the generated rel file.
*/
public Transfer generateRelationshipFile(Transfer transfer, TransferOperation op) {
final Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Relate generation for {}", transfer);
if (transfer == null) {
logger.debug("No transfer. No .rel generation performed.");
return null;
}
String txfrPath = transfer.getPath();
if (!txfrPath.endsWith(".pom")) {
logger.debug("This is not a pom transfer.");
return null;
}
ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
if (artPathInfo == null) {
logger.debug("Not an artifact download ({}). No .rel generation performed.", txfrPath);
return null;
}
ConcreteResource pomResource = transfer.getResource();
StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
ArtifactStore store;
try {
store = storeManager.getArtifactStore(storeKey);
} catch (final IndyDataException ex) {
logger.error("Error retrieving artifactStore with key " + storeKey, ex);
return null;
}
logger.debug("Generate .rel corresponding to associated POM download: {}/{}", storeKey, pomResource.getPath());
try {
URI source = new URI(pomResource.getLocation().getUri() + REL_SUFFIX);
ProjectVersionRef ref = artPathInfo.getProjectId();
// get all groups that this store is a member of
Set<ArtifactStore> stores = new HashSet<>();
stores.add(store);
stores.addAll(storeManager.query().getGroupsContaining(store.getKey()));
List<? extends Location> supplementalLocations = LocationUtils.toLocations(stores.toArray(new ArtifactStore[0]));
MavenPomView pomView = mavenPomReader.read(ref, transfer, supplementalLocations, ALL_PROFILES);
EProjectDirectRelationships rel = mavenModelProcessor.readRelationships(pomView, source, new ModelProcessorConfig());
Transfer transferRel = transfer.getSiblingMeta(REL_SUFFIX);
writeRelationships(rel, transferRel, op);
return transferRel;
} catch (Exception e) {
logger.error("Error generating .rel file for " + txfrPath + " from store " + store, e);
return null;
}
}
use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.
the class MavenModelProcessorTest method resolvePluginDependencyFromManagedInfo.
@Test
public void resolvePluginDependencyFromManagedInfo() throws Exception {
final URI src = new URI("http://nowhere.com/path/to/repo");
final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
lineage.put(childRef, "child.pom.xml");
lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
final String base = PROJ_BASE + "dependency-in-managed-parent-plugin/";
for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
final ProjectVersionRef ref = entry.getKey();
final String filename = entry.getValue();
final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
}
final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
assertThat(buildPlugins, notNullValue());
assertThat(buildPlugins.size(), equalTo(1));
final PluginView pv = buildPlugins.get(0);
assertThat(pv, notNullValue());
final List<PluginDependencyView> deps = pv.getLocalPluginDependencies();
assertThat(deps, notNullValue());
assertThat(deps.size(), equalTo(1));
final PluginDependencyView pdv = deps.get(0);
assertThat(pdv, notNullValue());
assertThat(pdv.asArtifactRef().getVersionString(), equalTo("1.0"));
final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
discoveryConfig.setIncludeManagedDependencies(true);
discoveryConfig.setIncludeBuildSection(true);
discoveryConfig.setIncludeManagedPlugins(false);
EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
logger.info("Found {} relationships:\n\n {}", rels.size(), new JoinString("\n ", rels));
boolean seen = false;
for (final ProjectRelationship<?, ?> rel : rels) {
if (rel.getType() == RelationshipType.PLUGIN_DEP && !rel.isManaged()) {
if (seen) {
fail("Multiple plugin dependencies found!");
}
seen = true;
assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
}
}
if (!seen) {
fail("Plugin-dependency relationship not found!");
}
}
Aggregations