use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method collectExtensionDependencies.
private void collectExtensionDependencies(Project project, Configuration deploymentConfiguration, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies) {
final ResolvedConfiguration rc = deploymentConfiguration.getResolvedConfiguration();
for (ResolvedArtifact a : rc.getResolvedArtifacts()) {
if (a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) {
final Project projectDep = project.getRootProject().findProject(((ProjectComponentIdentifier) a.getId().getComponentIdentifier()).getProjectPath());
final JavaPluginConvention javaExtension = projectDep == null ? null : projectDep.getConvention().findPlugin(JavaPluginConvention.class);
SourceSet mainSourceSet = javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
final ResolvedDependencyBuilder dep = appDependencies.computeIfAbsent(toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier()), k -> toDependency(a, mainSourceSet));
dep.setDeploymentCp();
dep.clearFlag(DependencyFlags.RELOADABLE);
} else if (isDependency(a)) {
final ResolvedDependencyBuilder dep = appDependencies.computeIfAbsent(toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier()), k -> toDependency(a));
dep.setDeploymentCp();
dep.clearFlag(DependencyFlags.RELOADABLE);
}
}
}
use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method collectDependencies.
private void collectDependencies(ResolvedConfiguration configuration, LaunchMode mode, Project project, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies, ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable wsModule) {
final Set<ResolvedArtifact> resolvedArtifacts = configuration.getResolvedArtifacts();
// if the number of artifacts is less than the number of files then probably
// the project includes direct file dependencies
final Set<File> artifactFiles = resolvedArtifacts.size() < configuration.getFiles().size() ? new HashSet<>(resolvedArtifacts.size()) : null;
configuration.getFirstLevelModuleDependencies().forEach(d -> {
collectDependencies(d, mode, project, appDependencies, artifactFiles, new HashSet<>(), modelBuilder, wsModule, (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS | COLLECT_RELOADABLE_MODULES));
});
if (artifactFiles != null) {
// detect FS paths that aren't provided by the resolved artifacts
for (File f : configuration.getFiles()) {
if (artifactFiles.contains(f) || !f.exists()) {
continue;
}
// here we are trying to represent a direct FS path dependency
// as an artifact dependency
// SHA1 hash is used to avoid long file names in the lib dir
final String parentPath = f.getParent();
final String group = HashUtil.sha1(parentPath == null ? f.getName() : parentPath);
String name = f.getName();
String type = ArtifactCoords.TYPE_JAR;
if (!f.isDirectory()) {
final int dot = f.getName().lastIndexOf('.');
if (dot > 0) {
name = f.getName().substring(0, dot);
type = f.getName().substring(dot + 1);
}
}
// hash could be a better way to represent the version
final String version = String.valueOf(f.lastModified());
final ResolvedDependencyBuilder artifactBuilder = ResolvedDependencyBuilder.newInstance().setGroupId(group).setArtifactId(name).setType(type).setVersion(version).setResolvedPath(f.toPath()).setDirect(true).setRuntimeCp();
processQuarkusDependency(artifactBuilder, modelBuilder);
appDependencies.put(artifactBuilder.getKey(), artifactBuilder);
}
}
}
use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method buildAll.
@Override
public Object buildAll(String modelName, ModelParameter parameter, Project project) {
final LaunchMode mode = LaunchMode.valueOf(parameter.getMode());
final List<org.gradle.api.artifacts.Dependency> enforcedPlatforms = ToolingUtils.getEnforcedPlatforms(project);
final PlatformImports platformImports = resolvePlatformImports(project, enforcedPlatforms);
final ResolvedDependency appArtifact = getProjectArtifact(project, mode);
final ApplicationModelBuilder modelBuilder = new ApplicationModelBuilder().setAppArtifact(appArtifact).addReloadableWorkspaceModule(appArtifact.getKey()).setPlatformImports(platformImports);
final ApplicationDeploymentClasspathBuilder classpathBuilder = new ApplicationDeploymentClasspathBuilder(project, mode, enforcedPlatforms);
final Configuration classpathConfig = classpathBuilder.getRuntimeConfiguration();
final Configuration deploymentConfig = classpathBuilder.getDeploymentConfiguration();
final Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies = new LinkedHashMap<>();
collectDependencies(classpathConfig.getResolvedConfiguration(), mode, project, appDependencies, modelBuilder, appArtifact.getWorkspaceModule().mutable());
collectExtensionDependencies(project, deploymentConfig, appDependencies);
for (ResolvedDependencyBuilder d : appDependencies.values()) {
modelBuilder.addDependency(d.build());
}
return modelBuilder.build();
}
use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method getProjectArtifact.
public static ResolvedDependency getProjectArtifact(Project project, LaunchMode mode) {
final ResolvedDependencyBuilder appArtifact = ResolvedDependencyBuilder.newInstance().setGroupId(project.getGroup().toString()).setArtifactId(project.getName()).setVersion(project.getVersion().toString());
final JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
if (javaConvention == null) {
throw new GradleException("Failed to locate Java plugin extension in " + project.getPath());
}
final WorkspaceModule.Mutable mainModule = WorkspaceModule.builder().setModuleId(new GAV(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion())).setModuleDir(project.getProjectDir().toPath()).setBuildDir(project.getBuildDir().toPath()).setBuildFile(project.getBuildFile().toPath());
initProjectModule(project, mainModule, javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME), SourceSet.MAIN_SOURCE_SET_NAME, ArtifactSources.MAIN);
if (mode.equals(LaunchMode.TEST) || mode.equals(LaunchMode.DEVELOPMENT)) {
initProjectModule(project, mainModule, javaConvention.getSourceSets().findByName(SourceSet.TEST_SOURCE_SET_NAME), SourceSet.TEST_SOURCE_SET_NAME, ArtifactSources.TEST);
}
final PathList.Builder paths = PathList.builder();
collectDestinationDirs(mainModule.getMainSources().getSourceDirs(), paths);
collectDestinationDirs(mainModule.getMainSources().getResourceDirs(), paths);
return appArtifact.setWorkspaceModule(mainModule).setResolvedPaths(paths.build()).build();
}
use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method collectDependencies.
private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency resolvedDep, LaunchMode mode, Project project, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies, Set<File> artifactFiles, Set<ArtifactKey> processedModules, ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable parentModule, byte flags) {
WorkspaceModule.Mutable projectModule = null;
for (ResolvedArtifact a : resolvedDep.getModuleArtifacts()) {
final ArtifactKey artifactKey = toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier());
if (!isDependency(a) || appDependencies.containsKey(artifactKey)) {
continue;
}
final ArtifactCoords depCoords = toArtifactCoords(a);
final ResolvedDependencyBuilder depBuilder = ResolvedDependencyBuilder.newInstance().setCoords(depCoords).setRuntimeCp();
if (isFlagOn(flags, COLLECT_DIRECT_DEPS)) {
depBuilder.setDirect(true);
flags = clearFlag(flags, COLLECT_DIRECT_DEPS);
}
if (parentModule != null) {
parentModule.addDependency(new ArtifactDependency(depCoords));
}
PathCollection paths = null;
if ((LaunchMode.DEVELOPMENT.equals(mode) || LaunchMode.TEST.equals(mode)) && a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) {
final Project projectDep = project.getRootProject().findProject(((ProjectComponentIdentifier) a.getId().getComponentIdentifier()).getProjectPath());
final JavaPluginConvention javaExtension = projectDep == null ? null : projectDep.getConvention().findPlugin(JavaPluginConvention.class);
final String classifier = a.getClassifier();
if (classifier == null || classifier.isEmpty()) {
final IncludedBuild includedBuild = ToolingUtils.includedBuild(project.getRootProject(), a.getName());
if (includedBuild != null) {
final PathList.Builder pathBuilder = PathList.builder();
addSubstitutedProject(pathBuilder, includedBuild.getProjectDir());
paths = pathBuilder.build();
} else if (javaExtension != null) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, SourceSet.MAIN_SOURCE_SET_NAME, false);
paths = pathBuilder.build();
}
} else if (javaExtension != null) {
if ("test".equals(classifier)) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, SourceSet.TEST_SOURCE_SET_NAME, true);
paths = pathBuilder.build();
} else if ("test-fixtures".equals(classifier)) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, "testFixtures", true);
paths = pathBuilder.build();
}
}
}
depBuilder.setResolvedPaths(paths == null ? PathList.of(a.getFile().toPath()) : paths).setWorkspaceModule(projectModule);
if (processQuarkusDependency(depBuilder, modelBuilder)) {
if (isFlagOn(flags, COLLECT_TOP_EXTENSION_RUNTIME_NODES)) {
depBuilder.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
flags = clearFlag(flags, COLLECT_TOP_EXTENSION_RUNTIME_NODES);
}
flags = clearFlag(flags, COLLECT_RELOADABLE_MODULES);
}
if (!isFlagOn(flags, COLLECT_RELOADABLE_MODULES)) {
depBuilder.clearFlag(DependencyFlags.RELOADABLE);
}
appDependencies.put(depBuilder.getKey(), depBuilder);
if (artifactFiles != null) {
artifactFiles.add(a.getFile());
}
}
processedModules.add(new GACT(resolvedDep.getModuleGroup(), resolvedDep.getModuleName()));
for (org.gradle.api.artifacts.ResolvedDependency child : resolvedDep.getChildren()) {
if (!processedModules.contains(new GACT(child.getModuleGroup(), child.getModuleName()))) {
collectDependencies(child, mode, project, appDependencies, artifactFiles, processedModules, modelBuilder, projectModule, flags);
}
}
}
Aggregations