Search in sources :

Example 26 with Module

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

the class NpmBuildInfoExtractor method createBuild.

private BuildInfo createBuild(List<Dependency> dependencies, String moduleId) {
    Module module = new ModuleBuilder().type(ModuleType.NPM).id(moduleId).dependencies(dependencies).build();
    List<Module> modules = new ArrayList<>();
    modules.add(module);
    BuildInfo buildInfo = new BuildInfo();
    buildInfo.setModules(modules);
    return buildInfo;
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ArrayList(java.util.ArrayList) Module(org.jfrog.build.extractor.ci.Module)

Example 27 with Module

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

the class ArtifactoryBuildInfoTrigger method getOrCreateModule.

private Module getOrCreateModule(Map<String, String> attributes) {
    List<Module> modules = ctx.getModules();
    final String org = attributes.get("organisation");
    final String moduleName = attributes.get("module");
    String moduleKey = getModuleIdString(org, moduleName, "");
    String moduleId = getModuleIdString(org, moduleName, attributes.get("revision"));
    Module module = findModule(modules, moduleKey);
    if (module == null) {
        ModuleBuilder moduleBuilder = new ModuleBuilder().type(ModuleType.IVY).id(moduleId).repository(ctx.getClientConf().publisher.getRepoKey());
        module = moduleBuilder.build();
        modules.add(module);
    } else {
        module.setId(moduleId);
    }
    return module;
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) Module(org.jfrog.build.extractor.ci.Module)

Example 28 with Module

use of org.jfrog.build.extractor.ci.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(new ArrayList<>());
    }
    List<Artifact> excludedArtifacts = module.getExcludedArtifacts();
    if (excludedArtifacts == null) {
        module.setExcludedArtifacts(new ArrayList<>());
    }
    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_ALGORITHM);
    String sha1 = checksums.get(SHA1_ALGORITHM);
    String sha256 = checksums.get(SHA256_ALGORITHM);
    artifactBuilder.md5(md5).sha1(sha1).sha256(sha256);
    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.extractor.clientConfiguration.deploy.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.extractor.builder.ArtifactBuilder) Artifact(org.jfrog.build.extractor.ci.Artifact) Project(org.apache.tools.ant.Project) Module(org.jfrog.build.extractor.ci.Module) File(java.io.File)

Aggregations

Module (org.jfrog.build.extractor.ci.Module)28 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)18 IOException (java.io.IOException)9 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)7 Path (java.nio.file.Path)6 Dependency (org.jfrog.build.extractor.ci.Dependency)6 Test (org.testng.annotations.Test)6 File (java.io.File)5 Artifact (org.jfrog.build.extractor.ci.Artifact)5 ArrayList (java.util.ArrayList)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)3 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)3 DockerImage (org.jfrog.build.extractor.docker.types.DockerImage)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 Project (org.apache.tools.ant.Project)2 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1