use of com.android.tools.idea.gradle.project.model.AndroidModuleModel 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.model.AndroidModuleModel in project android by JetBrains.
the class AndroidGeneratedSourcesFilter method isGeneratedSource.
// See: https://code.google.com/p/android/issues/detail?id=121156
// Alternative could be marking the entire build folder as generated source folder, but this have many side affects, e.g. a broken source
// file (e.g. have some syntax error / warning) under build folder that is not actually used in the project would be marked as red too and
// the user might be asked to fix it.
@Override
public boolean isGeneratedSource(@NotNull VirtualFile file, @NotNull Project project) {
GradleProjectInfo projectInfo = GradleProjectInfo.getInstance(project);
AndroidModuleModel androidModel = projectInfo.findAndroidModelInModule(file);
if (androidModel != null) {
return isAncestor(androidModel.getAndroidProject().getBuildFolder(), virtualToIoFile(file), false);
}
// Gradle projects also sometimes create a "build" folder at the top level (where there is no AndroidFacet module). Unfortunately, this
// folder is not available in the Gradle project model so we have to look for it by hardcoded name.
VirtualFile rootFolder = project.getBaseDir();
if (rootFolder == null) {
return false;
}
VirtualFile buildFolder = rootFolder.findChild(BUILD_DIR_DEFAULT_NAME);
return buildFolder != null && projectInfo.isBuildWithGradle() && isAncestor(buildFolder, file, false);
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class LintIdeProject method createModuleProject.
/** Creates a new module project */
@Nullable
private static LintModuleProject createModuleProject(@NonNull LintClient client, @NonNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
File dir = getLintProjectDirectory(module, facet);
if (dir == null)
return null;
LintModuleProject project = null;
if (facet == null) {
project = new LintModuleProject(client, dir, dir, module);
AndroidFacet f = findAndroidFacetInProject(module.getProject());
if (f != null) {
project.gradleProject = f.requiresAndroidModel();
}
} else if (facet.requiresAndroidModel()) {
AndroidModel androidModel = facet.getAndroidModel();
if (androidModel instanceof AndroidModuleModel) {
project = new LintGradleProject(client, dir, dir, facet, (AndroidModuleModel) androidModel);
} else {
project = new LintAndroidModelProject(client, dir, dir, facet, androidModel);
}
} else {
project = new LintAndroidProject(client, dir, dir, facet);
}
if (project != null) {
client.registerProject(dir, project);
}
return project;
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class LintIdeProject method addProjects.
/**
* Recursively add lint projects for the given module, and any other module or library it depends on, and also
* populate the reverse maps so we can quickly map from a lint project to a corresponding module/library (used
* by the lint client
*/
private static void addProjects(@NonNull LintClient client, @NonNull Module module, @Nullable List<VirtualFile> files, @NonNull Map<Module, Project> moduleMap, @NonNull Map<AndroidLibrary, Project> libraryMap, @NonNull Map<Project, Module> projectMap, @NonNull List<Project> projects) {
if (moduleMap.containsKey(module)) {
return;
}
LintModuleProject project = createModuleProject(client, module);
if (project == null) {
// It's possible for the module to *depend* on Android code, e.g. in a Gradle
// project there will be a top-level non-Android module
List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(module, false);
for (AndroidFacet dependentFacet : dependentFacets) {
addProjects(client, dependentFacet.getModule(), files, moduleMap, libraryMap, projectMap, projects);
}
return;
}
projects.add(project);
moduleMap.put(module, project);
projectMap.put(project, module);
if (processFileFilter(module, files, project)) {
// No need to process dependencies when doing single file analysis
return;
}
List<Project> dependencies = Lists.newArrayList();
// No, this shouldn't use getAllAndroidDependencies; we may have non-Android dependencies that this won't include
// (e.g. Java-only modules)
List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(module, true);
for (AndroidFacet dependentFacet : dependentFacets) {
Project p = moduleMap.get(dependentFacet.getModule());
if (p != null) {
dependencies.add(p);
} else {
addProjects(client, dependentFacet.getModule(), files, moduleMap, libraryMap, projectMap, dependencies);
}
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet);
if (androidModuleModel != null) {
addGradleLibraryProjects(client, files, libraryMap, projects, facet, androidModuleModel, project, projectMap, dependencies);
}
}
project.setDirectLibraries(dependencies);
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class AndroidRunState method execute.
@Nullable
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
ProcessHandler processHandler;
ConsoleView console;
String applicationId;
try {
applicationId = myApplicationIdProvider.getPackageName();
} catch (ApkProvisionException e) {
throw new ExecutionException("Unable to obtain application id", e);
}
// TODO: this class is independent of gradle, except for this hack
AndroidModuleModel model = AndroidModuleModel.get(myModule);
if (InstantRunSettings.isInstantRunEnabled() && InstantRunGradleUtils.getIrSupportStatus(model, null) == InstantRunGradleSupport.SUPPORTED) {
assert model != null;
InstantRunBuildInfo info = InstantRunGradleUtils.getBuildInfo(model);
if (info != null && !info.isCompatibleFormat()) {
throw new ExecutionException("This version of Android Studio is incompatible with the Gradle Plugin used. " + "Try disabling Instant Run (or updating either the IDE or the Gradle plugin to " + "the latest version)");
}
}
LaunchTasksProvider launchTasksProvider = myLaunchTasksProviderFactory.get();
if (launchTasksProvider.createsNewProcess()) {
// and the new one).
if (myPreviousSessionProcessHandler != null) {
myPreviousSessionProcessHandler.detachProcess();
}
processHandler = new AndroidProcessHandler(applicationId, launchTasksProvider.monitorRemoteProcess());
console = attachConsole(processHandler, executor);
} else {
assert myPreviousSessionProcessHandler != null : "No process handler from previous session, yet current tasks don't create one";
processHandler = myPreviousSessionProcessHandler;
console = null;
}
LaunchInfo launchInfo = new LaunchInfo(executor, runner, myEnv, myConsoleProvider);
LaunchTaskRunner task = new LaunchTaskRunner(myModule.getProject(), myLaunchConfigName, launchInfo, processHandler, myDeviceFutures, launchTasksProvider);
ProgressManager.getInstance().run(task);
return console == null ? null : new DefaultExecutionResult(console, processHandler);
}
Aggregations