use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class WorkspaceHelper method resolveBlazePackage.
/**
* Resolves the parent blaze package corresponding to this label.
*/
@Nullable
public static File resolveBlazePackage(Project project, Label label) {
if (!label.isExternal()) {
WorkspacePathResolver pathResolver = WorkspacePathResolverProvider.getInstance(project).getPathResolver();
return pathResolver != null ? pathResolver.resolveToFile(label.blazePackage()) : null;
}
Map<String, WorkspaceRoot> externalWorkspaces = getExternalWorkspaceRoots(project);
if (externalWorkspaces == null) {
return null;
}
WorkspaceRoot root = externalWorkspaces.get(label.externalWorkspaceName());
return root != null ? root.fileForPath(label.blazePackage()) : null;
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazePsiDirectoryRootNode method updateImpl.
@Override
protected void updateImpl(PresentationData data) {
super.updateImpl(data);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(getProject());
PsiDirectory psiDirectory = getValue();
assert psiDirectory != null;
WorkspacePath workspacePath = workspaceRoot.workspacePathFor(psiDirectory.getVirtualFile());
String text = workspacePath.relativePath();
for (BlazePsiDirectoryRootNodeNameModifier modifier : BlazePsiDirectoryRootNodeNameModifier.EP_NAME.getExtensions()) {
text = modifier.modifyRootNodeName(text);
}
data.setPresentableText(text);
data.clearText();
data.addText(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
data.setLocationString("");
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeTreeStructureProvider method createRootNode.
@Nullable
private WorkspaceRootNode createRootNode(Project project, ViewSettings settings) {
BlazeImportSettings importSettings = BlazeImportSettingsManager.getInstance(project).getImportSettings();
if (importSettings != null) {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromImportSettings(importSettings);
File fdir = workspaceRoot.directory();
VirtualFile vdir = LocalFileSystem.getInstance().findFileByIoFile(fdir);
if (vdir != null) {
final PsiManager psiManager = PsiManager.getInstance(project);
PsiDirectory directory = psiManager.findDirectory(vdir);
return new WorkspaceRootNode(project, workspaceRoot, directory, wrapViewSettings(settings));
}
}
return null;
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method getDecoder.
private static ArtifactLocationDecoder getDecoder() {
File root = new File("/root");
WorkspaceRoot workspaceRoot = new WorkspaceRoot(root);
BlazeInfo roots = BlazeInfo.createMockBlazeInfo("/", "/root", "/root/out/crosstool/bin", "/root/out/crosstool/gen");
return new ArtifactLocationDecoderImpl(roots, new WorkspacePathResolverImpl(workspaceRoot));
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BuildPluginBeforeRunTaskProvider method executeTask.
@Override
public final boolean executeTask(final DataContext dataContext, final RunConfiguration configuration, final ExecutionEnvironment env, Task task) {
if (!canExecuteTask(configuration, task)) {
return false;
}
BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
return Scope.root(context -> {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
context.push(new ExperimentScope()).push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build()).push(new IdeaLogScope());
BlazeIntellijPluginDeployer deployer = env.getUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY);
if (deployer == null) {
IssueOutput.error("Could not find BlazeIntellijPluginDeployer in env.").submit(context);
return false;
}
deployer.buildStarted();
final ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
IssueOutput.error("Could not load project view. Please resync project").submit(context);
return false;
}
final ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
String binaryPath = Blaze.getBuildSystemProvider(project).getBinaryPath();
BlazeIntellijPluginConfiguration config = (BlazeIntellijPluginConfiguration) configuration;
ListenableFuture<String> executionRootFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, binaryPath, workspaceRoot, config.getBlazeFlagsState().getExpandedFlags(), BlazeInfo.EXECUTION_ROOT_KEY);
String executionRoot;
try {
executionRoot = executionRootFuture.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
context.setCancelled();
return null;
} catch (ExecutionException e) {
IssueOutput.error(e.getMessage()).submit(context);
context.setHasError();
return null;
}
if (executionRoot == null) {
IssueOutput.error("Could not determine execution root").submit(context);
return null;
}
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
IssueOutput.error("Could not determine execution root").submit(context);
return null;
}
try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(f -> true)) {
BlazeCommand command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(config.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(config.getBlazeFlagsState().getExpandedFlags()).addExeFlags(config.getExeFlagsState().getExpandedFlags()).addBlazeFlags(buildResultHelper.getBuildFlags()).build();
if (command == null || context.hasErrors() || context.isCancelled()) {
return null;
}
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
if (retVal != 0) {
context.setHasError();
}
FileCaches.refresh(project);
deployer.reportBuildComplete(new File(executionRoot), buildResultHelper);
return null;
}
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle("Executing blaze build for IntelliJ plugin jar").submitTaskWithResult(buildTask);
try {
Futures.getChecked(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
}
if (context.hasErrors() || context.isCancelled()) {
return false;
}
return true;
});
}
Aggregations