use of org.jfrog.build.extractor.ci.Dependency 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.ci.Dependency 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);
}
}
use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.
the class DependenciesDownloaderHelper method downloadDependencies.
public List<Dependency> downloadDependencies(Set<DownloadableArtifact> downloadableArtifacts) throws IOException {
log.info("Beginning to resolve Build Info published dependencies.");
List<Dependency> dependencies = new ArrayList<>();
Set<DownloadableArtifact> downloadedArtifacts = new HashSet<>();
for (DownloadableArtifact downloadableArtifact : downloadableArtifacts) {
Dependency dependency = downloadArtifact(downloadableArtifact);
if (dependency != null) {
dependencies.add(dependency);
downloadedArtifacts.add(downloadableArtifact);
explodeDependenciesIfNeeded(downloadableArtifact);
}
}
removeUnusedArtifactsFromLocal(downloadedArtifacts);
log.info("Finished resolving Build Info published dependencies.");
return dependencies;
}
use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.
the class DependenciesDownloaderHelper method downloadArtifact.
/**
* Download artifact.
*
* @param downloadableArtifact download recipe
* @param artifactMetaData the artifact metadata
* @param uriWithParams full artifact uri with matrix params
* @param filePath the path to file in file system
* @return artifact dependency
*/
Dependency downloadArtifact(DownloadableArtifact downloadableArtifact, ArtifactMetaData artifactMetaData, String uriWithParams, String filePath) throws IOException {
String fileDestination = downloader.getTargetDir(downloadableArtifact.getTargetDirPath(), downloadableArtifact.getRelativeDirPath());
String remotePath = downloadableArtifact.getRepoUrl() + "/" + filePath;
Dependency dependencyResult = getDependencyLocally(artifactMetaData, fileDestination, remotePath);
if (dependencyResult != null) {
return dependencyResult;
}
try {
log.info(String.format("Downloading '%s'...", uriWithParams));
Map<String, String> checksumsMap = artifactMetaData.getSize() >= MIN_SIZE_FOR_CONCURRENT_DOWNLOAD && artifactMetaData.isAcceptRange() ? downloadFileConcurrently(uriWithParams, artifactMetaData.getSize(), fileDestination, filePath) : downloadFile(uriWithParams, fileDestination);
// If the checksums map is null then something went wrong and we should fail the build
if (checksumsMap == null) {
throw new IOException("Received null checksums map for downloaded file.");
}
dependencyResult = validateChecksumsAndBuildDependency(checksumsMap, artifactMetaData, filePath, fileDestination, remotePath);
log.info(String.format("Successfully downloaded '%s' to '%s'", uriWithParams, fileDestination));
return dependencyResult;
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.jfrog.build.extractor.ci.Dependency 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