Skip to content

Commit

Permalink
add support for ignoring some JSweet problems
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrignon committed Jul 4, 2018
1 parent b48dcdc commit 66a6d57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ header | file | A file that contains a header to be written at the beginning of
workingDir | directory | The directory JSweet uses to store temporary files such as extracted candies. JSweet uses '.jsweet' if left unspecified. | -
disableSinglePrecisionFloats | boolean | By default, for a target version >=ES5, JSweet will force Java floats to be mapped to JavaScript numbers that will be constrained with ES5 Math.fround function. If this option is true, then the calls to Math.fround are erased and the generated program will use the JavaScript default precision (double precision). | false
extraSystemPath | string | Allow an extra path to be added to the system path. | -
ignoredProblems | string[] | Array of JSweetProblems which won't be reported or cause failure. | -
## Run JSweet ##

Then, just run the maven command line as usual:
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/org/jsweet/AbstractJSweetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.jsweet.transpiler.ModuleKind;
import org.jsweet.transpiler.ModuleResolution;
import org.jsweet.transpiler.SourceFile;
import org.jsweet.transpiler.SourcePosition;
import org.jsweet.transpiler.util.ConsoleTranspilationHandler;
import org.jsweet.transpiler.util.ErrorCountTranspilationHandler;
import org.jsweet.transpiler.util.ProcessUtil;
Expand Down Expand Up @@ -130,6 +131,9 @@ public abstract class AbstractJSweetMojo extends AbstractMojo {
@Parameter(required = false)
protected String factoryClassName;

@Parameter(required = false)
protected List<JSweetProblem> ignoredProblems;

@Parameter(required = false)
protected Boolean ignoreTypeScriptErrors;

Expand Down Expand Up @@ -245,6 +249,7 @@ protected JSweetTranspiler createJSweetTranspiler(MavenProject project) throws M
logInfo("veryVerbose: " + veryVerbose);
logInfo("jdkHome: " + jdkHome);
logInfo("factoryClassName: " + factoryClassName);
logInfo("ignoredProblems: " + ignoredProblems);

JSweetConfig.initClassPath(jdkHome.getAbsolutePath());

Expand Down Expand Up @@ -284,7 +289,8 @@ protected JSweetTranspiler createJSweetTranspiler(MavenProject project) throws M
} catch (ClassNotFoundException e) {
logInfo("factory not found using ClassRealm.loadClass");
try {
ClassLoader classLoader = new URLClassLoader(realm.getURLs(), Thread.currentThread().getContextClassLoader());
ClassLoader classLoader = new URLClassLoader(realm.getURLs(),
Thread.currentThread().getContextClassLoader());
factory = (JSweetFactory) classLoader.loadClass(factoryClassName).newInstance();
} catch (ClassNotFoundException e2) {
logInfo("factory not found using Thread.currentThread().getContextClassLoader().loadClass");
Expand Down Expand Up @@ -484,10 +490,24 @@ protected MavenProject getMavenProject() {
return project;
}

private class JSweetMavenPluginTranspilationHandler extends ErrorCountTranspilationHandler {

public JSweetMavenPluginTranspilationHandler() {
super(new ConsoleTranspilationHandler());
}

@Override
public void report(JSweetProblem problem, SourcePosition sourcePosition, String message) {
if (ignoredProblems != null && ignoredProblems.contains(problem)) {
return;
}
super.report(problem, sourcePosition, message);
}
}

protected void transpile(MavenProject project, JSweetTranspiler transpiler) throws MojoExecutionException {
try {
ErrorCountTranspilationHandler transpilationHandler = new ErrorCountTranspilationHandler(
new ConsoleTranspilationHandler());
JSweetMavenPluginTranspilationHandler transpilationHandler = new JSweetMavenPluginTranspilationHandler();
try {

SourceFile[] sources = collectSourceFiles(project);
Expand Down

0 comments on commit 66a6d57

Please sign in to comment.