use of com.google.idea.blaze.base.ideinfo.LibraryArtifact 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.base.ideinfo.LibraryArtifact in project intellij by bazelbuild.
the class IdeInfoFromProtobuf method makeLibraryArtifact.
@Nullable
private static LibraryArtifact makeLibraryArtifact(IntellijIdeInfo.LibraryArtifact libraryArtifact) {
ArtifactLocation classJar = libraryArtifact.hasJar() ? makeArtifactLocation(libraryArtifact.getJar()) : null;
ArtifactLocation iJar = libraryArtifact.hasInterfaceJar() ? makeArtifactLocation(libraryArtifact.getInterfaceJar()) : null;
ImmutableList.Builder<ArtifactLocation> sourceJars = ImmutableList.builder();
if (!libraryArtifact.getSourceJarsList().isEmpty()) {
sourceJars.addAll(libraryArtifact.getSourceJarsList().stream().map(IdeInfoFromProtobuf::makeArtifactLocation).collect(Collectors.toList()));
} else if (libraryArtifact.hasSourceJar()) {
sourceJars.add(makeArtifactLocation(libraryArtifact.getSourceJar()));
}
if (iJar == null && classJar == null) {
// drop invalid ArtifactLocations
return null;
}
return new LibraryArtifact(iJar, classJar, sourceJars.build());
}
use of com.google.idea.blaze.base.ideinfo.LibraryArtifact 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()));
}
}
}
use of com.google.idea.blaze.base.ideinfo.LibraryArtifact in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method buildLibraries.
private ImmutableMap<LibraryKey, BlazeJarLibrary> buildLibraries(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, List<TargetIdeInfo> libraryTargets, List<TargetIdeInfo> protoLibraries) {
// Build library maps
Multimap<TargetKey, BlazeJarLibrary> targetKeyToLibrary = ArrayListMultimap.create();
Map<String, BlazeJarLibrary> jdepsPathToLibrary = Maps.newHashMap();
// Add any output jars from source rules
for (TargetKey key : workspaceBuilder.outputJarsFromSourceTargets.keySet()) {
Collection<BlazeJarLibrary> jars = workspaceBuilder.outputJarsFromSourceTargets.get(key);
targetKeyToLibrary.putAll(key, jars);
for (BlazeJarLibrary library : jars) {
addLibraryToJdeps(jdepsPathToLibrary, library);
}
}
for (TargetIdeInfo target : libraryTargets) {
JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
if (javaIdeInfo == null) {
continue;
}
List<LibraryArtifact> allJars = Lists.newArrayList();
allJars.addAll(javaIdeInfo.jars);
Collection<BlazeJarLibrary> libraries = allJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList());
targetKeyToLibrary.putAll(target.key, libraries);
for (BlazeJarLibrary library : libraries) {
addLibraryToJdeps(jdepsPathToLibrary, library);
}
}
// proto legacy jdeps support
for (TargetIdeInfo target : protoLibraries) {
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
if (protoLibraryLegacyInfo == null) {
continue;
}
for (LibraryArtifact libraryArtifact : Iterables.concat(protoLibraryLegacyInfo.jarsV1, protoLibraryLegacyInfo.jarsMutable, protoLibraryLegacyInfo.jarsImmutable)) {
addLibraryToJdeps(jdepsPathToLibrary, new BlazeJarLibrary(libraryArtifact));
}
}
Map<LibraryKey, BlazeJarLibrary> result = Maps.newHashMap();
// Collect jars from jdep references
for (String jdepsPath : workspaceBuilder.jdeps) {
if (sourceFilter.jdepsPathsForExcludedJars.contains(jdepsPath)) {
continue;
}
BlazeJarLibrary library = jdepsPathToLibrary.get(jdepsPath);
if (library == null) {
// It's in the target's jdeps, but our aspect never attached to the target building it
// Perhaps it's an implicit dependency, or not referenced in an attribute we propagate along
// Or it could be that this is a multi-configuration project, and jdeps refers to a
// configuration different from the one we picked for the TargetMap.
// Make a best-effort attempt to add it to the project anyway.
ExecutionPathFragmentAndRelativePath split = ExecutionPathFragmentAndRelativePath.split(jdepsPath);
ArtifactLocation location = ArtifactLocation.builder().setIsSource(false).setRootExecutionPathFragment(split.rootExecutionPathFragment).setRelativePath(split.relativePath).build();
library = new BlazeJarLibrary(new LibraryArtifact(location, null, ImmutableList.of()));
}
result.put(library.key, library);
}
// Collect jars referenced by direct deps from your working set
for (TargetKey deps : workspaceBuilder.directDeps) {
for (BlazeJarLibrary library : targetKeyToLibrary.get(deps)) {
result.put(library.key, library);
}
}
// Collect legacy proto libraries from direct deps
addProtoLegacyLibrariesFromDirectDeps(workspaceBuilder, targetMap, result);
// Collect generated jars from source rules
for (BlazeJarLibrary library : workspaceBuilder.generatedJarsFromSourceTargets) {
result.put(library.key, library);
}
return ImmutableMap.copyOf(result);
}
use of com.google.idea.blaze.base.ideinfo.LibraryArtifact in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporter method createAarLibraries.
private ImmutableList<AarLibrary> createAarLibraries(Iterable<TargetIdeInfo> libraryTargets) {
ImmutableList.Builder<AarLibrary> builder = ImmutableList.builder();
for (TargetIdeInfo target : libraryTargets) {
// don't have the equivalent of jdeps data.
if (target.androidAarIdeInfo == null || target.javaIdeInfo == null || target.javaIdeInfo.jars.isEmpty()) {
continue;
}
// aar_import should only have one jar (a merged jar from the AAR's jars).
LibraryArtifact firstJar = target.javaIdeInfo.jars.iterator().next();
builder.add(new AarLibrary(firstJar, target.androidAarIdeInfo.aar));
}
return builder.build();
}
Aggregations