Search in sources :

Example 1 with Vcs

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

the class ArtifactoryBuildListener method doDeploy.

private void doDeploy(BuildEvent event) {
    IvyBuildInfoLog log = getBuildInfoLog(event);
    log.info("[buildinfo:ant] Starting deployment");
    Project project = event.getProject();
    Set<DeployDetails> deployDetails = ctx.getDeployDetails();
    BuildInfoBuilder builder = new BuildInfoBuilder(project.getName()).modules(ctx.getModules()).number("0").durationMillis(System.currentTimeMillis() - ctx.getBuildStartTime()).startedDate(new Date(ctx.getBuildStartTime())).buildAgent(new BuildAgent("Ivy", Ivy.getIvyVersion())).agent(new Agent("Ivy", Ivy.getIvyVersion()));
    ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
    String agentName = clientConf.info.getAgentName();
    String agentVersion = clientConf.info.getAgentVersion();
    if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
        builder.agent(new Agent(agentName, agentVersion));
    }
    String buildAgentName = clientConf.info.getBuildAgentName();
    String buildAgentVersion = clientConf.info.getBuildAgentVersion();
    if (StringUtils.isNotBlank(buildAgentName) && StringUtils.isNotBlank(buildAgentVersion)) {
        builder.buildAgent(new BuildAgent(buildAgentName, buildAgentVersion));
    }
    String buildName = clientConf.info.getBuildName();
    if (StringUtils.isNotBlank(buildName)) {
        builder.name(buildName);
    }
    String buildNumber = clientConf.info.getBuildNumber();
    if (StringUtils.isNotBlank(buildNumber)) {
        builder.number(buildNumber);
    }
    String buildUrl = clientConf.info.getBuildUrl();
    if (StringUtils.isNotBlank(buildUrl)) {
        builder.url(buildUrl);
    }
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        builder.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        builder.vcsUrl(vcsUrl);
    }
    Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
    if (!vcs.isEmpty()) {
        builder.vcs(Arrays.asList(vcs));
    }
    String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
    if (StringUtils.isNotBlank(artifactoryPluginVersion)) {
        builder.artifactoryPluginVersion(artifactoryPluginVersion);
    } else {
        builder.artifactoryPluginVersion("Unknown");
    }
    String principal = clientConf.info.getPrincipal();
    if (StringUtils.isNotBlank(principal)) {
        builder.principal(principal);
    }
    String parentBuildName = clientConf.info.getParentBuildName();
    if (StringUtils.isNotBlank(parentBuildName)) {
        builder.parentName(parentBuildName);
    }
    String parentBuildNumber = clientConf.info.getParentBuildNumber();
    if (StringUtils.isNotBlank(parentBuildNumber)) {
        builder.parentNumber(parentBuildNumber);
    }
    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);
        }
        builder.issues(issues);
    }
    for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
        MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
        builder.addRunParameters(matrixParameter);
    }
    BuildInfo buildInfo = builder.build();
    PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
    String contextUrl = clientConf.publisher.getContextUrl();
    String username = clientConf.publisher.getUsername();
    String password = clientConf.publisher.getPassword();
    try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, log)) {
        configureProxy(clientConf, artifactoryManager);
        configConnectionTimeout(clientConf, artifactoryManager);
        configRetriesParams(clientConf, artifactoryManager);
        if (clientConf.publisher.isPublishArtifacts()) {
            IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
            deployArtifacts(project, artifactoryManager, deployDetails, patterns);
        }
        if (clientConf.publisher.isPublishBuildInfo()) {
            Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, clientConf);
        }
        isDidDeploy = true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Agent(org.jfrog.build.extractor.ci.Agent) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) Issue(org.jfrog.build.extractor.ci.Issue) Issues(org.jfrog.build.extractor.ci.Issues) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Vcs(org.jfrog.build.extractor.ci.Vcs) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Date(java.util.Date) Project(org.apache.tools.ant.Project) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) IvyBuildInfoLog(org.jfrog.build.util.IvyBuildInfoLog) Map(java.util.Map)

Example 2 with Vcs

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

the class IssuesCollectorTest method testCollectIssuesWithRevision.

@Test
public void testCollectIssuesWithRevision() throws IOException, InterruptedException {
    List<Vcs> vcsList = Collections.singletonList(new Vcs("http://TESTING.com", "6198a6294722fdc75a570aac505784d2ec0d1818"));
    runCollectIssues("git_issues2_.git_suffix", vcsList, 2);
}
Also used : Vcs(org.jfrog.build.extractor.ci.Vcs) Test(org.testng.annotations.Test)

