Search in sources :

Example 1 with JavacOption

use of com.sun.tools.javac.main.JavacOption in project ceylon-compiler by ceylon.

the class JavacTool method setOption1.

private void setOption1(String name, OptionKind kind, Object... args) {
    String arg = argsToString(args);
    JavacOption option = sharedCompiler.getOption(name);
    if (option == null || !match(kind, option.getKind()))
        throw new IllegalArgumentException(name);
    if ((args.length != 0) != option.hasArg())
        throw new IllegalArgumentException(name);
    if (option.hasArg()) {
        if (// FIXME
        option.process(null, name, arg))
            throw new IllegalArgumentException(name);
    } else {
        if (// FIXME
        option.process(null, name))
            throw new IllegalArgumentException(name);
    }
    options.add(new Pair<String, String>(name, arg));
}
Also used : JavacOption(com.sun.tools.javac.main.JavacOption)

Example 2 with JavacOption

use of com.sun.tools.javac.main.JavacOption in project ceylon-compiler by ceylon.

the class CeylonCompileTool method addJavacArguments.

private void addJavacArguments(List<String> arguments) {
    Options options = Options.instance(new Context());
    for (String argument : javac) {
        HELPER.lastError = null;
        String value = null;
        int index = argument.indexOf('=');
        if (index != -1) {
            value = index < argument.length() ? argument.substring(index + 1) : "";
            argument = argument.substring(0, index);
        }
        JavacOption javacOpt = getJavacOpt(argument.replaceAll(":.*", ":"));
        if (javacOpt == null) {
            throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.javac", argument));
        }
        if (value != null) {
            if (!javacOpt.hasArg()) {
                throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.syntax.javac", argument, "Unexpected argument given"));
            }
            if (!javacOpt.matches(argument)) {
                throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.javac", argument));
            }
            if (javacOpt.process(options, argument, value)) {
                throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.syntax.javac", argument, HELPER.lastError));
            }
        } else {
            if (javacOpt.hasArg()) {
                throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.syntax.javac", argument, "Missing expected argument"));
            }
            if (!javacOpt.matches(argument)) {
                throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.javac", argument));
            }
            if (javacOpt.process(options, argument)) {
                throw new IllegalArgumentException(CeylonCompileMessages.msg("option.error.syntax.javac", argument, HELPER.lastError));
            }
        }
        arguments.add(argument);
        if (value != null) {
            arguments.add(value);
        }
    }
}
Also used : Context(com.sun.tools.javac.util.Context) DefaultToolOptions(com.redhat.ceylon.common.config.DefaultToolOptions) RecognizedOptions(com.sun.tools.javac.main.RecognizedOptions) Options(com.sun.tools.javac.util.Options) JavacOption(com.sun.tools.javac.main.JavacOption)

Example 3 with JavacOption

use of com.sun.tools.javac.main.JavacOption in project ceylon-compiler by ceylon.

the class CeylonCompileTool method initialize.

