use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder 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.syncState.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 artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
for (BlazeLibrary library : libraries) {
if (!(library instanceof BlazeJarLibrary)) {
continue;
}
BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
files.add(artifactLocationDecoder.decode(jarLibrary.libraryArtifact.jarForIntellijLibrary()));
files.addAll(artifactLocationDecoder.decodeAll(jarLibrary.libraryArtifact.sourceJars));
}
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class SourceDirectoryCalculator method calculateContentEntries.
public ImmutableList<BlazeContentEntry> calculateContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, ImportRoots importRoots, Collection<SourceArtifact> sources, Map<TargetKey, ArtifactLocation> javaPackageManifests) {
ManifestFilePackageReader manifestFilePackageReader = Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("ReadPackageManifests", EventType.Other));
Map<TargetKey, Map<ArtifactLocation, String>> manifestMap = PackageManifestReader.getInstance().readPackageManifestFiles(project, childContext, artifactLocationDecoder, javaPackageManifests, packageReaderExecutorService);
return new ManifestFilePackageReader(manifestMap);
});
final List<JavaPackageReader> javaPackageReaders = Lists.newArrayList(manifestFilePackageReader, JavaSourcePackageReader.getInstance(), generatedFileJavaPackageReader);
Collection<SourceArtifact> nonGeneratedSources = filterGeneratedArtifacts(sources);
// Sort artifacts and excludes into their respective workspace paths
Multimap<WorkspacePath, SourceArtifact> sourcesUnderDirectoryRoot = sortArtifactLocationsByRootDirectory(context, importRoots, nonGeneratedSources);
List<BlazeContentEntry> result = Lists.newArrayList();
Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("CalculateSourceDirectories", EventType.Other));
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
File contentRoot = workspaceRoot.fileForPath(workspacePath);
ImmutableList<BlazeSourceDirectory> sourceDirectories = calculateSourceDirectoriesForContentRoot(context, workspaceRoot, artifactLocationDecoder, workspacePath, sourcesUnderDirectoryRoot.get(workspacePath), javaPackageReaders);
if (!sourceDirectories.isEmpty()) {
result.add(new BlazeContentEntry(contentRoot, sourceDirectories));
}
}
result.sort(Comparator.comparing(lhs -> lhs.contentRoot));
});
return ImmutableList.copyOf(result);
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporter method importWorkspace.
public BlazeAndroidImportResult importWorkspace() {
List<TargetIdeInfo> sourceTargets = targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.ANDROID).filter(target -> target.androidIdeInfo != null).filter(importFilter::isSourceTarget).filter(target -> !importFilter.excludeTarget(target)).collect(Collectors.toList());
TransitiveResourceMap transitiveResourceMap = new TransitiveResourceMap(targetMap);
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceTargets) {
addSourceTarget(workspaceBuilder, transitiveResourceMap, target);
}
GeneratedResourceWarnings.submit(project, context, projectViewSet, artifactLocationDecoder, workspaceBuilder.generatedResourceLocations, whitelistedGenResourcePaths);
ImmutableList<AndroidResourceModule> androidResourceModules = buildAndroidResourceModules(workspaceBuilder);
BlazeResourceLibrary resourceLibrary = createResourceLibrary(androidResourceModules);
ImmutableList<AarLibrary> aarLibraries = createAarLibraries(sourceFilter.getLibraryTargets());
return new BlazeAndroidImportResult(androidResourceModules, resourceLibrary, aarLibraries, getJavacJar(targetMap.targets()));
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class BlazeAndroidProjectStructureSyncer method updateInMemoryState.
private static void updateInMemoryState(Project project, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Module workspaceModule, AndroidResourceModuleRegistry registry, LightResourceClassService.Builder rClassBuilder) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData == null) {
return;
}
AndroidSdkPlatform androidSdkPlatform = syncData.androidSdkPlatform;
if (androidSdkPlatform == null) {
return;
}
updateWorkspaceModuleFacetInMemoryState(project, workspaceRoot, workspaceModule, androidSdkPlatform);
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
ModuleFinder moduleFinder = ModuleFinder.getInstance(project);
Executor resourceRepositoryExecutor = Executors.newSingleThreadExecutor();
Module libraryResourcesModule = moduleFinder.findModuleByName(LIBRARY_RESOURCES_MODULE_NAME);
if (libraryResourcesModule != null) {
updateLibraryResourcesModuleFacetInMemoryState(project, workspaceRoot, libraryResourcesModule, androidSdkPlatform, syncData.importResult.resourceLibrary == null ? ImmutableList.of() : artifactLocationDecoder.decodeAll(syncData.importResult.resourceLibrary.sources), resourceRepositoryExecutor);
} else if (useLibraryResourcesModule.getValue()) {
logger.warn("Library resources module missing.");
}
for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
TargetIdeInfo target = blazeProjectData.targetMap.get(androidResourceModule.targetKey);
String moduleName = moduleNameForAndroidModule(target.key);
Module module = moduleFinder.findModuleByName(moduleName);
if (module == null) {
logger.warn("No module found for resource target: " + target.key);
continue;
}
registry.put(module, androidResourceModule);
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, artifactLocationDecoder.decodeAll(useLibraryResourcesModule.getValue() ? androidResourceModule.resources : androidResourceModule.transitiveResources), resourceRepositoryExecutor);
rClassBuilder.addRClass(androidIdeInfo.resourceJavaPackage, module);
}
Set<TargetKey> androidResourceModules = syncData.importResult.androidResourceModules.stream().map(androidResourceModule -> androidResourceModule.targetKey).collect(toSet());
List<TargetIdeInfo> runConfigurationTargets = getRunConfigurationTargets(project, projectViewSet, blazeProjectData, androidResourceModules);
for (TargetIdeInfo target : runConfigurationTargets) {
String moduleName = moduleNameForAndroidModule(target.key);
Module module = moduleFinder.findModuleByName(moduleName);
if (module == null) {
logger.warn("No module found for run configuration target: " + target.key);
continue;
}
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
}
}
use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.
the class AndroidPrefetchFileSource method addFilesToPrefetch.
@Override
public void addFilesToPrefetch(Project project, ProjectViewSet projectViewSet, ImportRoots importRoots, BlazeProjectData blazeProjectData, Set<File> files) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData == null) {
return;
}
if (syncData.importResult.resourceLibrary == null) {
return;
}
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
files.addAll(artifactLocationDecoder.decodeAll(syncData.importResult.resourceLibrary.sources));
}
Aggregations