use of org.gradle.tooling.model.GradleProject in project android by JetBrains.
the class AndroidGradleProjectResolver method populateModuleContentRoots.
@Override
public void populateModuleContentRoots(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
ImportedModule importedModule = new ImportedModule(gradleModule);
ideModule.createChild(IMPORTED_MODULE, importedModule);
GradleProject gradleProject = gradleModule.getGradleProject();
GradleScript buildScript = null;
try {
buildScript = gradleProject.getBuildScript();
} catch (UnsupportedOperationException ignore) {
}
if (buildScript == null || !isAndroidGradleProject()) {
nextResolver.populateModuleContentRoots(gradleModule, ideModule);
return;
}
// do not derive module root dir based on *.iml file location
File moduleRootDirPath = new File(toSystemDependentName(ideModule.getData().getLinkedExternalProjectPath()));
AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
boolean androidProjectWithoutVariants = false;
String moduleName = gradleModule.getName();
if (androidProject != null) {
Variant selectedVariant = myVariantSelector.findVariantToSelect(androidProject);
if (selectedVariant == null) {
// If an Android project does not have variants, it would be impossible to build. This is a possible but invalid use case.
// For now we are going to treat this case as a Java library module, because everywhere in the IDE (e.g. run configurations,
// editors, test support, variants tool window, project building, etc.) we have the assumption that there is at least one variant
// per Android project, and changing that in the code base is too risky, for very little benefit.
// See https://code.google.com/p/android/issues/detail?id=170722
androidProjectWithoutVariants = true;
} else {
String variantName = selectedVariant.getName();
AndroidModuleModel model = new AndroidModuleModel(moduleName, moduleRootDirPath, androidProject, variantName);
ideModule.createChild(ANDROID_MODEL, model);
}
}
NativeAndroidProject nativeAndroidProject = resolverCtx.getExtraProject(gradleModule, NativeAndroidProject.class);
if (nativeAndroidProject != null) {
NdkModuleModel ndkModuleModel = new NdkModuleModel(moduleName, moduleRootDirPath, nativeAndroidProject);
ideModule.createChild(NDK_MODEL, ndkModuleModel);
}
File gradleSettingsFile = new File(moduleRootDirPath, FN_SETTINGS_GRADLE);
if (gradleSettingsFile.isFile() && androidProject == null && nativeAndroidProject == null) {
// This is just a root folder for a group of Gradle projects. We don't set an IdeaGradleProject so the JPS builder won't try to
// compile it using Gradle. We still need to create the module to display files inside it.
createJavaProject(gradleModule, ideModule, false);
return;
}
BuildScriptClasspathModel buildScriptModel = resolverCtx.getExtraProject(BuildScriptClasspathModel.class);
String gradleVersion = buildScriptModel != null ? buildScriptModel.getGradleVersion() : null;
File buildFilePath = buildScript.getSourceFile();
GradleModuleModel gradleModuleModel = new GradleModuleModel(moduleName, gradleProject, buildFilePath, gradleVersion);
ideModule.createChild(GRADLE_MODULE_MODEL, gradleModuleModel);
if (nativeAndroidProject == null && (androidProject == null || androidProjectWithoutVariants)) {
// This is a Java lib module.
createJavaProject(gradleModule, ideModule, androidProjectWithoutVariants);
}
}
use of org.gradle.tooling.model.GradleProject in project android by JetBrains.
the class GradleUtilIdeaTest method testGetGradleBuildFileFromModuleWithGradleFacet.
public void testGetGradleBuildFileFromModuleWithGradleFacet() {
GradleProject project = createMock(GradleProject.class);
expect(project.getPath()).andReturn(myModule.getName());
//noinspection unchecked
DomainObjectSet<? extends GradleTask> tasks = createMock(DomainObjectSet.class);
project.getTasks();
expectLastCall().andReturn(tasks);
expect(tasks.isEmpty()).andReturn(true);
replay(project, tasks);
GradleModuleModel gradleModuleModel = new GradleModuleModel(myModule.getName(), project, myBuildFile, "2.2.1");
GradleFacet facet = createAndAddGradleFacet(myModule);
facet.setGradleModuleModel(gradleModuleModel);
VirtualFile buildFile = GradleUtil.getGradleBuildFile(myModule);
assertIsGradleBuildFile(buildFile);
verify(project, tasks);
}
use of org.gradle.tooling.model.GradleProject in project gradle by gradle.
the class GradleBuildAdapterProducer method produceModel.
public <T> T produceModel(Class<T> type, ConsumerOperationParameters operationParameters) {
if (type.equals(GradleBuild.class)) {
GradleProject gradleProject = delegate.produceModel(GradleProject.class, operationParameters);
final DefaultGradleBuild convert = new GradleBuildConverter().convert(gradleProject);
return mappingProvider.applyCompatibilityMapping(adapter.builder(type), operationParameters).build(convert);
}
return delegate.produceModel(type, operationParameters);
}
use of org.gradle.tooling.model.GradleProject 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.GradleProject in project intellij-community by JetBrains.
the class GradleProjectResolver method exposeCompositeBuild.
@NotNull
private static Collection<IdeaModule> exposeCompositeBuild(ProjectImportAction.AllModels allModels, DefaultProjectResolverContext resolverCtx, DataNode<ProjectData> projectDataNode) {
if (resolverCtx.getSettings() != null && !resolverCtx.getSettings().getExecutionWorkspace().getBuildParticipants().isEmpty()) {
return Collections.emptyList();
}
CompositeBuildData compositeBuildData;
List<IdeaModule> gradleIncludedModules = new SmartList<>();
List<IdeaProject> includedBuilds = allModels.getIncludedBuilds();
if (!includedBuilds.isEmpty()) {
ProjectData projectData = projectDataNode.getData();
compositeBuildData = new CompositeBuildData(projectData.getLinkedExternalProjectPath());
for (IdeaProject project : includedBuilds) {
if (!project.getModules().isEmpty()) {
String rootProjectName = project.getName();
BuildParticipant buildParticipant = new BuildParticipant();
gradleIncludedModules.addAll(project.getModules());
GradleProject gradleProject = project.getModules().getAt(0).getGradleProject();
String projectPath = null;
do {
try {
projectPath = ExternalSystemApiUtil.toCanonicalPath(gradleProject.getProjectDirectory().getCanonicalPath());
} catch (IOException e) {
LOG.warn("construction of the canonical path for the module fails", e);
}
} while ((gradleProject = gradleProject.getParent()) != null);
if (projectPath != null) {
buildParticipant.setRootProjectName(rootProjectName);
buildParticipant.setRootPath(projectPath);
for (IdeaModule module : project.getModules()) {
try {
String modulePath = ExternalSystemApiUtil.toCanonicalPath(module.getGradleProject().getProjectDirectory().getCanonicalPath());
buildParticipant.getProjects().add(modulePath);
} catch (IOException e) {
LOG.warn("construction of the canonical path for the module fails", e);
}
}
compositeBuildData.getCompositeParticipants().add(buildParticipant);
}
}
}
projectDataNode.createChild(CompositeBuildData.KEY, compositeBuildData);
}
return gradleIncludedModules;
}
Aggregations