use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.
the class DataNodeCaches method isCacheMissingModels.
private static boolean isCacheMissingModels(@NotNull DataNode<ModuleData> cache, @NotNull Module module) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null) {
DataNode<GradleModuleModel> gradleDataNode = find(cache, GRADLE_MODULE_MODEL);
if (gradleDataNode == null) {
return true;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet != null) {
DataNode<AndroidModuleModel> androidDataNode = find(cache, ANDROID_MODEL);
if (androidDataNode == null || !isValidProxyObject(androidDataNode.getData().getAndroidProject())) {
return true;
}
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet != null) {
DataNode<JavaModuleModel> javaProjectDataNode = find(cache, JAVA_MODULE_MODEL);
if (javaProjectDataNode == null) {
return true;
}
}
}
}
NdkFacet ndkFacet = NdkFacet.getInstance(module);
if (ndkFacet != null) {
DataNode<NdkModuleModel> ndkModuleModelDataNode = find(cache, NDK_MODEL);
if (ndkModuleModelDataNode == null || !isValidProxyObject(ndkModuleModelDataNode.getData().getAndroidProject())) {
return true;
}
}
return false;
}
use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.
the class GradleBuildInvoker method findAndAddGradleBuildTasks.
private static void findAndAddGradleBuildTasks(@NotNull Module module, @NotNull BuildMode buildMode, @NotNull List<String> tasks, @NotNull TestCompileType testCompileType) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
return;
}
String gradlePath = gradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
if (isEmpty(gradlePath)) {
// Gradle project path is never, ever null. If the path is empty, it shows as ":". We had reports of this happening. It is likely that
// users manually added the Android-Gradle facet to a project. After all it is likely not to be a Gradle module. Better quit and not
// build the module.
String msg = String.format("Module '%1$s' does not have a Gradle path. It is likely that this module was manually added by the user.", module.getName());
getLogger().info(msg);
return;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet != null) {
JpsAndroidModuleProperties properties = androidFacet.getProperties();
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
switch(buildMode) {
// Intentional fall-through.
case CLEAN:
case SOURCE_GEN:
addAfterSyncTasks(tasks, gradlePath, properties);
addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
break;
case ASSEMBLE:
tasks.add(createBuildTask(gradlePath, properties.ASSEMBLE_TASK_NAME));
// Add assemble tasks for tests.
if (testCompileType != TestCompileType.NONE) {
for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
addTaskIfSpecified(tasks, gradlePath, artifact.getAssembleTaskName());
}
}
break;
default:
addAfterSyncTasks(tasks, gradlePath, properties);
addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
// no *.class files and would be just a waste of time.
if (testCompileType != TestCompileType.UNIT_TESTS) {
addTaskIfSpecified(tasks, gradlePath, properties.COMPILE_JAVA_TASK_NAME);
}
// Add compile tasks for tests.
for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
addTaskIfSpecified(tasks, gradlePath, artifact.getCompileTaskName());
}
break;
}
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet != null && javaFacet.getConfiguration().BUILDABLE) {
String gradleTaskName = javaFacet.getGradleTaskName(buildMode);
if (gradleTaskName != null) {
tasks.add(createBuildTask(gradlePath, gradleTaskName));
}
if (testCompileType == TestCompileType.UNIT_TESTS) {
tasks.add(createBuildTask(gradlePath, JavaFacet.TEST_CLASSES_TASK_NAME));
}
}
}
}
use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.
the class JavaFacetModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
JavaFacet facet = setAndGetJavaGradleFacet(module, ideModelsProvider);
GradleFacet gradleFacet = findFacet(module, ideModelsProvider, GradleFacet.getFacetTypeId());
if (gradleFacet != null) {
// This is an actual Gradle module, because it has the GradleFacet. Top-level modules in a multi-module project usually don't
// have this facet.
facet.setJavaModuleModel(javaModuleModel);
}
File buildFolderPath = javaModuleModel.getBuildFolderPath();
JavaFacetConfiguration facetProperties = facet.getConfiguration();
facetProperties.BUILD_FOLDER_PATH = buildFolderPath != null ? toSystemIndependentName(buildFolderPath.getPath()) : "";
facetProperties.BUILDABLE = javaModuleModel.isBuildable();
}
use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.
the class AndroidGradleJavaProjectModelModifier method changeLanguageLevel.
@Nullable
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull LanguageLevel level) {
Project project = module.getProject();
if (!isBuildWithGradle(module)) {
return null;
}
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel == null) {
return null;
}
if (getAndroidModel(module) != null) {
AndroidModel android = buildModel.android();
if (android == null) {
return null;
}
CompileOptionsModel compileOptions = android.compileOptions();
compileOptions.setSourceCompatibility(level);
compileOptions.setTargetCompatibility(level);
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet == null || javaFacet.getJavaModuleModel() == null) {
return null;
}
JavaModel javaModel = buildModel.java();
javaModel.setSourceCompatibility(level);
javaModel.setTargetCompatibility(level);
}
new WriteCommandAction(project, "Change Gradle Language Level") {
@Override
protected void run(@NotNull Result result) throws Throwable {
buildModel.applyChanges();
registerUndoAction(project);
}
}.execute();
return requestProjectSync(project);
}
use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.
the class ProjectStructureCleanupStep method updateTransitiveDependencies.
// See: https://code.google.com/p/android/issues/detail?id=213627
private void updateTransitiveDependencies(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @NotNull AndroidProject androidProject, @Nullable Module dependency) {
if (dependency == null) {
return;
}
JavaFacet javaFacet = JavaFacet.getInstance(dependency);
if (javaFacet != null && // BUILDABLE == false -> means this is an AAR-based module, not a regular Java lib module
javaFacet.getConfiguration().BUILDABLE) {
// Ignore Java lib modules. They are already set up properly.
return;
}
AndroidProject dependencyAndroidProject = getAndroidProject(dependency);
if (dependencyAndroidProject != null) {
AndroidModuleModel androidModel = AndroidModuleModel.get(dependency);
if (androidModel != null) {
DependencySet dependencies = myDependenciesExtractor.extractFrom(androidModel);
for (LibraryDependency libraryDependency : dependencies.onLibraries()) {
myDependenciesModuleSetupStep.updateLibraryDependency(module, ideModifiableModelsProvider, libraryDependency, androidModel.getAndroidProject());
}
Project project = module.getProject();
for (ModuleDependency moduleDependency : dependencies.onModules()) {
Module module1 = moduleDependency.getModule(project);
updateTransitiveDependencies(module, ideModifiableModelsProvider, androidProject, module1);
}
}
} else {
LibraryDependency backup = getModuleCompiledArtifact(dependency);
if (backup != null) {
myDependenciesModuleSetupStep.updateLibraryDependency(module, ideModifiableModelsProvider, backup, androidProject);
}
}
}
Aggregations