Search in sources :

Example 1 with Dependency

use of org.jfrog.build.api.Dependency in project build-info by JFrogDev.

the class DependencyBuilder method build.

/**
 * Assembles the dependency class
 *
 * @return Assembled dependency
 */
public Dependency build() {
    Dependency dependency = new Dependency();
    dependency.setId(id);
    dependency.setType(type);
    dependency.setScopes(scopes);
    dependency.setSha1(sha1);
    dependency.setSha256(sha256);
    dependency.setMd5(md5);
    dependency.setRequiredBy(requiredBy);
    dependency.setProperties(properties);
    return dependency;
}
Also used : Dependency(org.jfrog.build.api.Dependency)

Example 2 with Dependency

use of org.jfrog.build.api.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 = Lists.newArrayList();
        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(Sets.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, SHA1);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    String md5 = checksums.get(MD5);
                    String sha1 = checksums.get(SHA1);
                    dependencyBuilder.md5(md5).sha1(sha1);
                    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 : 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.api.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.api.builder.DependencyBuilder) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Module(org.jfrog.build.api.Module) File(java.io.File)

Example 3 with Dependency

use of org.jfrog.build.api.Dependency in project build-info by JFrogDev.

the class DependencyBuilderTest method testDefaultBuild.

/**
 * Validates the dependency values when using the defaults
 */
public void testDefaultBuild() {
    Dependency dependency = new DependencyBuilder().build();
    assertNull(dependency.getId(), "Unexpected default dependency ID.");
    assertNull(dependency.getType(), "Unexpected default dependency type.");
    assertNull(dependency.getScopes(), "Default dependency scopes should not have been initialized.");
    assertNull(dependency.getSha1(), "Default dependency SHA1 checksum should be null.");
    assertNull(dependency.getSha256(), "Default dependency SHA256 checksum should be null.");
    assertNull(dependency.getMd5(), "Default dependency MD5 checksum should be null.");
    assertNull(dependency.getRequiredBy(), "Default dependency required by should not have been initialized.");
    assertNull(dependency.getProperties(), "Default dependency properties should be null.");
}
Also used : Dependency(org.jfrog.build.api.Dependency)

Example 4 with Dependency

use of org.jfrog.build.api.Dependency in project build-info by JFrogDev.

the class DependencyBuilderTest method testBuilderSetters.

/**
 * Validates the dependency values after using the builder setters
 */
public void testBuilderSetters() {
    String id = "moo";
    String type = "bob";
    Set<String> scopes = Sets.newHashSet("mitzi");
    String sha1 = "pop";
    String sha256 = "lol";
    String md5 = "shmop";
    List<String> requiredBy = Lists.newArrayList("pitzi");
    Properties properties = new Properties();
    Dependency dependency = new DependencyBuilder().id(id).type(type).scopes(scopes).sha1(sha1).md5(md5).sha256(sha256).requiredBy(requiredBy).properties(properties).build();
    assertEquals(dependency.getId(), id, "Unexpected dependency ID.");
    assertEquals(dependency.getType(), type, "Unexpected dependency type.");
    assertEquals(dependency.getScopes(), scopes, "Unexpected dependency scopes.");
    assertEquals(dependency.getSha1(), sha1, "Unexpected dependency SHA1 checksum.");
    assertEquals(dependency.getSha256(), sha256, "Unexpected dependency SHA256 checksum.");
    assertEquals(dependency.getMd5(), md5, "Unexpected dependency SHA1 checksum.");
    assertEquals(dependency.getRequiredBy(), requiredBy, "Unexpected dependency required by.");
    assertEquals(dependency.getProperties(), properties, "Unexpected dependency properties.");
    assertTrue(dependency.getProperties().isEmpty(), "Dependency properties list should not have been populated.");
}
Also used : Dependency(org.jfrog.build.api.Dependency) Properties(java.util.Properties)

Example 5 with Dependency

use of org.jfrog.build.api.Dependency in project build-info by JFrogDev.

the class DependencyBuilderTest method testBuilderAddMethods.

/**
 * Validates the dependency values after using the builder add methods
 */
public void testBuilderAddMethods() {
    String requiredBy = "requiredMoo";
    String propertyKey = "key";
    String propertyValue = "value";
    Dependency dependency = new DependencyBuilder().addRequiredBy(requiredBy).addProperty(propertyKey, propertyValue).build();
    List<String> requiredByList = dependency.getRequiredBy();
    assertFalse(requiredByList.isEmpty(), "A dependency requirement should have been added.");
    assertEquals(requiredByList.iterator().next(), requiredBy, "Unexpected dependency requirement.");
    assertTrue(dependency.getProperties().containsKey(propertyKey), "A dependency property should have been added.");
    assertEquals(dependency.getProperties().get(propertyKey), propertyValue, "Unexpected dependency property value.");
}
Also used : Dependency(org.jfrog.build.api.Dependency)

Aggregations

Dependency (org.jfrog.build.api.Dependency)13 File (java.io.File)4 Artifact (org.jfrog.build.api.Artifact)3 Module (org.jfrog.build.api.Module)3 DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)3 Test (org.testng.annotations.Test)3 RandomAccessFile (java.io.RandomAccessFile)2 Properties (java.util.Properties)2 DependenciesDownloaderHelper (org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper)2 EndResolveEvent (org.apache.ivy.core.event.resolve.EndResolveEvent)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)1 ResolveReport (org.apache.ivy.core.report.ResolveReport)1 Project (org.apache.tools.ant.Project)1 DependencyBuilder (org.jfrog.build.api.builder.DependencyBuilder)1 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)1 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)1 FileSpec (org.jfrog.build.extractor.clientConfiguration.util.spec.FileSpec)1