use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class MockBlazeProjectDataBuilder method build.
public BlazeProjectData build() {
TargetMap targetMap = this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of());
BlazeInfo blazeInfo = this.blazeInfo;
if (blazeInfo == null) {
String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234";
blazeInfo = BlazeInfo.createMockBlazeInfo(outputBase, outputBase + "/execroot", outputBase + "/execroot/bin", outputBase + "/execroot/gen");
}
BlazeVersionData blazeVersionData = this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build();
WorkspacePathResolver workspacePathResolver = this.workspacePathResolver != null ? this.workspacePathResolver : new WorkspacePathResolverImpl(workspaceRoot);
ArtifactLocationDecoder artifactLocationDecoder = this.artifactLocationDecoder != null ? this.artifactLocationDecoder : new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
WorkspaceLanguageSettings workspaceLanguageSettings = this.workspaceLanguageSettings != null ? this.workspaceLanguageSettings : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of());
SyncState syncState = this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of());
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = this.reverseDependencies != null ? this.reverseDependencies : ImmutableMultimap.of();
return new BlazeProjectData(syncTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncState, reverseDependencies);
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class FastBuildCompilerFactoryImplTest method testNoJavaToolchain.
@Test
public void testNoJavaToolchain() {
Map<TargetKey, TargetIdeInfo> targetMap = new HashMap<>();
TargetIdeInfo buildTargetInfo = TargetIdeInfo.builder().setLabel(Label.create("//our/build:target")).addDependency(Label.create("//some/package:javalibs")).build();
targetMap.put(TargetKey.forPlainTarget(Label.create("//our/build:target")), buildTargetInfo);
targetMap.put(TargetKey.forPlainTarget(Label.create("//some/package:javalibs")), TargetIdeInfo.builder().build());
configureTestForTargetMap(targetMap);
try {
compilerFactory.getCompilerFor(buildTargetInfo);
fail("Should have thrown FastBuildException");
} catch (FastBuildException e) {
assertThat(e.getMessage()).contains("Java toolchain");
}
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class FastBuildCompilerFactoryImplTest method getCompiler.
public FastBuildCompiler getCompiler() throws FastBuildException {
Map<TargetKey, TargetIdeInfo> targetMap = new HashMap<>();
TargetIdeInfo buildTargetInfo = TargetIdeInfo.builder().setLabel(Label.create("//our/build:target")).addDependency(Label.create("//third_party/java/jdk:langtools")).build();
targetMap.put(TargetKey.forPlainTarget(Label.create("//our/build:target")), buildTargetInfo);
targetMap.put(TargetKey.forPlainTarget(Label.create("//third_party/java/jdk:langtools")), TargetIdeInfo.builder().setJavaToolchainIdeInfo(JavaToolchainIdeInfo.builder().setJavacJar(ArtifactLocation.builder().setRelativePath(JAVAC_JAR.getPath()).build())).build());
configureTestForTargetMap(targetMap);
return compilerFactory.getCompilerFor(buildTargetInfo);
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDepsForFlavor.
private void addProtoLegacyLibrariesFromDirectDepsForFlavor(TargetMap targetMap, ProtoLibraryLegacyInfo.ApiFlavor apiFlavor, List<TargetKey> targetKeys, Map<LibraryKey, BlazeJarLibrary> result) {
for (TargetKey key : targetKeys) {
TargetIdeInfo target = targetMap.get(key);
if (target == null) {
continue;
}
ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
if (protoLibraryLegacyInfo == null) {
continue;
}
final Collection<LibraryArtifact> libraries;
switch(apiFlavor) {
case VERSION_1:
libraries = protoLibraryLegacyInfo.jarsV1;
break;
case MUTABLE:
libraries = protoLibraryLegacyInfo.jarsMutable;
break;
case IMMUTABLE:
libraries = protoLibraryLegacyInfo.jarsImmutable;
break;
default:
// Can't happen
libraries = null;
break;
}
if (libraries != null) {
for (LibraryArtifact libraryArtifact : libraries) {
BlazeJarLibrary library = new BlazeJarLibrary(libraryArtifact);
result.put(library.key, library);
}
}
}
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method addTargetAsSource.
private void addTargetAsSource(WorkspaceBuilder workspaceBuilder, TargetIdeInfo target, Collection<ArtifactLocation> javaSources) {
JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
if (javaIdeInfo == null) {
return;
}
TargetKey targetKey = target.key;
Collection<String> jars = jdepsMap.getDependenciesForTarget(targetKey);
if (jars != null) {
workspaceBuilder.jdeps.addAll(jars);
}
// Add all deps if this rule is in the current working set
if (workingSet == null || workingSet.isTargetInWorkingSet(target)) {
// Add self, so we pick up our own gen jars if in working set
workspaceBuilder.directDeps.add(targetKey);
for (Dependency dep : target.dependencies) {
if (dep.dependencyType != DependencyType.COMPILE_TIME) {
continue;
}
// forward deps from java proto_library aspect targets
TargetIdeInfo depTarget = targetMap.get(dep.targetKey);
if (depTarget != null && Kind.JAVA_PROTO_LIBRARY_KINDS.contains(depTarget.kind)) {
workspaceBuilder.directDeps.addAll(depTarget.dependencies.stream().map(d -> d.targetKey).collect(Collectors.toList()));
} else {
workspaceBuilder.directDeps.add(dep.targetKey);
}
}
}
for (ArtifactLocation artifactLocation : javaSources) {
if (artifactLocation.isSource()) {
duplicateSourceDetector.add(targetKey, artifactLocation);
workspaceBuilder.sourceArtifacts.add(new SourceArtifact(targetKey, artifactLocation));
workspaceBuilder.addedSourceFiles.add(artifactLocation);
}
}
ArtifactLocation manifest = javaIdeInfo.packageManifest;
if (manifest != null) {
workspaceBuilder.javaPackageManifests.put(targetKey, manifest);
}
for (LibraryArtifact libraryArtifact : javaIdeInfo.jars) {
ArtifactLocation classJar = libraryArtifact.classJar;
if (classJar != null) {
workspaceBuilder.buildOutputJars.add(classJar);
}
}
workspaceBuilder.generatedJarsFromSourceTargets.addAll(javaIdeInfo.generatedJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList()));
if (javaIdeInfo.filteredGenJar != null) {
workspaceBuilder.generatedJarsFromSourceTargets.add(new BlazeJarLibrary(javaIdeInfo.filteredGenJar));
}
for (BlazeJavaSyncAugmenter augmenter : augmenters) {
augmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, workspaceBuilder.outputJarsFromSourceTargets.get(targetKey), workspaceBuilder.generatedJarsFromSourceTargets);
}
}
Aggregations