Search in sources :

Example 26 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class LibraryEditor method updateProjectLibraries.

public static void updateProjectLibraries(Project project, BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Collection<BlazeLibrary> libraries) {
    Set<LibraryKey> intelliJLibraryState = Sets.newHashSet();
    for (Library library : ProjectLibraryTable.getInstance(project).getLibraries()) {
        String name = library.getName();
        if (name != null) {
            intelliJLibraryState.add(LibraryKey.fromIntelliJLibraryName(name));
        }
    }
    context.output(PrintOutput.log(String.format("Workspace has %d libraries", libraries.size())));
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();
    try {
        for (BlazeLibrary library : libraries) {
            updateLibrary(project, blazeProjectData.artifactLocationDecoder, libraryTable, libraryTableModel, library);
        }
        // Garbage collect unused libraries
        List<LibrarySource> librarySources = Lists.newArrayList();
        for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
            LibrarySource librarySource = syncPlugin.getLibrarySource(projectViewSet, blazeProjectData);
            if (librarySource != null) {
                librarySources.add(librarySource);
            }
        }
        Predicate<Library> gcRetentionFilter = librarySources.stream().map(LibrarySource::getGcRetentionFilter).filter(Objects::nonNull).reduce(Predicate::or).orElse(o -> false);
        Set<LibraryKey> newLibraryKeys = libraries.stream().map((blazeLibrary) -> blazeLibrary.key).collect(Collectors.toSet());
        for (LibraryKey libraryKey : intelliJLibraryState) {
            String libraryIntellijName = libraryKey.getIntelliJLibraryName();
            if (!newLibraryKeys.contains(libraryKey)) {
                Library library = libraryTable.getLibraryByName(libraryIntellijName);
                if (!gcRetentionFilter.test(library)) {
                    if (library != null) {
                        libraryTableModel.removeLibrary(library);
                    }
                }
            }
        }
    } finally {
        libraryTableModel.commit();
    }
}
Also used : LibraryKey(com.google.idea.blaze.base.model.LibraryKey) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) OrderRootType(com.intellij.openapi.roots.OrderRootType) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) Set(java.util.Set) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Library(com.intellij.openapi.roots.libraries.Library) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) List(java.util.List) Lists(com.google.common.collect.Lists) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Objects(java.util.Objects) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) Library(com.intellij.openapi.roots.libraries.Library)

Example 27 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeSyncIntegrationTestCase method setProjectView.

protected void setProjectView(String... contents) {
    ProjectViewParser projectViewParser = new ProjectViewParser(context, new WorkspacePathResolverImpl(workspaceRoot));
    projectViewParser.parseProjectView(Joiner.on("\n").join(contents));
    ProjectViewSet result = projectViewParser.getResult();
    assertThat(result.getProjectViewFiles()).isNotEmpty();
    errorCollector.assertNoIssues();
    setProjectViewSet(result);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser)

Example 28 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeCidrLauncher method createProcess.

@Override
public ProcessHandler createProcess(CommandLineState state) throws ExecutionException {
    ImmutableList<String> testHandlerFlags = ImmutableList.of();
    BlazeTestUiSession testUiSession = useTestUi() ? TestUiSessionProvider.getInstance(project).getTestUiSession(configuration.getTarget()) : null;
    if (testUiSession != null) {
        testHandlerFlags = testUiSession.getBlazeFlags();
    }
    ProjectViewSet projectViewSet = Preconditions.checkNotNull(ProjectViewManager.getInstance(project).getProjectViewSet());
    List<String> fixedBlazeFlags = getFixedBlazeFlags();
    BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), handlerState.getCommandState().getCommand()).addTargets(configuration.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, handlerState.getCommandState().getCommand(), BlazeInvocationContext.NonSync)).addBlazeFlags(testHandlerFlags).addBlazeFlags(fixedBlazeFlags).addExeFlags(handlerState.getExeFlagsState().getExpandedFlags());
    state.setConsoleBuilder(createConsoleBuilder(testUiSession));
    state.addConsoleFilters(getConsoleFilters().toArray(new Filter[0]));
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    return new ScopedBlazeProcessHandler(project, command.build(), workspaceRoot, new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {

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

        @Override
        public ImmutableList<ProcessListener> createProcessListeners(BlazeContext context) {
            LineProcessingOutputStream outputStream = LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context));
            return ImmutableList.of(new LineProcessingProcessAdapter(outputStream));
        }
    });
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LineProcessingProcessAdapter(com.google.idea.blaze.base.run.processhandler.LineProcessingProcessAdapter) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ImmutableList(com.google.common.collect.ImmutableList) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedBlazeProcessHandler(com.google.idea.blaze.base.run.processhandler.ScopedBlazeProcessHandler) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) UrlFilter(com.intellij.execution.filters.UrlFilter) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) Filter(com.intellij.execution.filters.Filter) BlazeTargetFilter(com.google.idea.blaze.base.run.filter.BlazeTargetFilter) 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)

