Search in sources :

Example 1 with Artifact

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

the class PropertiesTest method propsTest.

@Test
public void propsTest() throws Exception {
    mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    propsTestPath = new File(this.getClass().getResource(PROPS_TEST_PATH).toURI()).getCanonicalFile();
    downloadSpec = readSpec(new File(propsTestPath, DOWNLOAD_SPEC), tempWorkspace.getPath());
    // Upload artifacts.
    String uploadSpec = readSpec(new File(propsTestPath, UPLOAD_SPEC), tempWorkspace.getPath());
    File uploadFromPath = new File(this.getClass().getResource("/workspace").toURI()).getCanonicalFile();
    List<Artifact> uploaded = specsHelper.uploadArtifactsBySpec(uploadSpec, uploadFromPath, new HashMap<>(), artifactoryManagerBuilder);
    Reporter.log("Uploaded " + uploaded.size() + " artifacts", true);
    // Edit properties on the uploaded artifacts and verify.
    editPropsAndVerify("setProps.json", EditPropertiesHelper.EditPropertiesActionType.SET, "p=v+1+d!", "setExpected.json");
    editPropsAndVerify("deleteProps.json", EditPropertiesHelper.EditPropertiesActionType.DELETE, "p", "deleteExpected.json");
}
Also used : File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Artifact(org.jfrog.build.extractor.ci.Artifact) Test(org.testng.annotations.Test)

Example 2 with Artifact

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

the class SpecsHelperIntegrationTest method integrationTests.

@Test(dataProvider = "testCases")
public void integrationTests(SingleSpecTest specTest) throws Exception {
    Reporter.log("Running test: " + specTest.testPath, false);
    // Upload artifacts.
    File uploadFromPath = new File(this.getClass().getResource("/workspace").toURI()).getCanonicalFile();
    List<Artifact> uploaded = specsHelper.uploadArtifactsBySpec(specTest.uploadSpec, uploadFromPath, new HashMap<>(), artifactoryManagerBuilder);
    Reporter.log("Uploaded " + uploaded.size() + " artifacts", false);
    // Download artifacts to compare against the expected result.
    List<Dependency> downloaded = specsHelper.downloadArtifactsBySpec(specTest.downloadSpec, artifactoryManager, tempWorkspace.getPath());
    Reporter.log("Downloaded " + downloaded.size() + " artifacts", false);
    // Verify expected results
    verifyExpected(specTest.expected, tempWorkspace);
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) File(java.io.File) Artifact(org.jfrog.build.extractor.ci.Artifact) Test(org.testng.annotations.Test)

Example 3 with Artifact

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

the class SpecsHelper method convertDeployDetailsToArtifacts.

private List<Artifact> convertDeployDetailsToArtifacts(Set<DeployDetails> details) {
    List<Artifact> result = new ArrayList<>();
    for (DeployDetails detail : details) {
        String ext = FilenameUtils.getExtension(detail.getFile().getName());
        ArtifactBuilder artifactBuilder = new ArtifactBuilder(detail.getFile().getName());
        artifactBuilder.md5(detail.getMd5()).sha1(detail.getSha1()).sha256(detail.getSha256()).type(ext).localPath(detail.getFile().getAbsolutePath()).remotePath(detail.getArtifactPath()).build();
        result.add(artifactBuilder.build());
    }
    return result;
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ArrayList(java.util.ArrayList) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) Artifact(org.jfrog.build.extractor.ci.Artifact)

Example 4 with Artifact

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

the class Utils method checkWebserviceArtifact.

/**
 * Check webservice-1.0-SNAPSHOT.jar artifact under webservice module.
 *
 * @param webservice - The webservice module
 */
