net.sourceforge.javadpkg.plugin.DebianPackageMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dpkg-maven-plugin Show documentation
Show all versions of dpkg-maven-plugin Show documentation
The plugin for creating Debian Packages during a Maven build process.
The newest version!
/*
* dpkg - Debian Package library and the Debian Package Maven plugin
* (c) Copyright 2016 Gerrit Hohl
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.sourceforge.javadpkg.plugin;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.logging.Log;
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.apache.maven.settings.Settings;
import net.sourceforge.javadpkg.BuildException;
import net.sourceforge.javadpkg.ChangeLog;
import net.sourceforge.javadpkg.Context;
import net.sourceforge.javadpkg.Copyright;
import net.sourceforge.javadpkg.DebianPackageBuilder;
import net.sourceforge.javadpkg.DebianPackageBuilderFactory;
import net.sourceforge.javadpkg.GlobalConstants;
import net.sourceforge.javadpkg.ParseException;
import net.sourceforge.javadpkg.Script;
import net.sourceforge.javadpkg.ScriptParser;
import net.sourceforge.javadpkg.ScriptVariableReplacer;
import net.sourceforge.javadpkg.Warning;
import net.sourceforge.javadpkg.control.BinaryControl;
import net.sourceforge.javadpkg.control.Size;
import net.sourceforge.javadpkg.impl.ContextImpl;
import net.sourceforge.javadpkg.impl.DebianPackageBuilderFactoryImpl;
import net.sourceforge.javadpkg.impl.ScriptParserImpl;
import net.sourceforge.javadpkg.impl.ScriptVariableReplacerImpl;
import net.sourceforge.javadpkg.io.DataSource;
import net.sourceforge.javadpkg.io.DataTarget;
import net.sourceforge.javadpkg.io.impl.DataFileSource;
import net.sourceforge.javadpkg.io.impl.DataFileTarget;
import net.sourceforge.javadpkg.io.impl.DataStreamSource;
import net.sourceforge.javadpkg.plugin.cfg.ChangeLogConfiguration;
import net.sourceforge.javadpkg.plugin.cfg.ControlConfiguration;
import net.sourceforge.javadpkg.plugin.cfg.CopyrightConfiguration;
import net.sourceforge.javadpkg.plugin.cfg.DataConfiguration;
import net.sourceforge.javadpkg.plugin.cfg.ScriptConfiguration;
import net.sourceforge.javadpkg.plugin.cfg.ScriptType;
import net.sourceforge.javadpkg.plugin.impl.BinaryControlBuilderImpl;
import net.sourceforge.javadpkg.plugin.impl.ChangeLogConfigurationParserImpl;
import net.sourceforge.javadpkg.plugin.impl.CopyrightConfigurationParserImpl;
import net.sourceforge.javadpkg.plugin.impl.DataConfigurationParserImpl;
import net.sourceforge.javadpkg.plugin.impl.TargetFileBuilderImpl;
import net.sourceforge.javadpkg.replace.ReplacementException;
import net.sourceforge.javadpkg.replace.Replacements;
/**
*
* Creates a Debian package.
*
*
* @author Gerrit Hohl ([email protected])
* @version 1.0, 03.05.2016 by Gerrit Hohl
*/
@Mojo(name = "dpkg", defaultPhase = LifecyclePhase.PACKAGE)
public class DebianPackageMojo extends AbstractMojo implements GlobalConstants {
/** The number format for the metrics in the log. */
private static final DecimalFormat FORMAT = new DecimalFormat("###,###,###,##0");
/** The session. */
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;
/** The project. */
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
/** The MOJO. */
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
private MojoExecution mojo;
/** The plug-in (only available in Maven 3). */
@Parameter(defaultValue = "${plugin}", readonly = true)
private PluginDescriptor plugin;
/** The settings. */
@Parameter(defaultValue = "${settings}", readonly = true)
private Settings settings;
/** The base directory. */
@Parameter(defaultValue = "${project.basedir}", readonly = true)
private File basedir;
/** The target directory. */
@Parameter(defaultValue = "${project.build.directory}", readonly = true)
private File target;
/** The encoding from the project. */
@Parameter(defaultValue = "${project.build.sourceEncoding}", readonly = true)
private String sourceEncoding;
/** The flag if the plug-in should fail if a warning is reported. */
@Parameter(name = "failOnWarning", defaultValue = "true")
private boolean failOnWarning;
/** The flag if the plug-in should be skipped. */
@Parameter(name = "skip", defaultValue = "false")
private boolean skip;
/** The output directory. */
@Parameter(name = "outputDirectory", defaultValue = "${project.build.directory}")
private File outputDirectory;
/** The control configuration. */
@Parameter(name = "control", required = true)
private ControlConfiguration control;
/** The script configurations. */
@Parameter(name = "scripts")
private List scripts;
/** The copyright configuration. */
@Parameter(name = "copyright", required = true)
private CopyrightConfiguration copyright;
/** The change log configuration. */
@Parameter(name = "changeLog", required = true)
private ChangeLogConfiguration changeLog;
/** The data configuration. */
@Parameter(name = "data", required = true)
private DataConfiguration data;
/** The properties. */
@Parameter(name = "properties")
private Properties properties;
/** The parser for the script. */
private ScriptParser scriptParser;
/** The variable replacer for the script. */
private ScriptVariableReplacer scriptVariableReplacer;
/** The parser for the copyright configuration. */
private CopyrightConfigurationParser copyrightConfigurationParser;
/** The parser for the change log configuration. */
private ChangeLogConfigurationParser changeLogConfigurationParser;
/**
*
* Creates the POJO.
*
*/
public DebianPackageMojo() {
super();
this.scriptParser = new ScriptParserImpl();
this.scriptVariableReplacer = new ScriptVariableReplacerImpl();
this.copyrightConfigurationParser = new CopyrightConfigurationParserImpl();
this.changeLogConfigurationParser = new ChangeLogConfigurationParserImpl();
}
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Log log;
Charset defaultEncoding;
DebianPackageBuilderFactory builderFactory;
DebianPackageBuilder builder;
DataConfigurationParser dataConfigurationParser;
File targetDirectory;
Properties pluginProperties;
Replacements replacements;
Size installedSize;
Context context, dataContext;
BinaryControlBuilder binaryControlBuilder;
BinaryControl control;
Copyright copyright;
ChangeLog changeLog;
TargetFileBuilder targetFileBuilder;
// --- Start logging ---
log = this.getLog();
if (log.isInfoEnabled()) {
log.info("dpkg-maven-plugin");
if (log.isDebugEnabled()) {
log.debug("Session : " + this.session);
log.debug("Project : " + this.project);
log.debug("Mojo : " + this.mojo);
log.debug("Plugin : " + this.plugin);
log.debug("Settings : " + this.settings);
log.debug("Basedir : " + this.basedir);
try {
log.debug("Target : " + (this.target == null ? "null" : this.target.getCanonicalPath()));
} catch (IOException e) {
throw new MojoExecutionException("Couldn't create canonical path (removing '..'): " + e.getMessage(), e);
}
try {
log.debug("Output Directory : "
+ (this.outputDirectory == null ? "null" : this.outputDirectory.getCanonicalPath()));
} catch (IOException e) {
throw new MojoExecutionException("Couldn't create canonical path (removing '..'): " + e.getMessage(), e);
}
if ((this.properties == null) || this.properties.isEmpty()) {
log.debug("Properties : No properties defined.");
} else {
log.debug("Properties :");
for (Entry