Search in sources :

Example 6 with Dependency

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

the class ModuleBuilderTest method testBuilderSetters.

/**
 * Validates the module values after using the builder setters
 */
public void testBuilderSetters() {
    String id = "moo";
    List<Artifact> artifacts = Lists.newArrayList();
    List<Dependency> dependencies = Lists.newArrayList();
    Properties properties = new Properties();
    Module module = new ModuleBuilder().id(id).artifacts(artifacts).dependencies(dependencies).properties(properties).build();
    assertEquals(module.getId(), id, "Unexpected module ID.");
    assertEquals(module.getArtifacts(), artifacts, "Unexpected module artifacts.");
    assertTrue(module.getArtifacts().isEmpty(), "Module artifacts list should not have been populated.");
    assertEquals(module.getDependencies(), dependencies, "Unexpected module dependencies.");
    assertTrue(module.getDependencies().isEmpty(), "Module dependencies list should not have been populated.");
    assertEquals(module.getProperties(), properties, "Unexpected module properties.");
    assertTrue(module.getProperties().isEmpty(), "Module properties list should not have been populated.");
}
Also used : Dependency(org.jfrog.build.api.Dependency) Properties(java.util.Properties) Module(org.jfrog.build.api.Module) Artifact(org.jfrog.build.api.Artifact)

Example 7 with Dependency

use of org.jfrog.build.api.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(dependenciesClient, ".", log);
    String repoUrl = dependenciesClient.getArtifactoryUrl() + "/" + localRepo + "/" + 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_NAME));
    Assert.assertEquals(artifactMetaData.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    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_NAME));
    Assert.assertEquals(dependency.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
}
Also used : DependenciesDownloaderHelper(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper) DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.api.Dependency) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 8 with Dependency

use of org.jfrog.build.api.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(dependenciesClient, ".", log);
    String repoUrl = dependenciesClient.getArtifactoryUrl() + "/" + localRepo + "/" + 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_NAME));
    Assert.assertEquals(artifactMetaData.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    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_NAME));
    Assert.assertEquals(dependency.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
}
Also used : DependenciesDownloaderHelper(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper) DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.api.Dependency) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 9 with Dependency

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

the class SpecsHelperIntegrationTest method integrationTests.

@Test(dataProvider = "testCases")
public void integrationTests(String testName, String uploadSpec, String downloadSpec, Expected expected) throws IOException, NoSuchAlgorithmException, URISyntaxException {
    Reporter.log("Running test: " + testName, true);
    // Upload artifacts.
    File uploadFromPath = new File(this.getClass().getResource("/workspace").toURI()).getCanonicalFile();
    List<Artifact> uploaded = specsHelper.uploadArtifactsBySpec(uploadSpec, uploadFromPath, new HashMap<String, String>(), buildInfoClient);
    Reporter.log("Uploaded " + uploaded.size() + " artifacts", true);
    // Download artifacts to compare against the expected result.
    List<Dependency> downloaded = specsHelper.downloadArtifactsBySpec(downloadSpec, dependenciesClient, tempWorkspace.getPath());
    Reporter.log("Downloaded " + downloaded.size() + " artifacts", true);
    // Verify expected results
    verifyExpected(expected);
}
Also used : Dependency(org.jfrog.build.api.Dependency) File(java.io.File) Artifact(org.jfrog.build.api.Artifact) Test(org.testng.annotations.Test)

Example 10 with Dependency

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

the class DependenciesDownloaderHelper method downloadArtifact.

/**
 * Download artifact.
 * @param downloadableArtifact download recipe
 * @param artifactMetaData the artifact metadata
 * @param uriWithParams full artifact uri with matrix params
 * @param filePath the path to file in file system
 * @return artifact dependency
 * @throws IOException
 */
Dependency downloadArtifact(DownloadableArtifact downloadableArtifact, ArtifactMetaData artifactMetaData, String uriWithParams, String filePath) throws IOException {
    String fileDestination = downloader.getTargetDir(downloadableArtifact.getTargetDirPath(), downloadableArtifact.getRelativeDirPath());
    Dependency dependencyResult = getDependencyLocally(artifactMetaData, fileDestination);
    if (dependencyResult != null) {
        return dependencyResult;
    }
    try {
        log.info(String.format("Downloading '%s'...", uriWithParams));
        Map<String, String> checksumsMap = artifactMetaData.getSize() >= MIN_SIZE_FOR_CONCURRENT_DOWNLOAD && artifactMetaData.isAcceptRange() ? downloadFileConcurrently(uriWithParams, artifactMetaData.getSize(), fileDestination, filePath) : downloadFile(uriWithParams, fileDestination);
        // If the checksums map is null then something went wrong and we should fail the build
        if (checksumsMap == null) {
            throw new IOException("Received null checksums map for downloaded file.");
        }
        dependencyResult = validateChecksumsAndBuildDependency(checksumsMap, artifactMetaData, filePath);
        log.info(String.format("Successfully downloaded '%s' to '%s'", uriWithParams, fileDestination));
        return dependencyResult;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
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