Example usage for com.google.common.util.concurrent Futures get

List of usage examples for com.google.common.util.concurrent Futures get

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures get.

Prototype

@Deprecated
@GwtIncompatible("reflection")
public static <V, X extends Exception> V get(Future<V> future, Class<X> exceptionClass) throws X 

Source Link

Document

Returns the result of Future#get() , converting most exceptions to a new instance of the given checked exception type.

Usage

From source file:com.google.idea.blaze.android.run.binary.instantrun.BlazeAndroidBinaryInstantRunContext.java

@Override
public ImmutableList<LaunchTask> getDeployTasks(IDevice device, LaunchOptions launchOptions)
        throws ExecutionException {
    InstantRunBuildAnalyzer analyzer = Futures.get(buildStep.getInstantRunBuildAnalyzer(),
            ExecutionException.class);
    return ImmutableList.<LaunchTask>builder().addAll(analyzer.getDeployTasks(launchOptions))
            .add(analyzer.getNotificationTask()).build();
}

From source file:com.google.idea.blaze.android.run.binary.instantrun.BlazeAndroidBinaryInstantRunContext.java

@Nullable
@Override//www . j a va2 s .  com
public LaunchTask getApplicationLaunchTask(LaunchOptions launchOptions, AndroidDebugger androidDebugger,
        AndroidDebuggerState androidDebuggerState, ProcessHandlerLaunchStatus processHandlerLaunchStatus)
        throws ExecutionException {
    BlazeApkBuildStepInstantRun.BuildResult buildResult = Futures.get(buildStep.getBuildResult(),
            ExecutionException.class);

    final StartActivityFlagsProvider startActivityFlagsProvider = new DefaultStartActivityFlagsProvider(
            androidDebugger, androidDebuggerState, project, launchOptions.isDebug(),
            configState.ACTIVITY_EXTRA_FLAGS);

    ApplicationIdProvider applicationIdProvider = getApplicationIdProvider();
    return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(project,
            applicationIdProvider, buildResult.mergedManifestFile, configState, startActivityFlagsProvider,
            processHandlerLaunchStatus);
}

From source file:com.spotify.asyncdatastoreclient.Datastore.java

/**
 * Start a new transaction.//from w w  w .  j  ava 2  s. c om
 *
 * The returned {@code TransactionResult} contains the transaction if the
 * request is successful.
 *
 * @return the result of the transaction request.
 */
public TransactionResult transaction() throws DatastoreException {
    return Futures.get(transactionAsync(IsolationLevel.SNAPSHOT), DatastoreException.class);
}

From source file:com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryNormalBuildRunContext.java

@Override
public LaunchTask getApplicationLaunchTask(LaunchOptions launchOptions, @Nullable Integer userId,
        AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState,
        ProcessHandlerLaunchStatus processHandlerLaunchStatus) throws ExecutionException {
    final StartActivityFlagsProvider startActivityFlagsProvider = new DefaultStartActivityFlagsProvider(
            androidDebugger, androidDebuggerState, project, launchOptions.isDebug(),
            UserIdHelper.getFlagsFromUserId(userId));

    BlazeAndroidDeployInfo deployInfo = Futures.get(buildStep.getDeployInfo(), ExecutionException.class);

    return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(project,
            applicationIdProvider, deployInfo.getMergedManifestFile(), configState, startActivityFlagsProvider,
            processHandlerLaunchStatus);
}

From source file:com.google.idea.blaze.android.run.test.BlazeAndroidTestRunContext.java

