Search in sources :

Example 1 with Dependency

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) Dependency(org.jfrog.build.extractor.ci.Dependency) EndResolveEvent(org.apache.ivy.core.event.resolve.EndResolveEvent) Project(org.apache.tools.ant.Project) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Module(org.jfrog.build.extractor.ci.Module) File(java.io.File)

Example 2 with Dependency

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);
}
Also used : DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.extractor.ci.Dependency) ArtifactMetaData(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.ArtifactMetaData) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with Dependency

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);
}
Also used : DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.extractor.ci.Dependency) ArtifactMetaData(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.ArtifactMetaData) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with Dependency

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);
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) File(java.io.File)

Example 5 with Dependency

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

Aggregations

Dependency (org.jfrog.build.extractor.ci.Dependency)29 File (java.io.File)12 DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)9 Module (org.jfrog.build.extractor.ci.Module)7 IOException (java.io.IOException)5 Test (org.testng.annotations.Test)5 Path (java.nio.file.Path)4 DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)4 RandomAccessFile (java.io.RandomAccessFile)3 ArrayList (java.util.ArrayList)3 Artifact (org.jfrog.build.extractor.ci.Artifact)3 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2