use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.
the class ArtifactoryBuildInfoTrigger method collectDependencyInformation.
/**
* Collect dependency information during the build.
*
* @param event The end of resolution Ivy event
*/
private void collectDependencyInformation(IvyEvent event) {
Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
ResolveReport report = ((EndResolveEvent) event).getReport();
@SuppressWarnings("unchecked") Map<String, String> attributes = event.getAttributes();
Module module = getOrCreateModule(attributes);
project.log("[buildinfo:collect] Collecting dependencies for " + module.getId(), Project.MSG_INFO);
if (module.getDependencies() == null || module.getDependencies().isEmpty()) {
String[] configurations = report.getConfigurations();
List<Dependency> moduleDependencies = new ArrayList<>();
for (String configuration : configurations) {
project.log("[buildinfo:collect] Configuration: " + configuration + " Dependencies", Project.MSG_DEBUG);
ConfigurationResolveReport configurationReport = report.getConfigurationReport(configuration);
ArtifactDownloadReport[] allArtifactsReports = configurationReport.getAllArtifactsReports();
for (final ArtifactDownloadReport artifactsReport : allArtifactsReports) {
project.log("[buildinfo:collect] Artifact Download Report for configuration: " + configuration + " : " + artifactsReport, Project.MSG_DEBUG);
ModuleRevisionId id = artifactsReport.getArtifact().getModuleRevisionId();
String type = getType(artifactsReport.getArtifact());
Dependency dependency = findDependencyInList(id, type, moduleDependencies);
if (dependency == null) {
DependencyBuilder dependencyBuilder = new DependencyBuilder();
dependencyBuilder.type(type).scopes(CommonUtils.newHashSet(configuration));
String idString = getModuleIdString(id.getOrganisation(), id.getName(), id.getRevision());
dependencyBuilder.id(idString);
File file = artifactsReport.getLocalFile();
Map<String, String> checksums;
try {
checksums = FileChecksumCalculator.calculateChecksums(file, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
} catch (Exception e) {
throw new RuntimeException(e);
}
String md5 = checksums.get(MD5_ALGORITHM);
String sha1 = checksums.get(SHA1_ALGORITHM);
String sha256 = checksums.get(SHA256_ALGORITHM);
dependencyBuilder.md5(md5).sha1(sha1).sha256(sha256);
dependency = dependencyBuilder.build();
moduleDependencies.add(dependency);
project.log("[buildinfo:collect] Added dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
} else {
if (!dependency.getScopes().contains(configuration)) {
dependency.getScopes().add(configuration);
project.log("[buildinfo:collect] Added scope " + configuration + " to dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
} else {
project.log("[buildinfo:collect] Find same dependency twice in configuration '" + configuration + "' for dependency '" + artifactsReport + "'", Project.MSG_WARN);
}
}
}
}
module.setDependencies(moduleDependencies);
}
}
use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.
the class NpmBuildInfoExtractor method getDependenciesMapFromBuild.
static Map<String, Dependency> getDependenciesMapFromBuild(BuildInfo buildInfo) {
Map<String, Dependency> previousBuildDependencies = new ConcurrentHashMap<>();
// Iterate over all modules and extract dependencies.
List<Module> modules = buildInfo.getModules();
for (Module module : modules) {
List<Dependency> dependencies = module.getDependencies();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
previousBuildDependencies.put(dependency.getId(), dependency);
}
}
}
return previousBuildDependencies;
}
use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.
the class PipExtractorTest method pipInstallTest.
@Test(dataProvider = "pipInstallProvider")
private void pipInstallTest(Project project) {
try {
if (!project.allowDirtyEnv) {
// Copy project files to temp.
projectDir = TestUtils.createTestProjectTempDir(project.targetDir, project.projectOrigin);
// Check pip env is clean.
validateEmptyPipEnv(driver);
}
// Run pip-install.
PipInstall pipInstall = new PipInstall(artifactoryManagerBuilder, virtualRepo, project.args, getLog(), projectDir, env, project.moduleId, getUsername(), getAdminToken(), null);
BuildInfo buildInfo = pipInstall.execute();
assertNotNull(buildInfo, "Pip execution returned empty buildInfo.");
// Validate produced build-info.
Module module = buildInfo.getModules().get(0);
assertEquals(module.getType(), "pypi");
assertEquals(module.getId(), project.moduleId);
assertEquals(module.getDependencies().size(), project.expectedDependencies);
if (project.cleanEnvAfterExecution) {
// Clean environment.
cleanPipEnv(projectDir);
FileUtils.deleteQuietly(projectDir.toFile());
}
} catch (Exception e) {
// Clean env in case of exception.
try {
cleanPipEnv(projectDir);
} finally {
fail(ExceptionUtils.getStackTrace(e));
if (projectDir != null) {
FileUtils.deleteQuietly(projectDir.toFile());
}
}
}
}
use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.
the class NpmExtractorTest method runNpmTest.
private void runNpmTest(Project project, Dependency[] expectedDependencies, String args, boolean packageJsonPath, boolean isNpmCi) {
Path projectDir = null;
try {
// Prepare.
projectDir = createProjectDir(project);
Path path = packageJsonPath ? projectDir.resolve("package.json") : projectDir;
if (isNpmCi) {
// Run npm install to generate package-lock.json file.
new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, false, null).execute();
}
// Execute command.
NpmInstallCi buildExecutor;
if (isNpmCi) {
buildExecutor = new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, true, null);
} else {
buildExecutor = new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, false, null);
}
BuildInfo buildInfo = buildExecutor.execute();
// Validate.
assertEquals(buildInfo.getModules().size(), 1);
Module module = buildInfo.getModules().get(0);
assertEquals(module.getType(), "npm");
assertEquals(module.getId(), project.getModuleId());
assertEqualsNoOrder(module.getDependencies().toArray(), expectedDependencies);
} catch (Exception e) {
fail(ExceptionUtils.getStackTrace(e));
} finally {
if (projectDir != null) {
FileUtils.deleteQuietly(projectDir.toFile());
}
}
}
use of org.jfrog.build.extractor.ci.Module in project build-info by JFrogDev.
the class PipBuildInfoExtractor method createBuild.
private BuildInfo createBuild(List<Dependency> dependenciesList, String moduleName) {
Module module = new ModuleBuilder().type(ModuleType.PYPI).id(moduleName).dependencies(dependenciesList).build();
List<Module> modules = new ArrayList<>();
modules.add(module);
BuildInfo buildInfo = new BuildInfo();
buildInfo.setModules(modules);
return buildInfo;
}
Aggregations