first sketch of jar:install goal

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162740 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michal Maczka 2004-06-10 19:00:04 +00:00
parent 60af082ea2
commit 368ae57a6b
2 changed files with 170 additions and 53 deletions

View File

@ -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 <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @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 <<artifacts>> which is not used
}
}

View File

@ -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 * Licensed under the Apache License, Version 2.0 (the "License");
* reserved. * 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 * http://www.apache.org/licenses/LICENSE-2.0
* modification, are permitted provided that the following conditions
* are met:
* *
* 1. Redistributions of source code must retain the above copyright * Unless required by applicable law or agreed to in writing, software
* notice, this list of conditions and the following disclaimer. * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 2. Redistributions in binary form must reproduce the above copyright * See the License for the specific language governing permissions and
* notice, this list of conditions and the following disclaimer in * limitations under the License.
* 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
* <http://www.apache.org/>.
*
* ====================================================================
*/ */
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
@ -93,7 +53,7 @@
* maven.jar.compress * maven.jar.compress
* maven.remote.group * maven.remote.group
*/ */
public class JarPlugin public class JarMojo
extends AbstractPlugin extends AbstractPlugin
{ {
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) public void execute( PluginExecutionRequest request, PluginExecutionResponse response )