From 1e565b55f7dc7c497d9bdae9e88f8fc0038d329f Mon Sep 17 00:00:00 2001
From: antelder destinationDirectory
does not exist, it
- * (and any parent directories) will be created. If a file source
in
- * destinationDirectory
exists, it will be overwritten.
- *
- * @param source An existing File
to copy.
- * @param destinationDirectory A directory to copy source
into.
- * @throws java.io.FileNotFoundException if source
isn't a normal file.
- * @throws IllegalArgumentException if destinationDirectory
isn't a directory.
- * @throws java.io.IOException if source
does not exist, the file in
- * destinationDirectory
cannot be written to, or an IO error occurs during copying.
- *
- * TO DO: Remove this method when Maven moves to plexus-utils version 1.4
- */
- private static void copyFileToDirectoryIfModified( File source, File destinationDirectory )
- throws IOException
- {
- // TO DO: Remove this method and use the method in WarFileUtils when Maven 2 changes
- // to plexus-utils 1.2.
- if ( destinationDirectory.exists() && !destinationDirectory.isDirectory() )
- {
- throw new IllegalArgumentException( "Destination is not a directory" );
- }
-
- copyFileIfModified( source, new File( destinationDirectory, source.getName() ) );
- }
-
- private FilterWrapper[] getFilterWrappers()
- {
- return new FilterWrapper[]{
- // support ${token}
- new FilterWrapper()
- {
- public Reader getReader( Reader fileReader, Map filterProperties )
- {
- return new InterpolationFilterReader( fileReader, filterProperties, "${", "}" );
- }
- },
- // support @token@
- new FilterWrapper()
- {
- public Reader getReader( Reader fileReader, Map filterProperties )
- {
- return new InterpolationFilterReader( fileReader, filterProperties, "@", "@" );
- }
- }};
- }
-
- /**
- * @param from
- * @param to
- * @param encoding
- * @param wrappers
- * @param filterProperties
- * @throws IOException TO DO: Remove this method when Maven moves to plexus-utils version 1.4
- */
- private static void copyFilteredFile( File from, File to, String encoding, FilterWrapper[] wrappers,
- Map filterProperties )
- throws IOException
- {
- // buffer so it isn't reading a byte at a time!
- Reader fileReader = null;
- Writer fileWriter = null;
- try
- {
- // fix for MWAR-36, ensures that the parent dir are created first
- to.getParentFile().mkdirs();
-
- if ( encoding == null || encoding.length() < 1 )
- {
- fileReader = new BufferedReader( new FileReader( from ) );
- fileWriter = new FileWriter( to );
- }
- else
- {
- FileInputStream instream = new FileInputStream( from );
-
- FileOutputStream outstream = new FileOutputStream( to );
-
- fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) );
-
- fileWriter = new OutputStreamWriter( outstream, encoding );
- }
-
- Reader reader = fileReader;
- for ( int i = 0; i < wrappers.length; i++ )
- {
- FilterWrapper wrapper = wrappers[i];
- reader = wrapper.getReader( reader, filterProperties );
- }
-
- IOUtil.copy( reader, fileWriter );
- }
- finally
- {
- IOUtil.close( fileReader );
- IOUtil.close( fileWriter );
- }
- }
-
- /**
- * Copy file from source to destination only if source timestamp is later than the destination timestamp.
- * The directories up to destination
will be created if they don't already exist.
- * destination
will be overwritten if it already exists.
- *
- * @param source An existing non-directory File
to copy bytes from.
- * @param destination A non-directory File
to write bytes to (possibly
- * overwriting).
- * @throws IOException if source
does not exist, destination
cannot be
- * written to, or an IO error occurs during copying.
- * @throws java.io.FileNotFoundException if destination
is a directory
- *
- * TO DO: Remove this method when Maven moves to plexus-utils version 1.4
- */
- private static void copyFileIfModified( File source, File destination )
- throws IOException
- {
- // TO DO: Remove this method and use the method in WarFileUtils when Maven 2 changes
- // to plexus-utils 1.2.
- if ( destination.lastModified() < source.lastModified() )
- {
- FileUtils.copyFile( source.getCanonicalFile(), destination );
- // preserve timestamp
- destination.setLastModified( source.lastModified() );
- }
- }
-
- /**
- * Copies a entire directory structure but only source files with timestamp later than the destinations'.
- *
- * Note:
- *
- *
- *
- * @param sourceDirectory
- * @param destinationDirectory
- * @throws IOException TO DO: Remove this method when Maven moves to plexus-utils version 1.4
- */
- private static void copyDirectoryStructureIfModified( File sourceDirectory, File destinationDirectory )
- throws IOException
- {
- if ( !sourceDirectory.exists() )
- {
- throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
- }
-
- File[] files = sourceDirectory.listFiles();
-
- String sourcePath = sourceDirectory.getAbsolutePath();
-
- for ( int i = 0; i < files.length; i++ )
- {
- File file = files[i];
-
- String dest = file.getAbsolutePath();
-
- dest = dest.substring( sourcePath.length() + 1 );
-
- File destination = new File( destinationDirectory, dest );
-
- if ( file.isFile() )
- {
- destination = destination.getParentFile();
-
- copyFileToDirectoryIfModified( file, destination );
- }
- else if ( file.isDirectory() )
- {
- if ( !destination.exists() && !destination.mkdirs() )
- {
- throw new IOException(
- "Could not create destination directory '" + destination.getAbsolutePath() + "'." );
- }
-
- copyDirectoryStructureIfModified( file, destination );
- }
- else
- {
- throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
- }
- }
- }
-
- /**
- * TO DO: Remove this interface when Maven moves to plexus-utils version 1.4
- */
- private interface FilterWrapper
- {
- Reader getReader( Reader fileReader, Map filterProperties );
- }
-
- /**
- * Converts the filename of an artifact to artifactId-version.type format.
- *
- * @param artifact
- * @return converted filename of the artifact
- */
- private String getDefaultFinalName( Artifact artifact )
- {
- String finalName = artifact.getArtifactId() + "-" + artifact.getVersion();
-
- String classifier = artifact.getClassifier();
- if ( ( classifier != null ) && ! ( "".equals( classifier.trim() ) ) )
- {
- finalName += "-" + classifier;
- }
-
- finalName = finalName + "." + artifact.getArtifactHandler().getExtension();
- return finalName;
- }
-
-}
diff --git a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/CompositeMap.java b/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/CompositeMap.java
deleted file mode 100644
index 813a1bd668..0000000000
--- a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/CompositeMap.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.apache.tuscany.maven.zip;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 java.util.AbstractMap;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @version $Id: CompositeMap.java 480784 2006-11-30 00:07:45Z jvanzyl $
- * @todo merge with resources/assembly plugin
- */
-public class CompositeMap
- extends AbstractMap
-{
- private Map recessive;
-
- private Map dominant;
-
- public CompositeMap( Map dominant, Map recessive )
- {
- this.dominant = Collections.unmodifiableMap( dominant );
-
- this.recessive = Collections.unmodifiableMap( recessive );
- }
-
- public synchronized Object get( Object key )
- {
- Object value = dominant.get( key );
-
- if ( value == null )
- {
- value = recessive.get( key );
- }
-
- return value;
- }
-
- public Set entrySet()
- {
- throw new UnsupportedOperationException( "Cannot enumerate properties in a composite map" );
- }
-}
diff --git a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/PropertyUtils.java b/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/PropertyUtils.java
deleted file mode 100644
index 8c204987f1..0000000000
--- a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/PropertyUtils.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.apache.tuscany.maven.zip;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.codehaus.plexus.util.IOUtil;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Properties;
-
-/**
- * @author Kenney Westerhof
- * @version $Id: PropertyUtils.java 480784 2006-11-30 00:07:45Z jvanzyl $
- * @todo this is duplicated from the resources plugin - migrate to plexus-utils
- */
-public final class PropertyUtils
-{
- private PropertyUtils()
- {
- // prevent instantiation
- }
-
- /**
- * Reads a property file, resolving all internal variables.
- *
- * @param propfile The property file to load
- * @param fail wheter to throw an exception when the file cannot be loaded or to return null
- * @param useSystemProps wheter to incorporate System.getProperties settings into the returned Properties object.
- * @return the loaded and fully resolved Properties object
- */
- public static Properties loadPropertyFile( File propfile, boolean fail, boolean useSystemProps )
- throws IOException
- {
- Properties props = new Properties();
-
- if ( useSystemProps )
- {
- props = new Properties( System.getProperties() );
- }
-
- if ( propfile.exists() )
- {
- FileInputStream inStream = new FileInputStream( propfile );
- try
- {
- props.load( inStream );
- }
- finally
- {
- IOUtil.close( inStream );
- }
- }
- else if ( fail )
- {
- throw new FileNotFoundException( propfile.toString() );
- }
-
- for ( Enumeration n = props.propertyNames(); n.hasMoreElements(); )
- {
- String k = (String) n.nextElement();
- props.setProperty( k, PropertyUtils.getPropertyValue( k, props ) );
- }
-
- return props;
- }
-
-
- /**
- * Retrieves a property value, replacing values like ${token}
- * using the Properties to look them up.
- *
- * It will leave unresolved properties alone, trying for System
- * properties, and implements reparsing (in the case that
- * the value of a property contains a key), and will
- * not loop endlessly on a pair like
- * test = ${test}.
- */
- private static String getPropertyValue( String k, Properties p )
- {
- // This can also be done using InterpolationFilterReader,
- // but it requires reparsing the file over and over until
- // it doesn't change.
-
- String v = p.getProperty( k );
- String ret = "";
- int idx, idx2;
-
- while ( ( idx = v.indexOf( "${" ) ) >= 0 )
- {
- // append prefix to result
- ret += v.substring( 0, idx );
-
- // strip prefix from original
- v = v.substring( idx + 2 );
-
- // if no matching } then bail
- if ( ( idx2 = v.indexOf( '}' ) ) < 0 )
- {
- break;
- }
-
- // strip out the key and resolve it
- // resolve the key/value for the ${statement}
- String nk = v.substring( 0, idx2 );
- v = v.substring( idx2 + 1 );
- String nv = p.getProperty( nk );
-
- // try global environment..
- if ( nv == null )
- {
- nv = System.getProperty( nk );
- }
-
- // if the key cannot be resolved,
- // leave it alone ( and don't parse again )
- // else prefix the original string with the
- // resolved property ( so it can be parsed further )
- // taking recursion into account.
- if ( nv == null || nv.equals( k ) )
- {
- ret += "${" + nk + "}";
- }
- else
- {
- v = nv + v;
- }
- }
- return ret + v;
- }
-}
diff --git a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/ReflectionProperties.java b/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/ReflectionProperties.java
deleted file mode 100644
index bceee39489..0000000000
--- a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/ReflectionProperties.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.apache.tuscany.maven.zip;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.project.MavenProject;
-import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
-
-import java.util.AbstractMap;
-import java.util.Set;
-
-/**
- * @version $Id: ReflectionProperties.java 480784 2006-11-30 00:07:45Z jvanzyl $
- * @todo merge with resources/assembly plugin
- */
-public class ReflectionProperties
- extends AbstractMap
-{
- private MavenProject project;
-
- public ReflectionProperties( MavenProject project )
- {
- this.project = project;
- }
-
- public synchronized Object get( Object key )
- {
- Object value = null;
- try
- {
- value = ReflectionValueExtractor.evaluate( String.valueOf( key ), project );
- }
- catch ( Exception e )
- {
- //TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
- }
- return value;
- }
-
- public Set entrySet()
- {
- throw new UnsupportedOperationException( "Cannot enumerate properties in a project" );
- }
-}
diff --git a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/ZipArchiver.java b/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/ZipArchiver.java
deleted file mode 100644
index a22ae9835a..0000000000
--- a/maven-plugins/trunk/maven-zip-plugin/src/main/java/org/apache/tuscany/maven/zip/ZipArchiver.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-package org.apache.tuscany.maven.zip;
-
-import org.codehaus.plexus.archiver.ArchiveEntry;
-import org.codehaus.plexus.archiver.ArchiverException;
-import org.codehaus.plexus.archiver.jar.JarArchiver;
-import org.codehaus.plexus.archiver.zip.ZipOutputStream;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * An extension of <jar> to create a WAR archive.
- * Contains special treatment for files that should end up in the
- * sourceDirectory
must exists.
- * WEB-INF/lib
, WEB-INF/classes
or
- * WEB-INF
directories of the Web Application Archive.
(The War task is a shortcut for specifying the particular layout of a WAR file. - * The same thing can be accomplished by using the prefix and fullpath - * attributes of zipfilesets in a Zip or Jar task.)
- *The extended zipfileset element from the zip task - * (with attributes prefix, fullpath, and src) - * is available in the War task.
- * - * @see JarArchiver - */ -public class ZipArchiver - extends JarArchiver -{ - - /** - * our web.xml deployment descriptor - */ - private File deploymentDescriptor; - - /** - * flag set if finding the webxml is to be expected. - */ - private boolean ignoreWebxml = true; - - /** - * flag set if the descriptor is added - */ - private boolean descriptorAdded; - - public void setIgnoreWebxml( boolean ignore ) { - ignoreWebxml = ignore; - } - - public ZipArchiver() - { - super(); - archiveType = "scazip"; - } - - /** - * set the deployment descriptor to use (WEB-INF/web.xml); - * required unless update=true - */ - public void setWebxml( File descr ) - throws ArchiverException - { - deploymentDescriptor = descr; - if ( !deploymentDescriptor.exists() ) - { - throw new ArchiverException( "Deployment descriptor: " - + deploymentDescriptor - + " does not exist." ); - } - - addFile( descr, "WEB-INF/web.xml" ); - } - - /** - * add a file under WEB-INF/lib/ - */ - - public void addLib( File fileName ) - throws ArchiverException - { - addDirectory( fileName.getParentFile(), "WEB-INF/lib/", new String[]{fileName.getName()}, null ); - } - - /** - * add files under WEB-INF/lib/ - */ - - public void addLibs( File directoryName, String[] includes, String[] excludes ) - throws ArchiverException - { - addDirectory( directoryName, "WEB-INF/lib/", includes, excludes ); - } - - /** - * add a file under WEB-INF/lib/ - */ - - public void addClass( File fileName ) - throws ArchiverException - { - addDirectory( fileName.getParentFile(), "WEB-INF/classes/", new String[]{fileName.getName()}, null ); - } - - /** - * add files under WEB-INF/classes - */ - public void addClasses( File directoryName, String[] includes, String[] excludes ) - throws ArchiverException - { - addDirectory( directoryName, "WEB-INF/classes/", includes, excludes ); - } - - /** - * files to add under WEB-INF; - */ - public void addWebinf( File directoryName, String[] includes, String[] excludes ) - throws ArchiverException - { - addDirectory( directoryName, "WEB-INF/", includes, excludes ); - } - - /** - * override of parent; validates configuration - * before initializing the output stream. - */ - protected void initZipOutputStream( ZipOutputStream zOut ) - throws IOException, ArchiverException - { - super.initZipOutputStream( zOut ); - } - - /** - * Overridden from ZipArchiver class to deal with web.xml - */ - protected void zipFile( ArchiveEntry entry, ZipOutputStream zOut, String vPath, int mode ) - throws IOException, ArchiverException - { - // If the file being added is WEB-INF/web.xml, we warn if it's - // not the one specified in the "webxml" attribute - or if - // it's being added twice, meaning the same file is specified - // by the "webxml" attribute and in afalse
if you don't want to install or
- * deploy it to the local repository instead of the default one in an execution.
- *
- * @parameter expression="${primaryArtifact}" default-value="true"
- */
- private boolean primaryArtifact;
-
- // ----------------------------------------------------------------------
- // Implementation
- // ----------------------------------------------------------------------
-
- /**
- * Overload this to produce a test-war, for example.
- */
- protected String getClassifier()
- {
- return classifier;
- }
-
- protected static File getFile( File basedir, String finalName, String classifier )
- {
- if ( classifier == null )
- {
- classifier = "";
- }
- else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
- {
- classifier = "-" + classifier;
- }
-
- return new File( basedir, finalName + classifier + ".zip" );
- }
-
- /**
- * Executes the Mojo on the current project.
- *
- * @throws MojoExecutionException if an error occured while building the SCA ZIP contribution
- */
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- File File = getFile( new File( outputDirectory ), contributionName, classifier );
-
- try
- {
- performPackaging( File );
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException( "Error assembling SCA ZIP: " + e.getMessage(), e );
- }
- catch ( ManifestException e )
- {
- throw new MojoExecutionException( "Error assembling SCA ZIP", e );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error assembling SCA ZIP", e );
- }
- catch ( ArchiverException e )
- {
- throw new MojoExecutionException( "Error assembling SCA ZIP: " + e.getMessage(), e );
- }
- }
-
- /**
- * Generates the SCA ZIP contribution according to the mode attribute.
- *
- * @param File the target war file
- * @throws IOException
- * @throws ArchiverException
- * @throws ManifestException
- * @throws DependencyResolutionRequiredException
- *
- */
- private void performPackaging( File File )
- throws IOException, ArchiverException, ManifestException, DependencyResolutionRequiredException,
- MojoExecutionException, MojoFailureException
- {
- buildExplodedWebapp( getZipDirectory() );
-
- //generate war file
- getLog().info( "Generating SCA ZIP contribution " + File.getAbsolutePath() );
-
- MavenArchiver archiver = new MavenArchiver();
-
- archiver.setArchiver( Archiver );
-
- archiver.setOutputFile( File );
-
- Archiver.addDirectory( getZipDirectory(), getIncludes(), getExcludes() );
-
- // create archive
- archiver.createArchive( getProject(), archive );
-
- String classifier = this.classifier;
- if ( classifier != null )
- {
- projectHelper.attachArtifact( getProject(), "", classifier, File );
- }
- else
- {
- Artifact artifact = getProject().getArtifact();
- if ( primaryArtifact )
- {
- artifact.setFile( File );
- }
- else if ( artifact.getFile() == null || artifact.getFile().isDirectory() )
- {
- artifact.setFile( File );
- }
- }
- }
-}
diff --git a/maven-plugins/trunk/maven-zip-plugin/src/main/resources/META-INF/plexus/components.xml b/maven-plugins/trunk/maven-zip-plugin/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index 8fa72d919c..0000000000
--- a/maven-plugins/trunk/maven-zip-plugin/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-