Skip to content

Commit

Permalink
Check for empty path before checking prefixes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 586059568
  • Loading branch information
Googler authored and copybara-github committed Nov 28, 2023
1 parent 7256d85 commit 1f8dfde
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ public ProjectProto.Project createProject(BuildGraphData graph) throws BuildExce
.build());
}
for (Path nonJavaDirPath : rootToNonJavaSource.get(dir)) {
if (javaSourceRoots.get(dir).keySet().stream().noneMatch(nonJavaDirPath::startsWith)) {
if (javaSourceRoots.get(dir).keySet().stream()
.noneMatch(p -> p.toString().isEmpty() || nonJavaDirPath.startsWith(p))) {
Path path = dir.resolve(nonJavaDirPath);
// TODO(b/305743519): make java source properties like package prefix specific to java
// source folders only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.idea.blaze.qsync.project.BuildGraphData;
import com.google.idea.blaze.qsync.project.LanguageClassProto.LanguageClass;
import com.google.idea.blaze.qsync.project.ProjectProto;
Expand Down Expand Up @@ -698,6 +699,39 @@ public void testProtoSourceFolders_whenSubfolderOfJavaRoot_notCreated() throws E
.build());
}

@Test
public void testNonJavaSourceFolders_whenSubfolderOfJavaRootAtContentEntry_notCreated()
throws Exception {

ImmutableMap<Path, String> sourcePackages =
ImmutableMap.of(
TestData.ROOT.resolve("protodep/TestClassProtoDep.java"),
"com.google.idea.blaze.qsync.testdata.protodep");

GraphToProjectConverter converter =
GraphToProjectConverters.builder()
.setPackageReader(sourcePackages::get)
.setProjectIncludes(ImmutableSet.of(TestData.ROOT))
.setLanguageClasses(ImmutableSet.of(QuerySyncLanguage.JAVA))
.build();
BuildGraphData buildGraphData =
BuildGraphs.forTestProject(TestData.JAVA_LIBRARY_PROTO_DEP_QUERY);

ProjectProto.Project projectProto = converter.createProject(buildGraphData);
ProjectProto.Module workspaceModule = Iterables.getOnlyElement(projectProto.getModulesList());
ProjectProto.ContentEntry contentEntry =
Iterables.getOnlyElement(workspaceModule.getContentEntriesList());
assertThat(contentEntry.getSourcesList())
.containsExactly(
ProjectProto.SourceFolder.newBuilder()
.setProjectPath(
ProjectPath.newBuilder()
.setBase(Base.WORKSPACE)
.setPath(TestData.ROOT.toString()))
.setPackagePrefix("com.google.idea.blaze.qsync.testdata")
.build());
}

@Test
public void testActiveLanguages_emptyProject() throws Exception {
GraphToProjectConverter converter = GraphToProjectConverters.builder().build();
Expand Down

0 comments on commit 1f8dfde

Please sign in to comment.