Search in sources :

Example 6 with Artifact

use of org.jfrog.build.api.Artifact in project build-info by JFrogDev.

the class SpecsHelper method convertDeployDetailsToArtifacts.

private List<Artifact> convertDeployDetailsToArtifacts(Set<DeployDetails> details) {
    List<Artifact> result = Lists.newArrayList();
    for (DeployDetails detail : details) {
        String ext = FilenameUtils.getExtension(detail.getFile().getName());
        Artifact artifact = new ArtifactBuilder(detail.getFile().getName()).md5(detail.getMd5()).sha1(detail.getSha1()).type(ext).build();
        result.add(artifact);
    }
    return result;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) ArtifactBuilder(org.jfrog.build.api.builder.ArtifactBuilder) Artifact(org.jfrog.build.api.Artifact)

Example 7 with Artifact

use of org.jfrog.build.api.Artifact in project build-info by JFrogDev.

the class BuildDeploymentHelper method prepareDeployableArtifacts.

private Set<DeployDetails> prepareDeployableArtifacts(Build build, Map<String, DeployDetails> deployableArtifactBuilders) {
    Set<DeployDetails> deployableArtifacts = Sets.newLinkedHashSet();
    List<Module> modules = build.getModules();
    for (Module module : modules) {
        List<Artifact> artifacts = module.getArtifacts();
        if (artifacts != null) {
            for (Artifact artifact : artifacts) {
                String artifactId = BuildInfoExtractorUtils.getArtifactId(module.getId(), artifact.getName());
                DeployDetails deployable = deployableArtifactBuilders.get(artifactId);
                if (deployable != null) {
                    File file = deployable.getFile();
                    setArtifactChecksums(file, artifact);
                    deployableArtifacts.add(new DeployDetails.Builder().artifactPath(deployable.getArtifactPath()).file(file).md5(artifact.getMd5()).sha1(artifact.getSha1()).addProperties(deployable.getProperties()).targetRepository(deployable.getTargetRepository()).build());
                }
            }
        }
    }
    return deployableArtifacts;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) Module(org.jfrog.build.api.Module) File(java.io.File) Artifact(org.jfrog.build.api.Artifact)

Example 8 with Artifact

use of org.jfrog.build.api.Artifact 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)

Example 9 with Artifact

use of org.jfrog.build.api.Artifact in project build-info by JFrogDev.

the class ModuleBuilderTest method testBuilderAddMethods.

/**
 * Validates the module values after using the builder add methods
 */
public void testBuilderAddMethods() {
    Artifact artifact = new Artifact();
    Dependency dependency = new Dependency();
    String propertyKey = "key";
    String propertyValue = "value";
    Module module = new ModuleBuilder().id("test").addArtifact(artifact).addDependency(dependency).addProperty(propertyKey, propertyValue).build();
    assertEquals(module.getId(), "test", "Unexpected module id");
    assertFalse(module.getArtifacts().isEmpty(), "A module artifact should have been added.");
    assertEquals(module.getArtifacts().get(0), artifact, "Unexpected module artifact.");
    assertFalse(module.getDependencies().isEmpty(), "A module dependency should have been added.");
    assertEquals(module.getDependencies().get(0), dependency, "Unexpected dependency artifact.");
    assertTrue(module.getProperties().containsKey(propertyKey), "A module property should have been added.");
    assertEquals(module.getProperties().get(propertyKey), propertyValue, "Unexpected module property value.");
}
Also used : Dependency(org.jfrog.build.api.Dependency) Module(org.jfrog.build.api.Module) Artifact(org.jfrog.build.api.Artifact)

Example 10 with Artifact

use of org.jfrog.build.api.Artifact in project build-info by JFrogDev.

the class ArtifactBuilder method build.

/**
 * Assembles the artifact class
 *
 * @return Assembled dependency
 */
public Artifact build() {
    if (StringUtils.isBlank(name)) {
        throw new IllegalArgumentException("Artifact must have a name");
    }
    Artifact artifact = new Artifact();
    artifact.setName(name);
    artifact.setType(type);
    artifact.setSha1(sha1);
    artifact.setSha256(sha256);
    artifact.setMd5(md5);
    artifact.setProperties(properties);
    return artifact;
}
Also used : Artifact(org.jfrog.build.api.Artifact)

Aggregations

Artifact (org.jfrog.build.api.Artifact)10 Module (org.jfrog.build.api.Module)4 File (java.io.File)3 Dependency (org.jfrog.build.api.Dependency)3 DeployDetails (org.jfrog.build.client.DeployDetails)3 Properties (java.util.Properties)2 ArtifactBuilder (org.jfrog.build.api.builder.ArtifactBuilder)2 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 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 Test (org.testng.annotations.Test)1