Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support more tags in the plugin doc generation #115

Merged
merged 2 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ public class ConfluenceUtils {
* @return
*/
public static String decode( String value ) {
if( null==value ) return value;
if( null==value ) return null;
final String result = value
.replace("{", "\\{")
.replace("}", "\\}")
.replaceAll("</?[Pp][Rr][Ee]>", "{noformat}")
.replaceAll("<[Cc][Oo][Dd][Ee]>", "{{")
.replaceAll("</[Cc][Oo][Dd][Ee]>", "}}")
.replaceAll("</?[Bb]>", "*")
.replaceAll("<[Bb][Rr]/?>", "\\\\")
.replaceAll("<[Hh][Rr]/?>", "----")
.replaceAll("<[Pp]>", "\n\n")
.replaceAll("</[Pp]>", "")
.replaceAll("([{}\\[\\]\\+\\*_])", "\\\\$1") // escape every char that would mean something for confluence
.replaceAll("(?i)</?pre>", "{noformat}")
.replaceAll("(?i)<code>", "{{")
.replaceAll("(?i)</code>", "}}")
.replaceAll("(?i)</?(b|strong)>", "*")
.replaceAll("(?i)<br/?>", "\\\\")
.replaceAll("(?i)<hr/?>", "----")
.replaceAll("(?i)</?p>", "\n")
.replaceAll("(?i)</?u>", "+")
.replaceAll("(?i)</?(s|del)>", "-")
.replaceAll("(?i)</?(i|em)>", "_")

;
return ConfluenceHtmlListUtils.replaceHtmlList(result);
Expand Down Expand Up @@ -95,7 +96,6 @@ public static PageSummary findPageByTitle( Confluence confluence, String parent
/**
*
* @param confluence
* @param parentPageId
* @param title
* @return
* @throws Exception
Expand Down Expand Up @@ -135,7 +135,6 @@ public static boolean removePage( Confluence confluence, Page parentPage, String
/**
*
* @param confluence
* @param parentPageId
* @param title
* @return
* @throws Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.bsc.confluence;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class ConfluenceUtilsTest {

@Test
public void decode() throws Exception {
String input = "<coDe>[I][RE]'.*moon[^dab]+'</CODE> : <EM>all</Em> <u>implemented</U> <s>specifications</S> <DEL>having</del> <Strong>the</Strong> <i>RE<I> '.*moon[^dab]+'";
String decoded = ConfluenceUtils.decode(input);
assertThat(decoded, is("{{\\[I\\]\\[RE\\]'.\\*moon\\[^dab\\]\\+'}} : _all_ +implemented+ -specifications- -having- *the* _RE_ '.\\*moon\\[^dab\\]\\+'"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void execute(Confluence confluence) throws Exception {

confluence.addLabelByName(label, Long.parseLong(confluenceHomePage.getId()) );
}

generateChildren( confluence, site.getHome(), confluenceHomePage, title, titlePrefix);
}

Expand Down Expand Up @@ -732,8 +732,6 @@ class PluginGenerator extends PluginConfluenceDocGenerator {

/**
*
* @param mojoDescriptor
* @param destinationDirectory
* @throws IOException
*/
public Page processMojoDescriptors(final PluginDescriptor pluginDescriptor,
Expand Down Expand Up @@ -762,12 +760,12 @@ public Page processMojoDescriptors(final PluginDescriptor pluginDescriptor,
getProperties().put("version", getProject().getVersion());

final java.io.InputStream is = Site.processUri(site.getHome().getUri(), getTitle()) ;

final MiniTemplator t = new MiniTemplator.Builder()
.setSkipUndefinedVars(true)
.build( is, getCharset() );

/*
/*
if (templateWiki == null || !templateWiki.exists()) {

getLog().warn("template not set! default using ...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package org.bsc.maven.confluence.plugin;

import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.tools.plugin.generator.GeneratorException;
import org.bsc.confluence.ConfluenceUtils;
import static org.bsc.confluence.ConfluenceUtils.decode;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.swizzle.confluence.Confluence;
import org.codehaus.swizzle.confluence.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.generator.Generator;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.swizzle.confluence.Confluence;
import org.codehaus.swizzle.confluence.Page;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import java.util.Collections;
import org.apache.maven.tools.plugin.generator.GeneratorException;
import static org.bsc.confluence.ConfluenceUtils.decode;

/**
*
Expand All @@ -29,6 +31,8 @@
@SuppressWarnings("unchecked")
public abstract class PluginConfluenceDocGenerator implements Generator {

private static final Logger LOGGER = LoggerFactory.getLogger(PluginConfluenceDocGenerator.class);

public static final String DEFAULT_PLUGIN_TEMPLATE_WIKI = "defaultPluginTemplate.confluence";

class Goal {
Expand All @@ -39,19 +43,14 @@ public Goal(MojoDescriptor mojoDescriptor) {
this.descriptor = mojoDescriptor;
}

/**
*
* @param writer
* @param mojoDescriptor
*/
public void write(ConfluenceWikiWriter w) {

w.appendBigHeading()
.appendAnchor(descriptor.getGoal(), descriptor.getFullGoalName())
.println();

String description = (descriptor.getDescription() != null)
? descriptor.getDescription()
? decode(descriptor.getDescription())
: "No description.";

w.printQuote(description);
Expand All @@ -73,7 +72,7 @@ public String getPageName( String parentName ) {
}

public Page generatePage( Confluence confluence, Page parent, String parentName ) throws Exception {

final String goalName = getPageName( parentName );

Page result = ConfluenceUtils.getOrCreatePage(confluence, parent, goalName);
Expand All @@ -86,7 +85,10 @@ public Page generatePage( Confluence confluence, Page parent, String parentName

writer.flush();

result.setContent(writer.toString());
String content = writer.toString();
LOGGER.debug("{} content to write:\n{}", goalName, content);

result.setContent(content);

result = confluence.storePage(result);

Expand All @@ -96,7 +98,6 @@ public Page generatePage( Confluence confluence, Page parent, String parentName

/**
*
* @param mojoDescriptor
* @param w
*/
private void writeAttributes(ConfluenceWikiWriter w) {
Expand Down Expand Up @@ -164,7 +165,6 @@ private void writeAttributes(ConfluenceWikiWriter w) {

/**
*
* @param mojoDescriptor
* @param w
*/
private void writeParameterTable(ConfluenceWikiWriter w) {
Expand Down Expand Up @@ -245,7 +245,7 @@ protected java.util.List<Goal> writeGoalsAsChildren( Writer writer, Page parent,
w.printf( "[%s|%s]",goal.descriptor.getFullGoalName(),
goal.getPageName(parentName) );
w.print('|');
w.print(goal.descriptor.getDescription());
w.print(decode(goal.descriptor.getDescription()));
w.println('|');

//w.appendBullet()
Expand Down