org.bsc.mojo.ConfluenceExportMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of confluence-reporting-maven-plugin Show documentation
Show all versions of confluence-reporting-maven-plugin Show documentation
plugin that document a project (using maven site style) and send result to a live confluence site
[http://www.atlassian.com/software/confluence/]
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.bsc.mojo;
import java.util.Optional;
import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.bsc.confluence.ConfluenceService;
import org.bsc.confluence.ConfluenceService.Model;
import org.bsc.confluence.ExportFormat;
/**
* Export a confluence page either in PDF or DOC
*
* @author bsorrentino
*
* @since 3.4.3
*/
@Mojo( name="export", threadSafe = true, requiresProject = false )
public class ConfluenceExportMojo extends AbstractBaseConfluenceMojo {
/**
* title of pageTitle that will be deleted
*
* @since 3.4.3
*/
@Parameter(alias = "title", property = "confluence.page", defaultValue = "${project.build.finalName}")
private String pageTitle;
/**
*
* type of output - either 'pdf' or 'doc'
*
* @since 3.4.3
*/
@Parameter(alias = "outputType", property = "outputType", defaultValue = "pdf")
private String outputType;
/**
*
* output file - if missing it will be ${project.build.directory}/${title}.${outputType}
*
* @since 3.4.3
*/
@Parameter(alias = "outputFile")
private java.io.File outputFile;
@Parameter(property="project.build.directory", readonly = true)
private java.io.File outputDirectory;
private void exportPage( ConfluenceService confluence ) throws Exception {
final ExportFormat exfmt = ExportFormat.valueOf( outputType.toUpperCase() );
final Model.Page parentPage = loadParentPage(confluence, Optional.empty())
.join();
if( outputFile == null ) {
outputFile = ( outputDirectory == null ) ?
new java.io.File( String.format("%s.%s", pageTitle, exfmt.name().toLowerCase())) :
new java.io.File( outputDirectory, String.format("%s.%s", pageTitle, exfmt.name().toLowerCase()))
;
}
FileUtils.forceMkdir( new java.io.File(outputFile.getParent()) );
final String url = ConfluenceService.Protocol.XMLRPC.removeFrom(ConfluenceExportMojo.super.getEndPoint());
confluence.exportPage( url,
parentPage.getSpace(),
pageTitle, //parentPage.getTitle(),
exfmt,
outputFile);
}
/**
*
* @throws MojoExecutionException
* @throws MojoFailureException
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
super.loadUserInfoFromSettings();
super.confluenceExecute( (ConfluenceService confluence) -> {
try {
exportPage(confluence);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy