From 368ae57a6b4b3b46ee5b7f3e25f137b41938edc6 Mon Sep 17 00:00:00 2001 From: Michal Maczka Date: Thu, 10 Jun 2004 19:00:04 +0000 Subject: [PATCH] first sketch of jar:install goal git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162740 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/jar/JarInstallMojo.java | 157 ++++++++++++++++++ .../{JarPlugin.java => jar/JarMojo.java} | 66 ++------ 2 files changed, 170 insertions(+), 53 deletions(-) create mode 100644 maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java rename maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/{JarPlugin.java => jar/JarMojo.java} (55%) diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java new file mode 100644 index 0000000000..62f0925db8 --- /dev/null +++ b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java @@ -0,0 +1,157 @@ +package org.apache.maven.plugin.jar; + +/* + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.AbstractPlugin; +import org.apache.maven.plugin.PluginExecutionRequest; +import org.apache.maven.plugin.PluginExecutionResponse; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; + + +/** + * @author Michal Maczka + * @version $Id$ + * + * @maven.plugin.id jar + * @maven.plugin.description Maven plugin to build jars + * + * @parameter jarName String true validator description + * @parameter outputDirectory String true validator description + * @parameter basedir String true validator description + * @parameter groupId String true validator description + * @parameter version String true validator description + * @parameter localRepository String true validator description + * @parameter pomFile java.io.File true validator description + * * + * @goal.name jar:install + * @goal.jar:install.description install a jar in local repository + * + * @goal.jar:install.prereq jar + * @goal.jar:install.parameter jarName #maven.final.name + * @goal.jar:install.parameter outputDirectory #maven.build.dir + * @goal.jar:install.parameter basedir #maven.build.dest + * @goal.jar:install.parameter pomFile #project.file + * @goal.jar:install.parameter groupId #project.groupId + * @goal.jar:install.parameter artifactId #project.artifactId + * @goal.jar:install.parameter version #project.version + * @goal.jar:install.parameter localRepository #project.localRepository + */ +public class JarInstallMojo + extends AbstractPlugin +{ + public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) + throws Exception + { + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + + String outputDirectory = ( String ) request.getParameter( "outputDirectory" ); + + String jarName = ( String ) request.getParameter( "jarName" ); + + String groupId = ( String ) request.getParameter( "groupId" ); + + String artifactId = ( String ) request.getParameter( "artifactId" ); + + //@todo if we have SNAPSHOT version should we do something special? + + String version = ( String ) request.getParameter( "version" ); + + File pomFile = ( File ) request.getParameter( "pomFile" ); + + String localRepository = ( String ) request.getParameter( "localRepository" ); + + File jarFile = new File( outputDirectory, jarName + ".jar" ); + + try + { + String jarPath = groupId + "/poms/" + artifactId + "-" + version + ".pom"; + + //here I imagine that also something like this can be made + // + // Dependecy = new Dependecy(); + // dependecy.setGroupid( groupId ) + // .... + // MavenArtifact artifact = artifactFactory.createArtifact( dependecy ) + // + // so maven artifact factory will be centralized service for creating + // repository paths + // + // I am not sure if this is good option but it is something which might be considered + installArtifact( jarPath, jarFile, localRepository ); + + } + catch ( Exception e ) + { + response.setException( e ); + + return; + } + + try + { + String pomPath = groupId + "/poms/" + artifactId + "-" + version + ".pom"; + + installArtifact( pomPath, pomFile, localRepository ); + } + catch ( Exception e ) + { + // @todo what shall we do when jar was installed but we failed to install pom? + + // response.setException ( e ); + + } + + + } + + //@todo do we need to crate md5 checksums in local repsitory? + //I think it would be nice if any local repository could be + // and at any moment in time used as remote repository + // so content of both repositories should be symetrical + private void installArtifact( String path, File source, String localRepository ) throws Exception + { + + File destination = new File( localRepository, path ); + + + // @todo should we use plexus classes? + FileUtils.fileCopy( source.getPath(), destination.getPath() ); + + // @todo we can use as well file wagon here. + +// FileWagon wagon = new FileWagon(); +// +// TransferObserver observer = new ChecksumObserver() +// +// wagon.addTransferObserver( observer ); +// +// Repository repository = new Repository( "file://xxxx" ); +// +// wagon.connect( repository ); +// +// wagon.put( path, file ); + + // and wagon has also built-in support for <> which is not used + } + + +} diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/JarPlugin.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java similarity index 55% rename from maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/JarPlugin.java rename to maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java index 2c4fc78e8a..0a99a6ea7f 100644 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/JarPlugin.java +++ b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java @@ -1,59 +1,19 @@ -package org.apache.maven.plugin; +package org.apache.maven.plugin.jar; -/* ==================================================================== - * The Apache Software License, Version 1.1 +/* + * Copyright 2001-2004 The Apache Software Foundation. * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Maven" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache Maven", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR - * ITS 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. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ import org.codehaus.plexus.util.FileUtils; @@ -93,7 +53,7 @@ * maven.jar.compress * maven.remote.group */ -public class JarPlugin +public class JarMojo extends AbstractPlugin { public void execute( PluginExecutionRequest request, PluginExecutionResponse response )