From 2379bafa025d9e10b127426b208eec0bcd79f53c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 1 Aug 2011 17:27:32 +0200 Subject: [PATCH] improve configuration --- .../sonia/scm/maven/AbstractBaseScmMojo.java | 29 +++- .../java/sonia/scm/maven/AbstractScmMojo.java | 93 +---------- .../java/sonia/scm/maven/WebApplication.java | 146 ++++++++++++++++++ 3 files changed, 178 insertions(+), 90 deletions(-) create mode 100644 maven/scm-maven-plugin/src/main/java/sonia/scm/maven/WebApplication.java diff --git a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractBaseScmMojo.java b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractBaseScmMojo.java index 50676a9410..41e7084f2d 100644 --- a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractBaseScmMojo.java +++ b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractBaseScmMojo.java @@ -45,7 +45,9 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; + +import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ @@ -211,8 +213,29 @@ public abstract class AbstractBaseScmMojo extends AbstractScmMojo protected File getWebApplicationArchive() throws MojoExecutionException { File warFile = null; - Artifact artifact = artifactFactory.createArtifact(groupId, artifactId, - version, "", type); + + if (Util.isEmpty(webApplication.getVersion())) + { + String version = null; + MavenProject parent = project.getParent(); + + if (parent != null) + { + version = parent.getVersion(); + } + else + { + version = project.getVersion(); + } + + webApplication.setVersion(version); + } + + Artifact artifact = + artifactFactory.createArtifact(webApplication.getGroupId(), + webApplication.getArtifactId(), + webApplication.getVersion(), "", + webApplication.getType()); try { diff --git a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractScmMojo.java b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractScmMojo.java index 5274e2ac38..cd8dc551eb 100644 --- a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractScmMojo.java +++ b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractScmMojo.java @@ -68,17 +68,6 @@ public abstract class AbstractScmMojo extends AbstractMojo return artifactFactory; } - /** - * Method description - * - * - * @return - */ - public String getArtifactId() - { - return artifactId; - } - /** * Method description * @@ -123,17 +112,6 @@ public abstract class AbstractScmMojo extends AbstractMojo return availableRepositoryLayouts; } - /** - * Method description - * - * - * @return - */ - public String getGroupId() - { - return groupId; - } - /** * Method description * @@ -206,20 +184,9 @@ public abstract class AbstractScmMojo extends AbstractMojo * * @return */ - public String getType() + public WebApplication getWebApplication() { - return type; - } - - /** - * Method description - * - * - * @return - */ - public String getVersion() - { - return version; + return webApplication; } //~--- set methods ---------------------------------------------------------- @@ -235,17 +202,6 @@ public abstract class AbstractScmMojo extends AbstractMojo this.artifactFactory = artifactFactory; } - /** - * Method description - * - * - * @param artifactId - */ - public void setArtifactId(String artifactId) - { - this.artifactId = artifactId; - } - /** * Method description * @@ -292,17 +248,6 @@ public abstract class AbstractScmMojo extends AbstractMojo this.availableRepositoryLayouts = availableRepositoryLayouts; } - /** - * Method description - * - * - * @param groupId - */ - public void setGroupId(String groupId) - { - this.groupId = groupId; - } - /** * Method description * @@ -373,22 +318,11 @@ public abstract class AbstractScmMojo extends AbstractMojo * Method description * * - * @param type + * @param webApplication */ - public void setType(String type) + public void setWebApplication(WebApplication webApplication) { - this.type = type; - } - - /** - * Method description - * - * - * @param version - */ - public void setVersion(String version) - { - this.version = version; + this.webApplication = webApplication; } //~--- fields --------------------------------------------------------------- @@ -402,11 +336,6 @@ public abstract class AbstractScmMojo extends AbstractMojo */ protected ArtifactFactory artifactFactory; - /** - * @parameter - */ - protected String artifactId = "scm-webapp"; - /** * @component */ @@ -432,11 +361,6 @@ public abstract class AbstractScmMojo extends AbstractMojo */ protected Map availableRepositoryLayouts; - /** - * @parameter - */ - protected String groupId = "sonia.scm"; - /** * @readonly * @parameter expression="${localRepository}" @@ -479,10 +403,5 @@ public abstract class AbstractScmMojo extends AbstractMojo /** * @parameter */ - protected String type = "war"; - - /** - * @parameter expression="${project.parent.version}" - */ - protected String version; + protected WebApplication webApplication = new WebApplication(); } diff --git a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/WebApplication.java b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/WebApplication.java new file mode 100644 index 0000000000..eb99098698 --- /dev/null +++ b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/WebApplication.java @@ -0,0 +1,146 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.maven; + +/** + * + * @author Sebastian Sdorra + */ +public class WebApplication +{ + + /** + * Method description + * + * + * @return + */ + public String getArtifactId() + { + return artifactId; + } + + /** + * Method description + * + * + * @return + */ + public String getGroupId() + { + return groupId; + } + + /** + * Method description + * + * + * @return + */ + public String getType() + { + return type; + } + + /** + * Method description + * + * + * @return + */ + public String getVersion() + { + return version; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param artifactId + */ + public void setArtifactId(String artifactId) + { + this.artifactId = artifactId; + } + + /** + * Method description + * + * + * @param groupId + */ + public void setGroupId(String groupId) + { + this.groupId = groupId; + } + + /** + * Method description + * + * + * @param type + */ + public void setType(String type) + { + this.type = type; + } + + /** + * Method description + * + * + * @param version + */ + public void setVersion(String version) + { + this.version = version; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private String artifactId = "scm-webapp"; + + /** Field description */ + private String groupId = "sonia.scm"; + + /** Field description */ + private String type = "war"; + + /** Field description */ + private String version; +}