Search in sources :

Example 11 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class DownloadTest method testDownloadArtifactFromDifferentPath.

public void testDownloadArtifactFromDifferentPath() throws IOException {
    String targetDirPath = tempWorkspace.getPath() + File.separatorChar + "testDownloadDupArtifactFromDifferentPath" + File.separatorChar;
    FileSpec fileSpec = new FileSpec();
    // Upload one file to different locations in Artifactory.
    try {
        File file = createRandomFile(tempWorkspace.getPath() + File.pathSeparatorChar + "file", 1);
        for (int i = 0; i < 3; i++) {
            String filePath = TEST_REPO_PATH + "/" + i + "/file";
            DeployDetails deployDetails = new DeployDetails.Builder().file(file).artifactPath(filePath).targetRepository(localRepo1).explode(false).packageType(DeployDetails.PackageType.GENERIC).build();
            FilesGroup fg = new FilesGroup();
            fg.setPattern(localRepo1 + "/" + filePath);
            fg.setTarget(targetDirPath);
            fileSpec.addFilesGroup(fg);
            // Upload artifact
            artifactoryManager.upload(deployDetails);
        }
        DependenciesDownloaderHelper helper = new DependenciesDownloaderHelper(artifactoryManager, tempWorkspace.getPath(), log);
        List<Dependency> dependencies = helper.downloadDependencies(fileSpec);
        Assert.assertEquals(dependencies.size(), 3);
    } finally {
        FileUtils.deleteDirectory(tempWorkspace);
    }
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) FileSpec(org.jfrog.filespecs.FileSpec) Dependency(org.jfrog.build.extractor.ci.Dependency) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FilesGroup(org.jfrog.filespecs.entities.FilesGroup)

Example 12 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class DownloadTest method testDownloadFilesProvider.

/**
 * Create and upload files to Artifactory.
 * The test files are created according to the data provided in testFilesMap
 */
@DataProvider
private Object[][] testDownloadFilesProvider() throws IOException, NoSuchAlgorithmException {
    if (artifactoryManager == null) {
        throw new IOException("tests were not initialized successfully. aborting");
    }
    Map<String, Integer> testFilesMap = new HashMap<String, Integer>() {

        {
            put("file1", MIN_SIZE_FOR_CONCURRENT_DOWNLOAD);
            put("file2", MIN_SIZE_FOR_CONCURRENT_DOWNLOAD - 1);
            put("zeroByte", 0);
        }
    };
    Object[][] tests = new Object[testFilesMap.size()][4];
    try {
        int i = 0;
        for (Map.Entry<String, Integer> entry : testFilesMap.entrySet()) {
            String fileName = entry.getKey();
            int fileSize = entry.getValue();
            // Create file and calculate checksum
            File file = createRandomFile(tempWorkspace.getPath() + File.pathSeparatorChar + fileName, fileSize);
            Map<String, String> checksum = FileChecksumCalculator.calculateChecksums(file, SHA1_ALGORITHM, MD5_ALGORITHM);
            DeployDetails deployDetails = new DeployDetails.Builder().file(file).artifactPath(TEST_REPO_PATH + "/" + fileName).targetRepository(localRepo1).md5(checksum.get(MD5_ALGORITHM)).sha1(checksum.get(SHA1_ALGORITHM)).explode(false).packageType(DeployDetails.PackageType.GENERIC).build();
            // Upload artifact
            artifactoryManager.upload(deployDetails);
            long createdFileSize = deployDetails.getFile().length();
            tests[i] = new Object[] { checksum, fileName, createdFileSize };
            i++;
        }
    } finally {
        FileUtils.deleteDirectory(tempWorkspace);
    }
    return tests;
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) HashMap(java.util.HashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) DataProvider(org.testng.annotations.DataProvider)

Example 13 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class NpmPublish method doDeploy.

