Skip to content

Commit

Permalink
Adds --jszip support to DepsGenerator.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=102605225
  • Loading branch information
stalcup authored and blickly committed Sep 9, 2015
1 parent 1c05f49 commit 9b5721a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/com/google/javascript/jscomp/SourceFile.java
Expand Up @@ -339,7 +339,11 @@ public static List<SourceFile> fromZipFile(String zipName, Charset inputCharset)
while (zipEntries.hasMoreElements()) {
ZipEntry zipEntry = zipEntries.nextElement();
URL zipEntryUrl = new URL("jar:file:" + absoluteZipPath + "!/" + zipEntry.getName());
sourceFiles.add(builder().withCharset(inputCharset).buildFromUrl(zipEntryUrl));
sourceFiles.add(
builder()
.withCharset(inputCharset)
.withOriginalPath(zipName + "!/" + zipEntry.getName())
.buildFromUrl(zipEntryUrl));
}
}
return sourceFiles;
Expand Down Expand Up @@ -408,6 +412,7 @@ public static Builder builder() {
*/
public static class Builder {
private Charset charset = UTF_8;
private String originalPath = null;

public Builder() {}

Expand All @@ -417,21 +422,26 @@ public Builder withCharset(Charset charset) {
return this;
}

public Builder withOriginalPath(String originalPath) {
this.originalPath = originalPath;
return this;
}

public SourceFile buildFromFile(String fileName) {
return buildFromFile(new File(fileName));
}

public SourceFile buildFromFile(File file) {
return new OnDisk(file, null /** originalPath */, charset);
return new OnDisk(file, originalPath, charset);
}

@GwtIncompatible("java.net.URL")
public SourceFile buildFromUrl(URL url) {
return new AtUrl(url, null /** originalPath */, charset);
return new AtUrl(url, originalPath, charset);
}

public SourceFile buildFromCode(String fileName, String code) {
return new Preloaded(fileName, null /** originalPath */, code);
return new Preloaded(fileName, originalPath, code);
}

@GwtIncompatible("java.io.InputStream")
Expand All @@ -449,7 +459,7 @@ public SourceFile buildFromReader(String fileName, Reader r)

public SourceFile buildFromGenerator(String fileName,
Generator generator) {
return new Generated(fileName, null /** originalPath */, generator);
return new Generated(fileName, originalPath, generator);
}
}

Expand Down Expand Up @@ -612,7 +622,7 @@ static class AtUrl extends SourceFile {
private String inputCharset = UTF_8.name();

AtUrl(URL url, String originalPath, Charset c) {
super(url.getPath());
super(originalPath);
this.url = url;
super.setOriginalPath(originalPath);
if (c != null) {
Expand Down
9 changes: 9 additions & 0 deletions src/com/google/javascript/jscomp/deps/DepsGenerator.java
Expand Up @@ -436,6 +436,15 @@ static List<SourceFile> createSourceFilesFromPaths(
return files;
}

static List<SourceFile> createSourceFilesFromZipPaths(
Collection<String> paths) throws IOException {
List<SourceFile> zipSourceFiles = new ArrayList<>();
for (String path : paths) {
zipSourceFiles.addAll(SourceFile.fromZipFile(path, UTF_8));
}
return zipSourceFiles;
}

static List<SourceFile> createSourceFilesFromPaths(
String ... paths) {
return createSourceFilesFromPaths(Arrays.asList(paths));
Expand Down

0 comments on commit 9b5721a

Please sign in to comment.