use of com.google.idea.blaze.java.sync.workingset.JavaWorkingSet in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testLibraryDependenciesWithJdepsReportingNothingShouldStillIncludeDirectDepsIfInWorkingSet.
@Test
public void testLibraryDependenciesWithJdepsReportingNothingShouldStillIncludeDirectDepsIfInWorkingSet() {
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();
TargetMapBuilder targetMapBuilder = targetMapForJdepsSuite();
workingSet = new JavaWorkingSet(workspaceRoot, new WorkingSet(ImmutableList.of(new WorkspacePath("java/apps/example/Test.java")), ImmutableList.of(), ImmutableList.of()), Predicate.isEqual("BUILD"));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
assertThat(result.libraries.values().stream().map(BlazeJavaWorkspaceImporterTest::libraryFileName).collect(Collectors.toList())).containsExactly("a.jar");
}
use of com.google.idea.blaze.java.sync.workingset.JavaWorkingSet in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testLegacyProtoLibraryInfo.
/**
* Test legacy proto_library jars, complete with overrides and everything.
*/
@Test
public void testLegacyProtoLibraryInfo() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:liba").setBuildFile(source("java/example/BUILD")).setKind("java_library").addSource(source("java/example/Liba.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//thirdparty/proto/a:a")).addTarget(TargetIdeInfo.builder().setLabel("//java/example:libb").setBuildFile(source("java/example/BUILD")).setKind("java_library").addSource(source("java/example/Libb.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//thirdparty/proto/b:b")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/a:a").setBuildFile(source("/thirdparty/a/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/a/liba-1-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/a/liba-ijar.jar")))).addDependency("//thirdparty/proto/b:b").addDependency("//thirdparty/proto/c:c")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/b:b").setBuildFile(source("/thirdparty/b/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/b/libb-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/b/libb-2-ijar.jar")))).addDependency("//thirdparty/proto/d:d")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/c:c").setBuildFile(source("/thirdparty/c/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/c/libc-1-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/c/libc-ijar.jar")))).addDependency("//thirdparty/proto/d:d")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/d:d").setBuildFile(source("/thirdparty/d/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/d/libd-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/d/libd-2-ijar.jar")))));
workingSet = new JavaWorkingSet(workspaceRoot, new WorkingSet(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()), Predicate.isEqual("BUILD"));
// First test - make sure that jdeps is working
jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/example:liba")), Lists.newArrayList(jdepsPath("thirdparty/proto/a/liba-ijar.jar")));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.libraries).hasSize(1);
assertThat(findLibrary(result.libraries, "liba-ijar.jar")).isNotNull();
// Second test
// Put everything in the working set, which should expand to include the direct deps
workingSet = new JavaWorkingSet(workspaceRoot, new WorkingSet(ImmutableList.of(new WorkspacePath("java/example/BUILD")), ImmutableList.of(), ImmutableList.of()), Predicate.isEqual("BUILD"));
result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.libraries).hasSize(2);
assertThat(findLibrary(result.libraries, "liba-ijar.jar")).isNotNull();
assertThat(findLibrary(result.libraries, "libb-ijar.jar")).isNotNull();
}
use of com.google.idea.blaze.java.sync.workingset.JavaWorkingSet in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testLibraryDepsWithJdepsReportingZeroShouldNotIncludeDirectDepsIfNotInWorkingSet.
@Test
public void testLibraryDepsWithJdepsReportingZeroShouldNotIncludeDirectDepsIfNotInWorkingSet() {
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();
TargetMapBuilder targetMapBuilder = targetMapForJdepsSuite();
workingSet = new JavaWorkingSet(workspaceRoot, new WorkingSet(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()), Predicate.isEqual("BUILD"));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
assertThat(result.libraries.values().stream().map(BlazeJavaWorkspaceImporterTest::libraryFileName).collect(Collectors.toList())).isEmpty();
}
use of com.google.idea.blaze.java.sync.workingset.JavaWorkingSet in project intellij by bazelbuild.
the class BlazeJavaSyncPlugin method updateSyncState.
@Override
public void updateSyncState(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, WorkspaceLanguageSettings workspaceLanguageSettings, BlazeInfo blazeInfo, @Nullable WorkingSet workingSet, WorkspacePathResolver workspacePathResolver, ArtifactLocationDecoder artifactLocationDecoder, TargetMap targetMap, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
JavaWorkingSet javaWorkingSet = null;
if (workingSet != null) {
javaWorkingSet = new JavaWorkingSet(workspaceRoot, workingSet, Blaze.getBuildSystemProvider(project)::isBuildFile);
}
JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
JdepsMap jdepsMap = jdepsFileReader.loadJdepsFiles(project, context, artifactLocationDecoder, sourceFilter.getSourceTargets(), syncStateBuilder, previousSyncState);
if (context.isCancelled()) {
return;
}
BlazeJavaWorkspaceImporter blazeJavaWorkspaceImporter = new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, workspaceLanguageSettings, targetMap, sourceFilter, jdepsMap, javaWorkingSet, artifactLocationDecoder);
BlazeJavaImportResult importResult = Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("JavaWorkspaceImporter", EventType.Other));
return blazeJavaWorkspaceImporter.importWorkspace(childContext);
});
Glob.GlobSet excludedLibraries = new Glob.GlobSet(ImmutableList.<Glob>builder().addAll(projectViewSet.listItems(ExcludeLibrarySection.KEY)).addAll(projectViewSet.listItems(ExcludedLibrarySection.KEY)).build());
BlazeJavaSyncData syncData = new BlazeJavaSyncData(importResult, excludedLibraries);
syncStateBuilder.put(BlazeJavaSyncData.class, syncData);
}
Aggregations