Search in sources :

Example 21 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class DuplicateSourceDetector method reportDuplicates.

public void reportDuplicates(BlazeContext context) {
    List<Duplicate> duplicates = Lists.newArrayList();
    for (ArtifactLocation key : artifacts.keySet()) {
        Collection<TargetKey> labels = artifacts.get(key);
        if (labels.size() > 1) {
            // Workaround for aspect bug. Can be removed after the next blaze release, as of May 27 2016
            Set<TargetKey> labelSet = Sets.newHashSet(labels);
            if (labelSet.size() > 1) {
                duplicates.add(new Duplicate(key, labelSet));
            }
        }
    }
    if (duplicates.isEmpty()) {
        return;
    }
    duplicates.sort(Comparator.comparing(lhs -> lhs.artifactLocation.getRelativePath()));
    context.output(new PerformanceWarning("Duplicate sources detected:"));
    for (Duplicate duplicate : duplicates) {
        ArtifactLocation artifactLocation = duplicate.artifactLocation;
        context.output(new PerformanceWarning("  Source: " + artifactLocation.getRelativePath()));
        context.output(new PerformanceWarning("  Consumed by rules:"));
        for (TargetKey targetKey : duplicate.targets) {
            context.output(new PerformanceWarning("    " + targetKey.label));
        }
        // Newline
        context.output(new PerformanceWarning(""));
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) List(java.util.List) Lists(com.google.common.collect.Lists) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) Collection(java.util.Collection) Set(java.util.Set) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Multimap(com.google.common.collect.Multimap) Comparator(java.util.Comparator) Sets(com.google.common.collect.Sets) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Example 22 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class SourceDirectoryCalculator method calculateContentEntries.

public ImmutableList<BlazeContentEntry> calculateContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, ImportRoots importRoots, Collection<SourceArtifact> sources, Map<TargetKey, ArtifactLocation> javaPackageManifests) {
    ManifestFilePackageReader manifestFilePackageReader = Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("ReadPackageManifests", EventType.Other));
        Map<TargetKey, Map<ArtifactLocation, String>> manifestMap = PackageManifestReader.getInstance().readPackageManifestFiles(project, childContext, artifactLocationDecoder, javaPackageManifests, packageReaderExecutorService);
        return new ManifestFilePackageReader(manifestMap);
    });
    final List<JavaPackageReader> javaPackageReaders = Lists.newArrayList(manifestFilePackageReader, JavaSourcePackageReader.getInstance(), generatedFileJavaPackageReader);
    Collection<SourceArtifact> nonGeneratedSources = filterGeneratedArtifacts(sources);
    // Sort artifacts and excludes into their respective workspace paths
    Multimap<WorkspacePath, SourceArtifact> sourcesUnderDirectoryRoot = sortArtifactLocationsByRootDirectory(context, importRoots, nonGeneratedSources);
    List<BlazeContentEntry> result = Lists.newArrayList();
    Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("CalculateSourceDirectories", EventType.Other));
        for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
            File contentRoot = workspaceRoot.fileForPath(workspacePath);
            ImmutableList<BlazeSourceDirectory> sourceDirectories = calculateSourceDirectoriesForContentRoot(context, workspaceRoot, artifactLocationDecoder, workspacePath, sourcesUnderDirectoryRoot.get(workspacePath), javaPackageReaders);
            if (!sourceDirectories.isEmpty()) {
                result.add(new BlazeContentEntry(contentRoot, sourceDirectories));
            }
        }
        result.sort(Comparator.comparing(lhs -> lhs.contentRoot));
    });
    return ImmutableList.copyOf(result);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TransientExecutor(com.google.idea.blaze.base.async.executor.TransientExecutor) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Multiset(com.google.common.collect.Multiset) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) HashMultiset(com.google.common.collect.HashMultiset) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) Objects(com.google.common.base.Objects) Logger(com.intellij.openapi.diagnostic.Logger) Splitter(com.google.common.base.Splitter) Nullable(javax.annotation.Nullable) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Comparator(java.util.Comparator) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) PackagePrefixCalculator(com.google.idea.blaze.base.util.PackagePrefixCalculator) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 23 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class BlazeJavaRunProfileState method startProcess.

