Search in sources :

Example 1 with JoocConfiguration

use of net.jangaroo.jooc.config.JoocConfiguration in project jangaroo-tools by CoreMedia.

the class JoocTest method setup.

@Before
public void setup() throws Exception {
    outputFolder = tmpFolder.newFolder("jangaroo-output");
    apiOutputFolder = tmpFolder.newFolder("joo-api");
    config = new JoocConfiguration();
    File sourceDir = getFile("/");
    List<File> sourcepath = new ArrayList<File>();
    sourcepath.add(sourceDir);
    config.setSourcePath(sourcepath);
    config.setDebugMode(DebugMode.SOURCE);
    config.setOutputDirectory(outputFolder);
    //noinspection ResultOfMethodCallIgnored
    config.setApiOutputDirectory(apiOutputFolder);
    testLog.reset();
    jooc = new Jooc(config, testLog);
}
Also used : ArrayList(java.util.ArrayList) JoocConfiguration(net.jangaroo.jooc.config.JoocConfiguration) File(java.io.File) Before(org.junit.Before)

Example 2 with JoocConfiguration

use of net.jangaroo.jooc.config.JoocConfiguration in project jangaroo-tools by CoreMedia.

the class Jooc method run.

public static int run(String[] argv, CompileLog log) {
    try {
        JoocCommandLineParser commandLineParser = new JoocCommandLineParser();
        JoocConfiguration config = commandLineParser.parse(argv);
        if (config != null) {
            return new Jooc(config, log).run().getResultCode();
        }
    } catch (CommandLineParseException e) {
        // NOSONAR this is a commandline tool
        System.out.println(e.getMessage());
        return e.getExitCode();
    }
    return CompilationResult.RESULT_CODE_OK;
}
Also used : CommandLineParseException(net.jangaroo.jooc.cli.CommandLineParseException) JoocCommandLineParser(net.jangaroo.jooc.cli.JoocCommandLineParser) JoocConfiguration(net.jangaroo.jooc.config.JoocConfiguration)

Example 3 with JoocConfiguration

use of net.jangaroo.jooc.config.JoocConfiguration in project jangaroo-tools by CoreMedia.

the class AbstractCompilerMojo method execute.

/**
   * Runs the compile mojo
   *
   * @throws MojoExecutionException
   * @throws MojoFailureException
   */
