use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact in project intellij by bazelbuild.
the class FileCacheDiffer method readTimestamps.
private static ImmutableMap<File, Long> readTimestamps(Map<String, ? extends BlazeArtifact> newOutputs, Map<String, File> cachedFiles) throws InterruptedException, ExecutionException {
boolean timestampsRequired = newOutputs.values().stream().anyMatch(a -> a instanceof LocalFileArtifact);
if (!timestampsRequired) {
return ImmutableMap.of();
}
Set<File> relevantFiles = new HashSet<>();
for (Map.Entry<String, ? extends BlazeArtifact> entry : newOutputs.entrySet()) {
BlazeArtifact newOutput = entry.getValue();
boolean needsTimestamp = newOutput instanceof LocalFileArtifact;
if (!needsTimestamp) {
continue;
}
relevantFiles.add(((LocalFileArtifact) newOutput).getFile());
File cached = cachedFiles.get(entry.getKey());
if (cached != null) {
relevantFiles.add(cached);
}
}
return ModifiedTimeScanner.readTimestamps(relevantFiles);
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact in project intellij by bazelbuild.
the class BlazeIntegrationTestCase method setUp.
@Before
public final void setUp() throws Throwable {
testFixture = createTestFixture();
testFixture.setUp();
fileSystem = new TestFileSystem(getProject(), testFixture.getTempDirFixture(), isLightTestCase());
runWriteAction(() -> {
VirtualFile workspaceRootVirtualFile = fileSystem.createDirectory("workspace");
workspaceRoot = new WorkspaceRoot(new File(workspaceRootVirtualFile.getPath()));
projectDataDirectory = fileSystem.createDirectory("project-data-dir");
workspace = new WorkspaceFileSystem(workspaceRoot, fileSystem);
});
BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(new BlazeImportSettings(workspaceRoot.toString(), "test-project", projectDataDirectory.getPath(), workspaceRoot.fileForPath(new WorkspacePath("project-view-file")).getPath(), buildSystem()));
registerApplicationService(InputStreamProvider.class, new InputStreamProvider() {
@Override
public InputStream forFile(File file) throws IOException {
VirtualFile vf = fileSystem.findFile(file.getPath());
if (vf == null) {
throw new FileNotFoundException();
}
return vf.getInputStream();
}
@Override
public BufferedInputStream forOutputArtifact(BlazeArtifact output) throws IOException {
if (output instanceof LocalFileArtifact) {
return new BufferedInputStream(forFile(((LocalFileArtifact) output).getFile()));
}
throw new RuntimeException("Can't handle output artifact type: " + output.getClass());
}
});
if (isLightTestCase()) {
registerApplicationService(FileOperationProvider.class, new TestFileSystem.MockFileOperationProvider());
registerApplicationService(VirtualFileSystemProvider.class, new TestFileSystem.TempVirtualFileSystemProvider());
}
String requiredPlugins = System.getProperty("idea.required.plugins.id");
if (requiredPlugins != null) {
VerifyRequiredPluginsEnabled.runCheck(requiredPlugins.split(","));
}
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact in project intellij by bazelbuild.
the class JarCache method copyLocally.
private static void copyLocally(BlazeArtifact output, File destination) throws IOException {
if (output instanceof LocalFileArtifact) {
File source = ((LocalFileArtifact) output).getFile();
Files.copy(Paths.get(source.getPath()), Paths.get(destination.getPath()), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
return;
}
try (InputStream stream = output.getInputStream()) {
Files.copy(stream, Paths.get(destination.getPath()), StandardCopyOption.REPLACE_EXISTING);
}
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact in project intellij by bazelbuild.
the class Unpacker method unpackAarToDir.
/**
* Each .aar file will be unpacked as <key_from_artifact_location>.aar directories in cache
* directory. A timestamp file will be created to decide if updated is needed when a new .aar file
* with same name is found next time.
*/
private static void unpackAarToDir(FileOperationProvider ops, AarLibraryContents aarAndJar, AarCache aarCache) {
String cacheKey = UnpackedAarUtils.getAarDirName(aarAndJar.aar());
try {
File aarDir = aarCache.recreateAarDir(ops, cacheKey);
// TODO(brendandouglas): decompress via ZipInputStream so we don't require a local file
File toCopy = getOrCreateLocalFile(aarAndJar.aar());
ZipUtil.extract(toCopy, aarDir, // which is more lightweight. But it's not applied to lint.jar
(dir, name) -> name.equals(FN_LINT_JAR) || !name.endsWith(".jar"));
BlazeArtifact aar = aarAndJar.aar();
try {
aarCache.createTimeStampFile(cacheKey, (aar instanceof LocalFileArtifact) ? ((LocalFileArtifact) aar).getFile() : null);
} catch (IOException e) {
logger.warn("Failed to set AAR cache timestamp for " + aar, e);
}
// copy merged jar
if (aarAndJar.jar() != null) {
try (InputStream stream = aarAndJar.jar().getInputStream()) {
Path destination = Paths.get(UnpackedAarUtils.getJarFile(aarDir).getPath());
ops.mkdirs(destination.getParent().toFile());
Files.copy(stream, destination, StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (IOException e) {
logger.warn(String.format("Failed to extract AAR %s to %s", aarAndJar.aar(), aarCache.aarDirForKey(cacheKey)), e);
}
}
Aggregations