Search in sources :

Example 1 with PublishEvent

use of org.apache.ivy.core.event.publish.PublishEvent in project build-info by JFrogDev.

the class ArtifactoryBuildInfoTrigger method collectModuleInformation.

/**
 * Collect module information for each module.
 *
 * @param event the Ivy publish event
 */
private void collectModuleInformation(IvyEvent event) {
    ArtifactoryClientConfiguration.PublisherHandler publisher = ctx.getClientConf().publisher;
    IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
    boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();
    Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
    // Finding module object from context
    @SuppressWarnings("unchecked") final Map<String, String> map = event.getAttributes();
    Module module = getOrCreateModule(map);
    List<Artifact> artifacts = module.getArtifacts();
    if (artifacts == null) {
        module.setArtifacts(Lists.<Artifact>newArrayList());
    }
    List<Artifact> excludedArtifacts = module.getExcludedArtifacts();
    if (excludedArtifacts == null) {
        module.setExcludedArtifacts(Lists.<Artifact>newArrayList());
    }
    final org.apache.ivy.core.module.descriptor.Artifact pubArtifact = ((PublishEvent) event).getArtifact();
    @SuppressWarnings("unchecked") Map<String, String> extraAttributes = pubArtifact.getExtraAttributes();
    // Using the original file, not the published one that can be far away (network wise)
    String file = map.get("file");
    // But all other attributes are taken from the actual published artifact
    final ModuleRevisionId mrid = pubArtifact.getModuleRevisionId();
    String moduleName = mrid.getName();
    String type = getType(pubArtifact);
    // By default simple name
    String name = pubArtifact.getName() + "-" + mrid.getRevision() + "." + pubArtifact.getExt();
    // Set name from name of published file
    String fullPath = IvyResolverHelper.calculateArtifactPath(publisher, map, extraAttributes);
    int lastSlash = fullPath.lastIndexOf('/');
    if (lastSlash > 0 && lastSlash + 1 < fullPath.length()) {
        name = fullPath.substring(lastSlash + 1);
    }
    project.log("[buildinfo:collect] Collecting artifact " + name + " for module " + moduleName + " using file " + file, Project.MSG_INFO);
    if (isArtifactExist(module.getArtifacts(), name) || isArtifactExist(module.getExcludedArtifacts(), name)) {
        return;
    }
    ArtifactBuilder artifactBuilder = new ArtifactBuilder(name);
    artifactBuilder.type(type);
    File artifactFile = new File(file);
    Map<String, String> checksums = calculateFileChecksum(artifactFile);
    String md5 = checksums.get(MD5);
    String sha1 = checksums.get(SHA1);
    artifactBuilder.md5(md5).sha1(sha1);
    Artifact artifact = artifactBuilder.build();
    if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(fullPath, patterns)) {
        module.getExcludedArtifacts().add(artifact);
    } else {
        module.getArtifacts().add(artifact);
    }
    @SuppressWarnings("unchecked") DeployDetails deployDetails = buildDeployDetails(artifactFile, artifact, ctx, map, extraAttributes);
    ctx.addDeployDetailsForModule(deployDetails);
    List<Module> contextModules = ctx.getModules();
    if (contextModules.indexOf(module) == -1) {
        ctx.addModule(module);
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) EndArtifactPublishEvent(org.apache.ivy.core.event.publish.EndArtifactPublishEvent) PublishEvent(org.apache.ivy.core.event.publish.PublishEvent) DeployDetails(org.jfrog.build.client.DeployDetails) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) ArtifactBuilder(org.jfrog.build.api.builder.ArtifactBuilder) Artifact(org.jfrog.build.api.Artifact) Project(org.apache.tools.ant.Project) Module(org.jfrog.build.api.Module) File(java.io.File)

Aggregations

File (java.io.File)1 EndArtifactPublishEvent (org.apache.ivy.core.event.publish.EndArtifactPublishEvent)1 PublishEvent (org.apache.ivy.core.event.publish.PublishEvent)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 Project (org.apache.tools.ant.Project)1 Artifact (org.jfrog.build.api.Artifact)1 Module (org.jfrog.build.api.Module)1 ArtifactBuilder (org.jfrog.build.api.builder.ArtifactBuilder)1 DeployDetails (org.jfrog.build.client.DeployDetails)1 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)1 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)1 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)1 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)1