@Override
protected ProcessHandler startProcess() throws ExecutionException {
    Project project = configuration.getProject();
    BlazeCommand.Builder blazeCommand;
    BlazeTestUiSession testUiSession = useTestUi() ? TestUiSessionProvider.getInstance(project).getTestUiSession(configuration.getTarget()) : null;
    if (testUiSession != null) {
        blazeCommand = getBlazeCommandBuilder(project, configuration, testUiSession.getBlazeFlags(), executorType);
        setConsoleBuilder(new TextConsoleBuilderImpl(project) {

            @Override
            protected ConsoleView createConsole() {
                return SmRunnerUtils.getConsoleView(project, configuration, getEnvironment().getExecutor(), testUiSession);
            }
        });
    } else {
        blazeCommand = getBlazeCommandBuilder(project, configuration, ImmutableList.of(), executorType);
    }
    addConsoleFilters(new BlazeTargetFilter(project, true), new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.NonSync, false));
    List<String> command = HotSwapUtils.canHotSwap(getEnvironment()) ? getBashCommandsToRunScript(blazeCommand) : blazeCommand.build().toList();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    return new ScopedBlazeProcessHandler(project, command, workspaceRoot, new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {

        @Override
        public void onBlazeContextStart(BlazeContext context) {
            context.push(new IssuesScope(project, BlazeUserSettings.getInstance().getShowProblemsViewForRunAction())).push(new IdeaLogScope());
        }

        @Override
        public ImmutableList<ProcessListener> createProcessListeners(BlazeContext context) {
            LineProcessingOutputStream outputStream = LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context));
            return ImmutableList.of(new LineProcessingProcessAdapter(outputStream));
        }
    });
}
Also used : IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) LineProcessingProcessAdapter(com.google.idea.blaze.base.run.processhandler.LineProcessingProcessAdapter) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ConsoleView(com.intellij.execution.ui.ConsoleView) ImmutableList(com.google.common.collect.ImmutableList) BlazeTargetFilter(com.google.idea.blaze.base.run.filter.BlazeTargetFilter) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedBlazeProcessHandler(com.google.idea.blaze.base.run.processhandler.ScopedBlazeProcessHandler) Project(com.intellij.openapi.project.Project) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) BlazeTestUiSession(com.google.idea.blaze.base.run.smrunner.BlazeTestUiSession) TextConsoleBuilderImpl(com.intellij.execution.filters.TextConsoleBuilderImpl)

Example 24 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext 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 25 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class BlazeKotlinSyncPluginTest method initTest.

@Override
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
    super.initTest(applicationServices, projectServices);
    ExtensionPointImpl<BuildSystemProvider> buildSystems = registerExtensionPoint(BuildSystemProvider.EP_NAME, BuildSystemProvider.class);
    buildSystems.registerExtension(new BazelBuildSystemProvider());
    ExtensionPointImpl<BlazeSyncPlugin> syncPlugins = registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
    syncPlugins.registerExtension(new BlazeJavaSyncPlugin());
    syncPlugins.registerExtension(new BlazeKotlinSyncPlugin());
    context = new BlazeContext();
    context.addOutputSink(IssueOutput.class, errorCollector);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeJavaSyncPlugin(com.google.idea.blaze.java.sync.BlazeJavaSyncPlugin) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BazelBuildSystemProvider(com.google.idea.blaze.base.bazel.BazelBuildSystemProvider) BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) BazelBuildSystemProvider(com.google.idea.blaze.base.bazel.BazelBuildSystemProvider)

Aggregations

BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)42 ImmutableList (com.google.common.collect.ImmutableList)18 Nullable (javax.annotation.Nullable)18 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 List (java.util.List)16 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)15 Project (com.intellij.openapi.project.Project)15 File (java.io.File)15 Set (java.util.Set)15 Lists (com.google.common.collect.Lists)13 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)12 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)12 Logger (com.intellij.openapi.diagnostic.Logger)12 Collection (java.util.Collection)12 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)11 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)10 Map (java.util.Map)10 ImmutableSet (com.google.common.collect.ImmutableSet)9 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)9 Collectors (java.util.stream.Collectors)9