Skip to content

Commit

Permalink
refactor: move generateGoalsPages method in AbstractPluginConfluenceD…
Browse files Browse the repository at this point in the history
…ocGenerator
  • Loading branch information
bsorrentino committed Feb 29, 2024
1 parent 564e2b9 commit d1a9a91
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 67 deletions.
43 changes: 12 additions & 31 deletions mojo/src/main/java/org/bsc/mojo/ConfluenceDeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -51,7 +52,7 @@
import org.bsc.confluence.ParentChildTuple;
import org.bsc.confluence.model.Site;
import org.bsc.mojo.configuration.MarkdownProcessorInfo;
import org.bsc.plugin.PluginConfluenceDocGenerator;
import org.bsc.plugin.AbstractPluginConfluenceDocGenerator;
import org.bsc.plugin.renderer.*;
import org.bsc.plugin.sink.ConfluenceSink;
import org.bsc.reporting.renderer.CalculateRuleForSinceTagName;
Expand All @@ -77,8 +78,7 @@ public class ConfluenceDeployMojo extends AbstractConfluenceDeployMojo {
private static final String GITLOG_JIRA_ISSUES_VAR = "gitlog.jiraIssues";
private static final String GITLOG_SINCE_TAG_NAME = "gitlog.sinceTagName";

public static final String PLUGIN_SUMMARY_VAR = "plugin.summary";
public static final String PLUGIN_GOALS_VAR = "plugin.goals";


/**
* Local Repository.
Expand Down Expand Up @@ -769,37 +769,16 @@ private void generatePluginReport( ConfluenceService confluence, final Site site
//
}

class PluginGenerator extends PluginConfluenceDocGenerator {


final java.util.List<Goal> goals = new ArrayList<>();

void generateGoalsPages(final ConfluenceService confluence,
final Model.Page confluenceHome,
final Map<String, Model.Page> varsToParentPageMap) {

// GENERATE GOAL
getLog().info(format("Get the right page to generate the %s pages under", PLUGIN_GOALS_VAR));

Model.Page goalsParentPage = confluenceHome;

if (varsToParentPageMap.containsKey(PLUGIN_GOALS_VAR)) {
goalsParentPage = varsToParentPageMap.get(PLUGIN_GOALS_VAR);
}
class PluginGenerator extends AbstractPluginConfluenceDocGenerator {

getLog().info(format("Plugin Goals parentPage is: %s", goalsParentPage.getTitle()));

for (PluginConfluenceDocGenerator.Goal goal : goals) {
try {
getLog().info(format("- generating: %s", goal.getPageName(confluenceHome.getTitle()) ));
goal.generatePage(confluence, goalsParentPage, confluenceHome.getTitle());
} catch (Exception ex) {
getLog().warn(format("error generatig page for goal [%s]", goal.descriptor.getGoal()), ex);
}
}

@Override
public Log getLog() {
return ConfluenceDeployMojo.this.getLog();
}


/**
*
* @param site
Expand Down Expand Up @@ -874,7 +853,7 @@ private CompletableFuture<Storage> getHomeContent(
final StringWriter writer = new StringWriter(100 * 1024);

//writeGoals(writer, mojos);
goals.addAll(writeGoalsAsChildren(writer, title, mojos));
getGoals().addAll(writeGoalsAsChildren(writer, title, mojos));

writer.flush();

Expand Down Expand Up @@ -978,7 +957,7 @@ private CompletableFuture<Model.Page> updateHomeContent(
final StringWriter writer = new StringWriter(100 * 1024);

//writeGoals(writer, mojos);
goals.addAll(writeGoalsAsChildren(writer, title, mojos));
getGoals().addAll(writeGoalsAsChildren(writer, title, mojos));

writer.flush();

Expand Down Expand Up @@ -1062,5 +1041,7 @@ public Model.Page processMojoDescriptors(
.join();

}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
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 java.util.Optional;
import java.util.*;
import java.util.concurrent.CompletableFuture;

import static java.lang.String.format;
import static org.bsc.confluence.ConfluenceHtmlUtils.replaceHTML;
import static org.bsc.plugin.ConfluenceWikiWriter.createAnchor;
import static org.bsc.plugin.ConfluenceWikiWriter.createLinkToAnchor;
Expand All @@ -31,9 +29,10 @@
* @author Sorrentino
*
*/
public abstract class PluginConfluenceDocGenerator implements Generator {
public abstract class AbstractPluginConfluenceDocGenerator implements Generator {

//private static final Logger LOGGER = LoggerFactory.getLogger(PluginConfluenceDocGenerator.class);
public static final String PLUGIN_SUMMARY_VAR = "plugin.summary";
public static final String PLUGIN_GOALS_VAR = "plugin.goals";

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

Expand Down Expand Up @@ -66,13 +65,10 @@ public void write(ConfluenceWikiWriter w) {
writeParameterTable( w);

}

public String getPageName( String parentName ) {
final String goalName = String.format( "%s - %s", parentName, descriptor.getGoal());

return goalName;
}

public String getPageName(String parentName ) {
return String.format( "%s - %s", parentName, descriptor.getGoal());
}
public Model.Page generatePage( ConfluenceService confluence, Model.Page parent, String parentName ) throws Exception {

final String goalName = getPageName( parentName );
Expand All @@ -99,7 +95,7 @@ public Model.Page generatePage( ConfluenceService confluence, Model.Page parent

/**
*
* @param w
* @param w ConfluenceWikiWriter
*/
private void writeAttributes(ConfluenceWikiWriter w) {
w.printNormalHeading("Mojo Attributes");
Expand Down Expand Up @@ -166,7 +162,7 @@ private void writeAttributes(ConfluenceWikiWriter w) {

/**
*
* @param w
* @param w ConfluenceWikiWriter
*/
private void writeParameterTable(ConfluenceWikiWriter w) {
List<Parameter> parameterList = descriptor.getParameters();
Expand All @@ -182,8 +178,44 @@ private void writeParameterTable(ConfluenceWikiWriter w) {
}

};



public abstract org.apache.maven.plugin.logging.Log getLog();


final java.util.List<Goal> goals = new ArrayList<>();

public java.util.List<Goal> getGoals() {
return goals;
}

public void generateGoalsPages(final ConfluenceService confluence,
final Model.Page confluenceHome,
final Map<String, Model.Page> varsToParentPageMap) {

// GENERATE GOAL
getLog().info(format("Get the right page to generate the %s pages under", PLUGIN_GOALS_VAR));

Model.Page goalsParentPage = confluenceHome;

if (varsToParentPageMap.containsKey(PLUGIN_GOALS_VAR)) {
goalsParentPage = varsToParentPageMap.get(PLUGIN_GOALS_VAR);
}

getLog().info(format("Plugin Goals parentPage is: %s", goalsParentPage.getTitle()));

for (Goal goal : goals) {
try {
getLog().info(format("- generating: %s", goal.getPageName(confluenceHome.getTitle()) ));
var page = goal.generatePage(confluence, goalsParentPage, confluenceHome.getTitle());
getLog().debug(format("page generated: %s", page.getTitle()));

} catch (Exception ex) {
getLog().warn(format("error generating page for goal [%s]", goal.descriptor.getGoal()), ex);
}
}

}

/**
*
* @param destinationDirectory
Expand All @@ -210,8 +242,8 @@ public void execute(File destinationDirectory, PluginToolsRequest request) throw

/**
*
* @param writer
* @param pluginDescriptor
* @param writer Writer
* @param pluginDescriptor Plugin Descriptor
*/
protected void writeSummary(Writer writer, PluginDescriptor pluginDescriptor) {

Expand All @@ -220,7 +252,7 @@ protected void writeSummary(Writer writer, PluginDescriptor pluginDescriptor) {
w.printBiggerHeading("Description");

Optional.ofNullable(pluginDescriptor.getDescription())
.ifPresent( description -> w.println(description) );
.ifPresent(w::println);

w.printNewParagraph();
}
Expand Down Expand Up @@ -278,11 +310,7 @@ private void writeGoals(Writer writer, List<MojoDescriptor> mojos) {

}

/**
*
* @param parameterList
* @return
*/

private List<Parameter> filterParameters(List<Parameter> parameterList) {
List<Parameter> filtered = new ArrayList<Parameter>();

Expand All @@ -304,8 +332,8 @@ private List<Parameter> filterParameters(List<Parameter> parameterList) {

/**
*
* @param parameterList
* @param w
* @param parameterList list of parameters
* @param w writer
*/
private void writeParameterDetails(List<Parameter> parameterList, ConfluenceWikiWriter w) {
w.printNormalHeading("Parameter Details");
Expand Down Expand Up @@ -351,8 +379,8 @@ private void writeDetail(String param, String value, ConfluenceWikiWriter w) {

/**
*
* @param parameterList
* @param w
* @param parameterList list of parameters
* @param w writer
*/
private void writeParameterSummary(List<Parameter> parameterList, ConfluenceWikiWriter w) {
List<Parameter> requiredParams = getParametersByRequired(true, parameterList);
Expand All @@ -368,9 +396,9 @@ private void writeParameterSummary(List<Parameter> parameterList, ConfluenceWiki

/**
*
* @param title
* @param parameterList
* @param w
* @param title title
* @param parameterList list of parameters
* @param w writer
*/
private void writeParameterList(String title, List<Parameter> parameterList, ConfluenceWikiWriter w) {
w.printNormalHeading(title);
Expand Down Expand Up @@ -415,9 +443,9 @@ private void writeParameterList(String title, List<Parameter> parameterList, Con

/**
*
* @param required
* @param parameterList
* @return
* @param required true if required, false if optional
* @param parameterList list of parameters
* @return list of parameters
*/
private List<Parameter> getParametersByRequired(boolean required, List<Parameter> parameterList) {
if( parameterList == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ConfluenceWikiWriter appendBigHeading() {
* This macro is useful for including helpful information in your confluence pages
* {info}
*
* @param value
* @param value value
*/
public void printInfo( String title, String value ) {
printf( "{info:title=%s}\n%s\n{info}", title, value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* Sink to produce confluence wiki render.
*
* @plexus.component role="cosm.maven.reporting.Sink" role-hint="Confluence"
* @plexus.component role="com.maven.reporting.Sink" role-hint="Confluence"
*
* @author Sorrentino
*
Expand Down

0 comments on commit d1a9a91

Please sign in to comment.