Example 29 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeJavaRunProfileState method getBlazeCommandBuilder.

@VisibleForTesting
static BlazeCommand.Builder getBlazeCommandBuilder(Project project, BlazeCommandRunConfiguration configuration, List<String> extraBlazeFlags, ExecutorType executorType) {
    List<String> blazeFlags = new ArrayList<>(extraBlazeFlags);
    ProjectViewSet projectViewSet = Preconditions.checkNotNull(ProjectViewManager.getInstance(project).getProjectViewSet());
    BlazeJavaRunConfigState handlerState = getState(configuration);
    String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath();
    BlazeCommandName blazeCommand = Preconditions.checkNotNull(handlerState.getCommandState().getCommand());
    if (executorType == ExecutorType.COVERAGE) {
        blazeCommand = BlazeCommandName.COVERAGE;
        blazeFlags.addAll(CoverageUtils.getBlazeFlags());
    }
    BlazeCommand.Builder command = BlazeCommand.builder(binaryPath, blazeCommand).addTargets(configuration.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, blazeCommand, BlazeInvocationContext.NonSync)).addBlazeFlags(blazeFlags).addBlazeFlags(handlerState.getBlazeFlagsState().getExpandedFlags());
    if (executorType == ExecutorType.DEBUG) {
        Kind kind = configuration.getTargetKind();
        boolean isBinary = kind != null && kind.ruleType == RuleType.BINARY;
        int debugPort = handlerState.getDebugPortState().port;
        if (isBinary) {
            command.addExeFlags(debugPortFlag(false, debugPort));
        } else {
            command.addBlazeFlags(BlazeFlags.JAVA_TEST_DEBUG);
            command.addBlazeFlags(debugPortFlag(true, debugPort));
        }
    }
    command.addExeFlags(handlerState.getExeFlagsState().getExpandedFlags());
    return command;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Kind(com.google.idea.blaze.base.model.primitives.Kind) ArrayList(java.util.ArrayList) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 30 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method importJavaWorkspace.

private BlazeJavaImportResult importJavaWorkspace(WorkspaceRoot workspaceRoot, TargetMapBuilder targetMapBuilder, ProjectView projectView) {
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
    TargetMap targetMap = targetMapBuilder.build();
    JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
    BlazeJavaWorkspaceImporter blazeWorkspaceImporter = new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, workspaceLanguageSettings, targetMap, sourceFilter, jdepsMap, workingSet, FAKE_ARTIFACT_DECODER);
    return blazeWorkspaceImporter.importWorkspace(context);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Aggregations

ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)74 File (java.io.File)30 Test (org.junit.Test)29 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)21 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)17 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)17 ImmutableList (com.google.common.collect.ImmutableList)16 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)16 Project (com.intellij.openapi.project.Project)16 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)15 Nullable (javax.annotation.Nullable)15 List (java.util.List)14 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)12 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)11 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)11 Kind (com.google.idea.blaze.base.model.primitives.Kind)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 Set (java.util.Set)11 Lists (com.google.common.collect.Lists)10 Collectors (java.util.stream.Collectors)10