Skip to content
This repository was archived by the owner on Feb 23, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
<guava.version>19.0</guava.version>
<guava.version>20.0</guava.version>
</properties>

<build>
Expand Down Expand Up @@ -186,7 +186,7 @@
<dependency> <!-- For com.google.debugging.sourcemap -->
<groupId>com.google.javascript</groupId>
<artifactId>closure-compiler-unshaded</artifactId>
<version>v20160713</version>
<version>v20170218</version>
</dependency>

<dependency>
Expand Down
4 changes: 3 additions & 1 deletion src/com/google/common/css/JobDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Map;
import java.util.Set;


/**
* Provides inputs and options to Closure Stylesheets.
* To construct an instance, use a {@link JobDescriptionBuilder}.
Expand Down Expand Up @@ -69,6 +68,7 @@ public class JobDescription {
public final Map<String, Integer> compileConstants;
public final boolean createSourceMap;
public final SourceMapDetailLevel sourceMapLevel;
public final boolean sourceMapIncludeContent;
public final boolean preserveImportantComments;

static final String CONDITION_FOR_LTR = "GSS_LTR";
Expand Down Expand Up @@ -142,6 +142,7 @@ public enum SourceMapDetailLevel { ALL, DEFAULT }
boolean suppressDependencyCheck, Map<String, Integer> compileConstants,
boolean createSourceMap,
SourceMapDetailLevel sourceMapLevel,
boolean sourceMapIncludeContent,
boolean preserveImportantComments) {
this.allowUndefinedConstants = allowUndefinedConstants;
Preconditions.checkArgument(!inputs.contains(null));
Expand Down Expand Up @@ -190,6 +191,7 @@ public enum SourceMapDetailLevel { ALL, DEFAULT }
this.compileConstants = ImmutableMap.copyOf(compileConstants);
this.createSourceMap = createSourceMap;
this.sourceMapLevel = sourceMapLevel;
this.sourceMapIncludeContent = sourceMapIncludeContent;
this.preserveImportantComments = preserveImportantComments;
}

Expand Down
10 changes: 9 additions & 1 deletion src/com/google/common/css/JobDescriptionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class JobDescriptionBuilder {
JobDescription job = null;
boolean createSourceMap;
SourceMapDetailLevel sourceMapLevel;
boolean sourceMapIncludeContent;

public JobDescriptionBuilder() {
this.inputs = Lists.newArrayList();
Expand Down Expand Up @@ -111,6 +112,7 @@ public JobDescriptionBuilder() {
this.compileConstants = new HashMap<>();
this.createSourceMap = false;
this.sourceMapLevel = SourceMapDetailLevel.DEFAULT;
this.sourceMapIncludeContent = false;
this.preserveImportantComments = false;
}

Expand Down Expand Up @@ -151,6 +153,7 @@ public JobDescriptionBuilder copyFrom(JobDescription jobToCopy) {
setCompileConstants(jobToCopy.compileConstants);
this.createSourceMap = jobToCopy.createSourceMap;
this.sourceMapLevel = jobToCopy.sourceMapLevel;
this.sourceMapIncludeContent = jobToCopy.sourceMapIncludeContent;
this.preserveImportantComments = jobToCopy.preserveImportantComments;
return this;
}
Expand Down Expand Up @@ -495,7 +498,8 @@ public JobDescription getJobDescription() {
gssFunctionMapProvider, cssSubstitutionMapProvider,
outputRenamingMapFormat, inputRenamingMap, preserveComments,
suppressDependencyCheck, compileConstants,
createSourceMap, sourceMapLevel, preserveImportantComments);
createSourceMap, sourceMapLevel, sourceMapIncludeContent,
preserveImportantComments);
return job;
}

Expand All @@ -509,4 +513,8 @@ public JobDescriptionBuilder setCreateSourceMap(boolean createSourceMap) {
return this;
}

public JobDescriptionBuilder setSourceMapIncludeContent(boolean sourceMapIncludeContent) {
this.sourceMapIncludeContent = sourceMapIncludeContent;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ static class Flags {
+ "mappings, and ALL, which outputs mappings for all elements.")
private SourceMapDetailLevel sourceMapLevel = SourceMapDetailLevel.DEFAULT;

@Option(name = "--source_map_include_content", usage = "Includes sources "
+ "content into source map. Greatly increases the size of source maps "
+ "but offers greater portability (default: false)")
private boolean sourceMapIncludeContent = false;

@Option(name = "--copyright-notice",
usage = "Copyright notice to prepend to the output")
private String copyrightNotice = null;
Expand Down Expand Up @@ -259,6 +264,7 @@ JobDescription createJobDescription() {
getGssFunctionMapProviderForName(gssFunctionMapProviderClassName);
builder.setGssFunctionMapProvider(gssFunctionMapProvider);
builder.setSourceMapLevel(sourceMapLevel);
builder.setSourceMapIncludeContent(sourceMapIncludeContent);
builder.setCreateSourceMap(!Strings.isNullOrEmpty(sourceMapFile));

if (inputRenamingMapFileName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private GssSourceMapGenerator createSourceMapGenerator(JobDescription job) {
if (!job.createSourceMap) {
return new NullGssSourceMapGenerator();
}
return new DefaultGssSourceMapGenerator(job.sourceMapLevel);
return new DefaultGssSourceMapGenerator(job.sourceMapLevel, job.sourceMapIncludeContent);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,25 @@ static class Mapping {

private SourceMapDetailLevel sourceMapDetailLevel;

private boolean sourceMapIncludeContent;

/** Predicate to determine whether to include current node under visit into {@code mappings}. **/
private Predicate<CssNode> detailLevelPredicate;

