use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method testSourcesToSourceDirectories_completePackagePathMismatch.
@Test
public void testSourcesToSourceDirectories_completePackagePathMismatch() throws Exception {
mockInputStreamProvider.addFile("/root/java/com/org/foo/Bla.java", "package com.facebook;\n public class Bla {}");
List<SourceArtifact> sourceArtifacts = ImmutableList.of(SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/org/foo/Bla.java").setIsSource(true)).build());
ImmutableList<BlazeContentEntry> result = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, decoder, buildImportRoots(ImmutableList.of(new WorkspacePath("java/com/org")), ImmutableList.of()), sourceArtifacts, NO_MANIFESTS);
assertThat(result).containsExactly(BlazeContentEntry.builder("/root/java/com/org").addSource(BlazeSourceDirectory.builder("/root/java/com/org").setPackagePrefix("com.org").build()).addSource(BlazeSourceDirectory.builder("/root/java/com/org/foo").setPackagePrefix("com.facebook").build()).build());
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method testMultipleDirectoriesAreMergedWithDirectoryRootAsWorkspaceRoot.
@Test
public void testMultipleDirectoriesAreMergedWithDirectoryRootAsWorkspaceRoot() throws Exception {
mockInputStreamProvider.addFile("/root/java/com/google/idea/blaze/plugin/run/Run.java", "package com.google.idea.blaze.plugin.run;\n public class run {}").addFile("/root/java/com/google/idea/blaze/plugin/sync/Sync.java", "package com.google.idea.blaze.plugin.sync;\n public class Sync {}").addFile("/root/java/com/google/idea/blaze/plugin/Plugin.java", "package com.google.idea.blaze.plugin;\n public class Plugin {}");
List<SourceArtifact> sourceArtifacts = ImmutableList.of(SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/idea/blaze/plugin/run/Run.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/idea/blaze/plugin/sync/Sync.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/idea/blaze/plugin/Plugin.java").setIsSource(true)).build());
ImmutableList<BlazeContentEntry> result = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, decoder, buildImportRoots(ImmutableList.of(new WorkspacePath("")), ImmutableList.of()), sourceArtifacts, NO_MANIFESTS);
issues.assertNoIssues();
assertThat(result).containsExactly(BlazeContentEntry.builder("/root").addSource(BlazeSourceDirectory.builder("/root").setPackagePrefix("").build()).addSource(BlazeSourceDirectory.builder("/root/java").setPackagePrefix("").build()).build());
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method testSourcesToSourceDirectories_packagesMatchPath.
@Test
public void testSourcesToSourceDirectories_packagesMatchPath() throws Exception {
mockInputStreamProvider.addFile("/root/java/com/google/Bla.java", "package com.google;\n public class Bla {}");
List<SourceArtifact> sourceArtifacts = ImmutableList.of(SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Bla.java").setIsSource(true)).build());
ImmutableList<BlazeContentEntry> result = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, decoder, buildImportRoots(ImmutableList.of(new WorkspacePath("java/com/google")), ImmutableList.of()), sourceArtifacts, NO_MANIFESTS);
issues.assertNoIssues();
assertThat(result).containsExactly(BlazeContentEntry.builder("/root/java/com/google").addSource(BlazeSourceDirectory.builder("/root/java/com/google").setPackagePrefix("com.google").build()).build());
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method testCompetingPackageDeclarationPicksMajority.
@Test
public void testCompetingPackageDeclarationPicksMajority() throws Exception {
mockInputStreamProvider.addFile("/root/java/com/google/Foo.java", "package com.google;\n public class Foo {}").addFile("/root/java/com/google/Bla.java", "package com.google.different;\n public class Bla {}").addFile("/root/java/com/google/Bla2.java", "package com.google.different;\n public class Bla2 {}").addFile("/root/java/com/google/Bla3.java", "package com.google.different;\n public class Bla3 {}");
List<SourceArtifact> sourceArtifacts = ImmutableList.of(SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Bla.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Bla2.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Bla3.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Foo.java").setIsSource(true)).build());
ImmutableList<BlazeContentEntry> result = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, decoder, buildImportRoots(ImmutableList.of(new WorkspacePath("java/com/google")), ImmutableList.of()), sourceArtifacts, NO_MANIFESTS);
issues.assertNoIssues();
assertThat(result).containsExactly(BlazeContentEntry.builder("/root/java/com/google").addSource(BlazeSourceDirectory.builder("/root/java/com/google").setPackagePrefix("com.google.different").build()).build());
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class JavaSourceFolderProviderTest method testInitializeSourceFolders.
@Test
public void testInitializeSourceFolders() {
ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java/apps").addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps").setPackagePrefix("apps").build()).addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps/gen").setPackagePrefix("apps.gen").setGenerated(true).build()).addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps/resources").setPackagePrefix("apps.resources").setResource(true).build()).build(), BlazeContentEntry.builder("/src/workspace/javatests/apps/example").addSource(BlazeSourceDirectory.builder("/src/workspace/javatests/apps/example").setPackagePrefix("apps.example").build()).build());
JavaSourceFolderProvider provider = new JavaSourceFolderProvider(new BlazeJavaSyncData(new BlazeJavaImportResult(contentEntries, ImmutableMap.of(), ImmutableList.of(), ImmutableSet.of(), null), new GlobSet(ImmutableList.of())));
VirtualFile root = workspace.createDirectory(new WorkspacePath("java/apps"));
VirtualFile gen = workspace.createDirectory(new WorkspacePath("java/apps/gen"));
VirtualFile res = workspace.createDirectory(new WorkspacePath("java/apps/resources"));
ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(getContentEntry(root));
assertThat(sourceFolders).hasSize(3);
SourceFolder rootSource = sourceFolders.get(new File(root.getPath()));
assertThat(rootSource.getPackagePrefix()).isEqualTo("apps");
assertThat(JavaSourceFolderProvider.isGenerated(rootSource)).isFalse();
assertThat(JavaSourceFolderProvider.isResource(rootSource)).isFalse();
SourceFolder genSource = sourceFolders.get(new File(gen.getPath()));
assertThat(genSource.getPackagePrefix()).isEqualTo("apps.gen");
assertThat(JavaSourceFolderProvider.isGenerated(genSource)).isTrue();
assertThat(JavaSourceFolderProvider.isResource(genSource)).isFalse();
SourceFolder resSource = sourceFolders.get(new File(res.getPath()));
assertThat(JavaSourceFolderProvider.isGenerated(resSource)).isFalse();
assertThat(JavaSourceFolderProvider.isResource(resSource)).isTrue();
VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("javatests/apps/example"));
sourceFolders = provider.initializeSourceFolders(getContentEntry(testRoot));
assertThat(sourceFolders).hasSize(1);
assertThat(sourceFolders.get(new File(testRoot.getPath())).getPackagePrefix()).isEqualTo("apps.example");
}
Aggregations