@Override
public ImmutableList<LaunchTask> getDeployTasks(IDevice device, LaunchOptions launchOptions)
        throws ExecutionException {
    if (!configState.isRunThroughBlaze()) {
        BlazeAndroidDeployInfo deployInfo = Futures.get(buildStep.getDeployInfo(), ExecutionException.class);
        if (!deployInfo.getDataToDeploy().isEmpty()) {
            throw new ExecutionException(
                    "This test target has data dependencies (defined in the 'data' attribute).\n"
                            + "These can only be installed if the configuration is run through 'blaze test'.\n"
                            + "Check the \"Run through 'blaze test'\" checkbox on your "
                            + "run configuration and try again.");
        }/* ww w .j a v a  2  s  .com*/
    }

    Collection<ApkInfo> apks;
    try {
        apks = apkProvider.getApks(device);
    } catch (ApkProvisionException e) {
        throw new ExecutionException(e);
    }
    return ImmutableList.of(new DeployApkTask(project, launchOptions, apks));
}

From source file:com.spotify.asyncdatastoreclient.Datastore.java

/**
 * Start a new transaction with a given isolation level.
 *
 * The returned {@code TransactionResult} contains the transaction if the
 * request is successful./* w  ww . ja  v a  2 s  .c o m*/
 *
 * @param isolationLevel the transaction isolation level to request.
 * @return the result of the transaction request.
 */
public TransactionResult transaction(final IsolationLevel isolationLevel) throws DatastoreException {
    return Futures.get(transactionAsync(isolationLevel), DatastoreException.class);
}

From source file:com.google.idea.blaze.plugin.run.BuildPluginBeforeRunTaskProvider.java

@Override
public final boolean executeTask(final DataContext dataContext, final RunConfiguration configuration,
        final ExecutionEnvironment env, Task task) {
    if (!canExecuteTask(configuration, task)) {
        return false;
    }/*from  w w w.  j  a  va2s.co  m*/
    boolean suppressConsole = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction();
    return Scope.root(context -> {
        context.push(new ExperimentScope()).push(new IssuesScope(project))
                .push(new BlazeConsoleScope.Builder(project).setSuppressConsole(suppressConsole).build())
                .push(new IdeaLogScope());

        final ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
        if (projectViewSet == null) {
            IssueOutput.error("Could not load project view. Please resync project").submit(context);
            return false;
        }

        final ScopedTask buildTask = new ScopedTask(context) {
            @Override
            protected void execute(BlazeContext context) {
                BlazeIntellijPluginConfiguration config = (BlazeIntellijPluginConfiguration) configuration;
                BlazeCommand command = config.buildBlazeCommand(project, projectViewSet);
                if (command == null || context.hasErrors() || context.isCancelled()) {
                    return;
                }
                SaveUtil.saveAllFiles();
                WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
                int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command).context(context)
                        .stderr(LineProcessingOutputStream
                                .of(new IssueOutputLineProcessor(project, context, workspaceRoot)))
                        .build().run(new LoggedTimingScope(project, Action.BLAZE_BUILD));
                if (retVal != 0) {
                    context.setHasError();
                }
                FileCaches.refresh(project);
            }
        };

        ListenableFuture<Void> buildFuture = BlazeExecutor.submitTask(project,
                "Executing blaze build for IntelliJ plugin jar", buildTask);

        try {
            Futures.get(buildFuture, ExecutionException.class);
        } catch (ExecutionException e) {
            context.setHasError();
        } catch (CancellationException e) {
            context.setCancelled();
        }

        if (context.hasErrors() || context.isCancelled()) {
            return false;
        }
        return true;
    });
}

From source file:com.google.idea.blaze.android.run.binary.mobileinstall.BlazeApkBuildStepMobileInstall.java

