use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class DockerImage method setDependencies.
private void setDependencies(ModuleBuilder moduleBuilder) throws IOException {
LinkedHashSet<Dependency> dependencies = new LinkedHashSet<>();
// Docker manifest may hold 'empty layers', as a result, docker promote will fail to promote the same layer more than once.
for (String digest : DockerUtils.getLayersDigests(manifest)) {
DockerLayer layer = layers.getByDigest(digest);
Dependency dependency = new DependencyBuilder().id(layer.getFileName()).sha1(layer.getSha1()).build();
dependencies.add(dependency);
}
moduleBuilder.dependencies(new ArrayList<>(dependencies));
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class GradleModuleExtractor method calculateDependencies.
private List<Dependency> calculateDependencies(Project project, String moduleId) throws Exception {
ArtifactoryDependencyResolutionListener artifactoryDependencyResolutionListener = project.getRootProject().getPlugins().getPlugin(ArtifactoryPlugin.class).getArtifactoryDependencyResolutionListener();
Map<String, String[][]> requestedByMap = artifactoryDependencyResolutionListener.getModulesHierarchyMap().get(moduleId);
Set<Configuration> configurationSet = project.getConfigurations();
List<Dependency> dependencies = newArrayList();
for (Configuration configuration : configurationSet) {
if (configuration.getState() != Configuration.State.RESOLVED) {
log.info("Artifacts for configuration '{}' were not all resolved, skipping", configuration.getName());
continue;
}
ResolvedConfiguration resolvedConfiguration = configuration.getResolvedConfiguration();
Set<ResolvedArtifact> resolvedArtifactSet = resolvedConfiguration.getResolvedArtifacts();
for (final ResolvedArtifact artifact : resolvedArtifactSet) {
File file = artifact.getFile();
if (file.exists()) {
ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
final String depId = getModuleIdString(id.getGroup(), id.getName(), id.getVersion());
// if it's already in the dependencies list just add the current scope
Dependency existingDependency = dependencies.stream().filter(input -> input.getId().equals(depId)).findAny().orElse(null);
if (existingDependency != null) {
Set<String> existingScopes = existingDependency.getScopes();
existingScopes.add(configuration.getName());
existingDependency.setScopes(existingScopes);
} else {
DependencyBuilder dependencyBuilder = new DependencyBuilder().type(getTypeString(artifact.getType(), artifact.getClassifier(), artifact.getExtension())).id(depId).scopes(Sets.newHashSet(configuration.getName()));
if (requestedByMap != null) {
dependencyBuilder.requestedBy(requestedByMap.get(depId));
}
if (file.isFile()) {
// In recent gradle builds (3.4+) subproject dependencies are represented by a dir not jar.
Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(file, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
dependencyBuilder.md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM));
}
dependencies.add(dependencyBuilder.build());
}
}
}
}
return dependencies;
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class BuildExtractorUtilsTest method testBuildToJson.
public void testBuildToJson() throws IOException {
String[] requestedByA = new String[] { "parentA", "b", "moduleId" };
String[] requestedByB = new String[] { "parentB", "d", "moduleId" };
Dependency dependencyA = new DependencyBuilder().id("depA").addRequestedBy(requestedByA).addRequestedBy(requestedByB).build();
Module module = new ModuleBuilder().id("moduleId").addDependency(dependencyA).build();
BuildInfo buildInfo = new BuildInfoBuilder("buildId").number("12").started("34").addModule(module).build();
// Serialize and deserialize again
BuildInfo actualBuildInfo = jsonStringToBuildInfo(buildInfoToJsonString(buildInfo));
// Check buildInfo
assertEquals(actualBuildInfo.getName(), buildInfo.getName());
assertEquals(actualBuildInfo.getNumber(), buildInfo.getNumber());
assertEquals(actualBuildInfo.getStarted(), buildInfo.getStarted());
// Check module
Module actualModule = actualBuildInfo.getModule(module.getId());
assertNotNull(actualModule);
// Check dependency
assertEquals(actualModule.getDependencies().size(), 1);
Dependency actualDependency = actualModule.getDependencies().get(0);
assertEquals(actualDependency.getId(), dependencyA.getId());
// Check requestedBy
String[][] requestedBy = actualDependency.getRequestedBy();
assertEquals(ArrayUtils.getLength(requestedBy), 2);
assertEquals(requestedBy[0], requestedByA);
assertEquals(requestedBy[1], requestedByB);
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class NpmExtractorConsumer method createDependencyFromAqlResult.
/**
* Create 'Dependency' from name and version of 'npmPackageInfo'. Try to retrieve sha1 and md5 from Artifactory.
*
* @param npmPackageInfo - The npm package information.
* @param id - The id of the dependency to create.
* @return Dependency or null in case of an exception, or in case the dependency does not exist in Artifactory.
*/
private Dependency createDependencyFromAqlResult(NpmPackageInfo npmPackageInfo, String id) {
String aql = String.format(NPM_AQL_FORMAT, npmPackageInfo.getName(), npmPackageInfo.getVersion());
AqlSearchResult searchResult;
try {
searchResult = artifactoryManager.searchArtifactsByAql(aql);
if (searchResult.getResults().isEmpty()) {
return null;
}
DependencyBuilder builder = new DependencyBuilder();
AqlSearchResult.SearchEntry searchEntry = searchResult.getResults().get(0);
return builder.id(id).addScope(npmPackageInfo.getScope()).md5(searchEntry.getActualMd5()).sha1(searchEntry.getActualSha1()).build();
} catch (IOException e) {
log.error(ExceptionUtils.getStackTrace(e), e);
return null;
}
}
use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.
the class NugetRun method collectDependenciesFromProjectAssets.
private List<Dependency> collectDependenciesFromProjectAssets(String projectAssetsPath) throws Exception {
File projectAssets = new File(projectAssetsPath);
List<Dependency> dependenciesList = new ArrayList<>();
NugetProjectAssets assets = new NugetProjectAssets();
assets.readProjectAssets(projectAssets);
for (Map.Entry<String, NugetProjectAssets.Library> entry : assets.getLibraries().entrySet()) {
String pkgKey = entry.getKey();
NugetProjectAssets.Library library = entry.getValue();
if (library.getType().equals("project")) {
continue;
}
File nupkg = new File(assets.getPackagesPath(), library.getNupkgFilePath());
if (nupkg.exists()) {
Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(nupkg, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
Dependency dependency = new DependencyBuilder().id(pkgKey.replace('/', ':')).md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM)).build();
dependenciesList.add(dependency);
} else {
if (isPackagePartOfTargetDependencies(library.getPath(), assets.getTargets())) {
logger.warn(String.format("The file %s doesn't exist in the NuGet cache directory but it does exist as a target in the assets files. %s", nupkg.getPath(), ABSENT_NUPKG_WARN_MSG));
continue;
}
throw new Exception(String.format("The file %s doesn't exist in the NuGet cache directory.", nupkg.getPath()));
}
}
return dependenciesList;
}
Aggregations