Search in sources :

Example 6 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeModuleSystem method getLibrariesForWorkspaceModule.

private static ImmutableList<ExternalAndroidLibrary> getLibrariesForWorkspaceModule(Project project, BlazeProjectData blazeProjectData) {
    ArtifactLocationDecoder decoder = blazeProjectData.getArtifactLocationDecoder();
    ExternalLibraryInterner externalLibraryInterner = ExternalLibraryInterner.getInstance(project);
    ImmutableList.Builder<ExternalAndroidLibrary> libraries = ImmutableList.builder();
    for (BlazeLibrary library : BlazeLibraryCollector.getLibraries(ProjectViewManager.getInstance(project).getProjectViewSet(), blazeProjectData)) {
        if (library instanceof AarLibrary) {
            ExternalAndroidLibrary externalLibrary = toExternalLibrary(project, (AarLibrary) library, decoder);
            if (externalLibrary != null) {
                libraries.add(externalLibraryInterner.intern(externalLibrary));
            }
        }
    }
    return libraries.build();
}
Also used : AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) ImmutableList(com.google.common.collect.ImmutableList) ExternalAndroidLibrary(com.android.projectmodel.ExternalAndroidLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 7 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeAndroidLibrarySource method getLibraryFilter.

@Nullable
@Override
public Predicate<BlazeLibrary> getLibraryFilter() {
    BlazeAndroidSyncData syncData = blazeProjectData.getSyncState().get(BlazeAndroidSyncData.class);
    if (syncData == null) {
        return null;
    }
    Predicate<BlazeLibrary> finalPredicate = null;
    if (!syncData.importResult.aarLibraries.isEmpty()) {
        finalPredicate = new AarJarFilter(syncData.importResult.aarLibraries.values());
    }
    if (filterResourceJarsEnabled.getValue() && !syncData.importResult.resourceJars.isEmpty()) {
        Predicate<BlazeLibrary> resJarFilter = new ResourceJarFilter(syncData.importResult.resourceJars);
        finalPredicate = finalPredicate == null ? resJarFilter : finalPredicate.and(resJarFilter);
    }
    return finalPredicate;
}
Also used : BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData) Nullable(javax.annotation.Nullable)

Example 8 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeAttachSourceProvider method attachSources.

private static void attachSources(Project project, BlazeProjectData blazeProjectData, Collection<BlazeLibrary> librariesToAttachSourceTo) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        IdeModifiableModelsProvider modelsProvider = BaseSdkCompat.createModifiableModelsProvider(project);
        for (BlazeLibrary blazeLibrary : librariesToAttachSourceTo) {
            // Make sure we don't do it twice
            if (AttachedSourceJarManager.getInstance(project).hasSourceJarAttached(blazeLibrary.key)) {
                continue;
            }
            AttachedSourceJarManager.getInstance(project).setHasSourceJarAttached(blazeLibrary.key, true);
            LibraryEditor.updateLibrary(project, blazeProjectData.getArtifactLocationDecoder(), modelsProvider, blazeLibrary);
        }
        modelsProvider.commit();
    });
}
Also used : BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)

Example 9 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary 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.getSyncState().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 decoder = blazeProjectData.getArtifactLocationDecoder();
    for (BlazeLibrary library : libraries) {
        if (!(library instanceof BlazeJarLibrary)) {
            continue;
        }
        files.addAll(OutputArtifactResolver.resolveAll(project, decoder, jarArtifacts((BlazeJarLibrary) library)));
    }
}
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 10 with BlazeLibrary

use of com.google.idea.blaze.base.model.BlazeLibrary in project intellij by bazelbuild.

the class BlazeJavaSyncPlugin method warnAboutDeployJars.

/**
 * Looks at your jars for anything that seems to be a deploy jar and warns about it. This often
 * turns out to be a duplicate copy of all your application's code, so you don't want it in your
 * project.
 */
private static void warnAboutDeployJars(BlazeContext context, BlazeJavaSyncData syncData) {
    for (BlazeLibrary library : syncData.getImportResult().libraries.values()) {
        if (!(library instanceof BlazeJarLibrary)) {
            continue;
        }
        BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
        LibraryArtifact libraryArtifact = jarLibrary.libraryArtifact;
        ArtifactLocation artifactLocation = libraryArtifact.jarForIntellijLibrary();
        if (artifactLocation.isExternal()) {
            return;
        }
        if (artifactLocation.getRelativePath().endsWith("deploy.jar") || artifactLocation.getRelativePath().endsWith("deploy-ijar.jar") || artifactLocation.getRelativePath().endsWith("deploy-hjar.jar")) {
            context.output(new PerformanceWarning("Performance warning: You have added a deploy jar as a library. " + "This can lead to poor indexing performance, and the debugger may " + "become confused and step into the deploy jar instead of your code. " + "Consider redoing the rule to not use deploy jars, exclude the target " + "from your .blazeproject, or exclude the library.\n" + "Library path: " + artifactLocation.getRelativePath()));
        }
    }
}
Also used : BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Aggregations

BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)21 ImmutableList (com.google.common.collect.ImmutableList)8 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)7 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)6 Library (com.intellij.openapi.roots.libraries.Library)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)5 Project (com.intellij.openapi.project.Project)5 File (java.io.File)5 Nullable (javax.annotation.Nullable)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)4 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)4 PrintOutput (com.google.idea.blaze.base.scope.output.PrintOutput)4 BlazeDataStorage (com.google.idea.blaze.base.sync.data.BlazeDataStorage)4 BlazeLibraryCollector (com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector)4 Logger (com.intellij.openapi.diagnostic.Logger)4 Collection (java.util.Collection)4 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)3