Skip to content

Commit

Permalink
Add support for --js=path/to/zip/file.zip!/relative/path/to/entry.js …
Browse files Browse the repository at this point in the history
…style js files.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=147522774
  • Loading branch information
tadeegan authored and dimvar committed Feb 15, 2017
1 parent f0ef082 commit 00e6b3b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/com/google/javascript/jscomp/SourceFile.java
Expand Up @@ -46,9 +46,9 @@
import java.util.zip.ZipFile;

/**
* An abstract representation of a source file that provides access to
* language-neutral features. The source file can be loaded from various
* locations, such as from disk or from a preloaded string.
* An abstract representation of a source file that provides access to language-neutral features.
* The source file can be loaded from various locations, such as from disk or from a preloaded
* string.
*
* @author nicksantos@google.com (Nick Santos)
*/
Expand Down Expand Up @@ -93,9 +93,9 @@ public interface Generator {
/**
* Construct a new abstract source file.
*
* @param fileName The file name of the source file. It does not necessarily
* need to correspond to a real path. But it should be unique. Will
* appear in warning messages emitted by the compiler.
* @param fileName The file name of the source file. It does not necessarily need to correspond to
* a real path. But it should be unique. Will appear in warning messages emitted by the
* compiler.
*/
public SourceFile(String fileName) {
if (isNullOrEmpty(fileName)) {
Expand Down Expand Up @@ -368,11 +368,14 @@ public static List<SourceFile> fromZipFile(String zipName, Charset inputCharset)
return sourceFiles;
}

static final String BANG_SLASH = "!/";
static final String JAR_URL_PREFIX = "jar:file:";

@GwtIncompatible("java.net.URL")
public static SourceFile fromZipEntry(
String originalZipPath, String absoluteZipPath, String entryPath, Charset inputCharset)
throws MalformedURLException {
String zipEntryPath = "jar:file:" + absoluteZipPath + "!/" + entryPath;
String zipEntryPath = JAR_URL_PREFIX + absoluteZipPath + BANG_SLASH + entryPath;
URL zipEntryUrl = new URL(zipEntryPath);

return builder()
Expand All @@ -382,8 +385,18 @@ public static SourceFile fromZipEntry(
}

@GwtIncompatible("java.io.File")
public static SourceFile fromFile(String fileName, Charset c) {
return builder().withCharset(c).buildFromFile(fileName);
public static SourceFile fromFile(String fileName, Charset charset) {
if (fileName.contains(BANG_SLASH)) {
String[] components = fileName.split(BANG_SLASH);
try {
String zipPath = components[0];
String relativePath = components[1];
return fromZipEntry(zipPath, zipPath, relativePath, charset);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
return builder().withCharset(charset).buildFromFile(fileName);
}

public static SourceFile fromFile(String fileName) {
Expand Down

0 comments on commit 00e6b3b

Please sign in to comment.