Search in sources :

Example 1 with HotSwapProgress

use of com.intellij.debugger.impl.HotSwapProgress in project intellij by bazelbuild.

the class ClassFileManifestBuilder method buildManifest.

/**
 * Builds a .class file manifest, then diffs against any previously calculated manifest for this
 * debugging session.
 *
 * @return null if no diff is available (either no manifest could be calculated, or no previously
 *     calculated manifest is available.
 */
@Nullable
public static ClassFileManifest.Diff buildManifest(ExecutionEnvironment env, @Nullable HotSwapProgress progress) throws ExecutionException {
    if (!HotSwapUtils.canHotSwap(env)) {
        return null;
    }
    BlazeCommandRunConfiguration configuration = getConfiguration(env);
    Project project = configuration.getProject();
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        throw new ExecutionException("Not synced yet; please sync project");
    }
    JavaClasspathAspectStrategy aspectStrategy = JavaClasspathAspectStrategy.findStrategy(projectData.blazeVersionData);
    if (aspectStrategy == null) {
        return null;
    }
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
        ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, aspectStrategy.getBuildFlags(), ImmutableList.of(), "Building debug binary");
        if (progress != null) {
            progress.setCancelWorker(() -> buildOperation.cancel(true));
        }
        try {
            SaveUtil.saveAllFiles();
            BuildResult result = buildOperation.get();
            if (result.status != BuildResult.Status.SUCCESS) {
                throw new ExecutionException("Blaze failure building debug binary");
            }
        } catch (InterruptedException | CancellationException e) {
            buildOperation.cancel(true);
            throw new RunCanceledByUserException();
        } catch (java.util.concurrent.ExecutionException e) {
            throw new ExecutionException(e);
        }
        ImmutableList<File> jars = buildResultHelper.getArtifactsForOutputGroups(ImmutableSet.of(JavaClasspathAspectStrategy.OUTPUT_GROUP)).stream().filter(f -> f.getName().endsWith(".jar")).collect(toImmutableList());
        ClassFileManifest oldManifest = getManifest(env);
        ClassFileManifest newManifest = ClassFileManifest.build(jars, oldManifest);
        env.getCopyableUserData(MANIFEST_KEY).set(newManifest);
        return oldManifest != null ? ClassFileManifest.modifiedClasses(oldManifest, newManifest) : null;
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) RunProfile(com.intellij.execution.configurations.RunProfile) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) WrappingRunConfiguration(com.intellij.execution.configurations.WrappingRunConfiguration) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeBeforeRunCommandHelper(com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ImmutableList(com.google.common.collect.ImmutableList) HotSwapProgress(com.intellij.debugger.impl.HotSwapProgress) Project(com.intellij.openapi.project.Project) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) GuavaHelper.toImmutableList(com.google.idea.common.guava.GuavaHelper.toImmutableList) Nullable(javax.annotation.Nullable) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Nullable(javax.annotation.Nullable)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 BlazeBeforeRunCommandHelper (com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper)1 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)1 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)1 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)1 SaveUtil (com.google.idea.blaze.base.util.SaveUtil)1 GuavaHelper.toImmutableList (com.google.idea.common.guava.GuavaHelper.toImmutableList)1 HotSwapProgress (com.intellij.debugger.impl.HotSwapProgress)1 ExecutionException (com.intellij.execution.ExecutionException)1 RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 WrappingRunConfiguration (com.intellij.execution.configurations.WrappingRunConfiguration)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 Project (com.intellij.openapi.project.Project)1 Key (com.intellij.openapi.util.Key)1 File (java.io.File)1