Search in sources :

Example 6 with FilesGroup

use of org.jfrog.filespecs.entities.FilesGroup in project build-info by JFrogDev.

the class LocalDistributionManagerTest method addedPropsTest.

@Test
public void addedPropsTest() throws IOException {
    // Create a release bundle with added props
    String fileName = uploadFile();
    FileSpec fileSpec = new FileSpec();
    FilesGroup filesGroup = new FilesGroup().setTargetProps("key1=value1,value2").setPattern(localRepo1 + "/data/" + fileName);
    fileSpec.addFilesGroup(filesGroup);
    CreateReleaseBundleRequest request = new CreateReleaseBundleRequest.Builder(RELEASE_BUNDLE_NAME, RELEASE_BUNDLE_VERSION).spec(fileSpec).build();
    distributionManager.createReleaseBundle(request);
    // Assert added props
    GetReleaseBundleStatusResponse bundleInfo = distributionManager.getReleaseBundleStatus(RELEASE_BUNDLE_NAME, RELEASE_BUNDLE_VERSION);
    assertNotNull(bundleInfo);
    List<Property> addedProps = bundleInfo.getSpec().getQueries().get(0).getAddedProps();
    assertFalse(addedProps.isEmpty());
    Property property = addedProps.get(0);
    assertEquals(property.getKey(), "key1");
    assertEquals(property.getValues(), Sets.newHashSet("value1", "value2"));
}
Also used : FileSpec(org.jfrog.filespecs.FileSpec) GetReleaseBundleStatusResponse(org.jfrog.build.extractor.clientConfiguration.client.distribution.response.GetReleaseBundleStatusResponse) Property(org.jfrog.filespecs.properties.Property) FilesGroup(org.jfrog.filespecs.entities.FilesGroup) CreateReleaseBundleRequest(org.jfrog.build.extractor.clientConfiguration.client.distribution.request.CreateReleaseBundleRequest) Test(org.testng.annotations.Test)

Example 7 with FilesGroup

use of org.jfrog.filespecs.entities.FilesGroup 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 8 with FilesGroup

use of org.jfrog.filespecs.entities.FilesGroup in project build-info by JFrogDev.

the class NpmExtractorTest method npmPublishTest.

@SuppressWarnings("unused")
@Test(dataProvider = "npmPublishProvider")
public void npmPublishTest(Project project, ArrayListMultimap<String, String> props, String targetPath, String packageName) {
    Path projectDir = null;
    try {
        // Run npm publish
        projectDir = createProjectDir(project);
        Path path = StringUtils.isNotBlank(packageName) ? projectDir.resolve(packageName) : projectDir;
        NpmPublish npmPublish = new NpmPublish(artifactoryManagerBuilder, props, path, localRepo1, log, null, null);
        BuildInfo buildInfo = npmPublish.execute();
        assertEquals(buildInfo.getModules().size(), 1);
        Module module = buildInfo.getModules().get(0);
        // Check correctness of the module and the artifact
        assertEquals(module.getType(), "npm");
        assertEquals(module.getId(), project.getModuleId());
        assertEquals(module.getRepository(), localRepo1);
        assertEquals(module.getArtifacts().size(), 1);
        assertEquals(module.getArtifacts().get(0).getName(), project.getModuleId());
        assertEquals(module.getArtifacts().get(0).getRemotePath(), project.getRemotePath());
        // DownloadBase the artifact and check for its properties
        StringJoiner propertiesBuilder = new StringJoiner(";");
        props.entries().forEach(property -> propertiesBuilder.add(property.getKey() + "=" + property.getValue()));
        FilesGroup fileSpec = new FilesGroup();
        fileSpec.setProps(propertiesBuilder.toString());
        fileSpec.setPattern(localRepo1 + "/" + targetPath);
        fileSpec.setTarget(projectDir.toString());
        FileSpec spec = new FileSpec();
        spec.addFilesGroup(fileSpec);
        assertEquals(downloaderHelper.downloadDependencies(spec).size(), 1);
    } catch (Exception e) {
        fail(ExceptionUtils.getStackTrace(e));
    } finally {
        if (projectDir != null) {
            FileUtils.deleteQuietly(projectDir.toFile());
        }
    }
}
Also used : Path(java.nio.file.Path) FileSpec(org.jfrog.filespecs.FileSpec) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) StringJoiner(java.util.StringJoiner) FilesGroup(org.jfrog.filespecs.entities.FilesGroup) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Aggregations

FilesGroup (org.jfrog.filespecs.entities.FilesGroup)8 FileSpec (org.jfrog.filespecs.FileSpec)5 Test (org.testng.annotations.Test)3 Dependency (org.jfrog.build.extractor.ci.Dependency)2 CreateReleaseBundleRequest (org.jfrog.build.extractor.clientConfiguration.client.distribution.request.CreateReleaseBundleRequest)2 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Path (java.nio.file.Path)1 StringJoiner (java.util.StringJoiner)1 DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)1 DownloadResponse (org.jfrog.build.client.DownloadResponse)1 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)1 Module (org.jfrog.build.extractor.ci.Module)1 GetReleaseBundleStatusResponse (org.jfrog.build.extractor.clientConfiguration.client.distribution.response.GetReleaseBundleStatusResponse)1 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)1 JsonUtils.toJsonString (org.jfrog.build.extractor.clientConfiguration.util.JsonUtils.toJsonString)1 Property (org.jfrog.filespecs.properties.Property)1