use of org.jfrog.build.extractor.ci.Dependency 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 = new ArrayList<>();
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(CommonUtils.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_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
} catch (Exception e) {
throw new RuntimeException(e);
}
String md5 = checksums.get(MD5_ALGORITHM);
String sha1 = checksums.get(SHA1_ALGORITHM);
String sha256 = checksums.get(SHA256_ALGORITHM);
dependencyBuilder.md5(md5).sha1(sha1).sha256(sha256);
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);
}
}
use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.
the class DownloadTest method testDownloadArtifact.
@Test(dataProvider = "testDownloadFilesProvider")
public void testDownloadArtifact(Map<String, String> uploadedChecksum, String fileName, long fileSize) throws Exception {
DependenciesDownloaderHelper dependenciesDownloaderHelper = new DependenciesDownloaderHelper(artifactoryManager, ".", log);
String repoUrl = localRepo1 + "/" + TEST_REPO_PATH;
String targetDirPath = tempWorkspace.getPath() + File.separatorChar + "download" + File.separatorChar;
String url = repoUrl + "/" + fileName;
ArtifactMetaData artifactMetaData = dependenciesDownloaderHelper.downloadArtifactMetaData(url);
Assert.assertEquals(artifactMetaData.getMd5(), uploadedChecksum.get(MD5_ALGORITHM));
Assert.assertEquals(artifactMetaData.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM));
Assert.assertEquals(artifactMetaData.getSize(), fileSize);
DownloadableArtifact downloadableArtifact = new DownloadableArtifact(repoUrl, targetDirPath, fileName, "", fileName, PatternType.NORMAL);
Dependency dependency = dependenciesDownloaderHelper.downloadArtifact(downloadableArtifact, artifactMetaData, url, fileName);
Assert.assertEquals(dependency.getId(), fileName);
Assert.assertEquals(dependency.getMd5(), uploadedChecksum.get(MD5_ALGORITHM));
Assert.assertEquals(dependency.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM));
Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
}
use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.
the class DownloadTest method testDownloadArtifactWithoutContentLength.
@Test(dataProvider = "testDownloadFilesProvider")
public void testDownloadArtifactWithoutContentLength(Map<String, String> uploadedChecksum, String fileName, long fileSize) throws Exception {
DependenciesDownloaderHelper dependenciesDownloaderHelper = new DependenciesDownloaderHelper(artifactoryManager, ".", log);
String repoUrl = localRepo1 + "/" + TEST_REPO_PATH;
String targetDirPath = tempWorkspace.getPath() + File.separatorChar + "download" + File.separatorChar;
String url = repoUrl + "/" + fileName;
ArtifactMetaData artifactMetaData = dependenciesDownloaderHelper.downloadArtifactMetaData(url);
Assert.assertEquals(artifactMetaData.getMd5(), uploadedChecksum.get(MD5_ALGORITHM));
Assert.assertEquals(artifactMetaData.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM));
Assert.assertEquals(artifactMetaData.getSize(), fileSize);
// When content-length is missing
artifactMetaData.setSize(0);
DownloadableArtifact downloadableArtifact = new DownloadableArtifact(repoUrl, targetDirPath, fileName, "", fileName, PatternType.NORMAL);
Dependency dependency = dependenciesDownloaderHelper.downloadArtifact(downloadableArtifact, artifactMetaData, url, fileName);
Assert.assertEquals(dependency.getId(), fileName);
Assert.assertEquals(dependency.getMd5(), uploadedChecksum.get(MD5_ALGORITHM));
Assert.assertEquals(dependency.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM));
Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
}
use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.
the class PropertiesTest method editPropsAndVerify.
private void editPropsAndVerify(String specPath, EditPropertiesHelper.EditPropertiesActionType editType, String props, String expectedPath) throws IOException {
String spec = readSpec(new File(propsTestPath, specPath), tempWorkspace.getPath());
Expected expected = mapper.readValue(new File(propsTestPath, expectedPath), Expected.class);
// Edit Properties on the uploaded artifacts
specsHelper.editPropertiesBySpec(spec, artifactoryManager, editType, props);
// DownloadBase artifacts to compare against the expected result.
List<Dependency> downloaded = specsHelper.downloadArtifactsBySpec(downloadSpec, artifactoryManager, tempWorkspace.getPath());
Reporter.log("Downloaded " + downloaded.size() + " artifacts", true);
// Verify expected results
verifyExpected(expected, tempWorkspace);
// Clean all files from download's target
FileUtils.deleteDirectory(tempWorkspace);
}
use of org.jfrog.build.extractor.ci.Dependency 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);
}
Aggregations