use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class FastBuildCompilerFactoryImpl method getJavacJar.
private File getJavacJar(TargetIdeInfo targetIdeInfo) throws FastBuildException {
BlazeProjectData projectData = projectDataManager.getBlazeProjectData();
checkState(projectData != null, "not a blaze project");
List<JavaToolchainIdeInfo> javaToolchains = new ArrayList<>();
for (Dependency dependency : targetIdeInfo.dependencies) {
TargetIdeInfo depInfo = projectData.targetMap.get(dependency.targetKey);
if (depInfo != null && depInfo.javaToolchainIdeInfo != null) {
javaToolchains.add(depInfo.javaToolchainIdeInfo);
}
}
if (javaToolchains.isEmpty()) {
throw new FastBuildException("Couldn't find a Java toolchain for target " + targetIdeInfo.key.label);
}
if (javaToolchains.size() > 1) {
throw new FastBuildException("Found multiple Java toolchains for target " + targetIdeInfo.key.label);
}
return projectData.artifactLocationDecoder.decode(javaToolchains.get(0).javacJar);
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class BlazeCreateResourceUtils method setupResDirectoryChoices.
static void setupResDirectoryChoices(Project project, @Nullable VirtualFile contextFile, JBLabel resDirLabel, ComboboxWithBrowseButton resDirComboAndBrowser) {
// Reset the item list before filling it back up.
resDirComboAndBrowser.getComboBox().removeAllItems();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData != null) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData != null) {
ImmutableCollection<TargetKey> rulesRelatedToContext = null;
File fileFromContext = null;
if (contextFile != null) {
fileFromContext = VfsUtilCore.virtualToIoFile(contextFile);
rulesRelatedToContext = SourceToTargetMap.getInstance(project).getRulesForSourceFile(fileFromContext);
if (rulesRelatedToContext.isEmpty()) {
rulesRelatedToContext = null;
}
}
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
// Sort:
// - contextFile/res if contextFile is a directory,
// to optimize the right click on directory case, or the "closest" string
// match to the contextFile from the res directories known to blaze
// - the rest of the direct dirs, then transitive dirs of the context rules,
// then any known res dir in the project
// as a backup, in alphabetical order.
Set<File> resourceDirs = Sets.newTreeSet();
Set<File> transitiveDirs = Sets.newTreeSet();
Set<File> allResDirs = Sets.newTreeSet();
for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
Collection<File> resources = artifactLocationDecoder.decodeAll(androidResourceModule.resources);
Collection<File> transitiveResources = artifactLocationDecoder.decodeAll(androidResourceModule.transitiveResources);
// labelsRelatedToContext should include deps,
// but as a first pass we only check the rules themselves
// for resources. If we come up empty, then have anyResDir as a backup.
allResDirs.addAll(transitiveResources);
if (rulesRelatedToContext != null && !rulesRelatedToContext.contains(androidResourceModule.targetKey)) {
continue;
}
resourceDirs.addAll(resources);
transitiveDirs.addAll(transitiveResources);
}
// No need to show some directories twice.
transitiveDirs.removeAll(resourceDirs);
JComboBox resDirCombo = resDirComboAndBrowser.getComboBox();
// Allow the user to browse and overwrite some of the entries,
// in case our inference is wrong.
resDirCombo.setEditable(true);
// After the use confirms the choice, a directory will be created if it is missing.
if (fileFromContext != null && fileFromContext.isDirectory()) {
File closestDirToContext = new File(fileFromContext.getPath(), "res");
resDirCombo.setSelectedItem(closestDirToContext);
} else {
// If we're not completely sure, let people know there are options
// via the placeholder text, and put the most likely on top.
String placeHolder = PLACEHOLDER_TEXT;
resDirCombo.addItem(placeHolder);
resDirCombo.setSelectedItem(placeHolder);
if (fileFromContext != null) {
File closestDirToContext = findClosestDirToContext(fileFromContext.getPath(), resourceDirs);
closestDirToContext = closestDirToContext != null ? closestDirToContext : findClosestDirToContext(fileFromContext.getPath(), transitiveDirs);
if (closestDirToContext != null) {
resDirCombo.addItem(closestDirToContext);
resourceDirs.remove(closestDirToContext);
transitiveDirs.remove(closestDirToContext);
}
}
}
if (!resourceDirs.isEmpty() || !transitiveDirs.isEmpty()) {
for (File resourceDir : resourceDirs) {
resDirCombo.addItem(resourceDir);
}
for (File resourceDir : transitiveDirs) {
resDirCombo.addItem(resourceDir);
}
} else {
for (File resourceDir : allResDirs) {
resDirCombo.addItem(resourceDir);
}
}
resDirComboAndBrowser.setVisible(true);
resDirLabel.setVisible(true);
}
}
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class BlazeBuildSystemService method addDependency.
@Override
public void addDependency(Module module, String artifact) {
Project project = module.getProject();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return;
}
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
TargetIdeInfo targetIdeInfo = blazeProjectData.targetMap.get(registry.getTargetKey(module));
if (targetIdeInfo == null || targetIdeInfo.buildFile == null) {
return;
}
// TODO: automagically edit deps instead of just opening the BUILD file?
// Need to translate Gradle coordinates into blaze targets.
// Will probably need to hardcode for each dependency.
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
PsiElement buildTargetPsi = BuildReferenceManager.getInstance(project).resolveLabel(targetIdeInfo.key.label);
if (buildTargetPsi != null) {
// If we can find a PSI for the target,
// then we can jump straight to the target in the build file.
fileEditorManager.openTextEditor(new OpenFileDescriptor(project, buildTargetPsi.getContainingFile().getVirtualFile(), buildTargetPsi.getTextOffset()), true);
} else {
// If not, just the build file is good enough.
File buildIoFile = blazeProjectData.artifactLocationDecoder.decode(targetIdeInfo.buildFile);
VirtualFile buildVirtualFile = VfsUtils.resolveVirtualFile(buildIoFile);
if (buildVirtualFile != null) {
fileEditorManager.openFile(buildVirtualFile, true);
}
}
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class BlazeRenderErrorContributor method reportIssues.
@Override
public Collection<RenderErrorModel.Issue> reportIssues() {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null || !logger.hasErrors()) {
return getIssues();
}
TargetMap targetMap = blazeProjectData.targetMap;
ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
AndroidResourceModule resourceModule = AndroidResourceModuleRegistry.getInstance(project).get(module);
if (resourceModule == null) {
return getIssues();
}
TargetIdeInfo target = targetMap.get(resourceModule.targetKey);
if (target == null) {
return getIssues();
}
reportGeneratedResources(resourceModule, targetMap, decoder);
reportNonStandardAndroidManifestName(target, decoder);
reportResourceTargetShouldDependOnClassTarget(target, targetMap, decoder);
return getIssues();
}
use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.
the class SyncCache method get.
/**
* Computes a value derived from the sync project data and caches it until the next sync.
*/
@Nullable
@SuppressWarnings("unchecked")
public synchronized <T> T get(Object key, SyncCacheComputable<T> computable) {
T value = (T) cache.get(key);
if (value == null) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData != null) {
value = computable.compute(project, blazeProjectData);
cache.put(key, value);
}
}
return value;
}
Aggregations