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.deployinfo.BlazeApkProvider.java

@NotNull
@Override/*from w w w . j a va 2s .co m*/
public Collection<ApkInfo> getApks(@NotNull IDevice device) throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = Futures.get(deployInfoFuture, ApkProvisionException.class);
    ImmutableList.Builder<ApkInfo> apkInfos = ImmutableList.builder();
    for (File apk : deployInfo.getApksToDeploy()) {
        apkInfos.add(new ApkInfo(apk, manifestPackageForApk(apk)));
    }
    return apkInfos.build();
}

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

@NotNull
@Override/*from  ww  w  .j  a v  a2s  . co  m*/
public String getPackageName() throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = Futures.get(deployInfoFuture, ApkProvisionException.class);
    Manifest manifest = deployInfo.getMergedManifest();
    if (manifest == null) {
        throw new ApkProvisionException(
                "Could not find merged manifest: " + deployInfo.getMergedManifestFile());
    }
    String applicationId = ApplicationManager.getApplication()
            .runReadAction((Computable<String>) () -> manifest.getPackage().getValue());
    if (applicationId == null) {
        throw new ApkProvisionException(
                "No application id in merged manifest: " + deployInfo.getMergedManifestFile());
    }
    return applicationId;
}

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

@NotNull
@Override/*from  w  w  w. ja va 2s.c  o m*/
public String getPackageName() throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = Futures.get(deployInfoFuture, ApkProvisionException.class);
    Manifest manifest = Iterables.getFirst(deployInfo.getAdditionalMergedManifests(), null);
    if (manifest == null) {
        // The application may not have a separate package,
        // and can instead be in the same package as the tests.
        return getTestPackageName();
    }
    String applicationId = ApplicationManager.getApplication()
            .runReadAction((Computable<String>) () -> manifest.getPackage().getValue());
    if (applicationId == null) {
        throw new ApkProvisionException("No application id in manifest under test");
    }
    return applicationId;
}

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

@Nullable
@Override/*from   w ww  .  j  a v  a2 s  .  c  o  m*/
public String getTestPackageName() throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = Futures.get(deployInfoFuture, ApkProvisionException.class);
    Manifest manifest = deployInfo.getMergedManifest();
    if (manifest == null) {
        throw new ApkProvisionException(
                "Could not find merged manifest: " + deployInfo.getMergedManifestFile());
    }
    String applicationId = ApplicationManager.getApplication()
            .runReadAction((Computable<String>) () -> manifest.getPackage().getValue());
    if (applicationId == null) {
        throw new ApkProvisionException(
                "No application id in merged manifest: " + deployInfo.getMergedManifestFile());
    }
    return applicationId;
}

From source file:com.torodb.torod.mongodb.commands.impl.aggregation.CountImplementation.java

@Override
public CommandResult<Long> apply(Command<? super CountArgument, ? super Long> command,
        CommandRequest<CountArgument> req) throws MongoException {

    CountArgument arg = req.getCommandArgument();
    ToroConnection connection = getToroConnection(req);

    QueryCriteria queryCriteria;/*  www.  j a  v a  2s . c o  m*/
    if (arg.getQuery() == null) {
        queryCriteria = TrueQueryCriteria.getInstance();
    } else {
        queryCriteria = queryCriteriaTranslator.translate(arg.getQuery());
    }

    try (ToroTransaction transaction = connection.createTransaction(TransactionMetainfo.READ_ONLY)) {
        return new NonWriteCommandResult<>(
                Futures.get(transaction.count(arg.getCollection(), queryCriteria), UnknownErrorException.class)
                        .longValue());
    } catch (ImplementationDbException ex) {
        throw new UnknownErrorException(ex);
    }
}

From source file:org.robotninjas.concurrent.FluentDecorator.java

@Override
public <E extends Exception> V get(Class<E> exceptionClass) throws E {
    return Futures.get(this, exceptionClass);
}

From source file:org.robotninjas.concurrent.FluentFutureTask.java

@Override
public <Y extends Exception> V get(Class<Y> exceptionClass) throws Y {
    return Futures.get(this, exceptionClass);
}

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

@Override
public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
    return Futures.get(buildStep.getApplicationIdProvider(), ExecutionException.class);
}

From source file:com.google.idea.blaze.android.run.runner.BlazeApkBuildStepNormalBuild.java

@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
    final ScopedTask buildTask = new ScopedTask(context) {
        @Override/*from   w  w  w .  ja v a2 s.com*/
        protected void execute(@NotNull BlazeContext context) {
            BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystem(project),
                    BlazeCommandName.BUILD);
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);

            command.addTargets(label).addBlazeFlags("--output_groups=+android_deploy_info")
                    .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(new LoggedTimingScope(project, Action.BLAZE_BUILD));
            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.instantrun.BlazeAndroidBinaryInstantRunContext.java

@Override
public LaunchTasksProvider getLaunchTasksProvider(LaunchOptions launchOptions,
        BlazeAndroidRunConfigurationDebuggerManager debuggerManager) throws ExecutionException {
    InstantRunBuildAnalyzer analyzer = Futures.get(buildStep.getInstantRunBuildAnalyzer(),
            ExecutionException.class);

    if (analyzer.canReuseProcessHandler()) {
        return new UpdateSessionTasksProvider(analyzer);
    }//from  w  w w .  ja  v a2  s. c om
    return new BlazeAndroidLaunchTasksProvider(project, this, getApplicationIdProvider(), launchOptions,
            debuggerManager);
}