Search in sources :

Example 16 with Module

use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.

the class NugetRun method singleProjectHandler.

private void singleProjectHandler(String projectName, String csprojPath, String globalCachePath) throws Exception {
    String dependenciesSource = getDependenciesSource(projectName, csprojPath);
    if (StringUtils.isEmpty(dependenciesSource)) {
        logger.debug("Project dependencies was not found for project: " + projectName);
        return;
    }
    // Collect dependencies according to the correct method:
    // Check if project uses packages.config or project.assets.json
    List<Dependency> dependencies = new ArrayList<>();
    if (dependenciesSource.endsWith(PACKAGES_CONFIG)) {
        dependencies = collectDependenciesFromPackagesConfig(dependenciesSource, globalCachePath);
    } else if (dependenciesSource.endsWith(PROJECT_ASSETS)) {
        dependencies = collectDependenciesFromProjectAssets(dependenciesSource);
    }
    Module projectModule = new ModuleBuilder().type(ModuleType.NUGET).id(projectName).dependencies(dependencies).build();
    if (StringUtils.isBlank(module)) {
        modulesList.add(projectModule);
    } else {
        // If a custom module name was provided, we will aggregate all projects under the same module.
        modulesList.get(0).append(projectModule);
    }
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency) Module(org.jfrog.build.extractor.ci.Module)

Example 17 with Module

use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.

the class NpmPublish method createBuild.

private BuildInfo createBuild() {
    String moduleID = StringUtils.isNotBlank(module) ? module : npmPackageInfo.toString();
    List<Artifact> artifactList = Collections.singletonList(deployedArtifact);
    Module module = new ModuleBuilder().type(ModuleType.NPM).id(moduleID).repository(repo).artifacts(artifactList).build();
    List<Module> modules = Collections.singletonList(module);
    BuildInfo buildInfo = new BuildInfo();
    buildInfo.setModules(modules);
    return buildInfo;
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) Artifact(org.jfrog.build.extractor.ci.Artifact)

Example 18 with Module

use of org.jfrog.build.extractor.ci.Module 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)

Example 19 with Module

use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.

the class NugetExtractorTest method executeAndAssertBuildInfo.

private void executeAndAssertBuildInfo(NugetRun nugetRun, String[] expectedModules, int... expectedDependencies) {
    BuildInfo buildInfo = nugetRun.execute();
    assertNotNull(buildInfo);
    assertEquals(buildInfo.getModules().size(), expectedModules.length);
    for (int i = 0; i < expectedModules.length; i++) {
        Module module = buildInfo.getModules().get(i);
        // Check correctness of the module and dependencies
        assertEquals(module.getType(), "nuget");
        assertEquals(module.getId(), expectedModules[i]);
        assertTrue(module.getDependencies().size() > 0);
    }
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module)

Example 20 with Module

use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.

the class GoExtractorTest method goRunTest.

@Test(dataProvider = "goRunProvider")
public void goRunTest(Project project, String args, ArtifactoryManagerBuilder artifactoryManagerBuilder, String repo) {
    Path projectDir = null;
    try {
        // Run Go build
        projectDir = createProjectDir(project.targetDir, project.projectOrigin);
        GoRun goRun = new GoRun(args, projectDir, null, artifactoryManagerBuilder, repo, getUsername(), getAdminToken(), getLog(), env);
        BuildInfo buildInfo = goRun.execute();
        // Check successful execution and correctness of the module and dependencies
        assertNotNull(buildInfo);
        assertEquals(buildInfo.getModules().size(), 1);
        Module module = buildInfo.getModules().get(0);
        assertEquals(module.getType(), "go");
        assertEquals(module.getId(), project.getModuleId());
        Set<String> moduleDependencies = module.getDependencies().stream().map(Dependency::getId).collect(Collectors.toSet());
        assertEquals(moduleDependencies, project.dependencies);
    } catch (Exception e) {
        fail(ExceptionUtils.getStackTrace(e));
    } finally {
        if (projectDir != null) {
            FileUtils.deleteQuietly(projectDir.toFile());
        }
    }
}
Also used : Path(java.nio.file.Path) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Aggregations

Module (org.jfrog.build.extractor.ci.Module)28 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)18 IOException (java.io.IOException)9 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)7 Path (java.nio.file.Path)6 Dependency (org.jfrog.build.extractor.ci.Dependency)6 Test (org.testng.annotations.Test)6 File (java.io.File)5 Artifact (org.jfrog.build.extractor.ci.Artifact)5 ArrayList (java.util.ArrayList)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)3 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)3 DockerImage (org.jfrog.build.extractor.docker.types.DockerImage)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 Project (org.apache.tools.ant.Project)2 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1