use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class NewBlazePackageAction method createPackageOnDisk.
private Optional<VirtualFile> createPackageOnDisk(Project project, BlazeContext context, Label newRule, Kind ruleKind) {
String commandName = String.format("Creating %s package: %s", Blaze.buildSystemName(project), newRule.toString());
return new WriteCommandAction<Optional<VirtualFile>>(project, commandName) {
@Override
protected void run(@NotNull Result<Optional<VirtualFile>> result) throws Throwable {
LocalHistory localHistory = LocalHistory.getInstance();
LocalHistoryAction action = localHistory.startAction(commandName);
try {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
File dir = workspaceRoot.fileForPath(newRule.blazePackage());
try {
VirtualFile newDirectory = VfsUtil.createDirectories(dir.getPath());
VirtualFile newFile = newDirectory.createChildData(this, BUILD_FILE_NAME);
BuildFileModifier buildFileModifier = BuildFileModifier.getInstance();
buildFileModifier.addRule(project, newRule, ruleKind);
result.setResult(Optional.of(newFile));
} catch (IOException e) {
String errorMessage = "Error creating new package: " + e.getMessage();
context.output(PrintOutput.error(errorMessage));
logger.warn("Error creating new package", e);
result.setResult(Optional.empty());
}
} finally {
action.finish();
}
}
}.execute().getResultObject();
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class AllInPackageBlazeConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
PsiDirectory dir = getTestDirectory(context);
if (dir == null) {
return false;
}
WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
WorkspacePath packagePath = getWorkspaceRelativeDirectoryPath(root, dir);
if (packagePath == null) {
return false;
}
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
return Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST) && Objects.equals(configuration.getTarget(), TargetExpression.allFromPackageRecursive(packagePath));
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeIssueParserTest method initTest.
@Override
protected void initTest(Container applicationServices, Container projectServices) {
super.initTest(applicationServices, projectServices);
applicationServices.register(ExperimentService.class, new MockExperimentService());
projectViewManager = mock(ProjectViewManager.class);
projectServices.register(ProjectViewManager.class, projectViewManager);
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(new File(".blazeproject"), ProjectView.builder().add(ListSection.builder(TargetSection.KEY).add(TargetExpression.fromStringSafe("//tests/com/google/a/b/c/d/baz:baz")).add(TargetExpression.fromStringSafe("//package/path:hello4"))).build()).build();
when(projectViewManager.getProjectViewSet()).thenReturn(projectViewSet);
workspaceRoot = new WorkspaceRoot(new File("/root"));
parsers = ImmutableList.of(new BlazeIssueParser.CompileParser(workspaceRoot), new BlazeIssueParser.TracebackParser(), new BlazeIssueParser.BuildParser(), new BlazeIssueParser.SkylarkErrorParser(), new BlazeIssueParser.LinelessBuildParser(), new BlazeIssueParser.ProjectViewLabelParser(projectViewSet), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "no such package '(.*)': BUILD file not found on package path"), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "no targets found beneath '(.*)'"), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "ERROR: invalid target format '(.*)'"), new BlazeIssueParser.FileNotFoundBuildParser(workspaceRoot), BlazeIssueParser.GenericErrorParser.INSTANCE);
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeBuildSystemServiceTest method createMockBlazeProjectData.
private BlazeProjectData createMockBlazeProjectData() {
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(Label.create("//foo:bar")).setBuildFile(ArtifactLocation.builder().setRelativePath("foo/BUILD").build()).build()).build();
ArtifactLocationDecoder decoder = (location) -> new File("/", location.getRelativePath());
return MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).setArtifactLocationDecoder(decoder).build();
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testEmptyResourceModuleIsAddedAsJar.
/**
* Test adding empty resource modules as jars.
*/
@Test
public void testEmptyResourceModuleIsAddedAsJar() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("javatests/apps/example")))).build();
/**
* Deps are project -> lib0 (no res) -> lib1 (has res) \ -> lib2 (has res)
*/
TargetMapBuilder response = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib0:lib0").setKind("android_library").setBuildFile(source("java/apps/example/lib0/BUILD")).addSource(source("java/apps/example/lib0/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib0/AndroidManifest.xml")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib0").setResourceJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0_resources.jar")).setClassJar(gen("java/apps/example/lib0/lib0_resources.jar")))).addDependency("//java/apps/example/lib1:lib1").addDependency("//java/apps/example/lib2:lib2").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0.jar")).setClassJar(gen("java/apps/example/lib0/lib0.jar"))).addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0_resources.jar")).setClassJar(gen("java/apps/example/lib0/lib0_resources.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib1:lib1").setKind("android_library").setBuildFile(source("java/apps/example/lib1/BUILD")).addSource(source("java/apps/example/lib1/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib1/AndroidManifest.xml")).addResource(source("java/apps/example/lib1/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib1").setResourceJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/li11_resources.jar")).setClassJar(gen("java/apps/example/lib1/lib1_resources.jar")))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/lib1.jar")).setClassJar(gen("java/apps/example/lib1/lib1.jar"))).addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/lib1_resources.jar")).setClassJar(gen("java/apps/example/lib1/lib1_resources.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib2:lib2").setBuildFile(source("java/apps/example/lib2/BUILD")).setKind("android_library").addSource(source("java/apps/example/lib2/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib2/AndroidManifest.xml")).addResource(source("java/apps/example/lib2/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.libraries.example.lib2").setResourceJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib2/lib2_resources.jar")).setClassJar(gen("java/apps/example/lib2/lib2_resources.jar")))).setBuildFile(source("java/apps/example/lib2/BUILD")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib2/lib2.jar")).setClassJar(gen("java/apps/example/lib2/lib2.jar"))).addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib2/lib2_resources.jar")).setClassJar(gen("java/apps/example/lib2/lib2_resources.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setKind("android_binary").setBuildFile(source("java/apps/example/BUILD")).addSource(source("java/apps/example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/AndroidManifest.xml")).addResource(source("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).addDependency("//java/apps/example/lib0:lib0").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar")))));
TargetMap targetMap = response.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(jars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("lib0_resources.jar");
}
Aggregations