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();
}
}
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);
}
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));
}
});
}
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;
}
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);
}
Aggregations