My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.bolinfest.closure;

import org.kohsuke.args4j.CmdLineException;

import com.google.common.collect.ImmutableSet;
import com.google.javascript.jscomp.CommandLineRunner;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.VariableRenamingPolicy;

/**
* DebugStrippingCompilerRunner is an extension of the Closure Compiler that
* strips debugging information when ADVANCED_OPTIMIZATIONS is used.
*
* @author bolinfest@gmail.com (Michael Bolin)
*/
public class DebugStrippingCompilerRunner extends CommandLineRunner {

public DebugStrippingCompilerRunner(String[] args) throws CmdLineException {
super(args);
}

@Override
protected CompilerOptions createOptions() {
CompilerOptions options = super.createOptions();

// Use this as a heuristic to determine whether ADVANCED_OPTIMIZATIONS is
// being used -- cannot access FLAG_compilation_level because it is private
// in CompilerRunner.
boolean isAdvancedOptionsEnabled =
options.variableRenaming == VariableRenamingPolicy.ALL;

// Only enable additional options when ADVANCED_OPTIMIZATIONS is specified.
if (isAdvancedOptionsEnabled) {
applyDebugStrippingOptions(options);
}
return options;
}

static void applyDebugStrippingOptions(CompilerOptions options) {
options.stripNameSuffixes = ImmutableSet.of("logger", "logger_");
options.stripTypePrefixes = ImmutableSet.of("goog.debug", "goog.asserts");
options.setDefineToBooleanLiteral("goog.DEBUG", false);
options.setIdGenerators(ImmutableSet.of("goog.events.getUniqueId"));
}

public static void main(String[] args) {
try {
(new DebugStrippingCompilerRunner(args)).run();
} catch (CmdLineException e) {
System.exit(-1);
}
}
}

Change log

r23 by bolinfest on Mar 7, 2010   Diff
updated files to reflect new compiler
dependency on args4j
Go to: 
Project members, sign in to write a code review

Older revisions

r22 by bolinfest on Feb 28, 2010   Diff
Updated code to use CommandLineRunner
(formerly CompilerRunner) and added
goog.asserts to the list of type
prefixes to strip.
r13 by bolinfest on Dec 16, 2009   Diff
refactored debug-stripping compiler
options
r2 by bolinfest on Nov 18, 2009   Diff
initial import
All revisions of this file

File info

Size: 1792 bytes, 53 lines
Powered by Google Project Hosting