Search in sources :

Example 1 with DownloadableArtifact

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

the class AntPatternsDependenciesHelper method performPatternSearch.

private Set<DownloadableArtifact> performPatternSearch(DependencyPattern dependencyPattern) throws IOException {
    Set<DownloadableArtifact> downloadableArtifacts = Sets.newHashSet();
    String pattern = dependencyPattern.getPattern();
    PatternResultFileSet fileSet = downloader.getClient().searchArtifactsByPattern(pattern);
    Set<String> filesToDownload = fileSet.getFiles();
    log.info("Found " + filesToDownload.size() + " dependencies by doing a pattern search.");
    for (String fileToDownload : filesToDownload) {
        downloadableArtifacts.add(new DownloadableArtifact(fileSet.getRepoUri(), dependencyPattern.getTargetDirectory(), fileToDownload, dependencyPattern.getMatrixParams(), pattern, dependencyPattern.getPatternType()));
    }
    return downloadableArtifacts;
}
Also used : PatternResultFileSet(org.jfrog.build.api.dependency.PatternResultFileSet) DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact)

Example 2 with DownloadableArtifact

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

the class AntPatternsDependenciesHelper method performPropertySearch.

private Set<DownloadableArtifact> performPropertySearch(DependencyPattern dependencyPattern) throws IOException {
    Set<DownloadableArtifact> downloadableArtifacts = Sets.newHashSet();
    String pattern = dependencyPattern.getPattern();
    String matrixParams = dependencyPattern.getMatrixParams();
    PropertySearchResult propertySearchResult = downloader.getClient().searchArtifactsByProperties(matrixParams);
    List<PropertySearchResult.SearchEntry> filteredEntries = filterResultEntries(propertySearchResult.getResults(), pattern);
    log.info("Found " + filteredEntries.size() + " dependencies by doing a property search.");
    for (PropertySearchResult.SearchEntry searchEntry : filteredEntries) {
        downloadableArtifacts.add(new DownloadableArtifact(searchEntry.getRepoUri(), dependencyPattern.getTargetDirectory(), searchEntry.getFilePath(), matrixParams, pattern, dependencyPattern.getPatternType()));
    }
    return downloadableArtifacts;
}
Also used : DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) PropertySearchResult(org.jfrog.build.api.dependency.PropertySearchResult)

Example 3 with DownloadableArtifact

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

the class DependenciesDownloaderHelper method removeUnusedArtifactsFromLocal.

private void removeUnusedArtifactsFromLocal(Set<DownloadableArtifact> downloadableArtifacts) throws IOException {
    Set<String> forDeletionFiles = Sets.newHashSet();
    Set<String> allResolvesFiles = Sets.newHashSet();
    for (DownloadableArtifact downloadableArtifact : downloadableArtifacts) {
        String fileDestination = downloader.getTargetDir(downloadableArtifact.getTargetDirPath(), downloadableArtifact.getRelativeDirPath());
        allResolvesFiles.add(fileDestination);
        if (PatternType.DELETE.equals(downloadableArtifact.getPatternType())) {
            forDeletionFiles.add(fileDestination);
        }
    }
    downloader.removeUnusedArtifactsFromLocal(allResolvesFiles, forDeletionFiles);
}
Also used : DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact)

Example 4 with DownloadableArtifact

use of org.jfrog.build.api.dependency.DownloadableArtifact 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 5 with DownloadableArtifact

use of org.jfrog.build.api.dependency.DownloadableArtifact 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)

Aggregations

DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)8 Dependency (org.jfrog.build.api.Dependency)3 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 DependenciesDownloaderHelper (org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper)2 Test (org.testng.annotations.Test)2 Pattern (java.util.regex.Pattern)1 PatternResultFileSet (org.jfrog.build.api.dependency.PatternResultFileSet)1 PropertySearchResult (org.jfrog.build.api.dependency.PropertySearchResult)1 AqlSearchResult (org.jfrog.build.api.search.AqlSearchResult)1