use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeClassJarProviderIntegrationTest method doSetup.
@Before
public void doSetup() {
module = testFixture.getModule();
ArtifactLocationDecoder decoder = (location) -> new File("/src", location.getExecutionRootRelativePath());
BlazeProjectData blazeProjectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(buildTargetMap()).setArtifactLocationDecoder(decoder).build();
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
classJarProvider = new BlazeClassJarProvider(getProject());
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeBuildSystemServiceTest method createMockBlazeProjectData.
private BlazeProjectData createMockBlazeProjectData() {
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(Label.create("//foo:bar")).setBuildFile(ArtifactLocation.builder().setRelativePath("foo/BUILD").build()).build()).build();
ArtifactLocationDecoder decoder = (location) -> new File("/", location.getRelativePath());
return MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).setArtifactLocationDecoder(decoder).build();
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method initTest.
@Override
protected void initTest(Container applicationServices, Container projectServices) {
MockExperimentService mockExperimentService = new MockExperimentService();
applicationServices.register(ExperimentService.class, mockExperimentService);
BlazeExecutor blazeExecutor = new MockBlazeExecutor();
applicationServices.register(BlazeExecutor.class, blazeExecutor);
projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager());
BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(DUMMY_IMPORT_SETTINGS);
MockFileOperationProvider mockFileOperationProvider = new MockFileOperationProvider();
applicationServices.register(FileOperationProvider.class, mockFileOperationProvider);
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
// For importJavaWorkspace.
applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader() {
@Nullable
@Override
public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
return null;
}
});
applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
applicationServices.register(PrefetchService.class, new MockPrefetchService());
registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeClassJarProvider method findModuleClassFile.
@Override
@Nullable
public VirtualFile findModuleClassFile(String className, Module module) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return null;
}
TargetMap targetMap = blazeProjectData.targetMap;
ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
TargetIdeInfo target = blazeProjectData.targetMap.get(registry.getTargetKey(module));
if (target == null || target.javaIdeInfo == null) {
return null;
}
// As a potential optimization, we could choose an arbitrary android_binary target
// that depends on the library to provide a single complete resource jar,
// instead of having to rely on dynamic class generation.
// TODO: benchmark to see if optimization is worthwhile.
String classNamePath = className.replace('.', File.separatorChar) + SdkConstants.DOT_CLASS;
List<LibraryArtifact> jarsToSearch = Lists.newArrayList(target.javaIdeInfo.jars);
jarsToSearch.addAll(TransitiveDependencyMap.getInstance(project).getTransitiveDependencies(target.key).stream().map(targetMap::get).filter(Objects::nonNull).flatMap(BlazeClassJarProvider::getNonResourceJars).collect(Collectors.toList()));
List<File> missingClassJars = Lists.newArrayList();
for (LibraryArtifact jar : jarsToSearch) {
if (jar.classJar == null || jar.classJar.isSource()) {
continue;
}
File classJarFile = decoder.decode(jar.classJar);
VirtualFile classJarVF = VirtualFileSystemProvider.getInstance().getSystem().findFileByIoFile(classJarFile);
if (classJarVF == null) {
if (classJarFile.exists()) {
missingClassJars.add(classJarFile);
}
continue;
}
VirtualFile classFile = findClassInJar(classJarVF, classNamePath);
if (classFile != null) {
return classFile;
}
}
maybeRefreshJars(missingClassJars, pendingJarsRefresh);
return null;
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeClassJarProvider method getModuleExternalLibraries.
@Override
public List<File> getModuleExternalLibraries(Module module) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return ImmutableList.of();
}
TargetMap targetMap = blazeProjectData.targetMap;
ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
TargetIdeInfo target = targetMap.get(registry.getTargetKey(module));
if (target == null) {
return ImmutableList.of();
}
AppResourceRepository repository = AppResourceRepository.getOrCreateInstance(module);
ImmutableList.Builder<File> results = ImmutableList.builder();
for (TargetKey dependencyTargetKey : TransitiveDependencyMap.getInstance(project).getTransitiveDependencies(target.key)) {
TargetIdeInfo dependencyTarget = targetMap.get(dependencyTargetKey);
if (dependencyTarget == null) {
continue;
}
// Add all import jars as external libraries.
JavaIdeInfo javaIdeInfo = dependencyTarget.javaIdeInfo;
if (javaIdeInfo != null) {
for (LibraryArtifact jar : javaIdeInfo.jars) {
if (jar.classJar != null && jar.classJar.isSource()) {
results.add(decoder.decode(jar.classJar));
}
}
}
// Tell ResourceClassRegistry which repository contains our resources and the java packages of
// the resources that we're interested in.
// When the class loader tries to load a custom view, and the view references resource
// classes, layoutlib will ask the class loader for these resource classes.
// If these resource classes are in a separate jar from the target (i.e., in a dependency),
// then offering their jars will lead to a conflict in the resource IDs.
// So instead, the resource class generator will produce dummy resource classes with
// non-conflicting IDs to satisfy the class loader.
// The resource repository remembers the dynamic IDs that it handed out and when the layoutlib
// calls to ask about the name and content of a given resource ID, the repository can just
// answer what it has already stored.
AndroidIdeInfo androidIdeInfo = dependencyTarget.androidIdeInfo;
if (androidIdeInfo != null && !Strings.isNullOrEmpty(androidIdeInfo.resourceJavaPackage) && repository != null) {
ResourceClassRegistry.get(module.getProject()).addLibrary(repository, androidIdeInfo.resourceJavaPackage);
}
}
return results.build();
}
Aggregations