use of org.gradle.tooling.model.GradleProject in project gradle by gradle.
the class GradleBuildConverter method convertChildren.
private void convertChildren(DefaultGradleBuild gradleBuild, PartialBasicGradleProject rootProject, GradleProject project) {
final List<? extends GradleProject> childProjects = new ArrayList<GradleProject>(project.getChildren());
Collections.sort(childProjects, new Comparator<GradleProject>() {
public int compare(GradleProject gp1, GradleProject gp2) {
return gp1.getName().compareTo(gp2.getName());
}
});
for (GradleProject childProject : childProjects) {
PartialBasicGradleProject basicGradleProject = toPartialGradleProject(childProject);
gradleBuild.addProject(basicGradleProject);
basicGradleProject.setParent(rootProject);
rootProject.addChild(basicGradleProject);
convertChildren(gradleBuild, basicGradleProject, childProject);
}
}
use of org.gradle.tooling.model.GradleProject in project gradle by gradle.
the class UseOtherTypesToFetchProjectModel method execute.
public Map<String, CustomModel> execute(BuildController controller) {
// Use an IdeaModule to reference a project
IdeaProject ideaProject = controller.getModel(IdeaProject.class);
for (IdeaModule ideaModule : ideaProject.getModules()) {
visit(ideaModule, controller, new HashMap<String, CustomModel>());
}
// Use an EclipseProject to reference a project
EclipseProject eclipseProject = controller.getModel(EclipseProject.class);
visit(eclipseProject, controller, new HashMap<String, CustomModel>());
// Use a GradleProject to reference a project
GradleProject rootProject = controller.getModel(GradleProject.class);
Map<String, CustomModel> projects = new HashMap<String, CustomModel>();
visit(rootProject, controller, projects);
return projects;
}
use of org.gradle.tooling.model.GradleProject in project intellij-community by JetBrains.
the class GradleUtil method getConfigPath.
/**
* Allows to build file system path to the target gradle sub-project given the root project path.
*
* @param subProject target sub-project which config path we're interested in
* @param rootProjectPath path to root project's directory which contains 'build.gradle'
* @return path to the given sub-project's directory which contains 'build.gradle'
*/
@NotNull
public static String getConfigPath(@NotNull GradleProject subProject, @NotNull String rootProjectPath) {
try {
GradleScript script = subProject.getBuildScript();
if (script != null) {
File file = script.getSourceFile();
if (file != null) {
if (!file.isDirectory()) {
// The file points to 'build.gradle' at the moment but we keep it's parent dir path instead.
file = file.getParentFile();
}
return ExternalSystemApiUtil.toCanonicalPath(file.getCanonicalPath());
}
}
} catch (Exception e) {
// As said by gradle team: 'One thing I'm interested in is whether you have any thoughts about how the tooling API should
// deal with missing details from the model - for example, when asking for details about the build scripts when using
// a version of Gradle that does not supply that information. Currently, you'll get a `UnsupportedOperationException`
// when you call the `getBuildScript()` method'.
//
// So, just ignore it and assume that the user didn't define any custom build file name.
}
File rootProjectParent = new File(rootProjectPath);
StringBuilder buffer = new StringBuilder(FileUtil.toCanonicalPath(rootProjectParent.getAbsolutePath()));
Stack<String> stack = ContainerUtilRt.newStack();
for (GradleProject p = subProject; p != null; p = p.getParent()) {
stack.push(p.getName());
}
// pop root project
stack.pop();
while (!stack.isEmpty()) {
buffer.append(ExternalSystemConstants.PATH_SEPARATOR).append(stack.pop());
}
return buffer.toString();
}
use of org.gradle.tooling.model.GradleProject in project intellij-community by JetBrains.
the class GradleProjectResolver method extractExternalProjectModels.
private static void extractExternalProjectModels(@NotNull ProjectImportAction.AllModels models, @NotNull ProjectResolverContext resolverCtx) {
resolverCtx.setModels(models);
final Class<? extends ExternalProject> modelClazz = resolverCtx.isPreviewMode() ? ExternalProjectPreview.class : ExternalProject.class;
final ExternalProject externalRootProject = models.getExtraProject((IdeaModule) null, modelClazz);
if (externalRootProject == null)
return;
final DefaultExternalProject wrappedExternalRootProject = new DefaultExternalProject(externalRootProject);
models.addExtraProject(wrappedExternalRootProject, ExternalProject.class);
final Map<String, ExternalProject> externalProjectsMap = createExternalProjectsMap(null, wrappedExternalRootProject);
DomainObjectSet<? extends IdeaModule> gradleModules = models.getIdeaProject().getModules();
if (gradleModules != null && !gradleModules.isEmpty()) {
for (IdeaModule ideaModule : gradleModules) {
final ExternalProject externalProject = externalProjectsMap.get(getModuleId(resolverCtx, ideaModule));
if (externalProject != null) {
models.addExtraProject(externalProject, ExternalProject.class, ideaModule.getGradleProject());
}
}
}
for (IdeaProject project : models.getIncludedBuilds()) {
DomainObjectSet<? extends IdeaModule> ideaModules = project.getModules();
if (ideaModules.isEmpty())
continue;
GradleProject gradleProject = ideaModules.getAt(0).getGradleProject();
while (gradleProject.getParent() != null) {
gradleProject = gradleProject.getParent();
}
final ExternalProject externalIncludedRootProject = models.getExtraProject(gradleProject, modelClazz);
if (externalIncludedRootProject == null)
continue;
final DefaultExternalProject wrappedExternalIncludedRootProject = new DefaultExternalProject(externalIncludedRootProject);
wrappedExternalRootProject.getChildProjects().put(wrappedExternalIncludedRootProject.getName(), wrappedExternalIncludedRootProject);
String compositePrefix = project.getName();
final Map<String, ExternalProject> externalIncludedProjectsMap = createExternalProjectsMap(compositePrefix, wrappedExternalIncludedRootProject);
for (IdeaModule ideaModule : ideaModules) {
final ExternalProject externalProject = externalIncludedProjectsMap.get(getModuleId(resolverCtx, ideaModule));
if (externalProject != null) {
models.addExtraProject(externalProject, ExternalProject.class, ideaModule.getGradleProject());
}
}
}
}
use of org.gradle.tooling.model.GradleProject in project android by JetBrains.
the class GradleModuleSetup method createGradleModel.
@NotNull
private static GradleModuleModel createGradleModel(@NotNull Module module, @NotNull SyncAction.ModuleModels models) {
GradleProject gradleProject = models.getModule().getGradleProject();
GradleScript buildScript = null;
try {
buildScript = gradleProject.getBuildScript();
} catch (Throwable e) {
// Ignored. We got here because the project is using Gradle 1.8 or older.
}
File buildFilePath = buildScript != null ? buildScript.getSourceFile() : null;
BuildScriptClasspathModel classpathModel = models.findModel(BuildScriptClasspathModel.class);
String gradleVersion = classpathModel != null ? classpathModel.getGradleVersion() : null;
return new GradleModuleModel(module.getName(), gradleProject, buildFilePath, gradleVersion);
}
Aggregations