Search in sources :

Example 1 with LocalFile

use of com.google.devtools.intellij.model.ProjectData.LocalFile in project intellij by bazelbuild.

the class ArtifactMetadata method forArtifact.

/**
 * Returns the relevant metadata for an {@code artifact} that needs to be persisted.
 *
 * @throws ArtifactNotFoundException if the artifact is not present.
 */
public static ArtifactMetadata forArtifact(OutputArtifact artifact) throws ArtifactNotFoundException {
    ArtifactState artifactState = artifact.toArtifactState();
    if (artifactState == null) {
        throw new ArtifactNotFoundException(artifact);
    }
    // Serialize to proto to make grabbing the fields easier
    LocalFileOrOutputArtifact serializedArtifact = artifactState.serializeToProto();
    if (serializedArtifact.hasArtifact()) {
        ProjectData.OutputArtifact o = serializedArtifact.getArtifact();
        return new ArtifactMetadata(o.getRelativePath(), o.getId());
    } else {
        LocalFile o = serializedArtifact.getLocalFile();
        String relativePath = o.getRelativePath().isEmpty() ? o.getPath() : o.getRelativePath();
        return new ArtifactMetadata(relativePath, Long.toString(o.getTimestamp()));
    }
}
Also used : LocalFile(com.google.devtools.intellij.model.ProjectData.LocalFile) ArtifactState(com.google.idea.blaze.base.filecache.ArtifactState) LocalFileOrOutputArtifact(com.google.devtools.intellij.model.ProjectData.LocalFileOrOutputArtifact) ProjectData(com.google.devtools.intellij.model.ProjectData)

Aggregations

ProjectData (com.google.devtools.intellij.model.ProjectData)1 LocalFile (com.google.devtools.intellij.model.ProjectData.LocalFile)1 LocalFileOrOutputArtifact (com.google.devtools.intellij.model.ProjectData.LocalFileOrOutputArtifact)1 ArtifactState (com.google.idea.blaze.base.filecache.ArtifactState)1