diff --git a/maven/io.sarl.maven.docs.generator/pom.xml b/maven/io.sarl.maven.docs.generator/pom.xml
index f93953feb8..fe6b2ad6ad 100644
--- a/maven/io.sarl.maven.docs.generator/pom.xml
+++ b/maven/io.sarl.maven.docs.generator/pom.xml
@@ -17,10 +17,15 @@
2.6.2
- 15.0
+ 15.0
+
+ junit
+ junit
+ runtime
+
org.jnario
report
@@ -33,13 +38,16 @@
org.apache.maven.plugin-tools
maven-plugin-annotations
-
- com.google.guava
- guava
- ${guava.version}
-
-
+
+
+
+ com.google.guava
+ guava
+ ${guava.version.for.jnario}
+
+
+
diff --git a/maven/io.sarl.maven.docs.generator/src/main/java/io/sarl/maven/docs/generator/SARLDocGenerate.java b/maven/io.sarl.maven.docs.generator/src/main/java/io/sarl/maven/docs/generator/SARLDocGenerate.java
index 2fe7d9ff5a..3796f01946 100644
--- a/maven/io.sarl.maven.docs.generator/src/main/java/io/sarl/maven/docs/generator/SARLDocGenerate.java
+++ b/maven/io.sarl.maven.docs.generator/src/main/java/io/sarl/maven/docs/generator/SARLDocGenerate.java
@@ -24,13 +24,16 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.net.URI;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.regex.Pattern;
-import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
@@ -41,6 +44,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
+import org.arakhne.afc.vmutil.FileSystem;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler;
import org.eclipse.xtend.lib.macro.file.Path;
@@ -103,6 +107,12 @@ public class SARLDocGenerate extends XtendTestCompile {
@SuppressWarnings("hiding")
protected MavenProject project;
+ /**
+ * The project base directory. This parameter is set by maven.
+ */
+ @Parameter(required = true, defaultValue = "${project.basedir}")
+ protected File projectBaseDir;
+
/**
* Set this to true to skip compiling Xtend sources.
*/
@@ -131,28 +141,55 @@ public class SARLDocGenerate extends XtendTestCompile {
@Override
protected void internalExecute() throws MojoExecutionException {
- // Only for injecting the attributes from Maven.
- super.project = this.project;
- super.skipXtend = this.skipXtend;
- super.encoding = this.encoding;
- super.writeTraceFiles = this.writeTraceFiles;
-
- getLog().debug("Set section numbering: " + Boolean.toString(this.sectionNumbering)); //$NON-NLS-1$
- MavenConfig.setSectionNumbering(this.sectionNumbering);
-
- getLog().info("Generating Jnario reports to " + this.docOutputDirectory); //$NON-NLS-1$
-
- // the order is important, the suite compiler must be executed last
- final List injectors = createInjectors(
- new SARLSpecStandaloneSetup(),
- new FeatureStandaloneSetup(),
- new SuiteStandaloneSetup());
- generateCssAndJsFiles(injectors);
- this.resourceSetProvider = new JnarioMavenProjectResourceSetProvider(this.project);
-
- final HashBasedSpec2ResultMapping resultMapping = createSpec2ResultMapping(injectors);
- for (final Injector injector : injectors) {
- generateDoc(injector, resultMapping);
+ try {
+ // Only for injecting the attributes from Maven.
+ super.project = this.project;
+ super.skipXtend = this.skipXtend;
+ super.encoding = this.encoding;
+ super.writeTraceFiles = this.writeTraceFiles;
+
+ getLog().info("Generating into " + this.docOutputDirectory); //$NON-NLS-1$
+
+ getLog().debug("Set section numbering: " + Boolean.toString(this.sectionNumbering)); //$NON-NLS-1$
+ MavenConfig.setSectionNumbering(this.sectionNumbering);
+
+ // the order is important, the suite compiler must be executed last
+ final InjectorCollection injectors = new InjectorCollection(
+ new SARLSpecStandaloneSetup(),
+ new FeatureStandaloneSetup(),
+ new SuiteStandaloneSetup());
+
+ generateCssAndJsFiles(injectors);
+
+ getLog().info("Creating Jnario-based resource provider"); //$NON-NLS-1$
+ this.resourceSetProvider = new JnarioMavenProjectResourceSetProvider(this.project);
+
+ getLog().info("Creating Jnario specification map"); //$NON-NLS-1$
+ final HashBasedSpec2ResultMapping resultMapping = createSpec2ResultMapping(injectors);
+ for (final String injectorId : injectors.getIdentifiers()) {
+ final Injector injector = injectors.getInjector(injectorId);
+ if (injector != null) {
+ generateDoc(injectorId, injector, resultMapping);
+ }
+ }
+ } finally {
+ cleanClassFolders();
+ }
+ }
+
+ private void cleanClassFolders() {
+ if (this.projectBaseDir != null) {
+ final Pattern pattern = Pattern.compile("^classes[0-9]+$"); //$NON-NLS-1$
+ for (final File child : this.projectBaseDir.listFiles()) {
+ if (child.isDirectory() && pattern.matcher(child.getName()).matches()) {
+ getLog().debug("Deleting " + child.getName()); //$NON-NLS-1$
+ try {
+ FileSystem.delete(child);
+ } catch (IOException e) {
+ getLog().warn(e);
+ }
+ }
+ }
}
}
@@ -161,8 +198,10 @@ protected void internalExecute() throws MojoExecutionException {
* @return the mapping
* @throws MojoExecutionException when no Surefire report was found.
*/
- protected HashBasedSpec2ResultMapping createSpec2ResultMapping(List injectors) throws MojoExecutionException {
- final HashBasedSpec2ResultMapping resultMapping = injectors.get(2).getInstance(HashBasedSpec2ResultMapping.class);
+ protected HashBasedSpec2ResultMapping createSpec2ResultMapping(InjectorCollection injectors) throws MojoExecutionException {
+ final Injector injector = injectors.getInjector(SuiteStandaloneSetup.class.getName());
+ final HashBasedSpec2ResultMapping resultMapping = injector.getInstance(HashBasedSpec2ResultMapping.class);
+ getLog().debug("Report directory: " + this.reportsDirectory); //$NON-NLS-1$
final File reportFolder = new File(this.reportsDirectory);
if (reportFolder.exists()) {
addExecutionResults(resultMapping, reportFolder);
@@ -174,11 +213,14 @@ protected HashBasedSpec2ResultMapping createSpec2ResultMapping(List in
/**
* @param injectors - the injector list.
+ * @throws MojoExecutionException when no Surefire report was found.
*/
- protected void generateCssAndJsFiles(List injectors) {
- final HtmlAssetsCompiler assetsCompiler = injectors.get(0).getInstance(HtmlAssetsCompiler.class);
+ protected void generateCssAndJsFiles(InjectorCollection injectors) throws MojoExecutionException {
+ getLog().info("Generating CSS and JS assets"); //$NON-NLS-1$
+ final Injector injector = injectors.getInjector(SARLSpecStandaloneSetup.class.getName());
+ final HtmlAssetsCompiler assetsCompiler = injector.getInstance(HtmlAssetsCompiler.class);
+ getLog().debug("Output path: " + this.docOutputDirectory); //$NON-NLS-1$
assetsCompiler.setOutputPath(this.docOutputDirectory);
- getLog().info("Generating HTML assets to " + this.docOutputDirectory); //$NON-NLS-1$
assetsCompiler.compile();
}
@@ -210,7 +252,8 @@ protected void compileTestSources(XtendBatchCompiler xtend2BatchCompiler) throws
compile(xtend2BatchCompiler, testClassPath, testCompileSourceRoots, this.docOutputDirectory);
}
- private void generateDoc(Injector injector, Executable2ResultMapping resultMapping) throws MojoExecutionException {
+ private void generateDoc(String id, Injector injector, Executable2ResultMapping resultMapping) throws MojoExecutionException {
+ getLog().info("Generating documentation with " + id); //$NON-NLS-1$
final JnarioDocCompiler docCompiler = injector.getInstance(JnarioDocCompiler.class);
docCompiler.setExecutable2ResultMapping(resultMapping);
compileTestSources(docCompiler);
@@ -280,15 +323,6 @@ private void configureWorkspace(List sourceDirectories, String outputPat
}
}
- private static List createInjectors(ISetup... setups) {
- return Lists.transform(Arrays.asList(setups), new Function() {
- @Override
- public Injector apply(ISetup input) {
- return input.createInjectorAndDoEMFRegistration();
- }
- });
- }
-
/** Copied from JnarioDocGenerate (version 1.0.1).
*
* @author $Author: sgalland$
@@ -309,4 +343,36 @@ public boolean accept(File dir, String name) {
}
+ /** Collection of injectors.
+ *
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ private final class InjectorCollection {
+
+ private final Map injectors = new HashMap<>();
+
+ private final List order = new ArrayList<>();
+
+ InjectorCollection(ISetup... setups) {
+ for (final ISetup setup : setups) {
+ final String id = setup.getClass().getName();
+ final Injector injector = setup.createInjectorAndDoEMFRegistration();
+ this.order.add(id);
+ this.injectors.put(id, injector);
+ }
+ }
+
+ public Injector getInjector(String id) {
+ return this.injectors.get(id);
+ }
+
+ public Iterable getIdentifiers() {
+ return Collections.unmodifiableCollection(this.order);
+ }
+
+ }
+
}