use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class ExcludeLibraryAction method actionPerformedInBlazeProject.
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return;
}
Library library = LibraryActionHelper.findLibraryForAction(e);
if (library == null) {
return;
}
BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
if (blazeLibrary == null) {
Messages.showErrorDialog(project, "Could not find this library in the project.", CommonBundle.getErrorTitle());
return;
}
final LibraryArtifact libraryArtifact = blazeLibrary.libraryArtifact;
final String path = libraryArtifact.jarForIntellijLibrary().getRelativePath();
ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
ListSection<Glob> existingSection = builder.getLast(ExcludeLibrarySection.KEY);
builder.replace(existingSection, ListSection.update(ExcludeLibrarySection.KEY, existingSection).add(new Glob(path)));
return true;
});
if (edit == null) {
Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
return;
}
edit.apply();
BlazeSyncManager.getInstance(project).incrementalProjectSync();
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class JarCache method onSync.
void onSync(BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData projectData, BlazeSyncParams.SyncMode syncMode) {
Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, projectData);
boolean fullRefresh = syncMode == SyncMode.FULL;
boolean removeMissingFiles = syncMode == SyncMode.INCREMENTAL;
boolean enabled = updateEnabled();
if (!enabled || fullRefresh) {
clearCache();
}
if (!enabled) {
return;
}
List<BlazeJarLibrary> jarLibraries = libraries.stream().filter(library -> library instanceof BlazeJarLibrary).map(library -> (BlazeJarLibrary) library).collect(Collectors.toList());
ArtifactLocationDecoder artifactLocationDecoder = projectData.artifactLocationDecoder;
BiMap<File, String> sourceFileToCacheKey = HashBiMap.create(jarLibraries.size());
for (BlazeJarLibrary library : jarLibraries) {
File jarFile = artifactLocationDecoder.decode(library.libraryArtifact.jarForIntellijLibrary());
sourceFileToCacheKey.put(jarFile, cacheKeyForJar(jarFile));
for (ArtifactLocation sourceJar : library.libraryArtifact.sourceJars) {
File srcJarFile = artifactLocationDecoder.decode(sourceJar);
sourceFileToCacheKey.put(srcJarFile, cacheKeyForSourceJar(srcJarFile));
}
}
this.traits = new JarCacheSynchronizerTraits(cacheDir, sourceFileToCacheKey);
refresh(context, removeMissingFiles);
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class BlazeAndroidLiteJavaSyncAugmenter method addJarsForSourceTarget.
@Override
public void addJarsForSourceTarget(WorkspaceLanguageSettings workspaceLanguageSettings, ProjectViewSet projectViewSet, TargetIdeInfo target, Collection<BlazeJarLibrary> jars, Collection<BlazeJarLibrary> genJars) {
if (!workspaceLanguageSettings.isLanguageActive(LanguageClass.ANDROID)) {
return;
}
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
if (androidIdeInfo == null) {
return;
}
// Add R.java jars
LibraryArtifact resourceJar = androidIdeInfo.resourceJar;
if (resourceJar != null) {
jars.add(new BlazeJarLibrary(resourceJar));
}
LibraryArtifact idlJar = androidIdeInfo.idlJar;
if (idlJar != null) {
genJars.add(new BlazeJarLibrary(idlJar));
}
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.
the class BlazeAndroidLiteSyncPlugin method getSdkLibrary.
@Nullable
private static BlazeLibrary getSdkLibrary(BlazeProjectData blazeProjectData) {
List<AndroidSdkIdeInfo> sdkTargets = androidSdkTargets(blazeProjectData.targetMap);
if (sdkTargets.isEmpty()) {
return null;
}
// for now, just add the first one found
// TODO: warn if there's more than one
ArtifactLocation sdk = sdkTargets.stream().map(info -> info.androidJar).filter(Objects::nonNull).findFirst().orElse(null);
return sdk != null ? new BlazeJarLibrary(new LibraryArtifact(null, sdk, ImmutableList.of())) : null;
}
use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary 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.importResult.libraries.values()) {
if (!(library instanceof BlazeJarLibrary)) {
continue;
}
BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
LibraryArtifact libraryArtifact = jarLibrary.libraryArtifact;
ArtifactLocation artifactLocation = libraryArtifact.jarForIntellijLibrary();
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()));
}
}
}
Aggregations