use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeRenderErrorContributorTest method createTargetMapWithNonStandardAndroidManifestNameInDependency.
private void createTargetMapWithNonStandardAndroidManifestNameInDependency() {
Label mainResourceTarget = Label.create("//com/google/example:main");
Label dependencyResourceTarget = Label.create("//com/google/example:dependency");
ArtifactLocation mainManifest = artifact("com/google/example/main/AndroidManifest.xml", true);
ArtifactLocation mainResource = artifact("com/google/example/main/res", true);
ArtifactLocation mainBuildFile = artifact("com/google/example/main/BUILD", true);
ArtifactLocation dependencyManifest = artifact("com/google/example/dependency/MyManifest.xml", true);
ArtifactLocation dependencyResource = artifact("com/google/example/dependency/res", true);
ArtifactLocation dependencyBuildFile = artifact("com/google/example/dependency/BUILD", true);
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
registry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(mainResourceTarget)).addResource(mainResource).addTransitiveResourceDependency(dependencyResourceTarget).addTransitiveResource(dependencyResource).build());
registry.put(mock(Module.class), AndroidResourceModule.builder(TargetKey.forPlainTarget(dependencyResourceTarget)).addResource(dependencyResource).build());
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(mainResourceTarget).setBuildFile(mainBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(mainManifest).addResource(mainResource))).addTarget(TargetIdeInfo.builder().setLabel(dependencyResourceTarget).setBuildFile(dependencyBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(dependencyManifest).addResource(dependencyResource))).build();
projectDataManager.setTargetMap(targetMap);
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeIntellijPluginConfiguration method checkConfiguration.
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
super.checkConfiguration();
Label label = getTarget();
if (label == null) {
throw new RuntimeConfigurationError("Select a target to run");
}
TargetInfo target = TargetFinder.findTargetInfo(getProject(), label);
if (target == null) {
throw new RuntimeConfigurationError("The selected target does not exist.");
}
if (!IntellijPluginRule.isPluginTarget(target)) {
throw new RuntimeConfigurationError("The selected target is not an intellij_plugin");
}
if (!IdeaJdkHelper.isIdeaJdk(pluginSdk)) {
throw new RuntimeConfigurationError("Select an IntelliJ Platform Plugin SDK");
}
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazePyRunConfigurationRunner method getExecutableToDebug.
/**
* Builds blaze python target and returns the output build artifact.
*
* @throws ExecutionException if the target cannot be debugged.
*/
private static File getExecutableToDebug(ExecutionEnvironment env) throws ExecutionException {
BlazeCommandRunConfiguration configuration = getConfiguration(env);
Project project = configuration.getProject();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
throw new ExecutionException("Not synced yet, please sync project");
}
String validationError = BlazePyDebugHelper.validateDebugTarget(env.getProject(), configuration.getTarget());
if (validationError != null) {
throw new WithBrowserHyperlinkExecutionException(validationError);
}
try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, BlazePyDebugHelper.getAllBlazeDebugFlags(Blaze.getBuildSystem(project)), ImmutableList.of(), "Building debug binary");
try {
SaveUtil.saveAllFiles();
BuildResult result = buildOperation.get();
if (result.status != BuildResult.Status.SUCCESS) {
throw new ExecutionException("Blaze failure building debug binary");
}
} catch (InterruptedException | CancellationException e) {
buildOperation.cancel(true);
throw new RunCanceledByUserException();
} catch (java.util.concurrent.ExecutionException e) {
throw new ExecutionException(e);
}
List<File> candidateFiles = buildResultHelper.getBuildArtifactsForTarget((Label) configuration.getTarget()).stream().filter(File::canExecute).collect(Collectors.toList());
if (candidateFiles.isEmpty()) {
throw new ExecutionException(String.format("No output artifacts found when building %s", configuration.getTarget()));
}
File file = findExecutable((Label) configuration.getTarget(), candidateFiles);
if (file == null) {
throw new ExecutionException(String.format("More than 1 executable was produced when building %s; " + "don't know which one to debug", configuration.getTarget()));
}
LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
return file;
}
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class FileLookupData method packageLocalFileLookup.
@Nullable
public static FileLookupData packageLocalFileLookup(String originalLabel, StringLiteral element, @Nullable BuildFile basePackage, @Nullable VirtualFileFilter fileFilter) {
if (basePackage == null) {
return null;
}
Label packageLabel = basePackage.getPackageLabel();
if (packageLabel == null) {
return null;
}
String basePackagePath = packageLabel.blazePackage().relativePath();
String filePath = basePackagePath + "/" + LabelUtils.getRuleComponent(originalLabel);
return new FileLookupData(originalLabel, basePackage, basePackagePath, filePath, PathFormat.PackageLocal, element.getQuoteType(), fileFilter);
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class PackageReferenceFragment method bindToElement.
@Override
public PsiElement bindToElement(PsiElement element) throws IncorrectOperationException {
if (!(element instanceof BuildFile)) {
return super.bindToElement(element);
}
if (element.equals(resolve())) {
return myElement;
}
Label newPackageLabel = ((BuildFile) element).getPackageLabel();
if (newPackageLabel == null) {
return myElement;
}
String newPath = newPackageLabel.blazePackage().toString();
String labelString = myElement.getStringContents();
int colonIndex = labelString.indexOf(':');
if (colonIndex != -1) {
return handleRename("//" + newPath + labelString.substring(colonIndex));
}
// need to assume there's an implicit rule name
return handleRename("//" + newPath + ":" + PathUtil.getFileName(labelString));
}
Aggregations