Search in sources :

Example 6 with BlazeContentEntry

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Test(org.junit.Test)

Example 7 with BlazeContentEntry

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Test(org.junit.Test)

Example 8 with BlazeContentEntry

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Test(org.junit.Test)

Example 9 with BlazeContentEntry

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Test(org.junit.Test)

Example 10 with BlazeContentEntry

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) SourceFolder(com.intellij.openapi.roots.SourceFolder) GlobSet(com.google.idea.blaze.base.projectview.section.Glob.GlobSet) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Aggregations

BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)29 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)27 Test (org.junit.Test)26 BlazeJavaSyncData (com.google.idea.blaze.java.sync.model.BlazeJavaSyncData)6 BlazeSourceDirectory (com.google.idea.blaze.java.sync.model.BlazeSourceDirectory)5 File (java.io.File)5 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)4 SourceFolder (com.intellij.openapi.roots.SourceFolder)4 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)3 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)3 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 GlobSet (com.google.idea.blaze.base.projectview.section.Glob.GlobSet)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)2 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)2 Joiner (com.google.common.base.Joiner)1 Objects (com.google.common.base.Objects)1 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1