use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class JavaSyncTest method testJavaClassesPresentInClassPath.
@Test
public void testJavaClassesPresentInClassPath() throws Exception {
setProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib");
workspace.createFile(new WorkspacePath("java/com/google/ClassWithUniqueName1.java"), "package com.google;", "public class ClassWithUniqueName1 {}");
workspace.createFile(new WorkspacePath("java/com/google/ClassWithUniqueName2.java"), "package com.google;", "public class ClassWithUniqueName2 {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("java_library").addSource(sourceRoot("java/com/google/ClassWithUniqueName1.java")).addSource(sourceRoot("java/com/google/ClassWithUniqueName2.java")).setJavaInfo(JavaIdeInfo.builder())).build();
setTargetMap(targetMap);
BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
runBlazeSync(syncParams);
errorCollector.assertNoIssues();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();
assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
assertThat(blazeProjectData.workspaceLanguageSettings.getWorkspaceType()).isEqualTo(WorkspaceType.JAVA);
BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
assertThat(contentEntries).hasSize(1);
BlazeContentEntry contentEntry = contentEntries.get(0);
assertThat(contentEntry.contentRoot.getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("java/com/google")).getPath());
assertThat(contentEntry.sources).hasSize(1);
BlazeSourceDirectory sourceDir = contentEntry.sources.get(0);
assertThat(sourceDir.getPackagePrefix()).isEqualTo("com.google");
assertThat(sourceDir.getDirectory().getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("java/com/google")).getPath());
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class JavaSourceFolderProviderTest method testRelativePackagePrefixWithoutParentPrefix.
@Test
public void testRelativePackagePrefixWithoutParentPrefix() {
ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java").addSource(BlazeSourceDirectory.builder("/src/workspace/java").setPackagePrefix("").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"));
ContentEntry contentEntry = getContentEntry(root);
ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry);
assertThat(sourceFolders).hasSize(1);
VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("java/apps/tests"));
SourceFolder testSourceChild = provider.setSourceFolderForLocation(contentEntry, sourceFolders.get(new File(root.getPath())), new File(testRoot.getPath()), true);
assertThat(testSourceChild.isTestSource()).isTrue();
assertThat(testSourceChild.getPackagePrefix()).isEqualTo("apps.tests");
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class JavaSourceFolderProvider method initializeSourceFolders.
@Override
public ImmutableMap<File, SourceFolder> initializeSourceFolders(ContentEntry contentEntry) {
Map<File, SourceFolder> map = new HashMap<>();
BlazeContentEntry javaContentEntry = blazeContentEntries.get(UrlUtil.urlToFile(contentEntry.getUrl()));
if (javaContentEntry != null) {
for (BlazeSourceDirectory sourceDirectory : javaContentEntry.sources) {
File file = sourceDirectory.getDirectory();
if (map.containsKey(file)) {
continue;
}
SourceFolder sourceFolder = addSourceFolderToContentEntry(contentEntry, sourceDirectory);
map.put(file, sourceFolder);
}
}
return ImmutableMap.copyOf(map);
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class ScalaSyncTest method testScalaClassesPresentInClassPath.
@Test
public void testScalaClassesPresentInClassPath() throws Exception {
setProjectView("directories:", " src/main/scala/com/google", "targets:", " //src/main/scala/com/google:lib", "additional_languages:", " scala");
workspace.createFile(new WorkspacePath("src/main/scala/com/google/ClassWithUniqueName1.scala"), "package com.google;", "public class ClassWithUniqueName1 {}");
workspace.createFile(new WorkspacePath("src/main/scala/com/google/ClassWithUniqueName2.scala"), "package com.google;", "public class ClassWithUniqueName2 {}");
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/scala/com/google/BUILD")).setLabel("//src/main/scala/com/google:lib").setKind("scala_library").addSource(sourceRoot("src/main/scala/com/google/ClassWithUniqueName1.scala")).addSource(sourceRoot("src/main/scala/com/google/ClassWithUniqueName2.scala")).setJavaInfo(JavaIdeInfo.builder())).build();
setTargetMap(targetMap);
BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
runBlazeSync(syncParams);
errorCollector.assertNoIssues();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();
assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
assertThat(blazeProjectData.workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.JAVA, LanguageClass.SCALA)));
BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
assertThat(javaSyncData).isNotNull();
List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
assertThat(contentEntries).hasSize(1);
BlazeContentEntry contentEntry = contentEntries.get(0);
assertThat(contentEntry.contentRoot.getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("src/main/scala/com/google")).getPath());
assertThat(contentEntry.sources).hasSize(1);
BlazeSourceDirectory sourceDir = contentEntry.sources.get(0);
assertThat(sourceDir.getPackagePrefix()).isEqualTo("com.google");
assertThat(sourceDir.getDirectory().getPath()).isEqualTo(workspaceRoot.fileForPath(new WorkspacePath("src/main/scala/com/google")).getPath());
}
Aggregations