Search in sources :

Example 1 with LocalFileArtifact

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);
}
Also used : LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) File(java.io.File) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with LocalFileArtifact

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(","));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) InputStreamProvider(com.google.idea.blaze.base.io.InputStreamProvider) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) IOException(java.io.IOException) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BufferedInputStream(java.io.BufferedInputStream) LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Before(org.junit.Before)

Example 3 with LocalFileArtifact

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);
    }
}
Also used : LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) InputStream(java.io.InputStream) File(java.io.File)

Example 4 with LocalFileArtifact

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);
    }
}
Also used : Path(java.nio.file.Path) LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) InputStream(java.io.InputStream) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) IOException(java.io.IOException) File(java.io.File)

Aggregations

LocalFileArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact)4 File (java.io.File)4 BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)3 InputStream (java.io.InputStream)3 IOException (java.io.IOException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 InputStreamProvider (com.google.idea.blaze.base.io.InputStreamProvider)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Before (org.junit.Before)1