From 2c53567249dbef321252ac8035336c723a53f6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Tue, 24 Jul 2018 10:38:27 +0200 Subject: [PATCH] [sarlc] Refactoring for using only Bootique injection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All the configurable elements/variables are now injected with Bootique modules. This version of sarlc uses the Bootique modules that are provided by AFC libraries (printconfig, synopsishelp...) Signed-off-by: Stéphane Galland --- products/sarlc/pom.xml | 39 +- .../io/sarl/lang/sarlc/BootiqueSarlcMain.java | 130 +++++ .../java/io/sarl/lang/sarlc/Constants.java | 54 +++ .../main/java/io/sarl/lang/sarlc/Main.java | 114 +---- .../lang/sarlc/commands/CompilerCommand.java | 10 +- .../io/sarl/lang/sarlc/commands/Messages.java | 1 - .../sarlc/commands/PrintConfigCommand.java | 111 ----- .../lang/sarlc/configs/LoggingConfig.java | 451 ------------------ .../{SarlcConfig.java => SarlConfig.java} | 82 ++-- .../{ => subconfigs}/CompilerConfig.java | 40 +- .../{ => subconfigs}/ValidatorConfig.java | 20 +- .../lang/sarlc/modules/CompilerModule.java | 274 ----------- .../lang/sarlc/modules/LoggingModule.java | 137 ------ .../sarl/lang/sarlc/modules/SarlcModule.java | 109 ----- .../lang/sarlc/modules/ValidatorModule.java | 84 ---- .../CompilerCommandModule.java} | 31 +- .../CompilerCommandModuleProvider.java | 53 ++ .../modules/{ => commands}/Messages.java | 32 +- .../VersionCommandModule.java} | 14 +- .../VersionCommandModuleProvider.java | 53 ++ .../modules/configs/CompilerConfigModule.java | 165 +++++++ .../configs/CompilerConfigModuleProvider.java | 53 ++ .../lang/sarlc/modules/configs/Messages.java | 72 +++ .../modules/configs/SarlcConfigModule.java | 111 +++++ .../configs/SarlcConfigModuleProvider.java | 64 +++ .../configs/ValidatorConfigModule.java | 64 +++ .../ValidatorConfigModuleProvider.java | 53 ++ .../lang/sarlc/modules/general/Messages.java | 51 ++ .../general/SARLRuntimeModuleProvider.java | 55 +++ .../general/SarlBatchCompilerModule.java | 114 +++++ .../SarlBatchCompilerModuleProvider.java | 53 ++ .../general/SarlcApplicationModule.java | 87 ++++ .../SarlcApplicationModuleProvider.java | 53 ++ .../general/SarlcDefaultCommandModule.java | 45 ++ .../SarlcDefaultCommandModuleProvider.java | 53 ++ .../lang/sarlc/commands/messages.properties | 1 - .../modules/commands/messages.properties | 2 + .../sarlc/modules/configs/messages.properties | 28 ++ .../sarlc/modules/general/messages.properties | 12 + .../lang/sarlc/modules/messages.properties | 28 -- 40 files changed, 1550 insertions(+), 1453 deletions(-) create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/BootiqueSarlcMain.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/Constants.java delete mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/PrintConfigCommand.java delete mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/LoggingConfig.java rename products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/{SarlcConfig.java => SarlConfig.java} (74%) rename products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/{ => subconfigs}/CompilerConfig.java (88%) rename products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/{ => subconfigs}/ValidatorConfig.java (84%) delete mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/CompilerModule.java delete mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/LoggingModule.java delete mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/SarlcModule.java delete mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/ValidatorModule.java rename products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/{PrintConfigModule.java => commands/CompilerCommandModule.java} (58%) create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModuleProvider.java rename products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/{ => commands}/Messages.java (52%) rename products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/{VersionModule.java => commands/VersionCommandModule.java} (79%) create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModule.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/Messages.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModule.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModule.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/Messages.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SARLRuntimeModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModule.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModule.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModuleProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModule.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModuleProvider.java create mode 100644 products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/commands/messages.properties create mode 100644 products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/configs/messages.properties create mode 100644 products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/general/messages.properties delete mode 100644 products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/messages.properties diff --git a/products/sarlc/pom.xml b/products/sarlc/pom.xml index e275659172..02927ece5c 100644 --- a/products/sarlc/pom.xml +++ b/products/sarlc/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -23,8 +24,24 @@ io.sarl.maven.batchcompiler - io.sarl.maven - io.sarl.maven.bqextension + org.arakhne.afc.bootique + bootique-applicationdata2 + + + org.arakhne.afc.bootique + bootique-synopsishelp + + + org.arakhne.afc.bootique + bootique-printconfig + + + org.arakhne.afc.bootique + bootique-variables + + + org.arakhne.afc.bootique + bootique-log4j @@ -112,12 +129,16 @@ - - - - - + + + + diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/BootiqueSarlcMain.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/BootiqueSarlcMain.java new file mode 100644 index 0000000000..02c7f5c6d8 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/BootiqueSarlcMain.java @@ -0,0 +1,130 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc; + +import java.util.List; + +import com.google.common.base.Throwables; +import com.google.inject.Injector; +import com.google.inject.ProvisionException; +import io.bootique.BQRuntime; +import io.bootique.Bootique; +import io.bootique.command.CommandOutcome; +import io.bootique.help.HelpOption; +import io.bootique.help.HelpOptions; +import io.bootique.meta.application.ApplicationMetadata; +import org.apache.log4j.Logger; + +import io.sarl.lang.SARLStandaloneSetup; +import io.sarl.lang.sarlc.modules.commands.CompilerCommandModuleProvider; +import io.sarl.lang.sarlc.modules.commands.VersionCommandModuleProvider; +import io.sarl.lang.sarlc.modules.configs.CompilerConfigModuleProvider; +import io.sarl.lang.sarlc.modules.configs.SarlcConfigModuleProvider; +import io.sarl.lang.sarlc.modules.configs.ValidatorConfigModuleProvider; +import io.sarl.lang.sarlc.modules.general.SARLRuntimeModuleProvider; +import io.sarl.lang.sarlc.modules.general.SarlBatchCompilerModuleProvider; +import io.sarl.lang.sarlc.modules.general.SarlcApplicationModuleProvider; +import io.sarl.lang.sarlc.modules.general.SarlcDefaultCommandModuleProvider; + +/** Class that implements the standard main function for running a SARL application + * with bootique modules. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class BootiqueSarlcMain { + + /** Create the compiler runtime. + * + * @param args the command line arguments. + * @return the runtime. + */ + @SuppressWarnings("static-method") + protected BQRuntime createRuntime(String... args) { + SARLStandaloneSetup.doPreSetup(); + Bootique bootique = Bootique.app(args); + // Configuration modules + bootique.module(new SarlcConfigModuleProvider()) + .module(new CompilerConfigModuleProvider()) + .module(new ValidatorConfigModuleProvider()); + // Command modules + bootique.module(new VersionCommandModuleProvider()) + .module(new CompilerCommandModuleProvider()); + // Core modules + bootique.module(new SARLRuntimeModuleProvider()) + .module(new SarlBatchCompilerModuleProvider()) + .module(new SarlcDefaultCommandModuleProvider()) + .module(new SarlcApplicationModuleProvider()); + bootique = bootique.autoLoadModules(); + final BQRuntime runtime = bootique.createRuntime(); + SARLStandaloneSetup.doPostSetup(runtime.getInstance(Injector.class)); + return runtime; + } + + /** Run the batch compiler. + * + *

This function runs the compiler and exits with the return code. + * + * @param args the command line arguments. + * @return the exit code. + */ + public int runCompiler(String... args) { + try { + final BQRuntime runtime = createRuntime(args); + final CommandOutcome outcome = runtime.run(); + return outcome.getExitCode(); + } catch (ProvisionException exception) { + final Throwable ex = Throwables.getRootCause(exception); + if (ex != null) { + Logger.getRootLogger().error(ex.getLocalizedMessage()); + } else { + Logger.getRootLogger().error(exception.getLocalizedMessage()); + } + } catch (Throwable exception) { + Logger.getRootLogger().error(exception.getLocalizedMessage()); + } + return Constants.ERROR_CODE; + } + + /** Replies the options of the program. + * + * @return the options of the program. + */ + public List getOptions() { + final BQRuntime runtime = createRuntime(); + final ApplicationMetadata application = runtime.getInstance(ApplicationMetadata.class); + final HelpOptions helpOptions = new HelpOptions(); + + application.getCommands().forEach(c -> { + helpOptions.add(c.asOption()); + c.getOptions().forEach(o -> helpOptions.add(o)); + }); + + application.getOptions().forEach(o -> helpOptions.add(o)); + + return helpOptions.getOptions(); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/Constants.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/Constants.java new file mode 100644 index 0000000000..606884e7fc --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/Constants.java @@ -0,0 +1,54 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc; + +/** Constants for sarlc. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public final class Constants { + + /** Return code when failure. + */ + public static final int ERROR_CODE = 255; + + /** Default name of the sarlc program. + */ + public static final String PROGRAM_NAME = "sarlc"; //$NON-NLS-1$ + + /** Name of the option for defining the output directory from SARL to Java, without the {@code -} and the {@code /} prefixes. + */ + public static final String SARL_OUTPUT_DIRECTORY_OPTION = "directory"; //$NON-NLS-1$ + + /** Name of the option for defining the output directory for the Java class files, without the {@code -} and the {@code /} prefixes. + */ + public static final String JAVA_OUTPUT_DIRECTORY_OPTION = "outputdir"; //$NON-NLS-1$ + + private Constants() { + // + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/Main.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/Main.java index babdbd6a9c..0aa15bd2d6 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/Main.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/Main.java @@ -23,31 +23,7 @@ import java.util.List; -import com.google.common.base.Throwables; -import com.google.inject.Injector; -import com.google.inject.ProvisionException; -import io.bootique.BQRuntime; -import io.bootique.Bootique; import io.bootique.help.HelpOption; -import io.bootique.help.HelpOptions; -import io.bootique.meta.application.ApplicationMetadata; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; - -import io.sarl.lang.SARLRuntimeModule; -import io.sarl.lang.SARLStandaloneSetup; -import io.sarl.lang.sarlc.configs.SarlcConfig; -import io.sarl.lang.sarlc.modules.CompilerModule; -import io.sarl.lang.sarlc.modules.LoggingModule; -import io.sarl.lang.sarlc.modules.PrintConfigModule; -import io.sarl.lang.sarlc.modules.SarlcModule; -import io.sarl.lang.sarlc.modules.ValidatorModule; -import io.sarl.lang.sarlc.modules.VersionModule; -import io.sarl.maven.bqextension.Constants; -import io.sarl.maven.bqextension.modules.ApplicationMetadataModule; -import io.sarl.maven.bqextension.modules.ApplicationMetadataUpdater; -import io.sarl.maven.bqextension.modules.DocumentedModuleProvider; /** Main entry point for the SARL batch compiler. * @@ -64,87 +40,28 @@ private Main() { } /** Main program of the batch compiler. - * - *

This function never returns. It invokes {@link #runCompiler(String...)} - * and stop the JVM with the replied exist code. * * @param args the command line arguments. - * @see #runCompiler(String...) */ public static void main(String[] args) { - final int retCode = runCompiler(args); + final int retCode = createMainObject().runCompiler(args); System.exit(retCode); } - /** Create the compiler runtime. - * - * @param args the command line arguments. - * @return the runtime. - */ - protected static BQRuntime createRuntime(String... args) { - SARLStandaloneSetup.doPreSetup(); - Bootique bootique = Bootique.app(args); - bootique = DocumentedModuleProvider.module(bootique, - SARLRuntimeModule.class, "The core of SARL runtime."); //$NON-NLS-1$ - bootique = DocumentedModuleProvider.modules(bootique, - LoggingModule.class, PrintConfigModule.class, - VersionModule.class, ApplicationMetadataModule.class, - SarlcModule.class, CompilerModule.class, ValidatorModule.class); - bootique = bootique.autoLoadModules(); - final BQRuntime runtime = bootique.createRuntime(); - forceApplicationName(runtime); - SARLStandaloneSetup.doPostSetup(runtime.getInstance(Injector.class)); - return runtime; - } - - private static void forceApplicationName(BQRuntime runtime) { - final ApplicationMetadataUpdater updater = runtime.getInstance(ApplicationMetadataUpdater.class); - final ApplicationMetadata metadata = runtime.getInstance(ApplicationMetadata.class); - final SarlcConfig sarlcConfig = runtime.getInstance(SarlcConfig.class); - updater.setName(metadata, sarlcConfig.getCompilerProgramName()); - } - - /** Run the batch compiler. - * - *

This function runs the compiler and exits with the return code. + /** Replies the default name of the program. * - * @param args the command line arguments. - * @return the exit code. - * @see #main(String[]) + * @return the default name of the program. */ - public static int runCompiler(String... args) { - configureLogger(); - try { - final BQRuntime runtime = createRuntime(args); - runtime.run(); - } catch (ProvisionException exception) { - final Throwable ex = Throwables.getRootCause(exception); - if (ex != null) { - Logger.getRootLogger().error(ex.getLocalizedMessage()); - } else { - Logger.getRootLogger().error(exception.getLocalizedMessage()); - } - return Constants.ERROR_CODE; - } catch (Throwable exception) { - Logger.getRootLogger().error(exception.getLocalizedMessage()); - return Constants.ERROR_CODE; - } - return Constants.SUCCESS_CODE; - } - - private static void configureLogger() { - final Logger root = Logger.getRootLogger(); - root.removeAllAppenders(); - root.addAppender(new ConsoleAppender( - new PatternLayout(Constants.LOGGER_PATTERN))); + public static String getDefaultCompilerProgramName() { + return Constants.PROGRAM_NAME; } - /** Replies the default name of the program. + /** Create the instance of the bootique main launcher. * - * @return the default name of the program. + * @return the main launcher. */ - public static String getDefaultCompilerProgramName() { - return SarlcConfig.COMPILER_PROGRAM_VALUE; + protected static BootiqueSarlcMain createMainObject() { + return new BootiqueSarlcMain(); } /** Replies the options of the program. @@ -152,18 +69,7 @@ public static String getDefaultCompilerProgramName() { * @return the options of the program. */ public static List getOptions() { - final BQRuntime runtime = createRuntime(); - final ApplicationMetadata application = runtime.getInstance(ApplicationMetadata.class); - final HelpOptions helpOptions = new HelpOptions(); - - application.getCommands().forEach(c -> { - helpOptions.add(c.asOption()); - c.getOptions().forEach(o -> helpOptions.add(o)); - }); - - application.getOptions().forEach(o -> helpOptions.add(o)); - - return helpOptions.getOptions(); + return createMainObject().getOptions(); } } diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/CompilerCommand.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/CompilerCommand.java index 20f9cc6b4b..240e35fcbf 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/CompilerCommand.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/CompilerCommand.java @@ -28,8 +28,8 @@ import io.bootique.meta.application.CommandMetadata; import io.sarl.lang.compiler.batch.SarlBatchCompiler; -import io.sarl.lang.sarlc.configs.SarlcConfig; -import io.sarl.maven.bqextension.Constants; +import io.sarl.lang.sarlc.Constants; +import io.sarl.lang.sarlc.configs.SarlConfig; /** * Command for compiling with SARL. @@ -44,7 +44,7 @@ public class CompilerCommand extends CommandWithMetadata { private final Provider compiler; - private final Provider configuration; + private final Provider configuration; private final Provider pathDetector; @@ -54,7 +54,7 @@ public class CompilerCommand extends CommandWithMetadata { * @param configuration the configuration of the tool. * @param pathDetector the detector of path. */ - public CompilerCommand(Provider compiler, Provider configuration, + public CompilerCommand(Provider compiler, Provider configuration, Provider pathDetector) { super(CommandMetadata .builder(CompilerCommand.class) @@ -71,7 +71,7 @@ public CommandOutcome run(Cli cli) { return CommandOutcome.failed(Constants.ERROR_CODE, Messages.CompilerCommand_1); } - final SarlcConfig config = this.configuration.get(); + final SarlConfig config = this.configuration.get(); final PathDetector paths = this.pathDetector.get(); paths.setSarlOutputPath(config.getOutputPath()); paths.setClassOutputPath(config.getClassOutputPath()); diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/Messages.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/Messages.java index cf4fb00705..0cd6b9f68c 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/Messages.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/Messages.java @@ -38,7 +38,6 @@ public class Messages extends NLS { public static String CompilerCommand_1; public static String VersionCommand_0; public static String VersionCommand_1; - public static String PrintConfigCommand_0; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/PrintConfigCommand.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/PrintConfigCommand.java deleted file mode 100644 index 2c9b93efee..0000000000 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/commands/PrintConfigCommand.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2018 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.sarl.lang.sarlc.commands; - -import java.io.StringWriter; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -import com.fasterxml.jackson.dataformat.yaml.snakeyaml.DumperOptions; -import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; -import com.google.inject.Provider; -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.log.BootLogger; -import io.bootique.meta.application.CommandMetadata; - -import io.sarl.maven.bqextension.configs.Config; -import io.sarl.maven.bqextension.configs.Configs; - -/** - * Command for showing configuration. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ -public class PrintConfigCommand extends CommandWithMetadata { - - private static final String CLI_NAME = "printconfig"; //$NON-NLS-1$ - - private static final char CLI_SHORTNAME = 'C'; - - private final BootLogger bootLogger; - - private final Provider> configs; - - /** Constructor. - * - * @param bootLogger the boot logger. - * @param configs the configurations. - */ - public PrintConfigCommand(BootLogger bootLogger, Provider> configs) { - super(CommandMetadata - .builder(PrintConfigCommand.class) - .description(Messages.PrintConfigCommand_0) - .name(CLI_NAME).shortName(CLI_SHORTNAME)); - this.bootLogger = bootLogger; - this.configs = configs; - } - - @Override - public CommandOutcome run(Cli cli) { - final Map yaml = new TreeMap<>(); - extractYaml(yaml, this.configs.get()); - this.bootLogger.stdout(generateYaml(yaml)); - return CommandOutcome.succeeded(); - } - - /** Extract the Yaml definition from the given configurations. - * - * @param yaml the Yaml to fill out. - * @param configs the configurations. - */ - @SuppressWarnings("static-method") - protected void extractYaml(Map yaml, Set configs) { - for (final Config config : configs) { - Configs.defineConfig(yaml, config); - } - } - - /** Generate the Yaml representation of the given map. - * - * @param yaml the Yaml to print out. - * @return the Yaml representation. - */ - @SuppressWarnings("static-method") - protected String generateYaml(Map yaml) { - final DumperOptions options = new DumperOptions(); - options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); - options.setPrettyFlow(true); - final Yaml yamlObj = new Yaml(options); - final StringWriter writer = new StringWriter(); - yamlObj.dump(yaml, writer); - return writer.toString(); - } - -} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/LoggingConfig.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/LoggingConfig.java deleted file mode 100644 index 2bef262061..0000000000 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/LoggingConfig.java +++ /dev/null @@ -1,451 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2018 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.sarl.lang.sarlc.configs; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import io.bootique.annotation.BQConfig; -import io.bootique.annotation.BQConfigProperty; -import io.bootique.config.ConfigurationFactory; -import org.eclipse.xtext.util.Strings; - -import io.sarl.maven.bqextension.configs.Config; - -/** - * Configuration for the logging. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ -@BQConfig("Configuration of the logging service") -public class LoggingConfig implements Config { - - /** - * Prefix for the configuration entries of the logging modules. - */ - public static final String PREFIX = "log"; //$NON-NLS-1$ - - /** - * Name of the property that contains the verbosity level of the SRE. - * - * @see #VERBOSE_LEVEL_VALUE - */ - public static final String VERBOSE_LEVEL_NAME = PREFIX + ".level"; //$NON-NLS-1$ - - /** - * The default verbosity level of the SRE. - * - * @see #VERBOSE_LEVEL_NAME - */ - public static final String VERBOSE_LEVEL_VALUE = "info"; //$NON-NLS-1$ - - /** - * Name of the property that contains the verbosity level of the SRE. - * - * @see #VERBOSE_LEVEL_VALUE - */ - public static final String DEFAULT_FORMAT_NAME = PREFIX + ".defaultLogFormat"; //$NON-NLS-1$ - - - /** Name of the property that contains the logging format within the JRE logging system. - */ - public static final String JRE_FORMAT_PROPERTY_KEY = "java.util.logging.SimpleFormatter.format"; //$NON-NLS-1$ - - /** Default format for the logging messages. - * - *

The parameters for the format string are: - *

    - *
  • %1: the date,
  • - *
  • %2: the name of the calling function,
  • - *
  • %3: the name of the logger,
  • - *
  • %4: the logging level,
  • - *
  • %5: the message, and
  • - *
  • %6: the throwable.
  • - *
- */ - public static final String LOG_FORMAT = "[%4$s, %1$tl:%1$tM:%1$tS%1$tp, %3$s] %5$s%6$s%n"; //$NON-NLS-1$ - - private String level; - - private Level levelObject; - - private String defaultLogFormat = LOG_FORMAT; - - /** Constructor. - */ - public LoggingConfig() { - setLevel(VERBOSE_LEVEL_VALUE); - } - - /** Replies the format of a log line. - * - *

The parameters for the format string are: - *

    - *
  • %1: the date,
  • - *
  • %2: the name of the calling function,
  • - *
  • %3: the name of the logger,
  • - *
  • %4: the logging level,
  • - *
  • %5: the message, and
  • - *
  • %6: the throwable.
  • - *
- * - * @return the log line format. - */ - public String getDefaultLogFormat() { - return this.defaultLogFormat; - } - - /** Change the format of the log lines. The format must be defined according to the - * {@link Logger} API. - * - * @param format the line format. - */ - @BQConfigProperty("Default format of each line within the log") - public void setDefaultLogFormat(String format) { - if (Strings.isEmpty(format)) { - this.defaultLogFormat = LOG_FORMAT; - } else { - this.defaultLogFormat = format; - } - } - - /** - * Replies the verbosity level. - * - * @param level the verbose level - */ - @BQConfigProperty("Name of the default verbosity level") - public void setLevel(String level) { - final Level levelObject = parseLoggingLevel(level); - this.level = levelObject.getName().toLowerCase(); - this.levelObject = levelObject; - } - - /** - * Replies the verbosity level. - * - * @return the verbose level - */ - public String getLevel() { - if (this.level == null) { - this.level = VERBOSE_LEVEL_VALUE; - this.levelObject = null; - } - return this.level; - } - - /** - * Replies the verbosity level. - * - * @return the verbose level - */ - public Level getJavaLevelObject() { - if (this.levelObject == null) { - this.levelObject = parseLoggingLevel(getLevel()); - } - return this.levelObject; - } - - /** - * Replies the verbosity level with log4j object. - * - * @return the verbose level - */ - @SuppressWarnings("checkstyle:npathcomplexity") - public org.apache.log4j.Level getLog4JLevelObject() { - if (this.levelObject == null) { - this.levelObject = parseLoggingLevel(getLevel()); - } - if (this.levelObject == Level.OFF) { - return org.apache.log4j.Level.OFF; - } - if (this.levelObject == Level.SEVERE) { - return org.apache.log4j.Level.ERROR; - } - if (this.levelObject == Level.WARNING) { - return org.apache.log4j.Level.WARN; - } - if (this.levelObject == Level.INFO) { - return org.apache.log4j.Level.INFO; - } - if (this.levelObject == Level.CONFIG || this.levelObject == Level.FINE) { - return org.apache.log4j.Level.DEBUG; - } - if (this.levelObject == Level.FINER || this.levelObject == Level.FINEST) { - return org.apache.log4j.Level.TRACE; - } - if (this.levelObject == Level.ALL) { - return org.apache.log4j.Level.ALL; - } - return org.apache.log4j.Level.INFO; - } - - /** - * Extract the logging level from the given string. - * - * @param level the string representation of the logging level. - * @return the logging level. - */ - public static Level parseLoggingLevel(String level) { - LogLabel defaultLabel = null; - for (final LogLabel label : LogLabel.values()) { - if (label.matchesLabel(level)) { - return label.toLevel(); - } - if (label.isDefaultLevel()) { - defaultLabel = label; - } - } - try { - return fromInt(Integer.parseInt(level)); - } catch (Throwable exception) { - // - } - assert defaultLabel != null; - return defaultLabel.toLevel(); - } - - /** - * Convert a numerical representation of logging level to the logging level. - * - * @param num the numerical index that corresponds to the given level. - * @return the logging level. - */ - public static Level fromInt(int num) { - final LogLabel[] labels = LogLabel.values(); - if (num >= 0 && num < labels.length) { - return labels[num].toLevel(); - } - if (num < 0) { - return Level.OFF; - } - return Level.ALL; - } - - /** Replies all the labels for the logger levels. - * - * @param separator the separator of the labels. - * @return the labels. - */ - public static String getLabels(String separator) { - final StringBuilder all = new StringBuilder(); - for (final LogLabel label : LogLabel.values()) { - if (all.length() > 0 && separator != null) { - all.append(separator); - } - all.append(label.getLabels()[0]); - } - return all.toString(); - } - - /** Replies the configuration factory for the logging. - * - * @param configFactory the general configuration factory. - * @return the logging configuration factory. - */ - public static LoggingConfig getConfiguration(ConfigurationFactory configFactory) { - assert configFactory != null; - return configFactory.config(LoggingConfig.class, PREFIX); - } - - /** Labels for the logger levels. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ - public enum LogLabel { - - /** None. - */ - OFF { - @Override - public String[] getLabels() { - return new String[] { - "off", //$NON-NLS-1$ - "none", //$NON-NLS-1$ - "false", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.OFF; - } - }, - /** Error. - */ - ERROR { - @Override - public String[] getLabels() { - return new String[] { - "error", //$NON-NLS-1$ - "severe", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.SEVERE; - } - }, - /** Warning. - */ - WARNING { - @Override - public String[] getLabels() { - return new String[] { - "warning", //$NON-NLS-1$ - "warn", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.WARNING; - } - }, - /** Info. - */ - INFO { - @Override - public String[] getLabels() { - return new String[] { - "info", //$NON-NLS-1$ - "true", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.INFO; - } - }, - /** Debug. - */ - DEBUG { - @Override - public String[] getLabels() { - return new String[] { - "debug", //$NON-NLS-1$ - "config", //$NON-NLS-1$ - "fine", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.FINE; - } - }, - /** Details. - */ - DETAILS { - @Override - public String[] getLabels() { - return new String[] { - "finer", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.FINER; - } - }, - /** More details. - */ - MORE_DETAILS { - @Override - public String[] getLabels() { - return new String[] { - "finest", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.FINEST; - } - }, - /** All. - */ - ALL { - @Override - public String[] getLabels() { - return new String[] { - "all", //$NON-NLS-1$ - }; - } - - @Override - public Level toLevel() { - return Level.ALL; - } - }; - - /** Replies the labels. - * - * @return the labels. - */ - public abstract String[] getLabels(); - - /** Replies the level for the label. - * - * @return the level. - */ - public abstract Level toLevel(); - - /** Replies if the level is the default one. - * - * @return {@code true} if default level. - */ - public boolean isDefaultLevel() { - return Strings.equal(getLabels()[0], VERBOSE_LEVEL_VALUE); - } - - /** Replies if the given label matches one of the labels. - * - * @param label the label to test. - * @return {@code true} if the label matches. - */ - public boolean matchesLabel(String label) { - if (label != null) { - final String lowerLabel = label.toLowerCase(); - for (final String lbl : getLabels()) { - if (Strings.equal(lowerLabel, lbl)) { - return true; - } - } - } - return isDefaultLevel(); - } - - } - -} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlcConfig.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java similarity index 74% rename from products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlcConfig.java rename to products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java index a6cf97cd77..a01602a85b 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlcConfig.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java @@ -26,13 +26,12 @@ import io.bootique.annotation.BQConfig; import io.bootique.annotation.BQConfigProperty; import io.bootique.config.ConfigurationFactory; -import org.eclipse.xtext.util.Strings; -import io.sarl.maven.bqextension.configs.Config; -import io.sarl.maven.bqextension.configs.Configs; +import io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig; +import io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig; /** - * Configuration for the sarlc tool. + * Configuration for the sarl tool. * * @author $Author: sgalland$ * @version $FullVersion$ @@ -41,12 +40,12 @@ * @since 0.8 */ @BQConfig("Configuration of the SARLC tool") -public class SarlcConfig implements Config { +public class SarlConfig { /** * Prefix for the configuration entries of the path modules. */ - public static final String PREFIX = Configs.SARL_ROOT_PROPERTY_PREFIX + "sarlc"; //$NON-NLS-1$ + public static final String PREFIX = "sarl"; //$NON-NLS-1$ /** * Name of the property that contains the output path for the SARL code. @@ -73,16 +72,6 @@ public class SarlcConfig implements Config { */ public static final String BOOT_CLASSPATH_NAME = PREFIX + ".bootclasspath"; //$NON-NLS-1$ - /** - * Name of the property that indicates the name of the compiler program. - */ - public static final String COMPILER_PROGRAM_NAME = PREFIX + ".compilerProgramName"; //$NON-NLS-1$ - - /** - * Default value of the property that indicates the name of the compiler program. - */ - public static final String COMPILER_PROGRAM_VALUE = "sarlc"; //$NON-NLS-1$ - private String classpath; private String bootClasspath; @@ -93,7 +82,19 @@ public class SarlcConfig implements Config { private File workingPath; - private String compilerProgramName = COMPILER_PROGRAM_VALUE; + private CompilerConfig compilerConfig; + + private ValidatorConfig validatorConfig; + + /** Replies the configuration factory for the logging. + * + * @param configFactory the general configuration factory. + * @return the logging configuration factory. + */ + public static SarlConfig getConfiguration(ConfigurationFactory configFactory) { + assert configFactory != null; + return configFactory.config(SarlConfig.class, PREFIX); + } /** Replies the classpath. * @@ -180,35 +181,44 @@ public void setWorkingPath(File path) { this.workingPath = path; } - /** Replies the name of the compiler program. + /** Replies the compiler configuration. + * + * @return the compiler configuration. + */ + public CompilerConfig getCompiler() { + if (this.compilerConfig == null) { + this.compilerConfig = new CompilerConfig(); + } + return this.compilerConfig; + } + + /** Change the compiler configuration. * - * @return the name of the program. + * @param config the compiler configuration. */ - public String getCompilerProgramName() { - return this.compilerProgramName; + @BQConfigProperty("Configuration of the SARL compiler") + public void setCompiler(CompilerConfig config) { + this.compilerConfig = config; } - /** Change the name of the compiler program name. + /** Replies the validator configuration. * - * @param name the name. - */ - @BQConfigProperty("Name of the compiler program") - public void setCompilerProgramName(String name) { - if (Strings.isEmpty(name)) { - this.compilerProgramName = COMPILER_PROGRAM_VALUE; - } else { - this.compilerProgramName = name; + * @return the validator configuration. + */ + public ValidatorConfig getValidator() { + if (this.validatorConfig == null) { + this.validatorConfig = new ValidatorConfig(); } + return this.validatorConfig; } - /** Replies the configuration factory for the logging. + /** Change the validator configuration. * - * @param configFactory the general configuration factory. - * @return the logging configuration factory. + * @param config the validator configuration. */ - public static SarlcConfig getConfiguration(ConfigurationFactory configFactory) { - assert configFactory != null; - return configFactory.config(SarlcConfig.class, PREFIX); + @BQConfigProperty("Configuration of the SARL validator") + public void setValidator(ValidatorConfig config) { + this.validatorConfig = config; } } diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/CompilerConfig.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/subconfigs/CompilerConfig.java similarity index 88% rename from products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/CompilerConfig.java rename to products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/subconfigs/CompilerConfig.java index 90e1dff9ff..ef2f8b90d0 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/CompilerConfig.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/subconfigs/CompilerConfig.java @@ -19,18 +19,16 @@ * limitations under the License. */ -package io.sarl.lang.sarlc.configs; +package io.sarl.lang.sarlc.configs.subconfigs; import java.nio.charset.Charset; import io.bootique.annotation.BQConfig; import io.bootique.annotation.BQConfigProperty; -import io.bootique.config.ConfigurationFactory; import io.sarl.lang.SARLVersion; import io.sarl.lang.compiler.GeneratorConfig2; -import io.sarl.maven.bqextension.configs.Config; -import io.sarl.maven.bqextension.configs.Configs; +import io.sarl.lang.sarlc.configs.SarlConfig; /** * Configuration for the compiler. @@ -42,12 +40,12 @@ * @since 0.8 */ @BQConfig("Configuration of the SARL compiler") -public class CompilerConfig implements Config { +public class CompilerConfig { /** * Prefix for the configuration entries of the path modules. */ - public static final String PREFIX = Configs.SARL_ROOT_PROPERTY_PREFIX + "compiler"; //$NON-NLS-1$ + public static final String PREFIX = SarlConfig.PREFIX + ".compiler"; //$NON-NLS-1$ /** * Name of the property that contains the file encoding. @@ -110,26 +108,6 @@ public class CompilerConfig implements Config { */ public static final String COMPRESS_INLINE_EXPRESSIONS_NAME = PREFIX + ".compressInlineExpressions"; //$NON-NLS-1$ - /** - * Name of the property that indicates if warnings are ignored. - */ - public static final String IGNORE_WARNINGS_NAME = PREFIX + ".ignoreWarnings"; //$NON-NLS-1$ - - /** - * Name of the property that indicates if all warnings are printed out. - */ - public static final String ALL_WARNINGS_NAME = PREFIX + ".allWarnings"; //$NON-NLS-1$ - - /** - * Name of the property that indicates if warnings are errors. - */ - public static final String ALL_ERRORS_NAME = PREFIX + ".allErrors"; //$NON-NLS-1$ - - /** - * Name of the property that indicates the levels of specific warnings. - */ - public static final String WARNING_LEVELS_NAME = PREFIX + ".warningLevels"; //$NON-NLS-1$ - private String fileEcoding = Charset.defaultCharset().displayName(); private String javaVersion = SARLVersion.MINIMAL_JDK_VERSION; @@ -358,14 +336,4 @@ public void setJavaVersion(String version) { this.javaVersion = version; } - /** Replies the configuration factory for the logging. - * - * @param configFactory the general configuration factory. - * @return the logging configuration factory. - */ - public static CompilerConfig getConfiguration(ConfigurationFactory configFactory) { - assert configFactory != null; - return configFactory.config(CompilerConfig.class, PREFIX); - } - } diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/ValidatorConfig.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/subconfigs/ValidatorConfig.java similarity index 84% rename from products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/ValidatorConfig.java rename to products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/subconfigs/ValidatorConfig.java index aedc71c436..009dd6066f 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/ValidatorConfig.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/subconfigs/ValidatorConfig.java @@ -19,18 +19,16 @@ * limitations under the License. */ -package io.sarl.lang.sarlc.configs; +package io.sarl.lang.sarlc.configs.subconfigs; import java.util.HashMap; import java.util.Map; import io.bootique.annotation.BQConfig; import io.bootique.annotation.BQConfigProperty; -import io.bootique.config.ConfigurationFactory; import org.eclipse.xtext.diagnostics.Severity; -import io.sarl.maven.bqextension.configs.Config; -import io.sarl.maven.bqextension.configs.Configs; +import io.sarl.lang.sarlc.configs.SarlConfig; /** * Configuration for the validator. @@ -42,12 +40,12 @@ * @since 0.8 */ @BQConfig("Configuration of the SARL validator") -public class ValidatorConfig implements Config { +public class ValidatorConfig { /** * Prefix for the configuration entries of the path modules. */ - public static final String PREFIX = Configs.SARL_ROOT_PROPERTY_PREFIX + "validator"; //$NON-NLS-1$ + public static final String PREFIX = SarlConfig.PREFIX + ".validator"; //$NON-NLS-1$ /** * Name of the property that indicates if warnings are ignored. @@ -149,14 +147,4 @@ public void setIgnoreWarnings(boolean ignore) { this.ignoreWarnings = ignore; } - /** Replies the configuration factory for the logging. - * - * @param configFactory the general configuration factory. - * @return the logging configuration factory. - */ - public static ValidatorConfig getConfiguration(ConfigurationFactory configFactory) { - assert configFactory != null; - return configFactory.config(ValidatorConfig.class, PREFIX); - } - } diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/CompilerModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/CompilerModule.java deleted file mode 100644 index b8ddf31171..0000000000 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/CompilerModule.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2018 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.sarl.lang.sarlc.modules; - -import static io.bootique.BQCoreModule.extend; -import static io.sarl.lang.sarlc.configs.CompilerConfig.COMPRESS_INLINE_EXPRESSIONS_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.FILE_ENCODING_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_CLONE_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_EQUALITY_TESTS_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_INLINES_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_PURES_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_SERIAL_IDS_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_TOSTRING_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.JAVA_COMPILER_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.JAVA_VERSION_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.OUTPUT_STORAGES_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.OUTPUT_TRACES_NAME; - -import java.nio.charset.Charset; -import java.text.MessageFormat; -import java.util.Map.Entry; - -import com.google.inject.Injector; -import com.google.inject.Provider; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import io.bootique.config.ConfigurationFactory; -import io.bootique.meta.application.OptionMetadata; -import org.apache.log4j.Level; -import org.eclipse.xtext.diagnostics.Severity; -import org.eclipse.xtext.util.Strings; - -import io.sarl.lang.SARLVersion; -import io.sarl.lang.compiler.GeneratorConfig2; -import io.sarl.lang.compiler.batch.SarlBatchCompiler; -import io.sarl.lang.sarlc.commands.CompilerCommand; -import io.sarl.lang.sarlc.commands.PathDetector; -import io.sarl.lang.sarlc.configs.CompilerConfig; -import io.sarl.lang.sarlc.configs.LoggingConfig; -import io.sarl.lang.sarlc.configs.SarlcConfig; -import io.sarl.lang.sarlc.configs.ValidatorConfig; -import io.sarl.maven.bqextension.modules.AbstractConfigModule; -import io.sarl.maven.bqextension.modules.BQConfigTypes; -import io.sarl.maven.bqextension.modules.BQModule; - -/** Module for the sarlc specific commands. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ -@BQModule("The SARL batch compiler.") -@BQConfigTypes(CompilerConfig.class) -public class CompilerModule extends AbstractConfigModule { - - @Override - protected void configure() { - associateEnvironmentVariable(FILE_ENCODING_NAME); - associateOption(OptionMetadata.builder( - "encoding", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_0, Charset.defaultCharset().displayName())) - .configPath(FILE_ENCODING_NAME) - .valueOptional(Messages.CompilerModule_1) - .defaultValue(Charset.defaultCharset().displayName())); - - associateEnvironmentVariable(JAVA_VERSION_NAME); - associateOption(OptionMetadata.builder( - "javaversion", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_2, SARLVersion.MINIMAL_JDK_VERSION)) - .configPath(JAVA_VERSION_NAME) - .valueOptional(Messages.CompilerModule_3) - .defaultValue(SARLVersion.MINIMAL_JDK_VERSION)); - - associateEnvironmentVariable(JAVA_COMPILER_NAME); - final String trueFalseValues = MessageFormat.format(Messages.CompilerModule_5, - Boolean.TRUE, Boolean.FALSE); - associateOption(OptionMetadata.builder( - "javacompiler", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_4, Boolean.TRUE)) - .configPath(JAVA_COMPILER_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.TRUE.toString())); - - associateEnvironmentVariable(OUTPUT_TRACES_NAME); - associateOption(OptionMetadata.builder( - "writetraces", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_6, Boolean.TRUE)) - .configPath(OUTPUT_TRACES_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.TRUE.toString())); - - associateEnvironmentVariable(OUTPUT_STORAGES_NAME); - associateOption(OptionMetadata.builder( - "writestorages", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_7, Boolean.TRUE)) - .configPath(OUTPUT_STORAGES_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.TRUE.toString())); - - associateEnvironmentVariable(GENERATE_INLINES_NAME); - associateOption(OptionMetadata.builder( - "generateinlines", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_8, - GeneratorConfig2.DEFAULT_GENERATE_INLINE_ANNOTATION)) - .configPath(GENERATE_INLINES_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_INLINE_ANNOTATION))); - - associateEnvironmentVariable(COMPRESS_INLINE_EXPRESSIONS_NAME); - - associateEnvironmentVariable(GENERATE_PURES_NAME); - associateOption(OptionMetadata.builder( - "generatepures", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_9, GeneratorConfig2.DEFAULT_GENERATE_PURE_ANNOTATION)) - .configPath(GENERATE_PURES_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_PURE_ANNOTATION))); - - associateEnvironmentVariable(GENERATE_EQUALITY_TESTS_NAME); - associateOption(OptionMetadata.builder( - "generateequalitytests", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_10, GeneratorConfig2.DEFAULT_GENERATE_EQUALITY_TEST_FUNCTIONS)) - .configPath(GENERATE_EQUALITY_TESTS_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_EQUALITY_TEST_FUNCTIONS))); - - associateEnvironmentVariable(GENERATE_TOSTRING_NAME); - associateOption(OptionMetadata.builder( - "generatetostring", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_11, GeneratorConfig2.DEFAULT_GENERATE_TOSTRING_FUNCTION)) - .configPath(GENERATE_TOSTRING_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_TOSTRING_FUNCTION))); - - associateEnvironmentVariable(GENERATE_CLONE_NAME); - associateOption(OptionMetadata.builder( - "generateclones", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_12, GeneratorConfig2.DEFAULT_GENERATE_CLONE_FUNCTION)) - .configPath(GENERATE_CLONE_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_CLONE_FUNCTION))); - - associateEnvironmentVariable(GENERATE_SERIAL_IDS_NAME); - associateOption(OptionMetadata.builder( - "generateserials", //$NON-NLS-1$ - MessageFormat.format(Messages.CompilerModule_13, GeneratorConfig2.DEFAULT_GENERATE_SERIAL_NUMBER_FIELD)) - .configPath(GENERATE_SERIAL_IDS_NAME) - .valueOptional(trueFalseValues) - .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_SERIAL_NUMBER_FIELD))); - - extend(binder()).setDefaultCommand(CompilerCommand.class); - } - - /** Replies the instance of the compiler configuration. - * - * @param configFactory accessor to the bootique factory. - * @param injector the current injector. - * @return the compiler configuration accessor. - */ - @SuppressWarnings("static-method") - @Provides - @Singleton - public CompilerConfig provideCompilerConfig(ConfigurationFactory configFactory, Injector injector) { - final CompilerConfig config = CompilerConfig.getConfiguration(configFactory); - injector.injectMembers(config); - return config; - } - - /** Provide the command for running the compiler. - * - * @param compiler the compiler. - * @param configuration the SARLC configuration. - * @param pathDetector the detector of paths. - * @return the command. - */ - @SuppressWarnings("static-method") - @Provides - @Singleton - public CompilerCommand provideSarlcCompilerCommand(Provider compiler, - Provider configuration, Provider pathDetector) { - return new CompilerCommand(compiler, configuration, pathDetector); - } - - /** Replies the SARL batch compiler. - * - * @param injector the current injector. - * @param sarlcConfig the configuration for the paths. - * @param compilerConfig the configuration for the compiler. - * @param validatorConfig the configuration for the validator. - * @param loggingConfig the configuration for the loggers. - * @return the SARL batch compiler - */ - @SuppressWarnings("static-method") - @Provides - @Singleton - public SarlBatchCompiler provideSarlBatchCompiler(Injector injector, SarlcConfig sarlcConfig, - CompilerConfig compilerConfig, - LoggingConfig loggingConfig, - ValidatorConfig validatorConfig) { - final SarlBatchCompiler compiler = new SarlBatchCompiler(); - injector.injectMembers(compiler); - - //final Logger logger = injector.getInstance(Logger.class); - //compiler.setLogger(logger); - - if (!Strings.isEmpty(sarlcConfig.getClasspath())) { - compiler.setClassPath(sarlcConfig.getClasspath()); - } - - if (!Strings.isEmpty(sarlcConfig.getBootClasspath())) { - compiler.setBootClassPath(sarlcConfig.getBootClasspath()); - } - - if (!Strings.isEmpty(compilerConfig.getFileEncoding())) { - compiler.setFileEncoding(compilerConfig.getFileEncoding()); - } - - if (!Strings.isEmpty(compilerConfig.getJavaVersion())) { - compiler.setJavaSourceVersion(compilerConfig.getJavaVersion()); - } - - compiler.setJavaPostCompilationEnable(compilerConfig.getJavaCompiler()); - compiler.setWriteTraceFiles(compilerConfig.getOutputTraceFiles()); - compiler.setWriteStorageFiles(compilerConfig.getOutputTraceFiles()); - - compiler.setGenerateInlineAnnotation(compilerConfig.getGenerateInlines()); - compiler.setUseExpressionInterpreterForInlineAnnotation(compilerConfig.getCompressInlineExpressions()); - compiler.setGeneratePureAnnotation(compilerConfig.getGeneratePures()); - compiler.setGenerateEqualityTestFunctions(compilerConfig.getGenerateEqualityTests()); - compiler.setGenerateToStringFunctions(compilerConfig.getGenerateToString()); - compiler.setGenerateCloneFunctions(compilerConfig.getGenerateClone()); - compiler.setGenerateSerialNumberFields(compilerConfig.getGenerateSerialIds()); - - final Level level = loggingConfig.getLog4JLevelObject(); - if (Level.DEBUG.isGreaterOrEqual(level)) { - compiler.setJavaCompilerVerbose(true); - } - compiler.getLogger().setLevel(level); - - if (validatorConfig.getAllErrors()) { - compiler.setAllWarningSeverities(Severity.ERROR); - } else if (validatorConfig.getIgnoreWarnings()) { - compiler.setAllWarningSeverities(Severity.IGNORE); - } - - for (final Entry entry : validatorConfig.getWarningLevels().entrySet()) { - compiler.setWarningSeverity(entry.getKey(), entry.getValue()); - } - - return compiler; - } - -} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/LoggingModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/LoggingModule.java deleted file mode 100644 index f27a129851..0000000000 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/LoggingModule.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2018 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.sarl.lang.sarlc.modules; - -import static io.bootique.BQCoreModule.extend; -import static io.sarl.lang.sarlc.configs.CompilerConfig.GENERATE_CLONE_NAME; -import static io.sarl.lang.sarlc.configs.LoggingConfig.DEFAULT_FORMAT_NAME; -import static io.sarl.lang.sarlc.configs.LoggingConfig.VERBOSE_LEVEL_NAME; - -import java.text.MessageFormat; -import java.util.logging.Level; - -import javax.inject.Inject; - -import com.google.inject.Injector; -import com.google.inject.Provider; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.name.Names; -import io.bootique.config.ConfigurationFactory; -import io.bootique.meta.application.OptionMetadata; - -import io.sarl.lang.sarlc.configs.LoggingConfig; -import io.sarl.lang.sarlc.configs.LoggingConfig.LogLabel; -import io.sarl.maven.bqextension.modules.AbstractConfigModule; -import io.sarl.maven.bqextension.modules.BQConfigTypes; -import io.sarl.maven.bqextension.modules.BQModule; - -/** Module for the logging services. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ -@BQModule("The basic logging system configurator.") -@BQConfigTypes(LoggingConfig.class) -public class LoggingModule extends AbstractConfigModule { - - @Override - protected void configure() { - for (final LogLabel label : LogLabel.values()) { - extend(binder()).setLogLevel(label.getLabels()[0], label.toLevel()); - } - associateEnvironmentVariable(VERBOSE_LEVEL_NAME); - final String allLabels = LoggingConfig.getLabels(Messages.LoggingModule_0); - associateOption(OptionMetadata.builder( - "verbose", //$NON-NLS-1$ - MessageFormat.format(Messages.LoggingModule_1, allLabels, LoggingConfig.VERBOSE_LEVEL_VALUE)) - .configPath(GENERATE_CLONE_NAME) - .valueRequired(Messages.LoggingModule_2)); - - associateEnvironmentVariable(DEFAULT_FORMAT_NAME); - - binder().bind(Level.class).annotatedWith(Names.named(LoggingConfig.VERBOSE_LEVEL_NAME)) - .toProvider(VerboseLevelObjectProvider.class).in(Singleton.class); - - binder().bind(String.class).annotatedWith(Names.named(LoggingConfig.VERBOSE_LEVEL_NAME)) - .toProvider(VerboseLevelStringProvider.class).in(Singleton.class); - } - - /** Replies the instance of the logging configuration. - * - * @param configFactory accessor to the bootique factory. - * @param injector the current injector. - * @return the logging configuration accessor. - */ - @SuppressWarnings("static-method") - @Provides - @Singleton - public LoggingConfig getLoggingConfig(ConfigurationFactory configFactory, Injector injector) { - final LoggingConfig config = LoggingConfig.getConfiguration(configFactory); - injector.injectMembers(config); - return config; - } - - /** Provider for the verbose level. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ - public static class VerboseLevelObjectProvider implements Provider { - - @Inject - private LoggingConfig config; - - @Override - public Level get() { - return this.config.getJavaLevelObject(); - } - - } - - /** Provider for the verbose level. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ - public static class VerboseLevelStringProvider implements Provider { - - @Inject - private LoggingConfig config; - - @Override - public String get() { - return this.config.getLevel(); - } - - } - -} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/SarlcModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/SarlcModule.java deleted file mode 100644 index d3afc23caf..0000000000 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/SarlcModule.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2018 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.sarl.lang.sarlc.modules; - -import static io.sarl.lang.sarlc.configs.SarlcConfig.BOOT_CLASSPATH_NAME; -import static io.sarl.lang.sarlc.configs.SarlcConfig.CLASSPATH_NAME; -import static io.sarl.lang.sarlc.configs.SarlcConfig.CLASS_OUTPUT_PATH_NAME; -import static io.sarl.lang.sarlc.configs.SarlcConfig.COMPILER_PROGRAM_NAME; -import static io.sarl.lang.sarlc.configs.SarlcConfig.OUTPUT_PATH_NAME; -import static io.sarl.lang.sarlc.configs.SarlcConfig.WORKING_PATH_NAME; - -import com.google.inject.Injector; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import io.bootique.config.ConfigurationFactory; -import io.bootique.meta.application.OptionMetadata; - -import io.sarl.lang.sarlc.configs.SarlcConfig; -import io.sarl.maven.bqextension.modules.AbstractConfigModule; -import io.sarl.maven.bqextension.modules.BQConfigTypes; -import io.sarl.maven.bqextension.modules.BQModule; - -/** - * Module for the sarlc tool. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ -@BQModule("The sarlc command line tool.") -@BQConfigTypes(SarlcConfig.class) -public class SarlcModule extends AbstractConfigModule { - - @Override - protected void configure() { - associateEnvironmentVariable(COMPILER_PROGRAM_NAME); - - associateEnvironmentVariable(OUTPUT_PATH_NAME); - associateOption(OptionMetadata.builder( - "directory", Messages.SarlcModule_0) //$NON-NLS-1$ - .configPath(OUTPUT_PATH_NAME) - .valueRequired(Messages.SarlcModule_1)); - - associateEnvironmentVariable(CLASS_OUTPUT_PATH_NAME); - associateOption(OptionMetadata.builder( - "outputdir", Messages.SarlcModule_7) //$NON-NLS-1$ - .configPath(CLASS_OUTPUT_PATH_NAME) - .valueRequired(Messages.SarlcModule_1)); - - associateEnvironmentVariable(WORKING_PATH_NAME); - associateOption(OptionMetadata.builder( - "workingdir", Messages.SarlcModule_2) //$NON-NLS-1$ - .configPath(WORKING_PATH_NAME) - .valueRequired(Messages.SarlcModule_1)); - - associateEnvironmentVariable(CLASSPATH_NAME); - associateOption(OptionMetadata.builder( - "classpath", Messages.SarlcModule_3) //$NON-NLS-1$ - .configPath(CLASSPATH_NAME) - .valueRequired(Messages.SarlcModule_4)); - associateOption(OptionMetadata.builder( - "cp", Messages.SarlcModule_5) //$NON-NLS-1$ - .configPath(CLASSPATH_NAME) - .valueRequired(Messages.SarlcModule_4)); - - associateEnvironmentVariable(BOOT_CLASSPATH_NAME); - associateOption(OptionMetadata.builder( - "bootclasspath", Messages.SarlcModule_6) //$NON-NLS-1$ - .configPath(BOOT_CLASSPATH_NAME) - .valueRequired(Messages.SarlcModule_4)); - } - - /** Replies the instance of the path configuration. - * - * @param configFactory accessor to the bootique factory. - * @param injector the current injector. - * @return the path configuration accessor. - */ - @SuppressWarnings("static-method") - @Provides - @Singleton - public SarlcConfig getSarlcConfig(ConfigurationFactory configFactory, Injector injector) { - final SarlcConfig config = SarlcConfig.getConfiguration(configFactory); - injector.injectMembers(config); - return config; - } - -} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/ValidatorModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/ValidatorModule.java deleted file mode 100644 index 121254d422..0000000000 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/ValidatorModule.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2018 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.sarl.lang.sarlc.modules; - -import static io.sarl.lang.sarlc.configs.CompilerConfig.ALL_ERRORS_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.ALL_WARNINGS_NAME; -import static io.sarl.lang.sarlc.configs.CompilerConfig.IGNORE_WARNINGS_NAME; - -import com.google.inject.Injector; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import io.bootique.config.ConfigurationFactory; -import io.bootique.meta.application.OptionMetadata; - -import io.sarl.lang.sarlc.configs.ValidatorConfig; -import io.sarl.maven.bqextension.modules.AbstractConfigModule; -import io.sarl.maven.bqextension.modules.BQConfigTypes; -import io.sarl.maven.bqextension.modules.BQModule; - -/** Module for the sarlc specific commands. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * @since 0.8 - */ -@BQModule("The SARL batch validator.") -@BQConfigTypes(ValidatorConfig.class) -public class ValidatorModule extends AbstractConfigModule { - - @Override - protected void configure() { - associateEnvironmentVariable(IGNORE_WARNINGS_NAME); - associateOption(OptionMetadata.builder( - "nowarn", Messages.ValidatorModule_0) //$NON-NLS-1$ - .configPath(IGNORE_WARNINGS_NAME)); - - associateEnvironmentVariable(ALL_WARNINGS_NAME); - associateOption(OptionMetadata.builder( - "wall", Messages.ValidatorModule_2) //$NON-NLS-1$ - .configPath(ALL_WARNINGS_NAME)); - - associateEnvironmentVariable(ALL_ERRORS_NAME); - associateOption(OptionMetadata.builder( - "werr", Messages.ValidatorModule_1) //$NON-NLS-1$ - .configPath(ALL_ERRORS_NAME)); - } - - /** Replies the instance of the validator configuration. - * - * @param configFactory accessor to the bootique factory. - * @param injector the current injector. - * @return the validator configuration accessor. - */ - @SuppressWarnings("static-method") - @Provides - @Singleton - public ValidatorConfig getValidatorConfig(ConfigurationFactory configFactory, Injector injector) { - final ValidatorConfig config = ValidatorConfig.getConfiguration(configFactory); - injector.injectMembers(config); - return config; - } - -} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/PrintConfigModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModule.java similarity index 58% rename from products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/PrintConfigModule.java rename to products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModule.java index bbaac00683..580c010329 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/PrintConfigModule.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModule.java @@ -19,21 +19,21 @@ * limitations under the License. */ -package io.sarl.lang.sarlc.modules; +package io.sarl.lang.sarlc.modules.commands; -import java.util.Set; +import static io.bootique.BQCoreModule.extend; +import com.google.inject.AbstractModule; import com.google.inject.Provider; import com.google.inject.Provides; import com.google.inject.Singleton; -import io.bootique.log.BootLogger; -import io.sarl.lang.sarlc.commands.PrintConfigCommand; -import io.sarl.maven.bqextension.configs.Config; -import io.sarl.maven.bqextension.modules.AbstractConfigModule; -import io.sarl.maven.bqextension.modules.BQModule; +import io.sarl.lang.compiler.batch.SarlBatchCompiler; +import io.sarl.lang.sarlc.commands.CompilerCommand; +import io.sarl.lang.sarlc.commands.PathDetector; +import io.sarl.lang.sarlc.configs.SarlConfig; -/** Module for the sarlc tool. +/** Module for the compiler command. * * @author $Author: sgalland$ * @version $FullVersion$ @@ -41,25 +41,26 @@ * @mavenartifactid $ArtifactId$ * @since 0.8 */ -@BQModule("The runtime for printed out the current Yaml configuration.") -public class PrintConfigModule extends AbstractConfigModule { +public class CompilerCommandModule extends AbstractModule { @Override protected void configure() { - associateCommand(PrintConfigCommand.class); + extend(binder()).addCommand(CompilerCommand.class); } /** Provide the command for running the compiler. * - * @param bootLogger the boot logger. - * @param configs the configurations. + * @param compiler the compiler. + * @param configuration the SARLC configuration. + * @param pathDetector the detector of paths. * @return the command. */ @SuppressWarnings("static-method") @Provides @Singleton - public PrintConfigCommand providePrintConfigCommand(BootLogger bootLogger, Provider> configs) { - return new PrintConfigCommand(bootLogger, configs); + public CompilerCommand provideSarlcCompilerCommand(Provider compiler, + Provider configuration, Provider pathDetector) { + return new CompilerCommand(compiler, configuration, pathDetector); } } diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModuleProvider.java new file mode 100644 index 0000000000..6cd049ebb5 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/CompilerCommandModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.commands; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the compiler command. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class CompilerCommandModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new CompilerCommandModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.CompilerCommandModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/Messages.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/Messages.java similarity index 52% rename from products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/Messages.java rename to products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/Messages.java index 217654067b..f6fd9563c0 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/Messages.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/Messages.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package io.sarl.lang.sarlc.modules; +package io.sarl.lang.sarlc.modules.commands; import org.eclipse.osgi.util.NLS; @@ -34,34 +34,8 @@ @SuppressWarnings("all") public class Messages extends NLS { private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$ - public static String LoggingModule_0; - public static String LoggingModule_1; - public static String LoggingModule_2; - public static String SarlcModule_0; - public static String SarlcModule_1; - public static String SarlcModule_2; - public static String SarlcModule_3; - public static String SarlcModule_4; - public static String SarlcModule_5; - public static String SarlcModule_6; - public static String SarlcModule_7; - public static String CompilerModule_0; - public static String CompilerModule_1; - public static String CompilerModule_2; - public static String CompilerModule_3; - public static String CompilerModule_4; - public static String CompilerModule_5; - public static String CompilerModule_6; - public static String CompilerModule_7; - public static String CompilerModule_8; - public static String CompilerModule_9; - public static String CompilerModule_10; - public static String CompilerModule_11; - public static String CompilerModule_12; - public static String CompilerModule_13; - public static String ValidatorModule_0; - public static String ValidatorModule_1; - public static String ValidatorModule_2; + public static String CompilerCommandModuleProvider_0; + public static String VersionCommandModuleProvider_0; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/VersionModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModule.java similarity index 79% rename from products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/VersionModule.java rename to products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModule.java index 85f622f6c9..552348e298 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/VersionModule.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModule.java @@ -19,17 +19,18 @@ * limitations under the License. */ -package io.sarl.lang.sarlc.modules; +package io.sarl.lang.sarlc.modules.commands; +import static io.bootique.BQCoreModule.extend; + +import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Singleton; import io.bootique.log.BootLogger; import io.sarl.lang.sarlc.commands.VersionCommand; -import io.sarl.maven.bqextension.modules.AbstractConfigModule; -import io.sarl.maven.bqextension.modules.BQModule; -/** Module for the sarlc specific commands. +/** Module for the command for printing out the sarlc version. * * @author $Author: sgalland$ * @version $FullVersion$ @@ -37,12 +38,11 @@ * @mavenartifactid $ArtifactId$ * @since 0.8 */ -@BQModule("The tools for printed out the sarlc version.") -public class VersionModule extends AbstractConfigModule { +public class VersionCommandModule extends AbstractModule { @Override protected void configure() { - associateCommand(VersionCommand.class); + extend(binder()).addCommand(VersionCommand.class); } /** Provide the command for displaying the sarlc version. diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModuleProvider.java new file mode 100644 index 0000000000..77eb2503c8 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/commands/VersionCommandModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.commands; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the version command. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class VersionCommandModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new VersionCommandModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.VersionCommandModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModule.java new file mode 100644 index 0000000000..f45b636ce0 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModule.java @@ -0,0 +1,165 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import static io.bootique.BQCoreModule.extend; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.COMPRESS_INLINE_EXPRESSIONS_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.FILE_ENCODING_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.GENERATE_CLONE_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.GENERATE_EQUALITY_TESTS_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.GENERATE_INLINES_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.GENERATE_PURES_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.GENERATE_SERIAL_IDS_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.GENERATE_TOSTRING_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.JAVA_COMPILER_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.JAVA_VERSION_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.OUTPUT_STORAGES_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig.OUTPUT_TRACES_NAME; + +import java.nio.charset.Charset; +import java.text.MessageFormat; + +import com.google.inject.AbstractModule; +import io.bootique.meta.application.OptionMetadata; +import org.arakhne.afc.bootique.variables.VariableDecls; + +import io.sarl.lang.SARLVersion; +import io.sarl.lang.compiler.GeneratorConfig2; + +/** Module for creating and configuring the sarlc compiler. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class CompilerConfigModule extends AbstractModule { + + @Override + protected void configure() { + VariableDecls.extend(binder()).declareVar(FILE_ENCODING_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "encoding", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_0, Charset.defaultCharset().displayName())) + .configPath(FILE_ENCODING_NAME) + .valueOptional(Messages.CompilerConfigModule_1) + .defaultValue(Charset.defaultCharset().displayName()) + .build()); + + VariableDecls.extend(binder()).declareVar(JAVA_VERSION_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "javaversion", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_2, SARLVersion.MINIMAL_JDK_VERSION)) + .configPath(JAVA_VERSION_NAME) + .valueOptional(Messages.CompilerConfigModule_3) + .defaultValue(SARLVersion.MINIMAL_JDK_VERSION) + .build()); + + VariableDecls.extend(binder()).declareVar(JAVA_COMPILER_NAME); + final String trueFalseValues = MessageFormat.format(Messages.CompilerConfigModule_5, + Boolean.TRUE, Boolean.FALSE); + extend(binder()).addOption(OptionMetadata.builder( + "javacompiler", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_4, Boolean.TRUE)) + .configPath(JAVA_COMPILER_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.TRUE.toString()) + .build()); + + VariableDecls.extend(binder()).declareVar(OUTPUT_TRACES_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "writetraces", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_6, Boolean.TRUE)) + .configPath(OUTPUT_TRACES_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.TRUE.toString()) + .build()); + + VariableDecls.extend(binder()).declareVar(OUTPUT_STORAGES_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "writestorages", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_7, Boolean.TRUE)) + .configPath(OUTPUT_STORAGES_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.TRUE.toString()) + .build()); + + VariableDecls.extend(binder()).declareVar(GENERATE_INLINES_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "generateinlines", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_8, + GeneratorConfig2.DEFAULT_GENERATE_INLINE_ANNOTATION)) + .configPath(GENERATE_INLINES_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_INLINE_ANNOTATION)) + .build()); + + VariableDecls.extend(binder()).declareVar(COMPRESS_INLINE_EXPRESSIONS_NAME); + + VariableDecls.extend(binder()).declareVar(GENERATE_PURES_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "generatepures", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_9, GeneratorConfig2.DEFAULT_GENERATE_PURE_ANNOTATION)) + .configPath(GENERATE_PURES_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_PURE_ANNOTATION)) + .build()); + + VariableDecls.extend(binder()).declareVar(GENERATE_EQUALITY_TESTS_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "generateequalitytests", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_10, GeneratorConfig2.DEFAULT_GENERATE_EQUALITY_TEST_FUNCTIONS)) + .configPath(GENERATE_EQUALITY_TESTS_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_EQUALITY_TEST_FUNCTIONS)) + .build()); + + VariableDecls.extend(binder()).declareVar(GENERATE_TOSTRING_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "generatetostring", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_11, GeneratorConfig2.DEFAULT_GENERATE_TOSTRING_FUNCTION)) + .configPath(GENERATE_TOSTRING_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_TOSTRING_FUNCTION)) + .build()); + + VariableDecls.extend(binder()).declareVar(GENERATE_CLONE_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "generateclones", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_12, GeneratorConfig2.DEFAULT_GENERATE_CLONE_FUNCTION)) + .configPath(GENERATE_CLONE_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_CLONE_FUNCTION)) + .build()); + + VariableDecls.extend(binder()).declareVar(GENERATE_SERIAL_IDS_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "generateserials", //$NON-NLS-1$ + MessageFormat.format(Messages.CompilerConfigModule_13, GeneratorConfig2.DEFAULT_GENERATE_SERIAL_NUMBER_FIELD)) + .configPath(GENERATE_SERIAL_IDS_NAME) + .valueOptional(trueFalseValues) + .defaultValue(Boolean.toString(GeneratorConfig2.DEFAULT_GENERATE_SERIAL_NUMBER_FIELD)) + .build()); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModuleProvider.java new file mode 100644 index 0000000000..c55589e15c --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/CompilerConfigModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the SARL compiler configuration. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class CompilerConfigModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new CompilerConfigModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.CompilerConfigModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/Messages.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/Messages.java new file mode 100644 index 0000000000..b8551f5425 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/Messages.java @@ -0,0 +1,72 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import org.eclipse.osgi.util.NLS; + +/** Messages for the SARL batch compiler. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @ExcludeFromApidoc + */ +@SuppressWarnings("all") +public class Messages extends NLS { + private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$ + public static String SarlcConfigModule_0; + public static String SarlcConfigModule_1; + public static String SarlcConfigModule_2; + public static String SarlcConfigModule_3; + public static String SarlcConfigModule_4; + public static String SarlcConfigModule_5; + public static String SarlcConfigModule_6; + public static String SarlcConfigModule_7; + public static String SarlcConfigModuleProvider_0; + public static String CompilerConfigModule_0; + public static String CompilerConfigModule_1; + public static String CompilerConfigModule_2; + public static String CompilerConfigModule_3; + public static String CompilerConfigModule_4; + public static String CompilerConfigModule_5; + public static String CompilerConfigModule_6; + public static String CompilerConfigModule_7; + public static String CompilerConfigModule_8; + public static String CompilerConfigModule_9; + public static String CompilerConfigModule_10; + public static String CompilerConfigModule_11; + public static String CompilerConfigModule_12; + public static String CompilerConfigModule_13; + public static String CompilerConfigModuleProvider_0; + public static String ValidatorConfigModule_0; + public static String ValidatorConfigModule_1; + public static String ValidatorConfigModule_2; + public static String ValidatorConfigModuleProvider_0; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModule.java new file mode 100644 index 0000000000..41a300e546 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModule.java @@ -0,0 +1,111 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import static io.bootique.BQCoreModule.extend; +import static io.sarl.lang.sarlc.configs.SarlConfig.BOOT_CLASSPATH_NAME; +import static io.sarl.lang.sarlc.configs.SarlConfig.CLASSPATH_NAME; +import static io.sarl.lang.sarlc.configs.SarlConfig.CLASS_OUTPUT_PATH_NAME; +import static io.sarl.lang.sarlc.configs.SarlConfig.OUTPUT_PATH_NAME; +import static io.sarl.lang.sarlc.configs.SarlConfig.WORKING_PATH_NAME; + +import com.google.inject.AbstractModule; +import com.google.inject.Injector; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import io.bootique.config.ConfigurationFactory; +import io.bootique.meta.application.OptionMetadata; +import org.arakhne.afc.bootique.variables.VariableDecls; + +import io.sarl.lang.sarlc.Constants; +import io.sarl.lang.sarlc.configs.SarlConfig; + +/** + * Module for creating and configuring the general/root sarlc configuration. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlcConfigModule extends AbstractModule { + + @Override + protected void configure() { + VariableDecls.extend(binder()).declareVar(OUTPUT_PATH_NAME); + extend(binder()).addOption(OptionMetadata.builder( + Constants.SARL_OUTPUT_DIRECTORY_OPTION, Messages.SarlcConfigModule_0) + .configPath(OUTPUT_PATH_NAME) + .valueRequired(Messages.SarlcConfigModule_1) + .build()); + + VariableDecls.extend(binder()).declareVar(CLASS_OUTPUT_PATH_NAME); + extend(binder()).addOption(OptionMetadata.builder( + Constants.JAVA_OUTPUT_DIRECTORY_OPTION, Messages.SarlcConfigModule_7) + .configPath(CLASS_OUTPUT_PATH_NAME) + .valueRequired(Messages.SarlcConfigModule_1) + .build()); + + VariableDecls.extend(binder()).declareVar(WORKING_PATH_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "workingdir", Messages.SarlcConfigModule_2) //$NON-NLS-1$ + .configPath(WORKING_PATH_NAME) + .valueRequired(Messages.SarlcConfigModule_1) + .build()); + + VariableDecls.extend(binder()).declareVar(CLASSPATH_NAME); + extend(binder()).addOptions(OptionMetadata.builder( + "classpath", Messages.SarlcConfigModule_3) //$NON-NLS-1$ + .configPath(CLASSPATH_NAME) + .valueRequired(Messages.SarlcConfigModule_4) + .build(), + OptionMetadata.builder( + "cp", Messages.SarlcConfigModule_5) //$NON-NLS-1$ + .configPath(CLASSPATH_NAME) + .valueRequired(Messages.SarlcConfigModule_4) + .build()); + + VariableDecls.extend(binder()).declareVar(BOOT_CLASSPATH_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "bootclasspath", Messages.SarlcConfigModule_6) //$NON-NLS-1$ + .configPath(BOOT_CLASSPATH_NAME) + .valueRequired(Messages.SarlcConfigModule_4) + .build()); + } + + /** Replies the instance of the path configuration. + * + * @param configFactory accessor to the bootique factory. + * @param injector the current injector. + * @return the path configuration accessor. + */ + @SuppressWarnings("static-method") + @Provides + @Singleton + public SarlConfig getSarlcConfig(ConfigurationFactory configFactory, Injector injector) { + final SarlConfig config = SarlConfig.getConfiguration(configFactory); + injector.injectMembers(config); + return config; + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModuleProvider.java new file mode 100644 index 0000000000..cb468bf468 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/SarlcConfigModuleProvider.java @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.Map; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +import io.sarl.lang.sarlc.configs.SarlConfig; + +/** Provider of the module for the sarlc configuration. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlcConfigModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new SarlcConfigModule(); + } + + @Override + public Map configs() { + return Collections.singletonMap(SarlConfig.PREFIX, SarlConfig.class); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.SarlcConfigModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModule.java new file mode 100644 index 0000000000..0b838197af --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModule.java @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import static io.bootique.BQCoreModule.extend; +import static io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig.ALL_ERRORS_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig.ALL_WARNINGS_NAME; +import static io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig.IGNORE_WARNINGS_NAME; + +import com.google.inject.AbstractModule; +import io.bootique.meta.application.OptionMetadata; +import org.arakhne.afc.bootique.variables.VariableDecls; + +/** Module for creating and configuring the sarlc validator's configuration. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class ValidatorConfigModule extends AbstractModule { + + @Override + protected void configure() { + VariableDecls.extend(binder()).declareVar(IGNORE_WARNINGS_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "nowarn", Messages.ValidatorConfigModule_0) //$NON-NLS-1$ + .configPath(IGNORE_WARNINGS_NAME) + .build()); + + VariableDecls.extend(binder()).declareVar(ALL_WARNINGS_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "wall", Messages.ValidatorConfigModule_2) //$NON-NLS-1$ + .configPath(ALL_WARNINGS_NAME) + .build()); + + VariableDecls.extend(binder()).declareVar(ALL_ERRORS_NAME); + extend(binder()).addOption(OptionMetadata.builder( + "werr", Messages.ValidatorConfigModule_1) //$NON-NLS-1$ + .configPath(ALL_ERRORS_NAME) + .build()); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModuleProvider.java new file mode 100644 index 0000000000..4e943e344b --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/configs/ValidatorConfigModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.configs; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the SARL configuration. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class ValidatorConfigModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new SarlcConfigModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.ValidatorConfigModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/Messages.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/Messages.java new file mode 100644 index 0000000000..b8c4315d28 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/Messages.java @@ -0,0 +1,51 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import org.eclipse.osgi.util.NLS; + +/** Messages for the SARL batch compiler. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @ExcludeFromApidoc + */ +@SuppressWarnings("all") +public class Messages extends NLS { + private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$ + public static String SarlBatchCompilerModuleProvider_0; + public static String SarlcDefaultCommandModuleProvider_0; + public static String SARLRuntimeModuleProvider_0; + public static String SarlcApplicationModule_0; + public static String SarlcApplicationModule_1; + public static String SarlcApplicationModule_2; + public static String SarlcApplicationModuleProvider_0; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SARLRuntimeModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SARLRuntimeModuleProvider.java new file mode 100644 index 0000000000..8038f78b55 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SARLRuntimeModuleProvider.java @@ -0,0 +1,55 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +import io.sarl.lang.SARLRuntimeModule; + +/** Provider of the module for the SARL compiler runtime. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SARLRuntimeModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new SARLRuntimeModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.SARLRuntimeModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModule.java new file mode 100644 index 0000000000..4b5477a9a4 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModule.java @@ -0,0 +1,114 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import java.util.Map.Entry; + +import com.google.inject.AbstractModule; +import com.google.inject.Injector; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import org.eclipse.xtext.diagnostics.Severity; +import org.eclipse.xtext.util.Strings; + +import io.sarl.lang.compiler.batch.SarlBatchCompiler; +import io.sarl.lang.sarlc.configs.SarlConfig; +import io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig; +import io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig; + +/** Module for creating the SARL batch compiler with the configuration provided by bootique modules. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlBatchCompilerModule extends AbstractModule { + + @Override + protected void configure() { + // + } + + /** Replies the SARL batch compiler. + * + * @param injector the current injector. + * @param sarlcConfig the configuration for the paths. + * @return the SARL batch compiler + */ + @SuppressWarnings("static-method") + @Provides + @Singleton + public SarlBatchCompiler provideSarlBatchCompiler( + Injector injector, SarlConfig sarlcConfig) { + final CompilerConfig compilerConfig = sarlcConfig.getCompiler(); + final ValidatorConfig validatorConfig = sarlcConfig.getValidator(); + + final SarlBatchCompiler compiler = new SarlBatchCompiler(); + injector.injectMembers(compiler); + + //final Logger logger = injector.getInstance(Logger.class); + //compiler.setLogger(logger); + + if (!Strings.isEmpty(sarlcConfig.getClasspath())) { + compiler.setClassPath(sarlcConfig.getClasspath()); + } + + if (!Strings.isEmpty(sarlcConfig.getBootClasspath())) { + compiler.setBootClassPath(sarlcConfig.getBootClasspath()); + } + + if (!Strings.isEmpty(compilerConfig.getFileEncoding())) { + compiler.setFileEncoding(compilerConfig.getFileEncoding()); + } + + if (!Strings.isEmpty(compilerConfig.getJavaVersion())) { + compiler.setJavaSourceVersion(compilerConfig.getJavaVersion()); + } + + compiler.setJavaPostCompilationEnable(compilerConfig.getJavaCompiler()); + compiler.setWriteTraceFiles(compilerConfig.getOutputTraceFiles()); + compiler.setWriteStorageFiles(compilerConfig.getOutputTraceFiles()); + + compiler.setGenerateInlineAnnotation(compilerConfig.getGenerateInlines()); + compiler.setUseExpressionInterpreterForInlineAnnotation(compilerConfig.getCompressInlineExpressions()); + compiler.setGeneratePureAnnotation(compilerConfig.getGeneratePures()); + compiler.setGenerateEqualityTestFunctions(compilerConfig.getGenerateEqualityTests()); + compiler.setGenerateToStringFunctions(compilerConfig.getGenerateToString()); + compiler.setGenerateCloneFunctions(compilerConfig.getGenerateClone()); + compiler.setGenerateSerialNumberFields(compilerConfig.getGenerateSerialIds()); + + if (validatorConfig.getAllErrors()) { + compiler.setAllWarningSeverities(Severity.ERROR); + } else if (validatorConfig.getIgnoreWarnings()) { + compiler.setAllWarningSeverities(Severity.IGNORE); + } + + for (final Entry entry : validatorConfig.getWarningLevels().entrySet()) { + compiler.setWarningSeverity(entry.getKey(), entry.getValue()); + } + + return compiler; + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModuleProvider.java new file mode 100644 index 0000000000..218182dbe3 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlBatchCompilerModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the SARL batch compiler. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlBatchCompilerModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new SarlBatchCompilerModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.SarlBatchCompilerModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModule.java new file mode 100644 index 0000000000..3121ed418f --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModule.java @@ -0,0 +1,87 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import static io.bootique.BQCoreModule.extend; + +import java.text.MessageFormat; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Provider; +import org.arakhne.afc.bootique.applicationdata2.annotations.DefaultApplicationName; +import org.arakhne.afc.bootique.synopsishelp.annotations.ApplicationArgumentSynopsis; +import org.arakhne.afc.bootique.synopsishelp.annotations.ApplicationDetailedDescription; + +import io.sarl.lang.SARLConfig; +import io.sarl.lang.sarlc.Constants; + +/** Module for configuring the sarlc application information. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlcApplicationModule extends AbstractModule { + + @Override + protected void configure() { + bind(String.class).annotatedWith(DefaultApplicationName.class).toInstance(Constants.PROGRAM_NAME); + bind(String.class).annotatedWith(ApplicationArgumentSynopsis.class).toInstance(Messages.SarlcApplicationModule_1); + bind(String.class).annotatedWith(ApplicationDetailedDescription.class).toProvider(LongDescriptionProvider.class); + extend(binder()).setApplicationDescription(Messages.SarlcApplicationModule_0); + } + + /** Provider of the long description of the application. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ + private static class LongDescriptionProvider implements Provider { + + /** Constructor. + * + */ + @Inject + LongDescriptionProvider() { + // + } + + @Override + public String get() { + final String sarlOutputDirectory = SARLConfig.FOLDER_SOURCE_GENERATED; + final String sarlOutputDirectoryOption = "--" + Constants.SARL_OUTPUT_DIRECTORY_OPTION; //$NON-NLS-1$ + final String javaOutputDirectory = SARLConfig.FOLDER_BIN; + final String javaOutputDirectoryOption = "--" + Constants.JAVA_OUTPUT_DIRECTORY_OPTION; //$NON-NLS-1$ + return MessageFormat.format(Messages.SarlcApplicationModule_2, + sarlOutputDirectory, sarlOutputDirectoryOption, + javaOutputDirectory, javaOutputDirectoryOption); + } + + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModuleProvider.java new file mode 100644 index 0000000000..f09de4b3fd --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcApplicationModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the sarlc application information. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlcApplicationModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new SarlcApplicationModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.SarlcApplicationModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModule.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModule.java new file mode 100644 index 0000000000..098b40cb1d --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModule.java @@ -0,0 +1,45 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import static io.bootique.BQCoreModule.extend; + +import com.google.inject.AbstractModule; + +import io.sarl.lang.sarlc.commands.CompilerCommand; + +/** Module for configuring the sarlc default command. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlcDefaultCommandModule extends AbstractModule { + + @Override + protected void configure() { + extend(binder()).setDefaultCommand(CompilerCommand.class); + } + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModuleProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModuleProvider.java new file mode 100644 index 0000000000..b695294627 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/modules/general/SarlcDefaultCommandModuleProvider.java @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2018 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.lang.sarlc.modules.general; + +import com.google.inject.Module; +import io.bootique.BQModule; +import io.bootique.BQModuleProvider; + +/** Provider of the module for the default sarlc command. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +public class SarlcDefaultCommandModuleProvider implements BQModuleProvider { + + @Override + public Module module() { + return new SarlcDefaultCommandModule(); + } + + @Override + public BQModule.Builder moduleBuilder() { + return BQModule + .builder(module()) + .overrides(overrides()) + .providerName(name()) + .configs(configs()) + .description(Messages.SarlcDefaultCommandModuleProvider_0); + } + +} diff --git a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/commands/messages.properties b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/commands/messages.properties index 8276635cd8..fe7f48ead2 100644 --- a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/commands/messages.properties +++ b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/commands/messages.properties @@ -2,4 +2,3 @@ CompilerCommand_0 = Run sarlc. CompilerCommand_1 = Not enough arguments. Source folders must be provided as arguments. VersionCommand_0 = Prints the version of sarlc. VersionCommand_1 = SARL Version: {0}\nSARL Specification Version: {1}\nJava Version: {2}\n -PrintConfigCommand_0 = Print the current configuration. \ No newline at end of file diff --git a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/commands/messages.properties b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/commands/messages.properties new file mode 100644 index 0000000000..3d6c9a7f26 --- /dev/null +++ b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/commands/messages.properties @@ -0,0 +1,2 @@ +CompilerCommandModuleProvider_0 = The command for starting the SARL compiler. +VersionCommandModuleProvider_0 = The command for printing out the version of this application. diff --git a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/configs/messages.properties b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/configs/messages.properties new file mode 100644 index 0000000000..a55d244448 --- /dev/null +++ b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/configs/messages.properties @@ -0,0 +1,28 @@ +SarlcConfigModule_0 = Output directory in which the Java source files will be generated. +SarlcConfigModule_1 = directory_name +SarlcConfigModule_2 = Directory in which the temporary files will be generated during the compilation process. +SarlcConfigModule_3 = Specify where to find user class files and annotation processors. +SarlcConfigModule_4 = path +SarlcConfigModule_5 = Specify where to find user class files and annotation processors. +SarlcConfigModule_6 = Override location of bootstrap class files. +SarlcConfigModule_7 = Output directory in which the Java byte code files will be generated. +SarlcConfigModuleProvider_0 = The configuration for the sarlc tool. +CompilerConfigModule_0 = Specify the character encoding of the files; default is {0}. +CompilerConfigModule_1 = encoding +CompilerConfigModule_2 = Generate Java files for a specific Java version; default is {0}. +CompilerConfigModule_3 = version +CompilerConfigModule_4 = Specify if the Java compiler should be run; default is {0}. +CompilerConfigModule_5 = {0}|{1} +CompilerConfigModule_6 = Specify if the trace files should be generated; default is {0}. +CompilerConfigModule_7 = Specify if the storage files should be generated; default is {0}. +CompilerConfigModule_8 = Specify if the @Inline annotations should be generated; default is {0}. +CompilerConfigModule_9 = Specify if the @Pure annotations should be generated; default is {0}. +CompilerConfigModule_10 = Specify if the equality tests should be generated; default is {0}. +CompilerConfigModule_11 = Specify if the toString functions should be generated; default is {0}. +CompilerConfigModule_12 = Specify if the clone functions should be generated; default is {0}. +CompilerConfigModule_13 = Specify if the serial identifiers should be generated; default is {0}. +CompilerConfigModuleProvider_0 = The configuration for the SARL compiler. +ValidatorConfigModule_0 = Specify if all the warnings are ignored. +ValidatorConfigModule_1 = Specify if any warning is assimilated to an error. +ValidatorConfigModule_2 = Specify if all the warnings are printed out. +ValidatorConfigModuleProvider_0 = The configuration for the SARL validator. diff --git a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/general/messages.properties b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/general/messages.properties new file mode 100644 index 0000000000..92480716b8 --- /dev/null +++ b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/general/messages.properties @@ -0,0 +1,12 @@ +SarlBatchCompilerModuleProvider_0 = The SARL batch compiler. +SarlcDefaultCommandModuleProvider_0 = The default command for the sarlc tool. +SARLRuntimeModuleProvider_0 = The SARL compiler runtime. +SarlcApplicationModule_0 = The command-line SARL compiler. +SarlcApplicationModule_1 = [SARL_SOURCE_FOLDER]... +SarlcApplicationModule_2 = The sarlc command reads definitions, written in the SARL programming language, and compiles \ + them into Java class files.\nTo pass source code to sarlc, you have to provide the names of the folders in which the \ + SARL code files are located.\nSource code file names must have .sarl suffixes, Java class file names must have .class \ + suffixes.\nBy default, the compiler puts each Java source file in the directory {0}. You can specify a separate destination \ + directory with the {1} option.\nBy default, the compiler puts each Java class file in the directory {2}. You can specify \ + a separate destination directory with the {3} option. +SarlcApplicationModuleProvider_0 = The name and description of the application. diff --git a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/messages.properties b/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/messages.properties deleted file mode 100644 index aa1bee1e21..0000000000 --- a/products/sarlc/src/main/resources/io/sarl/lang/sarlc/modules/messages.properties +++ /dev/null @@ -1,28 +0,0 @@ -LoggingModule_0 = , -LoggingModule_1 = Specify the logging level; value is one of '{'{0}'}'; Default is {1}. -LoggingModule_2 = value -SarlcModule_0 = Output directory in which the Java source files will be generated. -SarlcModule_1 = directory_name -SarlcModule_2 = Directory in which the temporary files will be generated during the compilation process. -SarlcModule_3 = Specify where to find user class files and annotation processors. -SarlcModule_4 = path -SarlcModule_5 = Specify where to find user class files and annotation processors. -SarlcModule_6 = Override location of bootstrap class files. -SarlcModule_7 = Output directory in which the Java byte code files will be generated. -CompilerModule_0 = Specify the character encoding of the files; default is {0}. -CompilerModule_1 = encoding -CompilerModule_2 = Generate Java files for a specific Java version; default is {0}. -CompilerModule_3 = version -CompilerModule_4 = Specify if the Java compiler should be run; default is {0}. -CompilerModule_5 = {0}|{1} -CompilerModule_6 = Specify if the trace files should be generated; default is {0}. -CompilerModule_7 = Specify if the storage files should be generated; default is {0}. -CompilerModule_8 = Specify if the @Inline annotations should be generated; default is {0}. -CompilerModule_9 = Specify if the @Pure annotations should be generated; default is {0}. -CompilerModule_10 = Specify if the equality tests should be generated; default is {0}. -CompilerModule_11 = Specify if the toString functions should be generated; default is {0}. -CompilerModule_12 = Specify if the clone functions should be generated; default is {0}. -CompilerModule_13 = Specify if the serial identifiers should be generated; default is {0}. -ValidatorModule_0 = Specify if all the warnings are ignored. -ValidatorModule_1 = Specify if any warning is assimilated to an error. -ValidatorModule_2 = Specify if all the warnings are printed out.