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);
}
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations