Search in sources :

Example 1 with BlazeExecutor

use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method initTest.

@Override
protected void initTest(Container applicationServices, Container projectServices) {
    MockExperimentService mockExperimentService = new MockExperimentService();
    applicationServices.register(ExperimentService.class, mockExperimentService);
    BlazeExecutor blazeExecutor = new MockBlazeExecutor();
    applicationServices.register(BlazeExecutor.class, blazeExecutor);
    projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager());
    BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(DUMMY_IMPORT_SETTINGS);
    MockFileOperationProvider mockFileOperationProvider = new MockFileOperationProvider();
    applicationServices.register(FileOperationProvider.class, mockFileOperationProvider);
    context = new BlazeContext();
    context.addOutputSink(IssueOutput.class, errorCollector);
    registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
    // For importJavaWorkspace.
    applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader() {

        @Nullable
        @Override
        public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
            return null;
        }
    });
    applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
    applicationServices.register(PrefetchService.class, new MockPrefetchService());
    registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) Nullable(javax.annotation.Nullable)

Example 2 with BlazeExecutor

use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.

the class BuildFileFormatter method formatTextWithTimeout.

/**
 * Format the BUILD file with a timeout. The tool may be fetched from a network filesystem, and we
 * don't want to block the UI if there is a network issue.
 *
 * @return formatted text, or null if there is an error or timeout
 */
@Nullable
static String formatTextWithTimeout(String text) {
    BlazeExecutor executor = BlazeExecutor.getInstance();
    ListenableFuture<String> result = executor.submit(() -> formatText(text));
    try {
        return result.get(TIMEOUT_SECS, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        result.cancel(true);
        return null;
    } catch (ExecutionException | TimeoutException e) {
        logger.warn(e);
        result.cancel(true);
        return null;
    }
}
Also used : BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Nullable(javax.annotation.Nullable)

Example 3 with BlazeExecutor

use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporterTest method initTest.

@Override
// False positive on getDeclaredPackageOfJavaFile.
@SuppressWarnings("FunctionalInterfaceClash")
protected void initTest(Container applicationServices, Container projectServices) {
    applicationServices.register(ExperimentService.class, new MockExperimentService());
    BlazeExecutor blazeExecutor = new MockBlazeExecutor();
    applicationServices.register(BlazeExecutor.class, blazeExecutor);
    projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager());
    BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(DUMMY_IMPORT_SETTINGS);
    // will silently fall back to FilePathJavaPackageReader
    applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader() {

        @Nullable
        @Override
        public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
            return null;
        }
    });
    applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
    applicationServices.register(PrefetchService.class, new MockPrefetchService());
    context = new BlazeContext();
    context.addOutputSink(IssueOutput.class, errorCollector);
    augmenters = registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
    registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) Nullable(javax.annotation.Nullable)

Example 4 with BlazeExecutor

use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.

the class SourceDirectoryCalculatorTest method initTest.

@Override
protected void initTest(Container applicationServices, Container projectServices) {
    super.initTest(applicationServices, projectServices);
    mockInputStreamProvider = new MockInputStreamProvider();
    applicationServices.register(InputStreamProvider.class, mockInputStreamProvider);
    applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader());
    applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
    applicationServices.register(FileOperationProvider.class, new MockFileOperationProvider());
    context.addOutputSink(IssueOutput.class, issues);
    sourceDirectoryCalculator = new SourceDirectoryCalculator();
    BlazeExecutor blazeExecutor = new MockBlazeExecutor();
    applicationServices.register(BlazeExecutor.class, blazeExecutor);
    experimentService = new MockExperimentService();
    applicationServices.register(ExperimentService.class, experimentService);
    applicationServices.register(PrefetchService.class, new MockPrefetchService());
    registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) MockInputStreamProvider(com.google.idea.blaze.base.io.MockInputStreamProvider) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor)

Example 5 with BlazeExecutor

use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.

the class BlazeAndroidTestLaunchTask method perform.

@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
    BlazeExecutor executor = BlazeExecutor.getInstance();
    ProcessHandlerLaunchStatus processHandlerLaunchStatus = (ProcessHandlerLaunchStatus) launchStatus;
    final ProcessHandler processHandler = processHandlerLaunchStatus.getProcessHandler();
    blazeResult = executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return Scope.root(new ScopedFunction<Boolean>() {

                @Override
                public Boolean execute(@NotNull BlazeContext context) {
                    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
                    if (projectViewSet == null) {
                        IssueOutput.error("Could not load project view. Please resync project.").submit(context);
                        return false;
                    }
                    BlazeCommand.Builder commandBuilder = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.TEST).addTargets(target);
                    // Build flags must match BlazeBeforeRunTask.
                    commandBuilder.addBlazeFlags(buildFlags);
                    // Run the test on the selected local device/emulator.
                    commandBuilder.addBlazeFlags(TEST_LOCAL_DEVICE, BlazeFlags.TEST_OUTPUT_STREAMED).addBlazeFlags(testDeviceSerialFlags(device.getSerialNumber())).addBlazeFlags(testFilter.getBlazeFlags());
                    if (debug) {
                        commandBuilder.addBlazeFlags(TEST_DEBUG, BlazeFlags.NO_CACHE_TEST_RESULTS);
                    }
                    BlazeCommand command = commandBuilder.build();
                    printer.stdout(String.format("Starting %s test...\n", Blaze.buildSystemName(project)));
                    printer.stdout(command + "\n");
                    LineProcessingOutputStream.LineProcessor stdoutLineProcessor = line -> {
                        printer.stdout(line);
                        return true;
                    };
                    LineProcessingOutputStream.LineProcessor stderrLineProcessor = line -> {
                        printer.stderr(line);
                        return true;
                    };
                    SaveUtil.saveAllFiles();
                    int retVal = ExternalTask.builder(WorkspaceRoot.fromProject(project)).addBlazeCommand(command).context(context).stdout(LineProcessingOutputStream.of(stdoutLineProcessor)).stderr(LineProcessingOutputStream.of(stderrLineProcessor)).build().run();
                    FileCaches.refresh(project);
                    if (retVal != 0) {
                        context.setHasError();
                    }
                    return !context.hasErrors();
                }
            });
        }
    });
    blazeResult.addListener(runContext::onLaunchTaskComplete, PooledThreadExecutor.INSTANCE);
    // The debug case is set up in ConnectBlazeTestDebuggerTask
    if (!debug) {
        waitAndSetUpForKillingBlazeOnStop(processHandler, launchStatus);
    }
    return true;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Callable(java.util.concurrent.Callable) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Aggregations

BlazeExecutor (com.google.idea.blaze.base.async.executor.BlazeExecutor)5 MockBlazeExecutor (com.google.idea.blaze.base.async.executor.MockBlazeExecutor)3 MockPrefetchService (com.google.idea.blaze.base.prefetch.MockPrefetchService)3 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)3 MockExperimentService (com.google.idea.common.experiments.MockExperimentService)3 Nullable (javax.annotation.Nullable)3 BlazeImportSettingsManager (com.google.idea.blaze.base.settings.BlazeImportSettingsManager)2 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)2 JavaLikeLanguage (com.google.idea.blaze.java.sync.source.JavaLikeLanguage)2 JavaSourcePackageReader (com.google.idea.blaze.java.sync.source.JavaSourcePackageReader)2 PackageManifestReader (com.google.idea.blaze.java.sync.source.PackageManifestReader)2 SourceArtifact (com.google.idea.blaze.java.sync.source.SourceArtifact)2 ProcessHandlerLaunchStatus (com.android.tools.idea.run.util.ProcessHandlerLaunchStatus)1 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)1 MockInputStreamProvider (com.google.idea.blaze.base.io.MockInputStreamProvider)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 BlazeJavaSyncAugmenter (com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1