Search in sources :

Example 1 with BuildSettings

use of com.android.tools.idea.gradle.project.BuildSettings in project android by JetBrains.

the class AndroidGradleBuildProcessParametersProvider method populateGradleTasksToInvoke.

@VisibleForTesting
void populateGradleTasksToInvoke(@NotNull BuildMode buildMode, @NotNull List<String> jvmArgs) {
    if (buildMode == ASSEMBLE_TRANSLATE) {
        jvmArgs.add(createJvmArg(GRADLE_TASKS_TO_INVOKE_PROPERTY_PREFIX + 0, ASSEMBLE_TRANSLATE_TASK_NAME));
        return;
    }
    BuildSettings buildSettings = BuildSettings.getInstance(myProject);
    Module[] modulesToBuild = buildSettings.getModulesToBuild();
    if (modulesToBuild == null || (buildMode == ASSEMBLE && GradleSyncState.getInstance(myProject).lastSyncFailed())) {
        jvmArgs.add(createJvmArg(GRADLE_TASKS_TO_INVOKE_PROPERTY_PREFIX + 0, DEFAULT_ASSEMBLE_TASK_NAME));
        return;
    }
    GradleBuildInvoker.TestCompileType testCompileType = GradleBuildInvoker.getTestCompileType(buildSettings.getRunConfigurationTypeId());
    List<String> tasks = GradleBuildInvoker.findTasksToExecute(modulesToBuild, buildMode, testCompileType);
    int taskCount = tasks.size();
    for (int i = 0; i < taskCount; i++) {
        String name = GRADLE_TASKS_TO_INVOKE_PROPERTY_PREFIX + i;
        jvmArgs.add(createJvmArg(name, tasks.get(i)));
    }
}
Also used : BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) Module(com.intellij.openapi.module.Module) GradleBuildInvoker(com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with BuildSettings

use of com.android.tools.idea.gradle.project.BuildSettings in project android by JetBrains.

the class AndroidGradleBuildTargetScopeProvider method getBuildTargetScopes.

@Override
@NotNull
public List<TargetTypeBuildScope> getBuildTargetScopes(@NotNull CompileScope baseScope, @NotNull CompilerFilter filter, @NotNull Project project, boolean forceBuild) {
    if (!AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        return Collections.emptyList();
    }
    BuildSettings buildSettings = BuildSettings.getInstance(project);
    String runConfigurationTypeId = baseScope.getUserData(CompilerManager.RUN_CONFIGURATION_TYPE_ID_KEY);
    buildSettings.setRunConfigurationTypeId(runConfigurationTypeId);
    if (baseScope instanceof ProjectCompileScope) {
        // Make or Rebuild project
        BuildMode buildMode = forceBuild ? BuildMode.REBUILD : BuildMode.ASSEMBLE;
        if (buildSettings.getBuildMode() == null) {
            buildSettings.setBuildMode(buildMode);
        }
        Module[] modulesToBuild = ModuleManager.getInstance(project).getModules();
        buildSettings.setModulesToBuild(modulesToBuild);
    } else if (baseScope instanceof ModuleCompileScope) {
        String userDataString = ((ModuleCompileScope) baseScope).getUserDataString();
        Module[] modulesToBuild;
        if (userDataString.contains("RUN_CONFIGURATION")) {
            // Triggered by a "Run Configuration"
            modulesToBuild = baseScope.getAffectedModules();
        } else {
            // Triggered by menu item.
            // Make selected modules
            modulesToBuild = Projects.getModulesToBuildFromSelection(project, null);
        }
        buildSettings.setModulesToBuild(modulesToBuild);
        buildSettings.setBuildMode(BuildMode.ASSEMBLE);
    } else if (baseScope instanceof CompositeScope) {
        // Compile selected modules
        buildSettings.setModulesToBuild(Projects.getModulesToBuildFromSelection(project, null));
        buildSettings.setBuildMode(BuildMode.COMPILE_JAVA);
    }
    TargetTypeBuildScope scope = CmdlineProtoUtil.createTargetsScope(AndroidGradleBuildTargetConstants.TARGET_TYPE_ID, Collections.singletonList(AndroidGradleBuildTargetConstants.TARGET_ID), forceBuild);
    return Collections.singletonList(scope);
}
Also used : ProjectCompileScope(com.intellij.compiler.impl.ProjectCompileScope) CompositeScope(com.intellij.compiler.impl.CompositeScope) BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) BuildMode(com.android.tools.idea.gradle.util.BuildMode) Module(com.intellij.openapi.module.Module) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BuildSettings

use of com.android.tools.idea.gradle.project.BuildSettings in project android by JetBrains.

the class PostProjectBuildTasksExecutor method onBuildCompletion.

@VisibleForTesting
void onBuildCompletion(Iterator<String> errorMessages, int errorCount) {
    if (AndroidProjectInfo.getInstance(myProject).requiresAndroidModel()) {
        executeProjectChanges(myProject, this::excludeOutputFolders);
        if (isOfflineBuildModeEnabled(myProject)) {
            while (errorMessages.hasNext()) {
                String error = errorMessages.next();
                if (error != null && unresolvedDependenciesFound(error)) {
                    notifyUnresolvedDependenciesInOfflineMode();
                    break;
                }
            }
        }
        // Refresh Studio's view of the file system after a compile. This is necessary for Studio to see generated code.
        refreshProject();
        BuildSettings buildSettings = BuildSettings.getInstance(myProject);
        BuildMode buildMode = buildSettings.getBuildMode();
        buildSettings.removeAll();
        myProject.putUserData(PROJECT_LAST_BUILD_TIMESTAMP_KEY, System.currentTimeMillis());
        notifyBuildFinished(buildMode);
        syncJavaLangLevel();
        if (isSyncNeeded(buildMode, errorCount)) {
            GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setGenerateSourcesOnSuccess(false);
            GradleSyncInvoker.getInstance().requestProjectSync(myProject, request, null);
        }
        if (isSyncRequestedDuringBuild(myProject)) {
            setSyncRequestedDuringBuild(myProject, null);
            // Sync was invoked while the project was built. Now that the build is finished, request a full sync.
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(myProject, null);
        }
    }
}
Also used : GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) BuildMode(com.android.tools.idea.gradle.util.BuildMode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)3 BuildMode (com.android.tools.idea.gradle.util.BuildMode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Module (com.intellij.openapi.module.Module)2 GradleBuildInvoker (com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 CompositeScope (com.intellij.compiler.impl.CompositeScope)1 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)1 ProjectCompileScope (com.intellij.compiler.impl.ProjectCompileScope)1 NotNull (org.jetbrains.annotations.NotNull)1 TargetTypeBuildScope (org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope)1