use of org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel 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);
}
use of org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel 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.jetbrains.plugins.gradle.model.BuildScriptClasspathModel in project intellij-community by JetBrains.
the class ModelBuildScriptClasspathBuilderImplTest method testModelBuildScriptClasspathBuilder.
@Test
@TargetVersions("2.0+")
public void testModelBuildScriptClasspathBuilder() throws Exception {
DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
List<BuildScriptClasspathModel> ideaModule = ContainerUtil.mapNotNull(ideaModules, new Function<IdeaModule, BuildScriptClasspathModel>() {
@Override
public BuildScriptClasspathModel fun(IdeaModule module) {
BuildScriptClasspathModel classpathModel = allModels.getExtraProject(module, BuildScriptClasspathModel.class);
if (module.getName().equals("moduleWithAdditionalClasspath")) {
assertNotNull(classpathModel);
assertEquals(3, classpathModel.getClasspath().size());
assertEquals("junit-4.11.jar", new File(classpathModel.getClasspath().getAt(0).getClasses().iterator().next()).getName());
assertEquals("hamcrest-core-1.3.jar", new File(classpathModel.getClasspath().getAt(1).getClasses().iterator().next()).getName());
assertEquals("someDep.jar", new File(classpathModel.getClasspath().getAt(2).getClasses().iterator().next()).getName());
} else if (module.getName().equals("baseModule") || module.getName().equals("moduleWithInheritedClasspath")) {
assertNotNull("Null build classpath for module: " + module.getName(), classpathModel);
assertEquals("Wrong build classpath for module: " + module.getName(), 3, classpathModel.getClasspath().size());
assertEquals("Wrong build classpath for module: " + module.getName(), "junit-4.11.jar", new File(classpathModel.getClasspath().getAt(0).getClasses().iterator().next()).getName());
assertEquals("Wrong build classpath for module: " + module.getName(), "hamcrest-core-1.3.jar", new File(classpathModel.getClasspath().getAt(1).getClasses().iterator().next()).getName());
assertEquals("Wrong build classpath for module: " + module.getName(), "inheritedDep.jar", new File(classpathModel.getClasspath().getAt(2).getClasses().iterator().next()).getName());
} else if (module.getName().equals("moduleWithoutAdditionalClasspath") || module.getName().equals("testModelBuildScriptClasspathBuilder")) {
assertNotNull("Wrong build classpath for module: " + module.getName(), classpathModel);
assertEquals("Wrong build classpath for module: " + module.getName(), 2, classpathModel.getClasspath().size());
} else {
fail("Unexpected module found: " + module.getName());
}
return classpathModel;
}
});
assertEquals(5, ideaModule.size());
}
use of org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel in project intellij-community by JetBrains.
the class AbstractModelBuilderTest method assertBuildClasspath.
protected void assertBuildClasspath(String projectPath, String... classpath) {
final Map<String, BuildScriptClasspathModel> classpathModelMap = getModulesMap(BuildScriptClasspathModel.class);
final BuildScriptClasspathModel classpathModel = classpathModelMap.get(projectPath);
assertNotNull(classpathModel);
final List<? extends ClasspathEntryModel> classpathEntryModels = classpathModel.getClasspath().getAll();
assertEquals(classpath.length, classpathEntryModels.size());
for (int i = 0, length = classpath.length; i < length; i++) {
String classpathEntry = classpath[i];
final ClasspathEntryModel classpathEntryModel = classpathEntryModels.get(i);
assertNotNull(classpathEntryModel);
assertEquals(1, classpathEntryModel.getClasses().size());
final String path = classpathEntryModel.getClasses().iterator().next();
assertEquals(classpathEntry, new File(path).getName());
}
}
Aggregations