Example 3 with Vcs

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

the class IssuesCollectorTest method testCollectIssuesWithoutRevision.

@Test
public void testCollectIssuesWithoutRevision() throws IOException, InterruptedException {
    List<Vcs> vcsList = Collections.singletonList(new Vcs());
    runCollectIssues("git_issues_.git_suffix", vcsList, 2);
}
Also used : Vcs(org.jfrog.build.extractor.ci.Vcs) Test(org.testng.annotations.Test)

Example 4 with Vcs

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

the class GitUtilsTest method testExtractVcsWithSubmodule.

@Test
private void testExtractVcsWithSubmodule() throws IOException, URISyntaxException {
    String parentDotGitResource = "git_submodule_parent_.git_suffix";
    String submoduleDotGitResource = "git_submodule_.git_suffix";
    File testResourcesPath = new File(this.getClass().getResource("/gitutils").toURI()).getCanonicalFile();
    File parentDotGitFile = new File(testResourcesPath, ".git");
    String submoduleDotGitFilePath = testResourcesPath.toString() + File.separator + "subDir" + File.separator + "subModule" + File.separator + ".git";
    File submoduleDotGitFile = new File(submoduleDotGitFilePath);
    try {
        // Copy the parent folder and create .git.
        FileUtils.copyDirectory(new File(testResourcesPath, parentDotGitResource), parentDotGitFile);
        // Copy the submodule .git file to the correct path.
        FileUtils.copyFile(new File(testResourcesPath, submoduleDotGitResource), submoduleDotGitFile);
        // Get VCS info.
        Log testLog = new TestingLog();
        Vcs vcs = GitUtils.extractVcs((new File(submoduleDotGitFilePath)).getAbsoluteFile(), testLog);
        // Validate.
        Assert.assertNotNull(vcs);
        Assert.assertEquals(vcs.getUrl(), "https://github.com/jfrog/subModule.git");
        Assert.assertEquals(vcs.getRevision(), "thisIsADummyRevision");
    } finally {
        // Cleanup.
        FileUtils.forceDelete(submoduleDotGitFile);
        FileUtils.deleteDirectory(parentDotGitFile);
    }
}
Also used : Log(org.jfrog.build.api.util.Log) TestingLog(org.jfrog.build.extractor.util.TestingLog) Vcs(org.jfrog.build.extractor.ci.Vcs) TestingLog(org.jfrog.build.extractor.util.TestingLog) File(java.io.File) Test(org.testng.annotations.Test)

Example 5 with Vcs

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

the class GitUtils method extractVcs.

/**
 * Extract Vcs details from .git configuration.
 *
 * @return Vcs with the details found, empty Vcs if failed to find .git directory
 */
public static Vcs extractVcs(File workingDir, Log log) throws IOException {
    log.debug("Extracting Vcs details from the .git directory.");
    File dotGit = getDotGit(workingDir);
    if (dotGit == null) {
        log.debug("Could not find the .git directory.");
        return new Vcs();
    }
    if (dotGit.isFile()) {
        // dotGit is a file and not a directory, assume submodule.
        dotGit = getSubmoduleDotGit(dotGit);
    }
    Vcs vcs = new Vcs();
    vcs.setRevision(extractVcsRevision(dotGit, log));
    vcs.setUrl(extractVcsUrl(dotGit, log));
    vcs.setMessage(extractVcsMessage(dotGit, log));
    vcs.setBranch(extractVcsBranch(dotGit, log));
    return vcs;
}
Also used : Vcs(org.jfrog.build.extractor.ci.Vcs) File(java.io.File)

Aggregations

Vcs (org.jfrog.build.extractor.ci.Vcs)9 Test (org.testng.annotations.Test)5 File (java.io.File)4 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)3 IOException (java.io.IOException)2 Date (java.util.Date)2 Map (java.util.Map)2 Log (org.jfrog.build.api.util.Log)2 BuildInfoBuilder (org.jfrog.build.extractor.builder.BuildInfoBuilder)2 Agent (org.jfrog.build.extractor.ci.Agent)2 BuildAgent (org.jfrog.build.extractor.ci.BuildAgent)2 Issue (org.jfrog.build.extractor.ci.Issue)2 IssueTracker (org.jfrog.build.extractor.ci.IssueTracker)2 Issues (org.jfrog.build.extractor.ci.Issues)2 MatrixParameter (org.jfrog.build.extractor.ci.MatrixParameter)2 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)2 ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)2 TestingLog (org.jfrog.build.extractor.util.TestingLog)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1