Search in sources :

Example 1 with Module

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

the class ModuleBuilder method build.

/**
 * Assembles the module class
 *
 * @return Assembled module
 */
public Module build() {
    if (id == null || id.trim().length() == 0) {
        throw new IllegalArgumentException("Cannot build module entity without Module ID value");
    }
    Module module = new Module();
    module.setId(id.trim());
    module.setArtifacts(artifacts);
    module.setDependencies(dependencies);
    module.setProperties(properties);
    module.setExcludedArtifacts(excludedArtifacts);
    return module;
}
Also used : Module(org.jfrog.build.api.Module)

Example 2 with Module

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

the class ArtifactoryBuildInfoTrigger method collectDependencyInformation.

/**
 * Collect dependency information during the build.
 *
 * @param event The end of resolution Ivy event
 */
private void collectDependencyInformation(IvyEvent event) {
    Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
    ResolveReport report = ((EndResolveEvent) event).getReport();
    @SuppressWarnings("unchecked") Map<String, String> attributes = event.getAttributes();
    Module module = getOrCreateModule(attributes);
    project.log("[buildinfo:collect] Collecting dependencies for " + module.getId(), Project.MSG_INFO);
    if (module.getDependencies() == null || module.getDependencies().isEmpty()) {
        String[] configurations = report.getConfigurations();
        List<Dependency> moduleDependencies = Lists.newArrayList();
        for (String configuration : configurations) {
            project.log("[buildinfo:collect] Configuration: " + configuration + " Dependencies", Project.MSG_DEBUG);
            ConfigurationResolveReport configurationReport = report.getConfigurationReport(configuration);
            ArtifactDownloadReport[] allArtifactsReports = configurationReport.getAllArtifactsReports();
            for (final ArtifactDownloadReport artifactsReport : allArtifactsReports) {
                project.log("[buildinfo:collect] Artifact Download Report for configuration: " + configuration + " : " + artifactsReport, Project.MSG_DEBUG);
                ModuleRevisionId id = artifactsReport.getArtifact().getModuleRevisionId();
                String type = getType(artifactsReport.getArtifact());
                Dependency dependency = findDependencyInList(id, type, moduleDependencies);
                if (dependency == null) {
                    DependencyBuilder dependencyBuilder = new DependencyBuilder();
                    dependencyBuilder.type(type).scopes(Sets.newHashSet(configuration));
                    String idString = getModuleIdString(id.getOrganisation(), id.getName(), id.getRevision());
                    dependencyBuilder.id(idString);
                    File file = artifactsReport.getLocalFile();
                    Map<String, String> checksums;
                    try {
                        checksums = FileChecksumCalculator.calculateChecksums(file, MD5, SHA1);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    String md5 = checksums.get(MD5);
                    String sha1 = checksums.get(SHA1);
                    dependencyBuilder.md5(md5).sha1(sha1);
                    dependency = dependencyBuilder.build();
                    moduleDependencies.add(dependency);
                    project.log("[buildinfo:collect] Added dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                } else {
                    if (!dependency.getScopes().contains(configuration)) {
                        dependency.getScopes().add(configuration);
                        project.log("[buildinfo:collect] Added scope " + configuration + " to dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                    } else {
                        project.log("[buildinfo:collect] Find same dependency twice in configuration '" + configuration + "' for dependency '" + artifactsReport + "'", Project.MSG_WARN);
                    }
                }
            }
        }
        module.setDependencies(moduleDependencies);
    }
}
Also used : ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) Dependency(org.jfrog.build.api.Dependency) EndResolveEvent(org.apache.ivy.core.event.resolve.EndResolveEvent) Project(org.apache.tools.ant.Project) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyBuilder(org.jfrog.build.api.builder.DependencyBuilder) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Module(org.jfrog.build.api.Module) File(java.io.File)

Example 3 with Module

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

the class ModuleBuilderTest method testBuilderSetters.

/**
 * Validates the module values after using the builder setters
 */
public void testBuilderSetters() {
    String id = "moo";
    List<Artifact> artifacts = Lists.newArrayList();
    List<Dependency> dependencies = Lists.newArrayList();
    Properties properties = new Properties();
    Module module = new ModuleBuilder().id(id).artifacts(artifacts).dependencies(dependencies).properties(properties).build();
    assertEquals(module.getId(), id, "Unexpected module ID.");
    assertEquals(module.getArtifacts(), artifacts, "Unexpected module artifacts.");
    assertTrue(module.getArtifacts().isEmpty(), "Module artifacts list should not have been populated.");
    assertEquals(module.getDependencies(), dependencies, "Unexpected module dependencies.");
    assertTrue(module.getDependencies().isEmpty(), "Module dependencies list should not have been populated.");
    assertEquals(module.getProperties(), properties, "Unexpected module properties.");
    assertTrue(module.getProperties().isEmpty(), "Module properties list should not have been populated.");
}
Also used : Dependency(org.jfrog.build.api.Dependency) Properties(java.util.Properties) Module(org.jfrog.build.api.Module) Artifact(org.jfrog.build.api.Artifact)

Example 4 with Module

use of org.jfrog.build.api.Module 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 5 with Module

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

Module (org.jfrog.build.api.Module)8 Artifact (org.jfrog.build.api.Artifact)4 File (java.io.File)3 Dependency (org.jfrog.build.api.Dependency)3 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)3 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 Project (org.apache.tools.ant.Project)2 DeployDetails (org.jfrog.build.client.DeployDetails)2 Properties (java.util.Properties)1 EndArtifactPublishEvent (org.apache.ivy.core.event.publish.EndArtifactPublishEvent)1 PublishEvent (org.apache.ivy.core.event.publish.PublishEvent)1 EndResolveEvent (org.apache.ivy.core.event.resolve.EndResolveEvent)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)1 ResolveReport (org.apache.ivy.core.report.ResolveReport)1 ArtifactBuilder (org.jfrog.build.api.builder.ArtifactBuilder)1 DependencyBuilder (org.jfrog.build.api.builder.DependencyBuilder)1 ModuleBuilder (org.jfrog.build.api.builder.ModuleBuilder)1 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)1