From 3294508263a59536e384d0e00a347107073ae018 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 30 Jul 2011 14:08:02 +0200 Subject: [PATCH] added AbstractScmMojo --- .../java/sonia/scm/maven/AbstractScmMojo.java | 457 ++++++++++++++++++ .../main/java/sonia/scm/maven/RunMojo.java | 143 ++---- 2 files changed, 508 insertions(+), 92 deletions(-) create mode 100644 maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractScmMojo.java 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 new file mode 100644 index 0000000000..098508f162 --- /dev/null +++ b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractScmMojo.java @@ -0,0 +1,457 @@ +/** + * 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; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugin.AbstractMojo; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * @author Sebastian Sdorra + */ +public abstract class AbstractScmMojo extends AbstractMojo +{ + + /** + * Method description + * + * + * @return + */ + public ArtifactFactory getArtifactFactory() + { + return artifactFactory; + } + + /** + * Method description + * + * + * @return + */ + public String getArtifactId() + { + return artifactId; + } + + /** + * Method description + * + * + * @return + */ + public ArtifactRepositoryFactory getArtifactRepositoryFactory() + { + return artifactRepositoryFactory; + } + + /** + * Method description + * + * + * @return + */ + public ArtifactResolver getArtifactResolver() + { + return artifactResolver; + } + + /** + * Method description + * + * + * @return + */ + public Set getArtifacts() + { + return artifacts; + } + + /** + * Method description + * + * + * @return + */ + public Map getAvailableRepositoryLayouts() + { + return availableRepositoryLayouts; + } + + /** + * Method description + * + * + * @return + */ + public String getGroupId() + { + return groupId; + } + + /** + * Method description + * + * + * @return + */ + public ArtifactRepository getLocalRepository() + { + return localRepository; + } + + /** + * Method description + * + * + * @return + */ + public Artifact getProjectArtifact() + { + return projectArtifact; + } + + /** + * Method description + * + * + * @return + */ + public List getRemoteRepositories() + { + return remoteRepositories; + } + + /** + * Method description + * + * + * @return + */ + public String getRepositoryLayout() + { + return repositoryLayout; + } + + /** + * Method description + * + * + * @return + */ + public String getScmHome() + { + return scmHome; + } + + /** + * Method description + * + * + * @return + */ + public String getType() + { + return type; + } + + /** + * Method description + * + * + * @return + */ + public String getVersion() + { + return version; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param artifactFactory + */ + public void setArtifactFactory(ArtifactFactory artifactFactory) + { + this.artifactFactory = artifactFactory; + } + + /** + * Method description + * + * + * @param artifactId + */ + public void setArtifactId(String artifactId) + { + this.artifactId = artifactId; + } + + /** + * Method description + * + * + * @param artifactRepositoryFactory + */ + public void setArtifactRepositoryFactory( + ArtifactRepositoryFactory artifactRepositoryFactory) + { + this.artifactRepositoryFactory = artifactRepositoryFactory; + } + + /** + * Method description + * + * + * @param artifactResolver + */ + public void setArtifactResolver(ArtifactResolver artifactResolver) + { + this.artifactResolver = artifactResolver; + } + + /** + * Method description + * + * + * @param artifacts + */ + public void setArtifacts(Set artifacts) + { + this.artifacts = artifacts; + } + + /** + * Method description + * + * + * @param availableRepositoryLayouts + */ + public void setAvailableRepositoryLayouts(Map availableRepositoryLayouts) + { + this.availableRepositoryLayouts = availableRepositoryLayouts; + } + + /** + * Method description + * + * + * @param groupId + */ + public void setGroupId(String groupId) + { + this.groupId = groupId; + } + + /** + * Method description + * + * + * @param localRepository + */ + public void setLocalRepository(ArtifactRepository localRepository) + { + this.localRepository = localRepository; + } + + /** + * Method description + * + * + * @param projectArtifact + */ + public void setProjectArtifact(Artifact projectArtifact) + { + this.projectArtifact = projectArtifact; + } + + /** + * Method description + * + * + * @param remoteRepositories + */ + public void setRemoteRepositories(List remoteRepositories) + { + this.remoteRepositories = remoteRepositories; + } + + /** + * Method description + * + * + * @param repositoryLayout + */ + public void setRepositoryLayout(String repositoryLayout) + { + this.repositoryLayout = repositoryLayout; + } + + /** + * Method description + * + * + * @param scmHome + */ + public void setScmHome(String scmHome) + { + this.scmHome = scmHome; + } + + /** + * 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 --------------------------------------------------------------- + + /** + * Used to look up Artifacts in the remote repository. + * + * @component role="org.apache.maven.artifact.factory.ArtifactFactory" + * @required + * @readonly + */ + protected ArtifactFactory artifactFactory; + + /** + * @parameter + */ + protected String artifactId = "scm-webapp"; + + /** + * @component + */ + protected ArtifactRepositoryFactory artifactRepositoryFactory; + + /** + * Used to look up Artifacts in the remote repository. + * + * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" + * @required + * @readonly + */ + protected ArtifactResolver artifactResolver; + + /** + * @readonly + * @parameter expression="${project.artifacts}" + */ + protected Set artifacts; + + /** + * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" + */ + protected Map availableRepositoryLayouts; + + /** + * @parameter + */ + protected String groupId = "sonia.scm"; + + /** + * @readonly + * @parameter expression="${localRepository}" + */ + protected ArtifactRepository localRepository; + + /** + * @readonly + * @parameter expression="${project.artifact}" + */ + protected Artifact projectArtifact; + + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + */ + protected List remoteRepositories; + + /** + * @parameter + */ + protected String repositoryLayout = "default"; + + /** + * @parameter expression="${project.build.directory}/scm-home" + */ + protected String scmHome; + + /** + * @parameter + */ + protected String type = "war"; + + /** + * @parameter expression="${project.parent.version}" + */ + protected String version; +} diff --git a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/RunMojo.java b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/RunMojo.java index 1939507eaa..4ee4f33bea 100644 --- a/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/RunMojo.java +++ b/maven/scm-maven-plugin/src/main/java/sonia/scm/maven/RunMojo.java @@ -39,15 +39,11 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.installer.ArtifactInstallationException; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; 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.artifact.resolver.ArtifactResolver; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -63,9 +59,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Scanner; -import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -78,7 +72,7 @@ import javax.xml.bind.JAXB; * @requiresDependencyResolution runtime * @phase package */ -public class RunMojo extends AbstractMojo +public class RunMojo extends AbstractScmMojo { /** Field description */ @@ -129,6 +123,56 @@ public class RunMojo extends AbstractMojo } } + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public String getContextPath() + { + return contextPath; + } + + /** + * Method description + * + * + * @return + */ + public int getPort() + { + return port; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param contextPath + */ + public void setContextPath(String contextPath) + { + this.contextPath = contextPath; + } + + /** + * Method description + * + * + * @param port + */ + public void setPort(int port) + { + this.port = port; + } + + //~--- methods -------------------------------------------------------------- + /** * Method description * @@ -430,98 +474,13 @@ public class RunMojo extends AbstractMojo //~--- fields --------------------------------------------------------------- - /** - * Used to look up Artifacts in the remote repository. - * - * @component role="org.apache.maven.artifact.factory.ArtifactFactory" - * @required - * @readonly - */ - private ArtifactFactory artifactFactory; - - /** - * @parameter - */ - private String artifactId = "scm-webapp"; - - /** - * @component - */ - private ArtifactRepositoryFactory artifactRepositoryFactory; - - /** - * Used to look up Artifacts in the remote repository. - * - * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" - * @required - * @readonly - */ - private ArtifactResolver artifactResolver; - - /** - * @readonly - * @parameter expression="${project.artifacts}" - */ - private Set artifacts; - - /** - * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" - */ - private Map availableRepositoryLayouts; - /** * @parameter */ private String contextPath = "/scm"; - /** - * @parameter - */ - private String groupId = "sonia.scm"; - - /** - * @readonly - * @parameter expression="${localRepository}" - */ - private ArtifactRepository localRepository; - /** * @parameter */ private int port = 8081; - - /** - * @readonly - * @parameter expression="${project.artifact}" - */ - private Artifact projectArtifact; - - /** - * List of Remote Repositories used by the resolver - * - * @parameter expression="${project.remoteArtifactRepositories}" - * @readonly - * @required - */ - private List remoteRepositories; - - /** - * @parameter - */ - private String repositoryLayout = "default"; - - /** - * @parameter expression="${project.build.directory}/scm-home" - */ - private String scmHome; - - /** - * @parameter - */ - private String type = "war"; - - /** - * @parameter expression="${project.parent.version}" - */ - private String version; }