use of org.gradle.tooling.model.gradle.GradleBuild in project gradle by gradle.
the class FetchIncludedGradleProjects method execute.
@Override
public List<GradleProject> execute(BuildController controller) {
List<GradleProject> projects = new ArrayList<GradleProject>();
GradleBuild build = controller.getBuildModel();
for (GradleBuild includedBuild : build.getIncludedBuilds()) {
projects.add(controller.getModel(includedBuild, GradleProject.class));
}
return projects;
}
use of org.gradle.tooling.model.gradle.GradleBuild in project intellij-community by JetBrains.
the class GradleProjectResolverUtil method getModuleConfigPath.
@NotNull
public static String getModuleConfigPath(@NotNull ProjectResolverContext resolverCtx, @NotNull IdeaModule gradleModule, @NotNull String rootProjectPath) {
GradleBuild build = resolverCtx.getExtraProject(gradleModule, GradleBuild.class);
if (build != null) {
String gradlePath = gradleModule.getGradleProject().getPath();
File moduleDirPath = getModuleDirPath(build, gradlePath);
if (moduleDirPath == null) {
throw new IllegalStateException(String.format("Unable to find root directory for module '%s'", gradleModule.getName()));
}
try {
return ExternalSystemApiUtil.toCanonicalPath(moduleDirPath.getCanonicalPath());
} catch (IOException e) {
LOG.warn("construction of the canonical path for the module fails", e);
}
}
return GradleUtil.getConfigPath(gradleModule.getGradleProject(), rootProjectPath);
}
use of org.gradle.tooling.model.gradle.GradleBuild in project intellij-community by JetBrains.
the class ProjectImportAction method execute.
@Nullable
@Override
public AllModels execute(final BuildController controller) {
configureAdditionalTypes(controller);
//outer conditional is needed to be compatible with 1.8
final IdeaProject ideaProject = myIsPreviewMode ? controller.getModel(BasicIdeaProject.class) : controller.getModel(IdeaProject.class);
if (ideaProject == null || ideaProject.getModules().isEmpty()) {
return null;
}
AllModels allModels = new AllModels(ideaProject);
allModels.setGradleProjectDirSupported(myIsGradleProjectDirSupported);
BuildEnvironment buildEnvironment = controller.findModel(BuildEnvironment.class);
allModels.setBuildEnvironment(buildEnvironment);
addExtraProject(controller, allModels, null);
for (IdeaModule module : ideaProject.getModules()) {
addExtraProject(controller, allModels, module);
}
if (myIsCompositeBuildsSupported) {
GradleBuild gradleBuild = controller.getModel(GradleBuild.class);
for (GradleBuild build : gradleBuild.getIncludedBuilds()) {
IdeaProject ideaIncludedProject = controller.findModel(build, IdeaProject.class);
allModels.getIncludedBuilds().add(ideaIncludedProject);
for (IdeaModule module : ideaIncludedProject.getModules()) {
addExtraProject(controller, allModels, module);
}
}
}
return allModels;
}
use of org.gradle.tooling.model.gradle.GradleBuild in project intellij-community by JetBrains.
the class BaseGradleProjectResolverExtension method populateModuleTasks.
@NotNull
@Override
public Collection<TaskData> populateModuleTasks(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule, @NotNull DataNode<ProjectData> ideProject) throws IllegalArgumentException, IllegalStateException {
final Collection<TaskData> tasks = ContainerUtil.newArrayList();
final String moduleConfigPath = ideModule.getData().getLinkedExternalProjectPath();
ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
String rootProjectPath = ideProject.getData().getLinkedExternalProjectPath();
try {
GradleBuild build = resolverCtx.getExtraProject(gradleModule, GradleBuild.class);
if (build != null) {
rootProjectPath = ExternalSystemApiUtil.toCanonicalPath(build.getRootProject().getProjectDirectory().getCanonicalPath());
}
} catch (IOException e) {
LOG.warn("construction of the canonical path for the module fails", e);
}
final boolean isFlatProject = !FileUtil.isAncestor(rootProjectPath, moduleConfigPath, false);
if (externalProject != null) {
for (ExternalTask task : externalProject.getTasks().values()) {
String taskName = isFlatProject ? task.getQName() : task.getName();
String taskGroup = task.getGroup();
if (taskName.trim().isEmpty() || isIdeaTask(taskName, taskGroup)) {
continue;
}
final String taskPath = isFlatProject ? rootProjectPath : moduleConfigPath;
TaskData taskData = new TaskData(GradleConstants.SYSTEM_ID, taskName, taskPath, task.getDescription());
taskData.setGroup(taskGroup);
taskData.setType(task.getType());
ideModule.createChild(ProjectKeys.TASK, taskData);
taskData.setInherited(StringUtil.equals(task.getName(), task.getQName()));
tasks.add(taskData);
}
return tasks;
}
for (GradleTask task : gradleModule.getGradleProject().getTasks()) {
String taskName = task.getName();
String taskGroup = getTaskGroup(task);
if (taskName == null || taskName.trim().isEmpty() || isIdeaTask(taskName, taskGroup)) {
continue;
}
TaskData taskData = new TaskData(GradleConstants.SYSTEM_ID, taskName, moduleConfigPath, task.getDescription());
taskData.setGroup(taskGroup);
ideModule.createChild(ProjectKeys.TASK, taskData);
tasks.add(taskData);
}
return tasks;
}
use of org.gradle.tooling.model.gradle.GradleBuild in project android by JetBrains.
the class ModuleFactory method getModulePath.
@NotNull
private String getModulePath(@NotNull IdeaModule ideaModule, @NotNull SyncAction.ModuleModels moduleModels) {
GradleProject gradleProject = ideaModule.getGradleProject();
GradleBuild gradleBuild = moduleModels.findModel(GradleBuild.class);
if (gradleBuild != null) {
File moduleDirPath = getModuleDirPath(gradleBuild, gradleProject.getPath());
if (moduleDirPath == null) {
throw new IllegalStateException(String.format("Unable to find root directory for module '%1$s'", ideaModule.getName()));
}
return toCanonicalPath(moduleDirPath.getPath());
}
String projectPath = myProject.getBasePath();
// We should not be dealing with 'default' project.
assert projectPath != null;
return toSystemDependentName(getConfigPath(gradleProject, projectPath));
}
Aggregations