Skip to content

Commit

Permalink
[docs] Upgrade for supporting Xtext 2.15 and the use of Bootique.
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 19, 2018
1 parent 6846806 commit 7e50053
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 79 deletions.
18 changes: 18 additions & 0 deletions docs/io.sarl.docs.markdown/pom.xml
Expand Up @@ -23,6 +23,24 @@
</properties>

<dependencies>
<!-- FIXME: Remove asap if the project compile without -->
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.12.2</version>
</dependency>
<!-- FIXME: Remove asap if the project compile without -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.12.0</version>
</dependency>
<!-- FIXME: Remove asap if the project compile without -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>io.sarl.maven</groupId>
<artifactId>io.sarl.maven.docs.testing</artifactId>
Expand Down
Expand Up @@ -2,7 +2,7 @@

[:Outline:]

[:Fact:]{(io.sarl.lang.sarlc.Main)::getCompilerProgramName == '[:name](sarlc)'}
[:Fact:]{(io.sarl.lang.sarlc.Main)::getDefaultCompilerProgramName == '[:name](sarlc)'}

A command-line compiler is a tool that could be invoked from the command-line shell in order to compiler a language source file.
[:name:] is the command-line compiler for the SARL language.
Expand All @@ -12,16 +12,15 @@ A command-line compiler is a tool that could be invoked from the command-line sh
The [:name:] tool takes arguments:


[:name!] --dir <[:outfolder](output folder)> [OPTIONS] <[:srcfolder](source folder)>...
[:name!] [OPTIONS] <[:srcfolder](source folder)>...


The [:outfolder:] is the name of the folder in which the generated Java files should be created by the SARL compiler.
The [:name:] tool takes at least one [:srcfolder:] from which the SARL files are read.

You could change the behavior of the [:name:] compiler with the command-line options.
For obtaining a list of the options, type:

[:name!] -help
[:name!] -h


## Command-Line Options
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -194,13 +195,17 @@ protected String internalExecute(Map<File, File> files, File outputFolder) {
return super.internalExecute(files, outputFolder);
}

@SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"})
@SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "all"})
@Override
protected void internalExecute(File sourceFolder, File inputFile, File relativeInputFile, File outputFolder,
AbstractMarkerLanguageParser parser) throws IOException {
getLog().debug(MessageFormat.format(Messages.GenerateTestsMojo_0, inputFile.getName()));
final List<ValidationComponent> successCompilationComponents = new ArrayList<>();
final List<ValidationComponent> failureCompilationComponents = new ArrayList<>();
final List<ValidationComponent> factualComponents = new ArrayList<>();
if (inputFile.getName().endsWith("Sarlc.md")) {
System.out.println("DBG");
}
for (final ValidationComponent component : parser.getStandardValidationComponents(inputFile)) {
if (component.isCompilable()) {
if (component.isExecutable()) {
Expand Down Expand Up @@ -242,6 +247,8 @@ protected void internalExecute(File sourceFolder, File inputFile, File relativeI

int i = 0;
for (final ValidationComponent component : successCompilationComponents) {
getLog().debug(MessageFormat.format(Messages.GenerateTestsMojo_1,
inputFile.getName(), component.getLineno(), component.getCode()));
final String actionName = "success_" + component.getLineno() + "_" + i; //$NON-NLS-1$ //$NON-NLS-2$
it.newLine();
it.append("@").append(Test.class); //$NON-NLS-1$
Expand All @@ -261,6 +268,8 @@ protected void internalExecute(File sourceFolder, File inputFile, File relativeI

i = 0;
for (final ValidationComponent component : failureCompilationComponents) {
getLog().debug(MessageFormat.format(Messages.GenerateTestsMojo_2,
inputFile.getName(), component.getLineno(), component.getCode()));
final String actionName = "failure_" + component.getLineno() + "_" + i; //$NON-NLS-1$ //$NON-NLS-2$
it.newLine();
it.append("@").append(Test.class); //$NON-NLS-1$
Expand All @@ -280,6 +289,8 @@ protected void internalExecute(File sourceFolder, File inputFile, File relativeI

i = 0;
for (final ValidationComponent component : factualComponents) {
getLog().debug(MessageFormat.format(Messages.GenerateTestsMojo_3,
inputFile.getName(), component.getLineno(), component.getCode()));
final String actionName = "fact_" + component.getLineno() + "_" + i; //$NON-NLS-1$ //$NON-NLS-2$
it.newLine();
it.append("@").append(Test.class); //$NON-NLS-1$
Expand Down Expand Up @@ -334,6 +345,8 @@ protected void internalExecute(File sourceFolder, File inputFile, File relativeI

i = 0;
for (final DynamicValidationComponent component : specificComponents) {
getLog().debug(MessageFormat.format(Messages.GenerateTestsMojo_4,
inputFile.getName(), component.functionName() + i));
final String actionName = component.functionName() + i;
it.newLine();
it.append("@").append(Test.class); //$NON-NLS-1$
Expand Down
Expand Up @@ -44,6 +44,11 @@ public class Messages extends NLS {
public static String GenerateMojo_2;
public static String GenerateMojo_3;
public static String GenerateMojo_4;
public static String GenerateTestsMojo_0;
public static String GenerateTestsMojo_1;
public static String GenerateTestsMojo_2;
public static String GenerateTestsMojo_3;
public static String GenerateTestsMojo_4;
public static String InitializeMojo_0;
public static String InitializeMojo_1;
public static String InitializeMojo_2;
Expand Down
Expand Up @@ -794,7 +794,7 @@ public void tag(ParsingContext context, Tag tag, String dynamicName, String para
}
}
});
final ParsingContext rootContextForReplacements = new ParsingContext(true);
final ParsingContext rootContextForReplacements = new ParsingContext(true, true);
initializeContext(rootContextForReplacements);
parse(content, inputFile, 0, Stage.FIRST, rootContextForReplacements, interceptor);
//
Expand Down Expand Up @@ -979,7 +979,7 @@ protected static void reportError(ParsingContext context, String message, Object
System.arraycopy(parameter, 0, args, 3, parameter.length);
final String msg = MessageFormat.format(message, args);
if (cause != null) {
throw new ParsingException(msg, file, lineno, cause);
throw new ParsingException(msg, file, lineno, Throwables.getRootCause(cause));
}
throw new ParsingException(msg, file, lineno);
}
Expand All @@ -998,7 +998,7 @@ protected static void reportError(String message, Object... parameters) {
}
final String msg = MessageFormat.format(message, parameters);
if (cause != null) {
throw new ParsingException(msg, null, 1, cause);
throw new ParsingException(msg, null, 1, Throwables.getRootCause(cause));
}
throw new ParsingException(msg, null, 1);
}
Expand Down Expand Up @@ -1196,6 +1196,8 @@ public static class ParsingContext {

private ScriptExecutor scriptExecutor;

private boolean isTestingPhase;

/** Constructor with standard visibility configuration.
*/
public ParsingContext() {
Expand All @@ -1207,9 +1209,11 @@ public ParsingContext() {
* @param forceVisibility forces all the elements to be visible. The visiblilty tags such as
* {@link Tag#ON} and {@link Tag#OFF} will have no effect if the value of this argument is
* {@code true}.
* @param isTestingPhase indicates if the context is created for testing phase.
*/
public ParsingContext(boolean forceVisibility) {
public ParsingContext(boolean forceVisibility, boolean isTestingPhase) {
this.forceVisibility = forceVisibility;
this.isTestingPhase = isTestingPhase;
}

/** Change the script executor.
Expand Down Expand Up @@ -1313,6 +1317,16 @@ public boolean isVisible() {
return !isInBlock() || this.isVisibleInblock || this.forceVisibility;
}

/** Replies if the context is created within a testing phase.
*
* <p>Usually, no code for generated the marker language is run during a testing phase.
*
* @return {@code true} if the content is outside a block or the visibility flag is on.
*/
public boolean isTestingPhase() {
return this.isTestingPhase;
}

/** Set the flag that indicates if the parser is on.
*
* @param enable {@code true} if parser is on.
Expand Down Expand Up @@ -1377,6 +1391,7 @@ public void linkTo(ParsingContext parentContext) {
this.isParsing = parentContext.isParsing;
this.isVisibleInblock = parentContext.isVisibleInblock;
this.forceVisibility = parentContext.forceVisibility;
this.isTestingPhase = parentContext.isTestingPhase;
this.lineno = parentContext.lineno;
this.scriptExecutor = parentContext.scriptExecutor;
}
Expand Down Expand Up @@ -1934,9 +1949,11 @@ public boolean isOpeningTag() {
@Override
public String passThrough(ParsingContext context, String dynamicTag, String parameter, String blockValue) {
context.getParserInterceptor().outline(context);
final String tag = context.getOutlineOutputTag();
if (!Strings.isNullOrEmpty(tag)) {
return Strings.nullToEmpty(context.getOutlineOutputTag());
if (!context.isTestingPhase()) {
final String tag = context.getOutlineOutputTag();
if (!Strings.isNullOrEmpty(tag)) {
return Strings.nullToEmpty(context.getOutlineOutputTag());
}
}
return ""; //$NON-NLS-1$
}
Expand Down Expand Up @@ -2103,21 +2120,23 @@ public String passThrough(ParsingContext context, String dynamicTag, String para
reportError(context, Messages.SarlDocumentationParser_5, name());
return null;
}
String code = parameter;
if (Strings.isNullOrEmpty(code)) {
code = blockValue;
}
if (!Strings.isNullOrEmpty(code)) {
final ScriptExecutor executor = context.getScriptExecutor();
if (executor != null) {
try {
final Object result = executor.execute(context.getLineNo(), code);
if (result != null) {
final String stringResult = Strings.nullToEmpty(Objects.toString(result));
return stringResult;
if (!context.isTestingPhase()) {
String code = parameter;
if (Strings.isNullOrEmpty(code)) {
code = blockValue;
}
if (!Strings.isNullOrEmpty(code)) {
final ScriptExecutor executor = context.getScriptExecutor();
if (executor != null) {
try {
final Object result = executor.execute(context.getLineNo(), code);
if (result != null) {
final String stringResult = Strings.nullToEmpty(Objects.toString(result));
return stringResult;
}
} catch (Exception exception) {
Throwables.propagate(exception);
}
} catch (Exception exception) {
Throwables.propagate(exception);
}
}
}
Expand Down Expand Up @@ -2171,21 +2190,23 @@ public String passThrough(ParsingContext context, String dynamicTag, String para
reportError(context, Messages.SarlDocumentationParser_5, name());
return null;
}
String code = blockValue;
if (Strings.isNullOrEmpty(code)) {
code = parameter;
}
if (!Strings.isNullOrEmpty(code)) {
final ScriptExecutor executor = context.getScriptExecutor();
if (executor != null) {
try {
final Object result = executor.execute(context.getLineNo(), code);
if (result != null) {
final String stringResult = Strings.nullToEmpty(Objects.toString(result));
return formatBlockText(stringResult, context.getOutputLanguage(), context.getBlockCodeFormat());
if (!context.isTestingPhase()) {
String code = blockValue;
if (Strings.isNullOrEmpty(code)) {
code = parameter;
}
if (!Strings.isNullOrEmpty(code)) {
final ScriptExecutor executor = context.getScriptExecutor();
if (executor != null) {
try {
final Object result = executor.execute(context.getLineNo(), code);
if (result != null) {
final String stringResult = Strings.nullToEmpty(Objects.toString(result));
return formatBlockText(stringResult, context.getOutputLanguage(), context.getBlockCodeFormat());
}
} catch (Exception exception) {
Throwables.propagate(exception);
}
} catch (Exception exception) {
Throwables.propagate(exception);
}
}
}
Expand Down Expand Up @@ -2470,24 +2491,27 @@ public String passThrough(ParsingContext context, String dynamicTag, String para
reportError(context, Messages.SarlDocumentationParser_5, name());
return null;
}
final Class<?> javaType;
try {
javaType = ReflectionUtil.forName(parameter);
} catch (ClassNotFoundException exception) {
reportError(context, Messages.SarlDocumentationParser_0, exception);
return null;
}
final String block;
if (javaType.isInterface()) {
block = extractInterface(javaType);
} else if (javaType.isEnum()) {
block = extractEnumeration(javaType);
} else if (javaType.isAnnotation()) {
block = extractAnnotation(javaType);
} else {
block = extractClass(javaType);
if (!context.isTestingPhase()) {
final Class<?> javaType;
try {
javaType = ReflectionUtil.forName(parameter);
} catch (ClassNotFoundException exception) {
reportError(context, Messages.SarlDocumentationParser_0, exception);
return null;
}
final String block;
if (javaType.isInterface()) {
block = extractInterface(javaType);
} else if (javaType.isEnum()) {
block = extractEnumeration(javaType);
} else if (javaType.isAnnotation()) {
block = extractAnnotation(javaType);
} else {
block = extractClass(javaType);
}
return formatBlockText(block, context.getOutputLanguage(), context.getBlockCodeFormat());
}
return formatBlockText(block, context.getOutputLanguage(), context.getBlockCodeFormat());
return ""; //$NON-NLS-1$
}

private String extractInterface(Class<?> type) {
Expand Down
Expand Up @@ -123,4 +123,9 @@ public String getCode() {
return this.code;
}

@Override
public String toString() {
return getCode();
}

}
Expand Up @@ -8,6 +8,11 @@ GenerateMojo_1=Generating {0}
GenerateMojo_2=Writing {0}
GenerateMojo_3=Treatment of {0} was finished
GenerateMojo_4=Invalid range format: {0}
GenerateTestsMojo_0=Generating tests from {0}
GenerateTestsMojo_1=Expected success {0}@{1}: {2}
GenerateTestsMojo_2=Expected failure {0}@{1}: {2}
GenerateTestsMojo_3=Fact {0}@{1}: {2}
GenerateTestsMojo_4=Dynamic fact {0}: {1}
InitializeMojo_0=Adding source folder: {0}
InitializeMojo_1=Source folder already defined: {0}
InitializeMojo_2=Adding test source folder: {0}
Expand Down
18 changes: 18 additions & 0 deletions main/externalmaven/io.sarl.maven.docs.testing/pom.xml
Expand Up @@ -13,6 +13,24 @@
<description>Provides API for testing documentation</description>

<dependencies>
<!-- FIXME: Remove asap if the project compile without -->
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.12.2</version>
</dependency>
<!-- FIXME: Remove asap if the project compile without -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.12.0</version>
</dependency>
<!-- FIXME: Remove asap if the project compile without -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>io.sarl.maven</groupId>
<artifactId>io.sarl.maven.sdk</artifactId>
Expand Down

0 comments on commit 7e50053

Please sign in to comment.