Search in sources :

Example 6 with BlazeJavaSyncData

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

the class JavaPrefetchFileSource method addFilesToPrefetch.

@Override
public void addFilesToPrefetch(Project project, ProjectViewSet projectViewSet, ImportRoots importRoots, BlazeProjectData blazeProjectData, Set<File> files) {
    BlazeJavaSyncData syncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
    if (syncData == null) {
        return;
    }
    // If we have a local jar cache we don't need to prefetch anything
    if (JarCache.getInstance(project).isEnabled()) {
        return;
    }
    Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, blazeProjectData);
    ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
    for (BlazeLibrary library : libraries) {
        if (!(library instanceof BlazeJarLibrary)) {
            continue;
        }
        BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
        files.add(artifactLocationDecoder.decode(jarLibrary.libraryArtifact.jarForIntellijLibrary()));
        files.addAll(artifactLocationDecoder.decodeAll(jarLibrary.libraryArtifact.sourceJars));
    }
}
Also used : BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 7 with BlazeJavaSyncData

use of com.google.idea.blaze.java.sync.model.BlazeJavaSyncData 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());
}
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) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 8 with BlazeJavaSyncData

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

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

the class BlazeJavaSyncPlugin method updateSyncState.

@Override
public void updateSyncState(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, WorkspaceLanguageSettings workspaceLanguageSettings, BlazeInfo blazeInfo, @Nullable WorkingSet workingSet, WorkspacePathResolver workspacePathResolver, ArtifactLocationDecoder artifactLocationDecoder, TargetMap targetMap, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    JavaWorkingSet javaWorkingSet = null;
    if (workingSet != null) {
        javaWorkingSet = new JavaWorkingSet(workspaceRoot, workingSet, Blaze.getBuildSystemProvider(project)::isBuildFile);
    }
    JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
    JdepsMap jdepsMap = jdepsFileReader.loadJdepsFiles(project, context, artifactLocationDecoder, sourceFilter.getSourceTargets(), syncStateBuilder, previousSyncState);
    if (context.isCancelled()) {
        return;
    }
    BlazeJavaWorkspaceImporter blazeJavaWorkspaceImporter = new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, workspaceLanguageSettings, targetMap, sourceFilter, jdepsMap, javaWorkingSet, artifactLocationDecoder);
    BlazeJavaImportResult importResult = Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("JavaWorkspaceImporter", EventType.Other));
        return blazeJavaWorkspaceImporter.importWorkspace(childContext);
    });
    Glob.GlobSet excludedLibraries = new Glob.GlobSet(ImmutableList.<Glob>builder().addAll(projectViewSet.listItems(ExcludeLibrarySection.KEY)).addAll(projectViewSet.listItems(ExcludedLibrarySection.KEY)).build());
    BlazeJavaSyncData syncData = new BlazeJavaSyncData(importResult, excludedLibraries);
    syncStateBuilder.put(BlazeJavaSyncData.class, syncData);
}
Also used : JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) Glob(com.google.idea.blaze.base.projectview.section.Glob) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter)

Example 10 with BlazeJavaSyncData

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

the class SyncStatusHelper method getSyncedJavaFiles.

@SuppressWarnings("unused")
private static Set<File> getSyncedJavaFiles(Project project, BlazeProjectData projectData) {
    BlazeJavaSyncData syncData = projectData.syncState.get(BlazeJavaSyncData.class);
    if (syncData == null) {
        return ImmutableSet.of();
    }
    ArtifactLocationDecoder artifactLocationDecoder = projectData.artifactLocationDecoder;
    return ImmutableSet.copyOf(artifactLocationDecoder.decodeAll(syncData.importResult.javaSourceFiles));
}
Also used : BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

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