From adf5be071b35f0818407f209b9c8999fb51b026c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Wed, 25 Jul 2018 14:49:31 +0200 Subject: [PATCH] [sarlc] Add SARL boot class path. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Galland --- products/sarlc/pom.xml | 5 +++ .../sarl/lang/sarlc/configs/SarlConfig.java | 26 ++++++++++- .../general/SarlBatchCompilerModule.java | 28 ++++++++---- .../general/SarlcApplicationModule.java | 18 +++----- .../tools/SARLBootClasspathProvider.java | 44 +++++++++++++++++++ .../SarlEmbddedSdkBootClasspathProvider.java | 43 ++++++++++++++++++ 6 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SARLBootClasspathProvider.java create mode 100644 products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SarlEmbddedSdkBootClasspathProvider.java diff --git a/products/sarlc/pom.xml b/products/sarlc/pom.xml index d1800cc968..8da1a1653d 100644 --- a/products/sarlc/pom.xml +++ b/products/sarlc/pom.xml @@ -48,6 +48,11 @@ progressbar 0.7.0 + + + io.sarl.maven + io.sarl.maven.sdk + diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java index a3bababd33..347f38ff6b 100644 --- a/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/configs/SarlConfig.java @@ -68,7 +68,12 @@ public class SarlConfig { public static final String CLASSPATH_NAME = PREFIX + ".classpath"; //$NON-NLS-1$ /** - * Name of the property that contains the boot classpath. + * Name of the property that contains the Java boot classpath. + */ + public static final String JAVA_BOOT_CLASSPATH_NAME = PREFIX + ".javabootclasspath"; //$NON-NLS-1$ + + /** + * Name of the property that contains the SARL boot classpath. */ public static final String BOOT_CLASSPATH_NAME = PREFIX + ".bootclasspath"; //$NON-NLS-1$ @@ -76,6 +81,8 @@ public class SarlConfig { private String bootClasspath; + private String javaBootClasspath; + private File outputPath; private File classOutputPath; @@ -130,6 +137,23 @@ public void setBootClasspath(String path) { this.bootClasspath = path; } + /** Replies the Java boot classpath. + * + * @return the Java boot classpath + */ + public String getJavaBootClasspath() { + return this.javaBootClasspath; + } + + /** Change the Java boot class path. + * + * @param path the Java boot class path. + */ + @BQConfigProperty("Java boot class path for the SARL compiler.") + public void setJavaBootClasspath(String path) { + this.javaBootClasspath = path; + } + /** Replies the class output path. * * @return the class output path 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 index c2cae941aa..3250996a79 100644 --- 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 @@ -26,6 +26,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Injector; +import com.google.inject.Provider; import com.google.inject.Provides; import com.google.inject.Singleton; import org.eclipse.xtext.diagnostics.Severity; @@ -36,6 +37,7 @@ import io.sarl.lang.sarlc.configs.SarlConfig; import io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig; import io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig; +import io.sarl.lang.sarlc.tools.SARLBootClasspathProvider; /** Module for creating the SARL batch compiler with the configuration provided by bootique modules. * @@ -78,20 +80,28 @@ public IssueMessageFormatter provideIssueMessageFormatter() { @Provides @Singleton public SarlBatchCompiler provideSarlBatchCompiler( - Injector injector, SarlConfig config, @BootClasspath String defaultBootClasspath, - IssueMessageFormatter issueMessageFormater) { - final CompilerConfig compilerConfig = config.getCompiler(); - final ValidatorConfig validatorConfig = config.getValidator(); + Injector injector, Provider config, Provider defaultBootClasspath, + Provider issueMessageFormater) { + final SarlConfig cfg = config.get(); + final CompilerConfig compilerConfig = cfg.getCompiler(); + final ValidatorConfig validatorConfig = cfg.getValidator(); final SarlBatchCompiler compiler = new SarlBatchCompiler(); injector.injectMembers(compiler); - if (!Strings.isEmpty(sarlcConfig.getClasspath())) { - compiler.setClassPath(sarlcConfig.getClasspath()); + String fullClassPath = cfg.getBootClasspath(); + if (Strings.isEmpty(fullClassPath)) { + fullClassPath = defaultBootClasspath.get().getClasspath(); } - if (!Strings.isEmpty(sarlcConfig.getBootClasspath())) { - compiler.setBootClassPath(sarlcConfig.getBootClasspath()); + final String userClassPath = cfg.getClasspath(); + if (!Strings.isEmpty(userClassPath) && !Strings.isEmpty(fullClassPath)) { + fullClassPath = fullClassPath + File.pathSeparator + userClassPath; + } + compiler.setClassPath(fullClassPath); + + if (!Strings.isEmpty(cfg.getJavaBootClasspath())) { + compiler.setBootClassPath(cfg.getJavaBootClasspath()); } if (!Strings.isEmpty(compilerConfig.getFileEncoding())) { @@ -124,7 +134,7 @@ public SarlBatchCompiler provideSarlBatchCompiler( compiler.setWarningSeverity(entry.getKey(), entry.getValue()); } - compiler.setIssueMessageFormatter(issueMessageFormater); + compiler.setIssueMessageFormatter(issueMessageFormater.get()); return compiler; } 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 index 3121ed418f..d6b4f03ca4 100644 --- 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 @@ -26,8 +26,8 @@ import java.text.MessageFormat; import com.google.inject.AbstractModule; -import com.google.inject.Inject; import com.google.inject.Provider; +import com.google.inject.Singleton; import org.arakhne.afc.bootique.applicationdata2.annotations.DefaultApplicationName; import org.arakhne.afc.bootique.synopsishelp.annotations.ApplicationArgumentSynopsis; import org.arakhne.afc.bootique.synopsishelp.annotations.ApplicationDetailedDescription; @@ -47,10 +47,14 @@ public class SarlcApplicationModule extends AbstractModule { @Override protected void configure() { + // Name of the application. 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); + // Short description of the application. extend(binder()).setApplicationDescription(Messages.SarlcApplicationModule_0); + // Long description of the application. + bind(String.class).annotatedWith(ApplicationDetailedDescription.class).toProvider(LongDescriptionProvider.class).in(Singleton.class); + // Synopsis of the application's arguments. + bind(String.class).annotatedWith(ApplicationArgumentSynopsis.class).toInstance(Messages.SarlcApplicationModule_1); } /** Provider of the long description of the application. @@ -63,14 +67,6 @@ protected void configure() { */ private static class LongDescriptionProvider implements Provider { - /** Constructor. - * - */ - @Inject - LongDescriptionProvider() { - // - } - @Override public String get() { final String sarlOutputDirectory = SARLConfig.FOLDER_SOURCE_GENERATED; diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SARLBootClasspathProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SARLBootClasspathProvider.java new file mode 100644 index 0000000000..40eec88d2c --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SARLBootClasspathProvider.java @@ -0,0 +1,44 @@ +/* + * $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.tools; + +import com.google.inject.ImplementedBy; + +/** + * A provider of the class path that must be used for compiling a SARL program. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +@ImplementedBy(SarlEmbddedSdkBootClasspathProvider.class) +public interface SARLBootClasspathProvider { + + /** Replies the class path that must be used for compiling a SARL program. + * + * @return the classpath. + */ + String getClasspath(); + +} diff --git a/products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SarlEmbddedSdkBootClasspathProvider.java b/products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SarlEmbddedSdkBootClasspathProvider.java new file mode 100644 index 0000000000..87f552b870 --- /dev/null +++ b/products/sarlc/src/main/java/io/sarl/lang/sarlc/tools/SarlEmbddedSdkBootClasspathProvider.java @@ -0,0 +1,43 @@ +/* + * $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.tools; + +import com.google.inject.Singleton; + +/** + * Provider of the SARL SDK class path. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.8 + */ +@Singleton +public class SarlEmbddedSdkBootClasspathProvider implements SARLBootClasspathProvider { + + @Override + public String getClasspath() { + return ""; //$NON-NLS-1$ + } + +}