Search in sources :

Example 1 with BuildDependencyBuilder

use of org.jfrog.build.api.builder.dependency.BuildDependencyBuilder in project build-info by JFrogDev.

the class BuildTest method testSetters.

/**
 * Validates the build values after using the build setters
 */
public void testSetters() {
    String version = "1.2.0";
    String name = "moo";
    String number = "15";
    BuildType buildType = GRADLE;
    Agent agent = new Agent("pop", "1.6");
    long durationMillis = 6L;
    String principal = "bob";
    String artifactoryPrincipal = "too";
    String artifactoryPluginVersion = "2.3.1";
    String url = "mitz";
    String parentName = "pooh";
    String parentNumber = "5";
    String vcsRevision = "2421";
    List<Module> modules = Lists.newArrayList();
    List<PromotionStatus> statuses = Lists.newArrayList();
    List<BuildDependency> buildDependencies = Arrays.asList(new BuildDependencyBuilder().name("foo").number("123").startedDate(new Date()).build(), new BuildDependencyBuilder().name("bar").number("456").startedDate(new Date()).build());
    Properties properties = new Properties();
    Build build = new Build();
    build.setVersion(version);
    build.setName(name);
    build.setNumber(number);
    build.setType(buildType);
    build.setAgent(agent);
    build.setDurationMillis(durationMillis);
    build.setPrincipal(principal);
    build.setArtifactoryPrincipal(artifactoryPrincipal);
    build.setArtifactoryPluginVersion(artifactoryPluginVersion);
    build.setUrl(url);
    build.setParentName(parentName);
    build.setParentNumber(parentNumber);
    build.setModules(modules);
    build.setStatuses(statuses);
    build.setProperties(properties);
    build.setVcsRevision(vcsRevision);
    build.setBuildDependencies(buildDependencies);
    assertEquals(build.getVersion(), version, "Unexpected build version.");
    assertEquals(build.getName(), name, "Unexpected build name.");
    assertEquals(build.getNumber(), number, "Unexpected build number.");
    assertEquals(build.getType(), buildType, "Unexpected build type.");
    assertEquals(build.getAgent(), agent, "Unexpected build agent.");
    assertEquals(build.getDurationMillis(), durationMillis, "Unexpected build duration millis.");
    assertEquals(build.getPrincipal(), principal, "Unexpected build principal.");
    assertEquals(build.getArtifactoryPrincipal(), artifactoryPrincipal, "Unexpected build artifactory principal.");
    assertEquals(build.getArtifactoryPluginVersion(), artifactoryPluginVersion, "Unexpected build artifactory principal.");
    assertEquals(build.getUrl(), url, "Unexpected build URL.");
    assertEquals(build.getParentName(), parentName, "Unexpected build parent build name.");
    assertEquals(build.getParentNumber(), parentNumber, "Unexpected build parent build number.");
    assertEquals(build.getVcsRevision(), vcsRevision, "Unexpected build vcs revision.");
    assertEquals(build.getModules(), modules, "Unexpected build modules.");
    assertTrue(build.getModules().isEmpty(), "Build modules list should not have been populated.");
    assertEquals(build.getStatuses(), statuses, "Unexpected build statuses.");
    assertTrue(build.getStatuses().isEmpty(), "Build statuses list should not have been populated.");
    assertEquals(build.getProperties(), properties, "Unexpected build properties.");
    assertTrue(build.getProperties().isEmpty(), "Build properties list should not have been populated.");
    assertEquals(build.getBuildDependencies(), buildDependencies, "Unexpected build dependencies list.");
}
Also used : BuildDependencyBuilder(org.jfrog.build.api.builder.dependency.BuildDependencyBuilder) Properties(java.util.Properties) BuildDependency(org.jfrog.build.api.dependency.BuildDependency) Date(java.util.Date) PromotionStatus(org.jfrog.build.api.release.PromotionStatus)

Example 2 with BuildDependencyBuilder

use of org.jfrog.build.api.builder.dependency.BuildDependencyBuilder in project build-info by JFrogDev.

the class BuildDependencyBuilderTest method testDefaultBuild.

/**
 * Validates the module values when using the defaults
 */
public void testDefaultBuild() {
    BuildDependency buildDependency = new BuildDependencyBuilder().name("foo").number("123").started(timestamp).build();
    assertNull(buildDependency.getUrl(), "URI should have not been initialized.");
}
Also used : BuildDependencyBuilder(org.jfrog.build.api.builder.dependency.BuildDependencyBuilder) BuildDependency(org.jfrog.build.api.dependency.BuildDependency)

Example 3 with BuildDependencyBuilder

use of org.jfrog.build.api.builder.dependency.BuildDependencyBuilder in project build-info by JFrogDev.

the class BuildDependencyBuilderTest method testBuilderSetters.

/**
 * Validates the build dependency values after using the builder setters
 */
public void testBuilderSetters() {
    String name = "foo";
    String number = "123";
    String url = "http://myhostA.com/artifactory/builds/foo/123/";
    BuildDependency buildDependency = new BuildDependencyBuilder().name(name).number(number).started(timestamp).url(url).build();
    assertEquals(buildDependency.getName(), name, "Unexpected name.");
    assertEquals(buildDependency.getNumber(), number, "Unexpected number.");
    assertEquals(buildDependency.getStarted(), timestamp, "Unexpected started.");
    assertEquals(buildDependency.getUrl(), url, "Unexpected url.");
}
Also used : BuildDependencyBuilder(org.jfrog.build.api.builder.dependency.BuildDependencyBuilder) BuildDependency(org.jfrog.build.api.dependency.BuildDependency)