@Override
public void initialize(CeylonTool mainTool) throws IOException {
    compiler = new Main("ceylon compile");
    Options options = Options.instance(new Context());
    if (modulesOrFiles.isEmpty() && !javac.contains("-help") && !javac.contains("-X") && !javac.contains("-version")) {
        throw new IllegalStateException("Argument moduleOrFile should appear at least 1 time(s)");
    }
    arguments = new ArrayList<>();
    if (cwd != null) {
        arguments.add("-cwd");
        arguments.add(cwd.getPath());
    }
    for (File source : applyCwd(this.sources)) {
        arguments.add("-src");
        arguments.add(source.getPath());
        options.addMulti(OptionName.SOURCEPATH, source.getPath());
    }
    for (File resource : applyCwd(this.resources)) {
        arguments.add("-res");
        arguments.add(resource.getPath());
    //options.addMulti(OptionName.RESOURCEPATH, resource.getPath());
    }
    if (resourceRoot != null) {
        arguments.add("-resroot");
        arguments.add(resourceRoot);
    }
    if (continueOnErrors) {
        arguments.add("-continue");
    }
    if (progress) {
        arguments.add("-progress");
    }
    if (offline) {
        arguments.add("-offline");
    }
    if (timeout != -1) {
        arguments.add("-timeout");
        arguments.add(String.valueOf(timeout));
    }
    if (flatClasspath) {
        arguments.add("-flat-classpath");
    }
    if (autoExportMavenDependencies) {
        arguments.add("-auto-export-maven-dependencies");
    }
    if (overrides != null) {
        arguments.add("-overrides");
        if (overrides.startsWith("classpath:")) {
            arguments.add(overrides);
        } else {
            arguments.add(applyCwd(new File(overrides)).getPath());
        }
    }
    if (noOsgi) {
        arguments.add("-noosgi");
    }
    if (osgiProvidedBundles != null && !osgiProvidedBundles.isEmpty()) {
        arguments.add("-osgi-provided-bundles");
        arguments.add(osgiProvidedBundles);
    }
    if (noPom) {
        arguments.add("-nopom");
    }
    if (pack200) {
        arguments.add("-pack200");
    }
    if (verbose != null) {
        if (verbose.isEmpty()) {
            arguments.add("-verbose");
        } else {
            arguments.add("-verbose:" + verbose);
        }
    }
    if (out != null) {
        arguments.add("-out");
        arguments.add(out);
    }
    if (user != null) {
        arguments.add("-user");
        arguments.add(user);
    }
    if (pass != null) {
        arguments.add("-pass");
        arguments.add(pass);
    }
    String fileEncoding = encoding;
    if (fileEncoding == null) {
        fileEncoding = DefaultToolOptions.getDefaultEncoding();
    }
    if (fileEncoding != null) {
        JavacOption encodingOpt = getJavacOpt(OptionName.ENCODING.toString());
        validateWithJavac(options, encodingOpt, OptionName.ENCODING.toString(), fileEncoding, "option.error.syntax.encoding");
        arguments.add(OptionName.ENCODING.toString());
        arguments.add(fileEncoding);
    }
    if (systemRepo != null) {
        arguments.add("-sysrep");
        arguments.add(systemRepo);
    }
    if (cacheRepo != null) {
        arguments.add("-cacherep");
        arguments.add(cacheRepo);
    }
    if (noDefRepos) {
        arguments.add("-nodefreps");
    }
    if (repo != null) {
        for (URI uri : this.repo) {
            arguments.add("-rep");
            arguments.add(uri.toString());
        }
    }
    if (suppressWarnings != null) {
        arguments.add("-suppress-warnings");
        arguments.add(EnumUtil.enumsToString(suppressWarnings));
    }
    addJavacArguments(arguments);
    List<File> srcs = applyCwd(this.sources);
    List<String> expandedModulesOrFiles = ModuleWildcardsHelper.expandWildcards(srcs, this.modulesOrFiles, Backend.Java);
    if (expandedModulesOrFiles.isEmpty()) {
        throw new ToolUsageError("No modules or source files to compile");
    }
    JavacOption sourceFileOpt = getJavacOpt(OptionName.SOURCEFILE.toString());
    if (sourceFileOpt != null) {
        for (String moduleOrFile : expandedModulesOrFiles) {
            validateWithJavac(options, sourceFileOpt, moduleOrFile, moduleOrFile, "argument.error");
        }
    }
    validateSourceArguments(expandedModulesOrFiles);
    arguments.addAll(expandedModulesOrFiles);
    if (verbose != null) {
        System.out.println(arguments);
        System.out.flush();
    }
}
Also used : Context(com.sun.tools.javac.util.Context) DefaultToolOptions(com.redhat.ceylon.common.config.DefaultToolOptions) RecognizedOptions(com.sun.tools.javac.main.RecognizedOptions) Options(com.sun.tools.javac.util.Options) JavacOption(com.sun.tools.javac.main.JavacOption) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Main(com.redhat.ceylon.compiler.java.launcher.Main) File(java.io.File) URI(java.net.URI)

Example 4 with JavacOption

use of com.sun.tools.javac.main.JavacOption in project ceylon-compiler by ceylon.

the class JavacTool method processOptions.

public static void processOptions(Context context, JavaFileManager fileManager, Iterable<String> options) {
    if (options == null)
        return;
    Options optionTable = Options.instance(context);
    JavacOption[] recognizedOptions = RecognizedOptions.getJavacToolOptions(new GrumpyHelper());
    Iterator<String> flags = options.iterator();
    while (flags.hasNext()) {
        String flag = flags.next();
        int j;
        for (j = 0; j < recognizedOptions.length; j++) if (recognizedOptions[j].matches(flag))
            break;
        if (j == recognizedOptions.length) {
            if (fileManager.handleOption(flag, flags)) {
                continue;
            } else {
                String msg = Main.getLocalizedString("err.invalid.flag", flag);
                throw new IllegalArgumentException(msg);
            }
        }
        JavacOption option = recognizedOptions[j];
        if (option.hasArg()) {
            if (!flags.hasNext()) {
                String msg = Main.getLocalizedString("err.req.arg", flag);
                throw new IllegalArgumentException(msg);
            }
            String operand = flags.next();
            if (option.process(optionTable, flag, operand))
                // in case of errors
                throw new IllegalArgumentException(flag + " " + operand);
        } else {
            if (option.process(optionTable, flag))
                // in case of errors
                throw new IllegalArgumentException(flag);
        }
    }
}
Also used : RecognizedOptions(com.sun.tools.javac.main.RecognizedOptions) Options(com.sun.tools.javac.util.Options) JavacOption(com.sun.tools.javac.main.JavacOption) GrumpyHelper(com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper)

Aggregations

JavacOption (com.sun.tools.javac.main.JavacOption)4 RecognizedOptions (com.sun.tools.javac.main.RecognizedOptions)3 Options (com.sun.tools.javac.util.Options)3 DefaultToolOptions (com.redhat.ceylon.common.config.DefaultToolOptions)2 Context (com.sun.tools.javac.util.Context)2 ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)1 Main (com.redhat.ceylon.compiler.java.launcher.Main)1 GrumpyHelper (com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper)1 File (java.io.File)1 URI (java.net.URI)1