Skip to content

Commit

Permalink
[sarlc] Add SARL boot class path.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jul 25, 2018
1 parent 20edf06 commit adf5be0
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 21 deletions.
5 changes: 5 additions & 0 deletions products/sarlc/pom.xml
Expand Up @@ -48,6 +48,11 @@
<artifactId>progressbar</artifactId>
<version>0.7.0</version>
</dependency>
<!-- The following dependency is included in order to have the SDK available on the class path by default -->
<dependency>
<groupId>io.sarl.maven</groupId>
<artifactId>io.sarl.maven.sdk</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -68,14 +68,21 @@ 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$

private String classpath;

private String bootClasspath;

private String javaBootClasspath;

private File outputPath;

private File classOutputPath;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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<SarlConfig> config, Provider<SARLBootClasspathProvider> defaultBootClasspath,
Provider<IssueMessageFormatter> 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())) {
Expand Down Expand Up @@ -124,7 +134,7 @@ public SarlBatchCompiler provideSarlBatchCompiler(
compiler.setWarningSeverity(entry.getKey(), entry.getValue());
}

compiler.setIssueMessageFormatter(issueMessageFormater);
compiler.setIssueMessageFormatter(issueMessageFormater.get());

return compiler;
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -63,14 +67,6 @@ protected void configure() {
*/
private static class LongDescriptionProvider implements Provider<String> {

/** Constructor.
*
*/
@Inject
LongDescriptionProvider() {
//
}

@Override
public String get() {
final String sarlOutputDirectory = SARLConfig.FOLDER_SOURCE_GENERATED;
Expand Down
@@ -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();

}
@@ -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$
}

}

0 comments on commit adf5be0

Please sign in to comment.