You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2024/05/01 14:06:01 UTC
(jspwiki) 02/04: JSPWIKI-1190: generate markdown flavour of wikipages as part of the build
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit f79d41cb5b60942a365000a2a435e1c8f40ae178
Author: Juan Pablo Santos RodrÃguez <ju...@gmail.com>
AuthorDate: Wed May 1 16:03:19 2024 +0200
JSPWIKI-1190: generate markdown flavour of wikipages as part of the build
---
jspwiki-markdown/pom.xml | 13 +++++++++
.../markdown/migration/WikiSyntaxConverter.java | 34 ++++++++++++++++++----
jspwiki-wikipages/.gitignore | 1 +
.../assembly/{zip.xml => zip-markdown.xml} | 4 +--
jspwiki-wikipages/assembly/zip.xml | 6 +++-
jspwiki-wikipages/pom.xml | 15 ++++++++++
6 files changed, 64 insertions(+), 9 deletions(-)
diff --git a/jspwiki-markdown/pom.xml b/jspwiki-markdown/pom.xml
index 359328456..2b19c5495 100644
--- a/jspwiki-markdown/pom.xml
+++ b/jspwiki-markdown/pom.xml
@@ -154,6 +154,19 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-markdown-pages</id>
+ <goals><goal>test</goal></goals>
+ <configuration>
+ <test>WikiSyntaxConverter</test>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
diff --git a/jspwiki-markdown/src/test/java/org/apache/wiki/markdown/migration/WikiSyntaxConverter.java b/jspwiki-markdown/src/test/java/org/apache/wiki/markdown/migration/WikiSyntaxConverter.java
index 7e26ea68a..e42cf7b36 100644
--- a/jspwiki-markdown/src/test/java/org/apache/wiki/markdown/migration/WikiSyntaxConverter.java
+++ b/jspwiki-markdown/src/test/java/org/apache/wiki/markdown/migration/WikiSyntaxConverter.java
@@ -18,12 +18,14 @@
*/
package org.apache.wiki.markdown.migration;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.wiki.TestEngine;
import org.apache.wiki.api.core.Attachment;
import org.apache.wiki.api.core.Context;
import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.core.Page;
+import org.apache.wiki.api.exceptions.WikiException;
import org.apache.wiki.api.spi.Wiki;
import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.htmltowiki.HtmlStringToWikiTranslator;
@@ -31,21 +33,41 @@ import org.apache.wiki.markdown.migration.parser.JSPWikiToMarkdownMarkupParser;
import org.apache.wiki.pages.PageManager;
import org.apache.wiki.plugin.PluginManager;
import org.apache.wiki.render.RenderingManager;
-import org.junit.jupiter.api.Test;
+import org.jdom2.JDOMException;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static org.apache.wiki.TestEngine.with;
-public class WikiSyntaxConverter {
+/**
+ * <p>Class used to autogenerate the initial set of markdown files, derived from the ones with jspwiki syntax, as part
+ * of the build,</p>
+ * <p>Can be used as a starting point to develop more complex converters from jspwiki to markdown syntax f.ex, to also
+ * convert page history, retain original authors, etc.</p>
+ */
+class WikiSyntaxConverter {
+
+ @ParameterizedTest
+ @ValueSource( strings = { "de", "en", "es", "fi", "fr", "it", "nl", "pt_BR", "ru", "zh_CN" } )
+ void jspwikiToMarkdownConverter( final String lang ) throws Exception {
+ final File target = new File( "../jspwiki-wikipages/" + lang + "/src/main/resources/markdown" );
+ target.delete();
+ translateJSPWikiToMarkdown( lang );
+ Arrays.stream( ArrayUtils.nullToEmpty( target.listFiles( ( dir, name ) -> name.endsWith( ".properties" ) ), File[].class ) )
+ .forEach( file -> file.delete() );
+ }
- @Test
- void jspwikiToMarkdownConverter() throws Exception {
- final Engine jspw = buildEngine( "jspwiki", "../jspwiki-wikipages/en/src/main/resources" );
- final Engine md = buildEngine( "markdown", "./target/pages-markdown" );
+ void translateJSPWikiToMarkdown( String lang ) throws JDOMException, IOException, ReflectiveOperationException, WikiException {
+ final Engine jspw = buildEngine( "jspwiki", "../jspwiki-wikipages/" + lang + "/src/main/resources" );
+ final Engine md = buildEngine( "markdown", "../jspwiki-wikipages/" + lang + "/src/main/resources/markdown" );
jspw.getManager( PluginManager.class ).enablePlugins( false );
final Collection< Page > pages = jspw.getManager( PageManager.class ).getAllPages();
diff --git a/jspwiki-wikipages/.gitignore b/jspwiki-wikipages/.gitignore
new file mode 100644
index 000000000..b0816431c
--- /dev/null
+++ b/jspwiki-wikipages/.gitignore
@@ -0,0 +1 @@
+*/src/main/resources/markdown/
diff --git a/jspwiki-wikipages/assembly/zip.xml b/jspwiki-wikipages/assembly/zip-markdown.xml
similarity index 93%
copy from jspwiki-wikipages/assembly/zip.xml
copy to jspwiki-wikipages/assembly/zip-markdown.xml
index 872cb1cb3..960fc8e03 100644
--- a/jspwiki-wikipages/assembly/zip.xml
+++ b/jspwiki-wikipages/assembly/zip-markdown.xml
@@ -20,14 +20,14 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
- <id>zip</id>
+ <id>markdown</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory></outputDirectory>
- <directory>src/main/resources</directory>
+ <directory>src/main/resources/markdown</directory>
<fileMode>0644</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
diff --git a/jspwiki-wikipages/assembly/zip.xml b/jspwiki-wikipages/assembly/zip.xml
index 872cb1cb3..00d159b92 100644
--- a/jspwiki-wikipages/assembly/zip.xml
+++ b/jspwiki-wikipages/assembly/zip.xml
@@ -20,7 +20,7 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
- <id>zip</id>
+ <id>jspwiki</id>
<formats>
<format>zip</format>
</formats>
@@ -28,6 +28,10 @@
<fileSet>
<outputDirectory></outputDirectory>
<directory>src/main/resources</directory>
+ <excludes>
+ <exclude>markdown</exclude>
+ <exclude>markdown/*</exclude>
+ </excludes>
<fileMode>0644</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
diff --git a/jspwiki-wikipages/pom.xml b/jspwiki-wikipages/pom.xml
index 52a2409f0..78bde6a91 100644
--- a/jspwiki-wikipages/pom.xml
+++ b/jspwiki-wikipages/pom.xml
@@ -59,4 +59,19 @@
</plugins>
</pluginManagement>
</build>
+
+ <dependencies>
+ <dependency><!-- artificial dependency just to ensure that the wiki pages are built after the markdown module has generated the markdown pages -->
+ <groupId>org.apache.jspwiki</groupId>
+ <artifactId>jspwiki-markdown</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
</project>