All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.jredmine.plugin.UpdateVersionMojo Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
/*
 * #%L
 * JRedmine :: Maven plugin
 * 
 * $Id: UpdateVersionMojo.java 210 2011-06-04 16:57:56Z tchemit $
 * $HeadURL: http://svn.nuiton.org/svn/jredmine/tags/jredmine-1.2.1/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/UpdateVersionMojo.java $
 * %%
 * Copyright (C) 2009 - 2010 Tony Chemit, CodeLutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */
package org.nuiton.jredmine.plugin;

import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.StringUtils;
import org.nuiton.jredmine.model.ModelHelper;
import org.nuiton.jredmine.model.Version;
import org.nuiton.jredmine.model.VersionStatusEnum;
import org.nuiton.plugin.PluginHelper;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;

/**
 * Create or update a version on redmine server.
 * 

* Will add a the version if not existing, otherwise, will update the version. * * @author tchemit * @goal update-version * @since 1.0.0 */ public class UpdateVersionMojo extends AbstractRedmineMojo { /** * Flag to know if anonymùous connexion to redmine server is required. *

* Note: If set to {@code false}, you should fill {@link #username} * and {@link #password} properties. * * @parameter expression="${redmine.anonymous}" default-value="false" * @since 1.1.3 */ protected boolean anonymous; /** * The news description to update to redmine server. *

* Note : if not set, no update of the description will be made. * * @parameter expression="${redmine.versionDescription}" * @since 1.0.0 */ protected String versionDescription; /** * A flag to close the version on redmine (will fix effectiveDate). *

* The status of the version will be setted to {@code closed} then. * * @parameter expression="${redmine.closeVersion}" default-value="false" * @since 1.0.0 */ protected boolean closeVersion; /** * The effective date to set on the version. *

* The format of the date is {@code yyyy-mm-dd}. *

* If not Set - will use current day date only if {@link #closeVersion} * flag is on. * * @parameter expression="${redmine.effectiveDate}" * @since 1.0.0 */ protected String effectiveDate; /** * The status to set on the version amoung values {@code open, lock, closed}. *

* If not Set - will use the {@code closed} value only if * {@link #closeVersion} flag is on. * * @parameter expression="${redmine.versionStatus}" * @since 1.2.1 */ protected String versionStatus; /** * A flag to skip the goal. * * @parameter expression="${redmine.skipUpdateVersion}" default-value="false" * @since 1.0.0 */ protected boolean skipUpdateVersion; /** * A flag to test plugin but send nothing to redmine. * * @parameter expression="${redmine.dryRun}" default-value="false" * @since 1.0.0 */ protected boolean dryRun; /** * A flag to restirct only one run in a build (for multi-module context). * * @parameter expression="${redmine.runOnce}" default-value="true" * @since 1.0.0 */ protected boolean runOnce; /** effective date to set */ private Date date; /** * new status to apply (stay null if nothing is asked). * * @since 1.2.1 */ private VersionStatusEnum newVersionStatus; public UpdateVersionMojo() { super(true, false, true); } @Override public boolean isAnonymous() { return anonymous; } @Override public void setAnonymous(boolean anonymous) { this.anonymous = anonymous; } @Override protected boolean isGoalSkip() { return skipUpdateVersion; } @Override protected boolean isRunOnce() { return runOnce; } @Override protected boolean checkRunOnceDone() { return isRunOnce() && !isExecutionRoot(); } @Override protected void init() throws Exception { if (versionId == null || versionId.trim().isEmpty()) { throw new MojoExecutionException("required a versionId parameter"); } versionId = PluginHelper.removeSnapshotSuffix(versionId); runOnceDone = false; if (isRunOnce()) { runOnceDone = checkRunOnceDone(); if (runOnceDone) { return; } } if (effectiveDate != null && !effectiveDate.trim().isEmpty()) { try { date = dateFormat.parse(effectiveDate); } catch (ParseException e) { throw new MojoExecutionException( "could not parse effectivate date " + effectiveDate + " for reason " + e.getMessage(), e); } } else if (closeVersion) { date = new Date(); } if (closeVersion) { // by default use the closed status when closing a version newVersionStatus = VersionStatusEnum.closed; } if (StringUtils.isNotEmpty(versionStatus)) { try { newVersionStatus = VersionStatusEnum.valueOf(versionStatus); } catch (IllegalArgumentException e) { throw new MojoExecutionException( "could not parse status " + versionStatus + " for reason " + e.getMessage() + ", should be one of values : " + Arrays.toString(VersionStatusEnum.values()), e); } if (closeVersion) { // warns user if (getLog().isWarnEnabled()) { getLog().warn("While using the closeVersion flag, you " + "should not set also the version status " + ": [" + versionStatus + "]"); } } } super.init(); } @Override protected void doAction() throws Exception { if (dryRun) { getLog().info("\n dryRun flag is on, no data will be send!\n"); } // get version boolean needCreateVersion; Version[] versions = service.getVersions(projectId); Version v = ModelHelper.byVersionName(versionId, versions); if (v == null) { // version must be created needCreateVersion = true; v = new Version(); v.setName(versionId); } else { needCreateVersion = false; } if (versionDescription != null && !versionDescription.trim().isEmpty()) { v.setDescription(versionDescription.trim()); } if (date != null) { v.setEffectiveDate(date); } if (newVersionStatus != null) { // change status of the version if (isVerbose()) { getLog().info("Will set status " + newVersionStatus); } v.setStatus(newVersionStatus.name()); } releaseVersion = v; // prepare version if (needCreateVersion) { // create version getLog().info("create version " + releaseVersion.getName()); if (!dryRun) { service.addVersion(projectId, releaseVersion); } } else { // update version getLog().info("udpate version " + releaseVersion.getName()); if (!dryRun) { service.updateVersion(projectId, releaseVersion); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy