Skip to content

Commit

Permalink
[sarlc] Add the command line options for running the extra-language g…
Browse files Browse the repository at this point in the history
…enerators.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Aug 5, 2018
1 parent a283dfe commit 456ba7e
Show file tree
Hide file tree
Showing 17 changed files with 303 additions and 26 deletions.
3 changes: 1 addition & 2 deletions main/targetplatform/io.sarl.lang.targetplatform.target
Expand Up @@ -36,8 +36,7 @@
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://download.eclipse.org/modeling/tmf/xtext/updates/composite/latest/"/>
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.15.0.v20180728-0209"/>
<unit id="org.eclipse.xtend.ui.feature.group" version="2.2.0.v201706050822"/>
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.15.0.v20180804-0209"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="aopalliance" version="1.0.0"/>
Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Expand Up @@ -306,6 +306,11 @@
<artifactId>io.sarl.maven.docs.testing</artifactId>
<version>${sarl.version}</version>
</dependency>
<dependency>
<groupId>io.sarl.pythongenerator</groupId>
<artifactId>io.sarl.pythongenerator.generator</artifactId>
<version>${sarl.version}</version>
</dependency>
<dependency>
<groupId>io.janusproject</groupId>
<artifactId>io.janusproject.kernel</artifactId>
Expand Down Expand Up @@ -525,6 +530,11 @@
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
6 changes: 5 additions & 1 deletion products/sarlc/pom.xml
Expand Up @@ -46,13 +46,17 @@
<dependency>
<groupId>me.tongfei</groupId>
<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>
<!-- The following dependency is included in order to have extra-language generators -->
<dependency>
<groupId>io.sarl.pythongenerator</groupId>
<artifactId>io.sarl.pythongenerator.generator</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -64,24 +64,24 @@ public class CompilerCommand extends CommandWithMetadata {

private final Provider<PathDetector> pathDetector;

private final Provider<ProgressBarConfig> commandConfig;
private final Provider<ProgressBarConfig> progressConfig;

/** Constructor.
*
* @param compiler the SARL batch compiler.
* @param configuration the configuration of the tool.
* @param pathDetector the detector of path.
* @param commandConfig the configuration of the command.
* @param progressConfig the configuration of the progress bar.
*/
public CompilerCommand(Provider<SarlBatchCompiler> compiler, Provider<SarlConfig> configuration,
Provider<PathDetector> pathDetector, Provider<ProgressBarConfig> commandConfig) {
Provider<PathDetector> pathDetector, Provider<ProgressBarConfig> progressConfig) {
super(CommandMetadata
.builder(CompilerCommand.class)
.description(Messages.CompilerCommand_0));
this.compiler = compiler;
this.configuration = configuration;
this.pathDetector = pathDetector;
this.commandConfig = commandConfig;
this.progressConfig = progressConfig;
}

@Override
Expand Down Expand Up @@ -125,10 +125,21 @@ public CommandOutcome run(Cli cli) {
final AtomicInteger nbFiles = new AtomicInteger(0);
comp.addCompiledResourceReceiver(it -> nbFiles.incrementAndGet());

final ProgressBarConfig commandConfig = this.commandConfig.get();
// Configuration of the extra-language generators
final String extraGenerators = config.getExtraGenerators();
if (!Strings.isNullOrEmpty(extraGenerators)) {
comp.setExtraLanguageGenerators(extraGenerators);
}

return runCompiler(comp, firstErrorMessage, nbErrors, nbWarnings, nbFiles);
}

private CommandOutcome runCompiler(SarlBatchCompiler comp, OutParameter<String> firstErrorMessage,
AtomicInteger nbErrors, AtomicInteger nbWarnings, AtomicInteger nbFiles) {
final ProgressBarConfig progressConfig = this.progressConfig.get();
final boolean compilationResult;
if (commandConfig.getEnable()) {
compilationResult = comp.compile(new ConsoleProgressMonitor(commandConfig.getStyle()));
if (progressConfig.getEnable()) {
compilationResult = comp.compile(new ConsoleProgressMonitor(progressConfig.getStyle()));
} else {
compilationResult = comp.compile();
}
Expand Down
@@ -0,0 +1,89 @@
/*
* $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.util.Set;
import java.util.TreeSet;

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.lang.extralanguage.IExtraLanguageContribution;
import io.sarl.lang.extralanguage.IExtraLanguageContributions;

/**
* Command for showing up the list of extra languages that are available on the classpath.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
public class ExtraLanguageListCommand extends CommandWithMetadata {

/** Name of the option for enabling the progress bar.
*/
public static final String EXTRA_LANGUAGE_LIST_OPTION_NAME = "printgenerators"; //$NON-NLS-1$

/** Name of the option for enabling the progress bar.
*/
public static final char EXTRA_LANGUAGE_LIST_OPTION_SHORT_NAME = 'G';

private final BootLogger bootLogger;

private final Provider<IExtraLanguageContributions> contributions;

/** Constructor.
*
* @param bootLogger the logger.
* @param contributions the provider of the extra-language contributions.
*/
public ExtraLanguageListCommand(BootLogger bootLogger, Provider<IExtraLanguageContributions> contributions) {
super(CommandMetadata
.builder(ExtraLanguageListCommand.class)
.description(Messages.ExtraLanguageListCommand_0)
.name(EXTRA_LANGUAGE_LIST_OPTION_NAME)
.shortName(EXTRA_LANGUAGE_LIST_OPTION_SHORT_NAME));
this.bootLogger = bootLogger;
this.contributions = contributions;
}

@Override
public CommandOutcome run(Cli cli) {
final Set<String> identifiers = new TreeSet<>();
for (final IExtraLanguageContribution contribution : this.contributions.get().getContributions()) {
identifiers.addAll(contribution.getIdentifiers());
}
final StringBuilder text = new StringBuilder();
for (final String id : identifiers) {
text.append(id).append("\n"); //$NON-NLS-1$
}
this.bootLogger.stdout(text.toString());
return CommandOutcome.succeeded();
}

}
Expand Up @@ -45,6 +45,7 @@ public class Messages extends NLS {
public static String CompilerCommand_8;
public static String CompilerCommand_9;
public static String CompilerCommand_10;
public static String ExtraLanguageListCommand_0;
public static String VersionCommand_0;
public static String VersionCommand_1;
static {
Expand Down
Expand Up @@ -60,7 +60,7 @@ public class SarlConfig {
/**
* Name of the property that contains the output path for the Java byte code.
*/
public static final String CLASS_OUTPUT_PATH_NAME = PREFIX + ".classOutputPath"; //$NON-NLS-1$
public static final String CLASS_OUTPUT_PATH_NAME = PREFIX + ".classutputPath"; //$NON-NLS-1$

/**
* Name of the property that contains the classpath.
Expand All @@ -70,12 +70,17 @@ public class SarlConfig {
/**
* Name of the property that contains the Java boot classpath.
*/
public static final String JAVA_BOOT_CLASSPATH_NAME = PREFIX + ".javabootclasspath"; //$NON-NLS-1$
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$
public static final String BOOT_CLASSPATH_NAME = PREFIX + ".bootClasspath"; //$NON-NLS-1$

/**
* Name of the property that contains the list of the extra-language generators.
*/
public static final String EXTRA_GENERATOR_NAME = PREFIX + ".extraGenerators"; //$NON-NLS-1$

private String classpath;

Expand All @@ -93,6 +98,8 @@ public class SarlConfig {

private ValidatorConfig validatorConfig;

private String extraGenerators;

/** Replies the configuration factory for the logging.
*
* @param configFactory the general configuration factory.
Expand Down Expand Up @@ -245,4 +252,21 @@ public void setValidator(ValidatorConfig config) {
this.validatorConfig = config;
}

/** Replies the enabled extra generators.
*
* @return the identifiers of the extra generators, separator by {@link File#pathSeparator}.
*/
public String getExtraGenerators() {
return this.extraGenerators;
}

/** Change the list of the enabled extra generators.
*
* @param identifiers the extra generators, separated by {@link File#pathSeparator}.
*/
@BQConfigProperty("List of the enable extra-language generators.")
public void setExtraGenerators(String identifiers) {
this.extraGenerators = identifiers;
}

}
Expand Up @@ -53,7 +53,8 @@ public class CompilerCommandModule extends AbstractModule {

@Override
protected void configure() {
extend(binder()).addOption(OptionMetadata.builder(
extend(binder())
.addOption(OptionMetadata.builder(
CompilerCommand.PROGRESS_OPTION_NAME, Messages.CompilerCommandModule_0)
.configPath(ProgressBarConfig.ENABLE)
.defaultValue(Boolean.TRUE.toString())
Expand Down
@@ -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.commands;

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.extralanguage.IExtraLanguageContributions;
import io.sarl.lang.sarlc.commands.ExtraLanguageListCommand;

/** Module for the command for printing out the available extra-language generators.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
public class ExtraLanguageListCommandModule extends AbstractModule {

@Override
protected void configure() {
extend(binder()).addCommand(ExtraLanguageListCommand.class);
}

/** Provide the command for displaying the available extra-language generators.
*
* @param bootLogger the logger.
* @param contributions the provider of the extra-language contributions.
* @return the command.
*/
@SuppressWarnings("static-method")
@Provides
@Singleton
public ExtraLanguageListCommand provideExtraLanguageListCommand(BootLogger bootLogger,
Provider<IExtraLanguageContributions> contributions) {
return new ExtraLanguageListCommand(bootLogger, contributions);
}

}
@@ -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 printing out the available extra-language generators.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
public class ExtraLanguageListCommandModuleProvider implements BQModuleProvider {

@Override
public Module module() {
return new ExtraLanguageListCommandModule();
}

@Override
public BQModule.Builder moduleBuilder() {
return BQModule
.builder(module())
.overrides(overrides())
.providerName(name())
.configs(configs())
.description(Messages.ExtraLanguageListCommandModuleProvider_0);
}

}

0 comments on commit 456ba7e

Please sign in to comment.