@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
    final ScopedTask buildTask = new ScopedTask(context) {
        @Override/*  w w w.j av a  2 s  . c  o  m*/
        protected void execute(BlazeContext context) {
            boolean incrementalInstall = env.getExecutor() instanceof IncrementalInstallExecutor;

            DeviceFutures deviceFutures = deviceSession.deviceFutures;
            assert deviceFutures != null;
            IDevice device = resolveDevice(context, deviceFutures);
            if (device == null) {
                return;
            }
            BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystem(project),
                    BlazeCommandName.MOBILE_INSTALL);
            command.addBlazeFlags(BlazeFlags.adbSerialFlags(device.getSerialNumber()));

            if (USE_SDK_ADB.getValue()) {
                File adb = getSdkAdb(project);
                if (adb != null) {
                    command.addBlazeFlags(ImmutableList.of("--adb", adb.toString()));
                }
            }

            // split-apks only supported for API level 23 and above
            if (useSplitApksIfPossible && device.getVersion().getApiLevel() >= 23) {
                command.addBlazeFlags(BlazeFlags.SPLIT_APKS);
            } else if (incrementalInstall) {
                command.addBlazeFlags(BlazeFlags.INCREMENTAL);
            }
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);

            command.addTargets(label).addBlazeFlags(buildFlags)
                    .addBlazeFlags(BlazeFlags.EXPERIMENTAL_SHOW_ARTIFACTS);

            BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project,
                    buildFlags);

            SaveUtil.saveAllFiles();
            int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context)
                    .stderr(LineProcessingOutputStream.of(deployInfoHelper.getLineProcessor(),
                            new IssueOutputLineProcessor(project, context, workspaceRoot)))
                    .build().run();
            FileCaches.refresh(project);

            if (retVal != 0) {
                context.setHasError();
                return;
            }

            BlazeAndroidDeployInfo deployInfo = deployInfoHelper.readDeployInfo(context);
            if (deployInfo == null) {
                IssueOutput.error("Could not read apk deploy info from build").submit(context);
                return;
            }
            deployInfoFuture.set(deployInfo);
        }
    };

    ListenableFuture<Void> buildFuture = BlazeExecutor.submitTask(project,
            String.format("Executing %s apk build", Blaze.buildSystemName(project)), buildTask);

    try {
        Futures.get(buildFuture, ExecutionException.class);
    } catch (ExecutionException e) {
        context.setHasError();
    } catch (CancellationException e) {
        context.setCancelled();
    }
    return context.shouldContinue();
}

From source file:com.google.idea.blaze.android.run.binary.mobileinstall.BlazeApkBuildStepMobileInstall.java

@Nullable
private static IDevice resolveDevice(BlazeContext context, DeviceFutures deviceFutures) {
    if (deviceFutures.get().size() != 1) {
        IssueOutput.error("Only one device can be used with mobile-install.").submit(context);
        return null;
    }/*from w ww  .  ja  v  a2  s .co m*/
    context.output(new StatusOutput("Waiting for mobile-install device target..."));
    try {
        return Futures.get(Iterables.getOnlyElement(deviceFutures.get()), ExecutionException.class);
    } catch (ExecutionException | UncheckedExecutionException e) {
        IssueOutput.error("Could not get device: " + e.getMessage()).submit(context);
        return null;
    } catch (CancellationException e) {
        // The user cancelled the device launch.
        context.setCancelled();
        return null;
    }
}

From source file:com.google.idea.blaze.android.run.test.BlazeAndroidTestRunContext.java

@Nullable
@Override//from w w  w. j a va2 s .c  o m
public LaunchTask getApplicationLaunchTask(LaunchOptions launchOptions, @Nullable Integer userId,
        AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState,
        ProcessHandlerLaunchStatus processHandlerLaunchStatus) throws ExecutionException {
    if (configState.isRunThroughBlaze()) {
        return new BlazeAndroidTestLaunchTask(project, label, buildFlags,
                new BlazeAndroidTestFilter(configState.getTestingType(), configState.getClassName(),
                        configState.getMethodName(), configState.getPackageName()),
                this, launchOptions.isDebug());
    }
    BlazeAndroidDeployInfo deployInfo = Futures.get(buildStep.getDeployInfo(), ExecutionException.class);
    return StockAndroidTestLaunchTask.getStockTestLaunchTask(configState, applicationIdProvider,
            launchOptions.isDebug(), deployInfo, processHandlerLaunchStatus);
}