diff --git a/aadarchi-maven-plugin/pom.xml b/aadarchi-maven-plugin/pom.xml index 3734c2cd..7235581d 100644 --- a/aadarchi-maven-plugin/pom.xml +++ b/aadarchi-maven-plugin/pom.xml @@ -12,7 +12,7 @@ Agile Architecture Documentation System : Maven plugin - + org.twdata.maven mojo-executor @@ -39,6 +39,11 @@ base ${project.version} + + net.alchim31 + livereload-jvm + 0.2.0 + @@ -51,40 +56,52 @@ - - - org.apache.maven.plugins - maven-invoker-plugin - 1.10 - - true - - ${project.version} - - src/it - - **/pom.xml - - - ${project.build.directory}/it - - ${project.build.directory}/local-repo - - src/it/settings.xml - verify.groovy - - - - - - install - run - - - - - + + + integration-tests + + + !skip_integration + + + + + + org.apache.maven.plugins + maven-invoker-plugin + 1.10 + + true + + ${project.version} + + src/it + + **/pom.xml + + + ${project.build.directory}/it + + ${project.build.directory}/local-repo + + src/it/settings.xml + verify.groovy + + + + + + install + run + + + + + + + + \ No newline at end of file diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/LiveReload.java b/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/LiveReload.java new file mode 100644 index 00000000..22e6cdb3 --- /dev/null +++ b/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/LiveReload.java @@ -0,0 +1,158 @@ +package org.ndx.agile.architecture.documentation.system.maven.plugin; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.element; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.name; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import java.io.File; +import java.io.IOException; +import java.net.ServerSocket; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Executors; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.ndx.agile.architecture.base.enhancers.ModelElementKeys.ConfigProperties.WorkspaceDsl; +import org.twdata.maven.mojoexecutor.MojoExecutor.Element; + +import net_alchim31_livereload.LRServer; //#from net.alchim31:livereload-jvm:0.2.0 + +@Mojo(name = "livereload", defaultPhase = LifecyclePhase.PACKAGE) +public class LiveReload extends AbstractMojo { + + @Component + private MavenProject mavenProject; + + @Component + private MavenSession mavenSession; + + @Component + private BuildPluginManager pluginManager; + /** + * Input folder where asciidoc files are stored. + */ + @Parameter(name="html-docs-source-dir", defaultValue="${project.basedir}/src/docs/asciidoc", property = "asciidoc.source.docs.directory") + private File htmlDocsSourceDir; + /** + * Input folder where asciidoc files for slides are stored + */ + @Parameter(name="html-slides-source-dir", defaultValue="${project.basedir}/src/slides/asciidoc", property = "asciidoc.source.slides.directory") + private File htmlSlidesSourceDir; + /** + * Input workspace.dsl file + */ + @Parameter(name="architecture-dsl", defaultValue=WorkspaceDsl.VALUE, property = WorkspaceDsl.NAME) + private File architectureDsl; + @Parameter(defaultValue="${project.build.sourceDirectory}", readonly = true, required = true) + private File javaSourcesDir; + + /** + * Port used for livereload of generated documentation + */ + @Parameter(name="livereload-port", defaultValue="35729") + private int livereloadPort; + + /** + * List of goals to execute after live-reload. + * As it is a list, the default value is not provided in a way compatible with maven annotation. + * + * The default value for that goal is + * + * + */ + @Parameter(name="goals-to-execute") + private List goalsToExecute = Arrays.asList("prepare-package", + "io.github.Riduidel.agile-architecture-documentation-system:aadarchi-maven-plugin@generate-html-docs", + "io.github.Riduidel.agile-architecture-documentation-system:aadarchi-maven-plugin@generate-html-slides" + ); + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + try (ServerSocket test = new ServerSocket(livereloadPort)){ + getLog().debug(String.format("port %d can be used", livereloadPort)); + } catch (IOException e) { + throw new MojoFailureException(String.format("port %d not available", livereloadPort)); + } + + Path docroot = FileSystems.getDefault().getPath(mavenProject.getBuild().getDirectory()); + Executors.newSingleThreadExecutor().execute(() -> { + try { + new LRServer(livereloadPort, docroot).run(); // == start() + join() + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + + executeMojo( + plugin( + groupId("com.fizzed"), + artifactId("fizzed-watcher-maven-plugin"), + version("1.0.6") + ), + goal("run"), + configuration( + element(name("touchFile"), "target/watcher.touchfile"), + element(name("watches"), + watches() + ), + element(name("goals"), + goals() + ) + ), + executionEnvironment( + mavenProject, + mavenSession, + pluginManager + ) + ); + } + + private Element[] goals() { + // First, get our artifact name + return goalsToExecute.stream() + .map(text -> element(name("goal"), text)) + .toArray(Element[]::new); + } + + private Element[] watches() { + List files = new ArrayList(Arrays.asList( + javaSourcesDir, + htmlDocsSourceDir, + htmlSlidesSourceDir, + architectureDsl.getParentFile() + )); + + for(Resource r : mavenProject.getResources()) { + files.add(new File(r.getDirectory())); + } + + return files.stream() + .filter(File::exists) + .map(File::getAbsolutePath) + .map(text -> element(name("watch"), element(name("directory"), text))).toArray(Element[]::new); + } +} diff --git a/architecture-documentation/pom.xml b/architecture-documentation/pom.xml index 55597ad9..8bd27116 100644 --- a/architecture-documentation/pom.xml +++ b/architecture-documentation/pom.xml @@ -324,80 +324,16 @@ package - org.codehaus.mojo - exec-maven-plugin - - - package - start-livereload-server in background - - exec - - - - java - - - -classpath - - net.alchim31:livereload-jvm - org.eclipse.jetty:jetty-util - org.eclipse.jetty:jetty-io - org.eclipse.jetty.orbit:javax.servlet:jar - org.eclipse.jetty:jetty-continuation - org.eclipse.jetty:jetty-server - org.eclipse.jetty.orbit:javax.servlet - org.eclipse.jetty:jetty-http - com.googlecode.json-simple:json-simple - org.eclipse.jetty:jetty-websocket - - net_alchim31_livereload.Main - -d - ${asciidoc.target.base.directory} - - true - true - - - - - - com.fizzed - fizzed-watcher-maven-plugin + ${project.groupId} + aadarchi-maven-plugin + ${project.version} - watch source + generate-html-slides package - run + livereload - - target/watcher.touchfile - - - ${project.basedir}/src/main/java - - - ${project.basedir}/src/architecture/resources - - - ${project.basedir}/src/main/resources - - - ${project.basedir}/src/docs/asciidoc - - - ${project.basedir}/src/slides/asciidoc - - - - prepare-package - org.asciidoctor:asciidoctor-maven-plugin:process-asciidoc@generate-slides - org.asciidoctor:asciidoctor-maven-plugin:process-asciidoc@generate-html-doc - - diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/ModelElementKeys.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/ModelElementKeys.java index aa52aae7..9cd99840 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/ModelElementKeys.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/ModelElementKeys.java @@ -34,6 +34,10 @@ public interface ModelElementKeys { * */ public static interface ConfigProperties { + public static interface WorkspaceDsl { + public String NAME = ModelElementKeys.PREFIX + "dsl"; + public String VALUE = "${project.basedir}/src/architecture/resources/workspace.dsl"; + } public static interface AsciidocSourceDir { public String NAME = "asciidoc.source.docs.directory"; public String VALUE = "${project.basedir}/src/docs/asciidoc"; diff --git a/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java b/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java index bb1c2a07..fcf9e495 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java @@ -9,7 +9,7 @@ import org.apache.deltaspike.core.api.config.ConfigProperty; import org.ndx.agile.architecture.base.ArchitectureModelProvider; -import org.ndx.agile.architecture.base.enhancers.ModelElementKeys; +import org.ndx.agile.architecture.base.enhancers.ModelElementKeys.ConfigProperties.WorkspaceDsl; import com.structurizr.Workspace; import com.structurizr.dsl.StructurizrDslParser; @@ -19,9 +19,8 @@ @Named("Using workspace.dsl") public class FromDsl implements ArchitectureModelProvider { - private static final String WORKSPACE_DSL = ModelElementKeys.PREFIX + "dsl"; @Inject - @ConfigProperty(name = WORKSPACE_DSL, defaultValue = "${project.basedir}/src/architecture/resources/workspace.dsl") File workspace; + @ConfigProperty(name = WorkspaceDsl.NAME, defaultValue = WorkspaceDsl.VALUE) File workspace; @Override public Workspace describeArchitecture() { @@ -31,7 +30,7 @@ public Workspace describeArchitecture() { + "We tried to read file %s but there was nothing.\n" + "Please either move that file into that location or set the property %s", workspace.getAbsolutePath(), - WORKSPACE_DSL)); + WorkspaceDsl.NAME)); } StructurizrDslParser parser = new StructurizrDslParser(); try {