private static void checkWebserviceArtifact(Module webservice) {
    Artifact webServiceJar = webservice.getArtifacts().stream().filter(artifact -> StringUtils.equals(artifact.getName(), "webservice-1.0-SNAPSHOT.jar")).findAny().orElse(null);
    assertNotNull(webServiceJar);
    assertEquals(webServiceJar.getType(), "jar");
    assertEquals(webServiceJar.getRemotePath(), "org/jfrog/test/gradle/publish/webservice/1.0-SNAPSHOT/webservice-1.0-SNAPSHOT.jar");
    assertTrue(StringUtils.isNotBlank(webServiceJar.getMd5()));
    assertTrue(StringUtils.isNotBlank(webServiceJar.getSha1()));
    assertTrue(StringUtils.isNotBlank(webServiceJar.getSha256()));
}
Also used : Artifact(org.jfrog.build.extractor.ci.Artifact)

Example 5 with Artifact

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

the class GradleBuildInfoExtractor method extract.

@Override
public BuildInfo extract(Project rootProject) {
    String buildName = clientConf.info.getBuildName();
    BuildInfoBuilder bib = new BuildInfoBuilder(buildName);
    String buildNumber = clientConf.info.getBuildNumber();
    bib.number(buildNumber);
    String buildStartedIso = clientConf.info.getBuildStarted();
    Date buildStartDate = null;
    try {
        buildStartDate = new SimpleDateFormat(BuildInfo.STARTED_FORMAT).parse(buildStartedIso);
    } catch (ParseException e) {
        log.error("Build start date format error: " + buildStartedIso, e);
    }
    bib.started(buildStartedIso);
    BuildAgent buildAgent = new BuildAgent(clientConf.info.getBuildAgentName(), clientConf.info.getBuildAgentVersion());
    bib.buildAgent(buildAgent);
    // CI agent
    String agentName = clientConf.info.getAgentName();
    String agentVersion = clientConf.info.getAgentVersion();
    if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
        bib.agent(new Agent(agentName, agentVersion));
    } else {
        // Fallback for standalone builds
        bib.agent(new Agent(buildAgent.getName(), buildAgent.getVersion()));
    }
    long durationMillis = buildStartDate != null ? System.currentTimeMillis() - buildStartDate.getTime() : 0;
    bib.durationMillis(durationMillis);
    Set<File> moduleFilesWithModules = moduleInfoFileProducers.stream().filter(ModuleInfoFileProducer::hasModules).flatMap(moduleInfoFileProducer -> moduleInfoFileProducer.getModuleInfoFiles().getFiles().stream()).collect(Collectors.toSet());
    moduleFilesWithModules.forEach(moduleFile -> {
        try {
            Module module = ModuleExtractorUtils.readModuleFromFile(moduleFile);
            List<Artifact> artifacts = module.getArtifacts();
            List<Dependency> dependencies = module.getDependencies();
            if ((artifacts != null && !artifacts.isEmpty()) || (dependencies != null && !dependencies.isEmpty())) {
                bib.addModule(module);
            }
        } catch (IOException e) {
            throw new RuntimeException("Cannot load module info from file: " + moduleFile.getAbsolutePath(), e);
        }
    });
    String parentName = clientConf.info.getParentBuildName();
    String parentNumber = clientConf.info.getParentBuildNumber();
    if (parentName != null && parentNumber != null) {
        bib.parentName(parentName);
        bib.parentNumber(parentNumber);
    }
    String principal = clientConf.info.getPrincipal();
    if (StringUtils.isBlank(principal)) {
        principal = System.getProperty("user.name");
    }
    bib.principal(principal);
    String artifactoryPrincipal = clientConf.publisher.getUsername();
    if (StringUtils.isBlank(artifactoryPrincipal)) {
        artifactoryPrincipal = System.getProperty("user.name");
    }
    bib.artifactoryPrincipal(artifactoryPrincipal);
    String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
    if (StringUtils.isBlank(artifactoryPluginVersion)) {
        artifactoryPluginVersion = "Unknown";
    }
    bib.artifactoryPluginVersion(artifactoryPluginVersion);
    String buildUrl = clientConf.info.getBuildUrl();
    if (StringUtils.isNotBlank(buildUrl)) {
        bib.url(buildUrl);
    }
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        bib.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        bib.vcsUrl(vcsUrl);
    }
    Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
    if (!vcs.isEmpty()) {
        bib.vcs(Arrays.asList(vcs));
    }
    if (clientConf.info.isReleaseEnabled()) {
        String stagingRepository = clientConf.publisher.getRepoKey();
        String comment = clientConf.info.getReleaseComment();
        if (comment == null) {
            comment = "";
        }
        bib.addStatus(new PromotionStatusBuilder(Promotion.STAGED).timestampDate(buildStartDate).comment(comment).repository(stagingRepository).ciUser(principal).user(artifactoryPrincipal).build());
    }
    String issueTrackerName = clientConf.info.issues.getIssueTrackerName();
    if (StringUtils.isNotBlank(issueTrackerName)) {
        Issues issues = new Issues();
        issues.setAggregateBuildIssues(clientConf.info.issues.getAggregateBuildIssues());
        issues.setAggregationBuildStatus(clientConf.info.issues.getAggregationBuildStatus());
        issues.setTracker(new IssueTracker(issueTrackerName, clientConf.info.issues.getIssueTrackerVersion()));
        Set<Issue> affectedIssuesSet = clientConf.info.issues.getAffectedIssuesSet();
        if (!affectedIssuesSet.isEmpty()) {
            issues.setAffectedIssues(affectedIssuesSet);
        }
        bib.issues(issues);
    }
    for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
        MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
        bib.addRunParameters(matrixParameter);
    }
    log.debug("buildInfoBuilder = " + bib);
    // for backward compatibility for Artifactory 2.2.3
    BuildInfo buildInfo = bib.build();
    if (parentName != null && parentNumber != null) {
        buildInfo.setParentBuildId(parentName);
    }
    PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
    return buildInfo;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) Agent(org.jfrog.build.extractor.ci.Agent) StringUtils(org.apache.commons.lang3.StringUtils) Logger(org.gradle.api.logging.Logger) Issues(org.jfrog.build.extractor.ci.Issues) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Artifact(org.jfrog.build.extractor.ci.Artifact) BuildInfoExtractor(org.jfrog.build.extractor.BuildInfoExtractor) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) Module(org.jfrog.build.extractor.ci.Module) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Map(java.util.Map) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) ParseException(java.text.ParseException) Dependency(org.jfrog.build.extractor.ci.Dependency) PackageManagerUtils(org.jfrog.build.extractor.packageManager.PackageManagerUtils) Project(org.gradle.api.Project) PromotionStatusBuilder(org.jfrog.build.api.builder.PromotionStatusBuilder) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Logging(org.gradle.api.logging.Logging) Issue(org.jfrog.build.extractor.ci.Issue) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Promotion(org.jfrog.build.api.release.Promotion) Vcs(org.jfrog.build.extractor.ci.Vcs) ModuleExtractorUtils(org.jfrog.build.extractor.ModuleExtractorUtils) ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Issue(org.jfrog.build.extractor.ci.Issue) Issues(org.jfrog.build.extractor.ci.Issues) Vcs(org.jfrog.build.extractor.ci.Vcs) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Agent(org.jfrog.build.extractor.ci.Agent) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Dependency(org.jfrog.build.extractor.ci.Dependency) IOException(java.io.IOException) Date(java.util.Date) Artifact(org.jfrog.build.extractor.ci.Artifact) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) PromotionStatusBuilder(org.jfrog.build.api.builder.PromotionStatusBuilder) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ParseException(java.text.ParseException) Module(org.jfrog.build.extractor.ci.Module) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Map(java.util.Map)

Aggregations

Artifact (org.jfrog.build.extractor.ci.Artifact)14 File (java.io.File)8 Module (org.jfrog.build.extractor.ci.Module)5 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)3 ArtifactBuilder (org.jfrog.build.extractor.builder.ArtifactBuilder)3 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)3 Dependency (org.jfrog.build.extractor.ci.Dependency)3 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)3 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)2 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1