Search in sources :

Example 1 with BuildMode

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

the class AndroidGradleTargetBuilder method doBuild.

private static void doBuild(@NotNull CompileContext context, @NotNull List<String> buildTasks, @NotNull BuilderExecutionSettings executionSettings, @Nullable String androidHome) throws ProjectBuildException {
    GradleConnector connector = getGradleConnector(executionSettings);
    ProjectConnection connection = connector.connect();
    ByteArrayOutputStream stdout = new ByteArrayOutputStream(BUFFER_SIZE);
    ByteArrayOutputStream stderr = new ByteArrayOutputStream(BUFFER_SIZE);
    try {
        BuildLauncher launcher = connection.newBuild();
        launcher.forTasks(toStringArray(buildTasks));
        List<String> jvmArgs = Lists.newArrayList();
        BuildMode buildMode = executionSettings.getBuildMode();
        if (BuildMode.ASSEMBLE_TRANSLATE == buildMode) {
            String arg = AndroidGradleSettings.createJvmArg(GradleBuilds.ENABLE_TRANSLATION_JVM_ARG, true);
            jvmArgs.add(arg);
        }
        if (androidHome != null && !androidHome.isEmpty()) {
            String androidSdkArg = AndroidGradleSettings.createAndroidHomeJvmArg(androidHome);
            jvmArgs.add(androidSdkArg);
        }
        jvmArgs.addAll(executionSettings.getJvmOptions());
        LOG.info("Build JVM args: " + jvmArgs);
        if (!jvmArgs.isEmpty()) {
            launcher.setJvmArguments(toStringArray(jvmArgs));
        }
        List<String> commandLineArgs = Lists.newArrayList();
        commandLineArgs.addAll(executionSettings.getCommandLineOptions());
        commandLineArgs.add(AndroidGradleSettings.createProjectProperty(AndroidProject.PROPERTY_INVOKED_FROM_IDE, true));
        if (executionSettings.isParallelBuild() && !commandLineArgs.contains(PARALLEL_BUILD_OPTION)) {
            commandLineArgs.add(PARALLEL_BUILD_OPTION);
        }
        if (executionSettings.isOfflineBuild() && !commandLineArgs.contains(OFFLINE_MODE_OPTION)) {
            commandLineArgs.add(OFFLINE_MODE_OPTION);
        }
        if (executionSettings.isConfigureOnDemand() && !commandLineArgs.contains(CONFIGURE_ON_DEMAND_OPTION)) {
            commandLineArgs.add(CONFIGURE_ON_DEMAND_OPTION);
        }
        LOG.info("Build command line args: " + commandLineArgs);
        if (!commandLineArgs.isEmpty()) {
            launcher.withArguments(toStringArray(commandLineArgs));
        }
        File javaHomeDir = executionSettings.getJavaHomeDir();
        if (javaHomeDir != null) {
            launcher.setJavaHome(javaHomeDir);
        }
        launcher.setStandardOutput(stdout);
        launcher.setStandardError(stderr);
        launcher.run();
    } catch (BuildException e) {
        handleBuildException(e, context, stderr.toString());
    } finally {
        String outText = stdout.toString();
        context.processMessage(new ProgressMessage(outText, 1.0f));
        try {
            Closeables.close(stdout, true);
            Closeables.close(stderr, true);
        } catch (IOException e) {
            LOG.debug(e);
        }
        connection.close();
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildException(org.gradle.tooling.BuildException) IOException(java.io.IOException) BuildMode(com.android.tools.idea.gradle.util.BuildMode) File(java.io.File) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector)

Example 2 with BuildMode

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

the class AndroidGradleBuildProcessParametersProvider method populateJvmArgs.

private void populateJvmArgs(@NotNull BuildSettings buildSettings, @NotNull List<String> jvmArgs) {
    BuildMode buildMode = buildSettings.getBuildMode();
    if (buildMode == null) {
        buildMode = BuildMode.DEFAULT_BUILD_MODE;
    }
    jvmArgs.add(createJvmArg(BUILD_MODE, buildMode.toString()));
    populateGradleTasksToInvoke(buildMode, jvmArgs);
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode)

Example 3 with BuildMode

use of com.android.tools.idea.gradle.util.BuildMode 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 4 with BuildMode

use of com.android.tools.idea.gradle.util.BuildMode 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)

Example 5 with BuildMode

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

the class GradleBuildInvoker method rebuild.

public void rebuild() {
    BuildMode buildMode = REBUILD;
    setProjectBuildMode(buildMode);
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    List<String> tasks = findTasksToExecute(moduleManager.getModules(), buildMode, TestCompileType.NONE);
    executeTasks(tasks);
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode) ModuleManager(com.intellij.openapi.module.ModuleManager)

Aggregations

BuildMode (com.android.tools.idea.gradle.util.BuildMode)10 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)2 GradleBuildInvoker (com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 NotNull (org.jetbrains.annotations.NotNull)2 InstantRunBuilder (com.android.tools.idea.fd.InstantRunBuilder)1 InstantRunContext (com.android.tools.idea.fd.InstantRunContext)1 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CompositeScope (com.intellij.compiler.impl.CompositeScope)1 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)1 ProjectCompileScope (com.intellij.compiler.impl.ProjectCompileScope)1 Module (com.intellij.openapi.module.Module)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1