public void execute() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();
    if (getCompileSourceRoots().isEmpty()) {
        log.info("No sources to compile");
        return;
    }
    // ----------------------------------------------------------------------
    // Create the compiler configuration
    // ----------------------------------------------------------------------
    JoocConfiguration configuration = new JoocConfiguration();
    configuration.setEnableAssertions(enableAssertions);
    configuration.setAllowDuplicateLocalVariables(allowDuplicateLocalVariables);
    configuration.setVerbose(verbose);
    configuration.setExcludeClassByDefault(excludeClassByDefault);
    if (StringUtils.isNotEmpty(debuglevel)) {
        try {
            configuration.setDebugMode(DebugMode.valueOf(debuglevel.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("The specified debug level: '" + debuglevel + "' is unsupported. " + "Legal values are 'none', 'lines', and 'source'.");
        }
    }
    if (StringUtils.isNotEmpty(autoSemicolon)) {
        try {
            configuration.setSemicolonInsertionMode(SemicolonInsertionMode.valueOf(autoSemicolon.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("The specified semicolon insertion mode: '" + autoSemicolon + "' is unsupported. " + "Legal values are 'error', 'warn', and 'quirks'.");
        }
    }
    if (StringUtils.isNotEmpty(publicApiViolations)) {
        try {
            configuration.setPublicApiViolationsMode(PublicApiViolationsMode.valueOf(publicApiViolations.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("The specified public API violations mode: '" + publicApiViolations + "' is unsupported. " + "Legal values are 'error', 'warn', and 'allow'.");
        }
    }
    HashSet<File> sources = new HashSet<File>();
    log.debug("starting source inclusion scanner");
    sources.addAll(computeStaleSources(staleMillis));
    if (sources.isEmpty()) {
        log.info("Nothing to compile - all classes are up to date");
        return;
    }
    configuration.setSourceFiles(new ArrayList<File>(sources));
    try {
        configuration.setSourcePath(getCompileSourceRoots());
    } catch (IOException e) {
        throw new MojoFailureException("could not canonicalize source paths: " + getCompileSourceRoots(), e);
    }
    configuration.setClassPath(getActionScriptClassPath());
    configuration.setOutputDirectory(getClassesOutputDirectory());
    configuration.setApiOutputDirectory(getApiOutputDirectory());
    if (log.isDebugEnabled()) {
        log.debug("Source path: " + configuration.getSourcePath().toString().replace(',', '\n'));
        log.debug("Class path: " + configuration.getClassPath().toString().replace(',', '\n'));
        log.debug("Output directory: " + configuration.getOutputDirectory());
        if (configuration.getApiOutputDirectory() != null) {
            log.debug("API output directory: " + configuration.getApiOutputDirectory());
        }
    }
    int result = compile(configuration);
    boolean compilationError = (result != CompilationResult.RESULT_CODE_OK);
    if (!compilationError) {
        // for now, always set debug mode to "false" for concatenated file:
        configuration.setDebugMode(null);
        configuration.setOutputDirectory(getTempClassesOutputDirectory());
        configuration.setApiOutputDirectory(null);
        result = compile(configuration);
        if (result == CompilationResult.RESULT_CODE_OK) {
            buildOutputFile(getTempClassesOutputDirectory(), getModuleClassesJsFile());
        }
        compilationError = (result != CompilationResult.RESULT_CODE_OK);
    }
    List<CompilerError> messages = Collections.emptyList();
    if (compilationError && failOnError) {
        log.info("-------------------------------------------------------------");
        log.error("COMPILATION ERROR : ");
        log.info("-------------------------------------------------------------");
        if (messages != null) {
            for (CompilerError message : messages) {
                log.error(message.toString());
            }
            log.info(messages.size() + ((messages.size() > 1) ? " errors " : "error"));
            log.info("-------------------------------------------------------------");
        }
        throw new MojoFailureException("Compilation failed");
    } else {
        for (CompilerError message : messages) {
            log.warn(message.toString());
        }
    }
}
Also used : AbstractCompileLog(net.jangaroo.jooc.AbstractCompileLog) Log(org.apache.maven.plugin.logging.Log) MojoFailureException(org.apache.maven.plugin.MojoFailureException) JoocConfiguration(net.jangaroo.jooc.config.JoocConfiguration) CompilerError(org.codehaus.plexus.compiler.CompilerError) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet)

Example 4 with JoocConfiguration

use of net.jangaroo.jooc.config.JoocConfiguration in project jangaroo-tools by CoreMedia.

the class JsCodeGenerator method visitAssignmentOpExpr.

@Override
public void visitAssignmentOpExpr(AssignmentOpExpr assignmentOpExpr) throws IOException {
    if (assignmentOpExpr.getOp().sym == sym.ANDANDEQ || assignmentOpExpr.getOp().sym == sym.OROREQ) {
        assignmentOpExpr.getArg1().visit(this);
        out.writeSymbolWhitespace(assignmentOpExpr.getOp());
        out.writeToken("=");
        // TODO: refactor for a simpler way to switch off white-space temporarily:
        JoocConfiguration options = (JoocConfiguration) out.getOptions();
        DebugMode mode = options.getDebugMode();
        options.setDebugMode(null);
        assignmentOpExpr.getArg1().visit(this);
        options.setDebugMode(mode);
        out.writeToken(assignmentOpExpr.getOp().sym == sym.ANDANDEQ ? "&&" : "||");
        out.writeToken("(");
        assignmentOpExpr.getArg2().visit(this);
        out.writeToken(")");
    } else {
        visitBinaryOpExpr(assignmentOpExpr);
    }
}
Also used : DebugMode(net.jangaroo.jooc.config.DebugMode) JoocConfiguration(net.jangaroo.jooc.config.JoocConfiguration)

Example 5 with JoocConfiguration

use of net.jangaroo.jooc.config.JoocConfiguration in project jangaroo-tools by CoreMedia.

the class JoocCommandLineParser method parse.

public JoocConfiguration parse(String[] args) throws CommandLineParseException {
    JoocConfiguration config = new JoocConfiguration();
    CmdLineParser parser = new CmdLineParser(config);
    try {
        // parse the arguments.
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        StringBuilder msg = extendedUsage(parser, e);
        throw new CommandLineParseException(msg.toString(), -1);
    }
    return parseConfig(parser, config);
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) JoocConfiguration(net.jangaroo.jooc.config.JoocConfiguration) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

JoocConfiguration (net.jangaroo.jooc.config.JoocConfiguration)5 File (java.io.File)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AbstractCompileLog (net.jangaroo.jooc.AbstractCompileLog)1 CommandLineParseException (net.jangaroo.jooc.cli.CommandLineParseException)1 JoocCommandLineParser (net.jangaroo.jooc.cli.JoocCommandLineParser)1 DebugMode (net.jangaroo.jooc.config.DebugMode)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 Log (org.apache.maven.plugin.logging.Log)1 CompilerError (org.codehaus.plexus.compiler.CompilerError)1 Before (org.junit.Before)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1