use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class BlazeXmlToTestEventsConverter method parseTestXml.
/**
* Parse all test XML files from a single test target.
*/
private static ParsedTargetResults parseTestXml(Label label, Collection<BlazeTestResult> results) {
List<BlazeArtifact> outputFiles = new ArrayList<>();
results.forEach(result -> outputFiles.addAll(result.getOutputXmlFiles()));
List<TestSuite> targetSuites = new ArrayList<>();
for (BlazeArtifact file : outputFiles) {
try (InputStream input = file.getInputStream()) {
targetSuites.add(BlazeXmlSchema.parse(input));
} catch (Exception e) {
// ignore parsing errors -- most common cause is user cancellation, which we can't easily
// recognize.
}
}
return new ParsedTargetResults(label, results, outputFiles, targetSuites);
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class JarCache method repackageJars.
/**
* Repackage jars when necessary to avoid package name conflict.
*/
private ImmutableList<ListenableFuture<?>> repackageJars(BlazeProjectData projectData, Collection<BlazeArtifact> updatedJars) {
JarRepackager jarRepackager = JarRepackager.getInstance();
FileOperationProvider ops = FileOperationProvider.getInstance();
if (!jarRepackager.isEnabled()) {
return ImmutableList.of();
}
return LintJarHelper.collectLintJarsArtifacts(projectData).stream().map(blazeArtifact -> FetchExecutor.EXECUTOR.submit(() -> {
try {
repackageJar(jarRepackager, blazeArtifact, file -> {
// repackage a jar when it's just updated or never repackaged.
if (updatedJars.contains(blazeArtifact)) {
return true;
}
File repackagedJar = new File(jarCacheFolderProvider.getJarCacheFolder(), jarRepackager.getRepackagePrefix() + file.getName());
return ops.exists(file) && !ops.exists(repackagedJar);
});
} catch (IOException | InterruptedException e) {
logger.warn(String.format("Failed to repackage artifact %s to %s", blazeArtifact, jarCacheFolderProvider.getJarCacheFolder().getPath()), e);
}
})).collect(toImmutableList());
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class JarCache method getCachedSourceJar.
/**
* Gets the cached file for a source jar. If it doesn't exist, we return the file from the
* library, or null if that also can't be accessed locally.
*/
@Nullable
public File getCachedSourceJar(ArtifactLocationDecoder decoder, ArtifactLocation sourceJar) {
boolean enabled = isEnabled();
BlazeArtifact artifact = decoder.resolveOutput(sourceJar);
if (!enabled) {
return getFallbackFile(artifact);
}
String cacheKey = cacheKeyForSourceJar(artifact);
return getCacheFile(cacheKey).orElseGet(() -> getFallbackFile(artifact));
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class RenderJarCache method getCachedJarForBinaryTarget.
/**
* Returns the RenderJAR corresponding to {@code target} or null if no RenderJAR corresponding to
* {@code target} exists in cache.
*/
@Nullable
public File getCachedJarForBinaryTarget(ArtifactLocationDecoder artifactLocationDecoder, TargetIdeInfo target) {
if (!RenderJarClassFileFinder.isEnabled()) {
return null;
}
AndroidIdeInfo androidIdeInfo = target.getAndroidIdeInfo();
if (androidIdeInfo == null) {
return null;
}
ArtifactLocation jarArtifactLocation = androidIdeInfo.getRenderResolveJar();
if (jarArtifactLocation == null) {
return null;
}
BlazeArtifact jarArtifact = artifactLocationDecoder.resolveOutput(jarArtifactLocation);
if (!(jarArtifact instanceof OutputArtifact)) {
Logger.getInstance(RenderJarCache.class).warn("Unexpected render jar that is not an OutputArtifact: " + jarArtifactLocation);
return null;
}
Path jarPath = artifactCache.get((OutputArtifact) jarArtifact);
return jarPath == null ? null : jarPath.toFile();
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class UnpackedAars method getClassJar.
/**
* Returns the merged jar derived from an AAR, in the unpacked AAR directory.
*/
@Nullable
public File getClassJar(ArtifactLocationDecoder decoder, AarLibrary library) {
if (library.libraryArtifact == null) {
return null;
}
BlazeArtifact jar = decoder.resolveOutput(library.libraryArtifact.jarForIntellijLibrary());
if (aarCache.isEmpty()) {
logger.warn("Cache state is empty");
return getFallbackFile(jar);
}
BlazeArtifact aar = decoder.resolveOutput(library.aarArtifact);
File aarDir = getAarDir(decoder, library);
// check if it was actually cached
if (aarDir == null) {
// cannot find any fallback file.
if (jar instanceof RemoteOutputArtifact) {
logger.warn(String.format("Fail to look up %s from cache state for library [aarArtifact = %s, jar = %s]", aarDir, aar, jar));
logger.debug("Cache state contains the following keys: " + aarCache.getCachedKeys());
}
return getFallbackFile(jar);
}
return UnpackedAarUtils.getJarFile(aarDir);
}
Aggregations