Example 4 with BuildDependencyBuilder

use of org.jfrog.build.api.builder.dependency.BuildDependencyBuilder in project build-info by JFrogDev.

the class BuildDependenciesHelper method collectArtifactsToDownload.

private Set<DownloadableArtifact> collectArtifactsToDownload(Map<String, Map<String, List<BuildDependencyPattern>>> dependencyPatterns, List<BuildPatternArtifactsRequest> artifactsRequests, List<BuildPatternArtifacts> artifactsResponses, Set<BuildDependency> buildDependencies) {
    Set<DownloadableArtifact> downloadableArtifacts = Sets.newHashSet();
    verifySameSize(artifactsRequests, artifactsResponses);
    for (int i = 0; i < artifactsRequests.size(); i++) {
        BuildPatternArtifacts artifacts = artifactsResponses.get(i);
        if (artifacts == null) {
            // Pattern didn't match any results: wrong build name or build number.
            continue;
        }
        List<BuildDependencyPattern> buildDependencyPatterns = dependencyPatterns.get(artifacts.getBuildName()).get(artifactsRequests.get(i).getBuildNumber());
        for (int j = 0; j < buildDependencyPatterns.size(); j++) {
            BuildDependencyPattern buildDependencyPattern = buildDependencyPatterns.get(j);
            if (!buildDependencyPattern.getBuildName().equals(artifacts.getBuildName())) {
                throw new IllegalArgumentException(String.format("Build names don't match: [%s] != [%s]", buildDependencyPattern.getBuildName(), artifacts.getBuildName()));
            }
            final String message = String.format("Dependency on build [%s], number [%s]", buildDependencyPattern.getBuildName(), buildDependencyPattern.getBuildNumber());
            /**
             * Build number response is null for unresolved dependencies (wrong build name or build number).
             */
            if (artifacts.getBuildNumber() == null) {
                log.info(message + " - no results found, check correctness of dependency build name and build number.");
            } else {
                PatternResult patternResult = artifacts.getPatternResults().get(j);
                List<PatternArtifact> patternArtifacts = patternResult.getPatternArtifacts();
                log.info(message + String.format(", pattern [%s] - [%s] result%s found.", buildDependencyPattern.getPattern(), patternArtifacts.size(), (patternArtifacts.size() == 1 ? "" : "s")));
                for (PatternArtifact patternArtifact : patternArtifacts) {
                    // "libs-release-local/com/goldin/plugins/gradle/0.1.1/gradle-0.1.1.jar"
                    final String uri = patternArtifact.getUri();
                    final int indexOfFirstSlash = uri.indexOf('/');
                    assert (indexOfFirstSlash > 0) : String.format("Failed to locate '/' in [%s]", uri);
                    final String repoUrl = patternArtifact.getArtifactoryUrl() + '/' + uri.substring(0, indexOfFirstSlash);
                    final String filePath = uri.substring(indexOfFirstSlash + 1);
                    downloadableArtifacts.add(new DownloadableArtifact(repoUrl, buildDependencyPattern.getTargetDirectory(), filePath, buildDependencyPattern.getMatrixParams(), buildDependencyPattern.getPattern(), buildDependencyPattern.getPatternType()));
                }
                if (!patternArtifacts.isEmpty()) {
                    BuildDependency buildDependency = new BuildDependencyBuilder().name(artifacts.getBuildName()).number(artifacts.getBuildNumber()).url(artifacts.getUrl()).started(artifacts.getStarted()).build();
                    buildDependencies.add(buildDependency);
                }
            }
        }
    }
    return downloadableArtifacts;
}
Also used : BuildDependencyBuilder(org.jfrog.build.api.builder.dependency.BuildDependencyBuilder) BuildDependencyPattern(org.jfrog.build.api.dependency.pattern.BuildDependencyPattern)

Example 5 with BuildDependencyBuilder

use of org.jfrog.build.api.builder.dependency.BuildDependencyBuilder in project build-info by JFrogDev.

the class BuildTest method testAddBuildDependencyMethod.

public void testAddBuildDependencyMethod() {
    Build build = new Build();
    assertNull(build.getBuildDependencies(), "Default buildDependencies list should be null.");
    BuildDependency buildDependency = new BuildDependencyBuilder().name("foo").number("123").startedDate(new Date()).build();
    build.addBuildDependency(buildDependency);
    assertFalse(build.getBuildDependencies().isEmpty(), "BuildDependency object should have been added.");
    assertEquals(getOnlyElement(build.getBuildDependencies()), buildDependency, "Unexpected build dependency object.");
    BuildDependency otherBuildDependency = new BuildDependencyBuilder().name("bar").number("456").startedDate(new Date()).build();
    build.addBuildDependency(otherBuildDependency);
    assertEquals(build.getBuildDependencies().size(), 2, "Second BuildDependency object should have been added.");
    assertEquals(getLast(build.getBuildDependencies()), otherBuildDependency, "Unexpected build dependency object.");
}
Also used : BuildDependencyBuilder(org.jfrog.build.api.builder.dependency.BuildDependencyBuilder) BuildDependency(org.jfrog.build.api.dependency.BuildDependency) Date(java.util.Date)

Aggregations

BuildDependencyBuilder (org.jfrog.build.api.builder.dependency.BuildDependencyBuilder)5 BuildDependency (org.jfrog.build.api.dependency.BuildDependency)4 Date (java.util.Date)2 Properties (java.util.Properties)1 BuildDependencyPattern (org.jfrog.build.api.dependency.pattern.BuildDependencyPattern)1 PromotionStatus (org.jfrog.build.api.release.PromotionStatus)1