private void doDeploy() throws IOException {
    DeployDetails deployDetails = new DeployDetails.Builder().file(path.toFile()).targetRepository(repo).addProperties(properties).artifactPath(npmPackageInfo.getDeployPath()).packageType(DeployDetails.PackageType.NPM).build();
    ArtifactoryUploadResponse response = artifactoryManager.upload(deployDetails);
    deployedArtifact = new ArtifactBuilder(npmPackageInfo.getModuleId()).md5(response.getChecksums().getMd5()).sha1(response.getChecksums().getSha1()).remotePath(StringUtils.substringBeforeLast(npmPackageInfo.getDeployPath(), "/")).build();
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) ArtifactoryManagerBuilder(org.jfrog.build.extractor.clientConfiguration.ArtifactoryManagerBuilder) ArtifactoryUploadResponse(org.jfrog.build.client.ArtifactoryUploadResponse) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder)

Example 14 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class NpmExtractorTest method deployTestDependencies.

private void deployTestDependencies(Project... projects) throws IOException {
    for (Project project : projects) {
        DeployDetails deployDetails = new DeployDetails.Builder().file(project.projectOrigin.toPath().resolve(project.getPackedFileName()).toFile()).targetRepository(localRepo1).artifactPath(project.getTargetPath()).packageType(DeployDetails.PackageType.NPM).build();
        artifactoryManager.upload(deployDetails);
    }
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)

Example 15 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class GradleModuleExtractor method extractModule.

@Override
public Module extractModule(Project project) {
    Set<GradleDeployDetails> gradleDeployDetails = Sets.newHashSet();
    String artifactName = project.getName();
    ArtifactoryTask artifactoryTask = ProjectUtils.getBuildInfoTask(project);
    if (artifactoryTask != null) {
        artifactName = project.getName();
        try {
            artifactoryTask.collectDescriptorsAndArtifactsForUpload();
        } catch (IOException e) {
            throw new RuntimeException("Cannot collect deploy details for " + artifactoryTask.getPath(), e);
        }
        gradleDeployDetails = artifactoryTask.deployDetails;
    }
    String repo = gradleDeployDetails.stream().map(GradleDeployDetails::getDeployDetails).map(DeployDetails::getTargetRepository).findAny().orElse("");
    String moduleId = getModuleIdString(project.getGroup().toString(), artifactName, project.getVersion().toString());
    ModuleBuilder builder = new ModuleBuilder().type(ModuleType.GRADLE).id(moduleId).repository(repo);
    try {
        // Extract the module's artifacts information if a publisher exists.
        ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(project);
        if (publisher != null) {
            boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();
            IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
            Iterable<GradleDeployDetails> deployExcludeDetails;
            Iterable<GradleDeployDetails> deployIncludeDetails;
            if (excludeArtifactsFromBuild) {
                deployIncludeDetails = Iterables.filter(gradleDeployDetails, new IncludeExcludePredicate(project, patterns, true));
                deployExcludeDetails = Iterables.filter(gradleDeployDetails, new IncludeExcludePredicate(project, patterns, false));
            } else {
                deployIncludeDetails = Iterables.filter(gradleDeployDetails, new ProjectPredicate(project));
                deployExcludeDetails = new ArrayList<>();
            }
            builder.artifacts(calculateArtifacts(deployIncludeDetails)).excludedArtifacts(calculateArtifacts(deployExcludeDetails));
        } else {
            log.warn("No publisher config found for project: " + project.getName());
        }
        builder.dependencies(calculateDependencies(project, moduleId));
    } catch (Exception e) {
        log.error("Error during extraction: ", e);
    }
    return builder.build();
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) IOException(java.io.IOException) IOException(java.io.IOException) ArtifactoryTask(org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask)

Aggregations

DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)24 File (java.io.File)8 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)7 IOException (java.io.IOException)6 ArtifactBuilder (org.jfrog.build.extractor.builder.ArtifactBuilder)6 ArtifactoryUploadResponse (org.jfrog.build.client.ArtifactoryUploadResponse)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)4 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)4 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)4 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)4 Artifact (org.jfrog.build.extractor.ci.Artifact)3 ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)3 GradleDeployDetails (org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)3 RandomAccessFile (java.io.RandomAccessFile)2 Map (java.util.Map)2 Project (org.apache.tools.ant.Project)2 DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)2 Module (org.jfrog.build.extractor.ci.Module)2 PublishArtifactInfo (org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo)2 Path (java.nio.file.Path)1