Search in sources :

Example 66 with Transfer

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);
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) Location(org.commonjava.maven.galley.model.Location)

Example 67 with Transfer

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) Transfer(org.commonjava.maven.galley.model.Transfer) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 68 with Transfer

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;
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ThreadContext(org.commonjava.cdi.util.weft.ThreadContext) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Example 69 with Transfer

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;
    }
}
Also used : Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) IOException(java.io.IOException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) ModelProcessorConfig(org.commonjava.maven.galley.maven.rel.ModelProcessorConfig) Transfer(org.commonjava.maven.galley.model.Transfer) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) HashSet(java.util.HashSet)

Example 70 with Transfer

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!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

Transfer (org.commonjava.maven.galley.model.Transfer)154 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)63 Test (org.junit.Test)62 IOException (java.io.IOException)39 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)38 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)37 InputStream (java.io.InputStream)27 StoreKey (org.commonjava.indy.model.core.StoreKey)27 Logger (org.slf4j.Logger)26 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)22 ByteArrayInputStream (java.io.ByteArrayInputStream)21 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)21 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 Group (org.commonjava.indy.model.core.Group)20 ArrayList (java.util.ArrayList)19 IndyDataException (org.commonjava.indy.data.IndyDataException)19 OutputStream (java.io.OutputStream)15 HashSet (java.util.HashSet)15 Location (org.commonjava.maven.galley.model.Location)14 TransferException (org.commonjava.maven.galley.TransferException)12