Search in sources :

Example 1 with BlazeJavaSyncData

use of com.google.idea.blaze.java.sync.model.BlazeJavaSyncData 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)

Example 2 with BlazeJavaSyncData

use of com.google.idea.blaze.java.sync.model.BlazeJavaSyncData in project intellij by bazelbuild.

the class JavaSourceFolderProviderTest method testRelativePackagePrefix.

@Test
public void testRelativePackagePrefix() {
    ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java/apps").addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps").setPackagePrefix("apps").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"));
    ContentEntry contentEntry = getContentEntry(root);
    ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry);
    assertThat(sourceFolders).hasSize(1);
    VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("java/apps/tests/model"));
    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.model");
}
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) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) 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)

Example 3 with BlazeJavaSyncData

use of com.google.idea.blaze.java.sync.model.BlazeJavaSyncData in project intellij by bazelbuild.

the class KotlinSyncTest method testKotlinClassesPresentInClassPath.

@Test
public void testKotlinClassesPresentInClassPath() {
    setProjectView("directories:", "  src/main/kotlin/com/google", "targets:", "  //src/main/kotlin/com/google:lib", "additional_languages:", "  kotlin");
    workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName1.kt"), "package com.google;", "public class ClassWithUniqueName1 {}");
    workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName2.kt"), "package com.google;", "public class ClassWithUniqueName2 {}");
    workspace.createDirectory(new WorkspacePath("external/com_github_jetbrains_kotlin"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/kotlin/com/google/BUILD")).setLabel("//src/main/kotlin/com/google:lib").setKind("kt_jvm_library").addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName1.scala")).addSource(sourceRoot("src/main/kotlin/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);
    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.KOTLIN)));
    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(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/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(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 4 with BlazeJavaSyncData

use of com.google.idea.blaze.java.sync.model.BlazeJavaSyncData in project intellij by bazelbuild.

the class LibraryActionHelper method findLibraryFromIntellijLibrary.

@Nullable
static BlazeJarLibrary findLibraryFromIntellijLibrary(Project project, BlazeProjectData blazeProjectData, Library library) {
    String libName = library.getName();
    if (libName == null) {
        return null;
    }
    LibraryKey libraryKey = LibraryKey.fromIntelliJLibraryName(libName);
    BlazeJavaSyncData syncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
    if (syncData == null) {
        Messages.showErrorDialog(project, "Project isn't synced. Please resync project.", "Error");
        return null;
    }
    return syncData.importResult.libraries.get(libraryKey);
}
Also used : BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) Nullable(javax.annotation.Nullable)

Example 5 with BlazeJavaSyncData

use of com.google.idea.blaze.java.sync.model.BlazeJavaSyncData in project intellij by bazelbuild.

the class BlazeJavaSyncPlugin method validate.

@Override
public boolean validate(Project project, BlazeContext context, BlazeProjectData blazeProjectData) {
    BlazeJavaSyncData syncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
    if (syncData == null) {
        return true;
    }
    warnAboutDeployJars(context, syncData);
    return true;
}
Also used : BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData)

Aggregations

BlazeJavaSyncData (com.google.idea.blaze.java.sync.model.BlazeJavaSyncData)11 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)6 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)6 Test (org.junit.Test)6 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)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 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)3 BlazeSourceDirectory (com.google.idea.blaze.java.sync.model.BlazeSourceDirectory)3 SourceFolder (com.intellij.openapi.roots.SourceFolder)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)2 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)1 LibraryKey (com.google.idea.blaze.base.model.LibraryKey)1 Glob (com.google.idea.blaze.base.projectview.section.Glob)1