/**
* Constructor to get source map class to use.
*
* @param sourceMapDetailLevel used to control the output details of source map
* @param sourceMapIncludeContent used to include content in source map
*/
public DefaultGssSourceMapGenerator(SourceMapDetailLevel sourceMapDetailLevel) {
public DefaultGssSourceMapGenerator(SourceMapDetailLevel sourceMapDetailLevel,
boolean sourceMapIncludeContent) {
Preconditions.checkState(sourceMapDetailLevel != null);
this.mappings = new ArrayDeque<>();
this.generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3);
this.allMappings = new ArrayList<>();
this.sourceMapDetailLevel = sourceMapDetailLevel;
this.sourceMapIncludeContent = sourceMapIncludeContent;
this.detailLevelPredicate = DETAIL_LEVEL_PREDICATES.get(this.sourceMapDetailLevel);
}

Expand Down Expand Up @@ -202,19 +207,26 @@ private void generateSourceMap() {
completeMapping.sourceFile, null,
completeMapping.inputStart,
completeMapping.outputStart, completeMapping.outputEnd);

if (sourceMapIncludeContent) {
generator.addSourcesContent(
completeMapping.sourceFile, completeMapping.sourceContents);
}
}
}


private static final class CompleteMapping implements Comparable<CompleteMapping> {
final String sourceFile;
final String sourceContents;
final FilePosition inputStart;
final FilePosition outputStart;
final FilePosition outputEnd;

CompleteMapping(Mapping mapping) {
CssNode node = mapping.node;
this.sourceFile = getSourceFileName(node);
this.sourceContents = getSourceFileContents(node);
this.inputStart = new FilePosition(
getStartLineno(node), getStartCharIndex(node));
this.outputStart = mapping.start;
Expand All @@ -237,6 +249,13 @@ private static String getSourceFileName(CssNode node) {
return node.getSourceCodeLocation().getSourceCode().getFileName();
}

/**
* Gets the source file contents for current node.
*/
private static String getSourceFileContents(CssNode node) {
return node.getSourceCodeLocation().getSourceCode().getFileContents();
}

/**
* Gets the start line index in the source code of {@code node} adjusted to 0-based indices.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class TestParser {
private List<SourceCode> sources = new ArrayList<>();
private TestErrorManager errorManager = new TestErrorManager(new String[0]);
private GssSourceMapGenerator generator =
new DefaultGssSourceMapGenerator(SourceMapDetailLevel.ALL);
new DefaultGssSourceMapGenerator(SourceMapDetailLevel.ALL, true);
private String output = null;
private SourceMapping sourceMap = null;
private String sourceMapString = null;
Expand Down