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.");
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations