You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/07/07 12:28:25 UTC
[maven-assembly-plugin] branch master updated: remove dependency on
maven-shared-io (#31)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 289a4b6 remove dependency on maven-shared-io (#31)
289a4b6 is described below
commit 289a4b6d99d8539b0f54c5c98390117176a07d5a
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Tue Jul 7 08:28:13 2020 -0400
remove dependency on maven-shared-io (#31)
* remove dependency on maven-shared-io
---
pom.xml | 6 +-
....java => ClasspathResourceLocatorStrategy.java} | 38 +-
.../plugins/assembly/io/DefaultAssemblyReader.java | 13 +-
.../plugins/assembly/io/DefaultMessageHolder.java | 594 +++++++++++++++++++++
.../maven/plugins/assembly/io/FileLocation.java | 175 ++++++
...catorStrategy.java => FileLocatorStrategy.java} | 20 +-
.../apache/maven/plugins/assembly/io/Location.java | 77 +++
.../apache/maven/plugins/assembly/io/Locator.java | 114 ++++
.../maven/plugins/assembly/io/LocatorStrategy.java | 35 ++
.../maven/plugins/assembly/io/MessageHolder.java | 290 ++++++++++
.../maven/plugins/assembly/io/MessageLevels.java | 117 ++++
.../maven/plugins/assembly/io/MessageSink.java | 55 ++
.../io/PrefixedClasspathLocatorStrategy.java | 4 -
.../assembly/io/RelativeFileLocatorStrategy.java | 5 -
.../maven/plugins/assembly/io/URLLocation.java | 81 +++
.../io/PrefixedClasspathLocatorStrategyTest.java | 14 +-
16 files changed, 1570 insertions(+), 68 deletions(-)
diff --git a/pom.xml b/pom.xml
index b99246d..710b01a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,11 +141,7 @@ under the License.
<artifactId>plexus-archiver</artifactId>
<version>4.2.1</version>
</dependency>
- <dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-shared-io</artifactId>
- <version>3.0.0</version>
- </dependency>
+
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java b/src/main/java/org/apache/maven/plugins/assembly/io/ClasspathResourceLocatorStrategy.java
similarity index 57%
copy from src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
copy to src/main/java/org/apache/maven/plugins/assembly/io/ClasspathResourceLocatorStrategy.java
index b0062ba..7d65dec 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/ClasspathResourceLocatorStrategy.java
@@ -19,42 +19,46 @@ package org.apache.maven.plugins.assembly.io;
* under the License.
*/
-import org.apache.maven.shared.io.location.FileLocation;
-import org.apache.maven.shared.io.location.Location;
-import org.apache.maven.shared.io.location.LocatorStrategy;
-import org.apache.maven.shared.io.logging.MessageHolder;
-
-import java.io.File;
+import java.net.URL;
/**
- *
+ * classpath resource locator strategy.
*/
-class RelativeFileLocatorStrategy
+class ClasspathResourceLocatorStrategy
implements LocatorStrategy
{
- private final File basedir;
+ private String tempFilePrefix = "location.";
+
+ private String tempFileSuffix = ".cpurl";
- RelativeFileLocatorStrategy( File basedir )
+ private boolean tempFileDeleteOnExit = true;
+
+ /**
+ * Create instance.
+ */
+ ClasspathResourceLocatorStrategy()
{
- this.basedir = basedir;
}
- @Override
+ /** {@inheritDoc} */
public Location resolve( String locationSpecification, MessageHolder messageHolder )
{
- File file = new File( basedir, locationSpecification );
- messageHolder.addInfoMessage( "Searching for file location: " + file.getAbsolutePath() );
+ ClassLoader cloader = Thread.currentThread().getContextClassLoader();
+
+ URL resource = cloader.getResource( locationSpecification );
Location location = null;
- if ( file.exists() )
+ if ( resource != null )
{
- location = new FileLocation( file, locationSpecification );
+ location = new URLLocation( resource, locationSpecification, tempFilePrefix, tempFileSuffix,
+ tempFileDeleteOnExit );
}
else
{
- messageHolder.addMessage( "File: " + file.getAbsolutePath() + " does not exist." );
+ messageHolder.addMessage( "Failed to resolve classpath resource: " + locationSpecification
+ + " from classloader: " + cloader );
}
return location;
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java b/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java
index a638d3c..3344c53 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java
@@ -37,11 +37,6 @@ import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader;
import org.apache.maven.plugins.assembly.resolved.AssemblyId;
import org.apache.maven.plugins.assembly.utils.InterpolationConstants;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy;
-import org.apache.maven.shared.io.location.FileLocatorStrategy;
-import org.apache.maven.shared.io.location.Location;
-import org.apache.maven.shared.io.location.Locator;
-import org.apache.maven.shared.io.location.LocatorStrategy;
import org.apache.maven.shared.utils.ReaderFactory;
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
import org.codehaus.plexus.interpolation.RecursionInterceptor;
@@ -368,10 +363,10 @@ public class DefaultAssemblyReader
/**
* Add the contents of all included components to main assembly
*
- * @param assembly The assembly
- * @param assemblyDir The assembly directory
- * @param transformer The component interpolator
- * @throws AssemblyReadException .
+ * @param assembly the assembly
+ * @param assemblyDir the assembly directory
+ * @param transformer the component interpolator
+ * @throws AssemblyReadException
*/
protected void mergeComponentsWithMainAssembly( final Assembly assembly, final File assemblyDir,
final AssemblerConfigurationSource configSource,
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/DefaultMessageHolder.java b/src/main/java/org/apache/maven/plugins/assembly/io/DefaultMessageHolder.java
new file mode 100644
index 0000000..5826f5d
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/DefaultMessageHolder.java
@@ -0,0 +1,594 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Default Message Holder.
+ *
+ */
+class DefaultMessageHolder
+ implements MessageHolder
+{
+
+ private List<Message> messages = new ArrayList<Message>();
+
+ private Message currentMessage;
+
+ private int defaultMessageLevel = MessageLevels.LEVEL_INFO;
+
+ private boolean[] messageLevelStates;
+
+ private MessageSink onDemandSink;
+
+ /**
+ * Create instance.
+ */
+ DefaultMessageHolder()
+ {
+ this.messageLevelStates = MessageLevels.getLevelStates( MessageLevels.LEVEL_INFO );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addMessage( CharSequence messagePart, Throwable error )
+ {
+ return addMessage( defaultMessageLevel, messagePart, error );
+ }
+
+ /**
+ * @param level Level.
+ * @param messagePart Message part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addMessage( int level, CharSequence messagePart, Throwable error )
+ {
+ newMessage( level );
+ append( messagePart.toString() );
+ append( error );
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addMessage( CharSequence messagePart )
+ {
+ return addMessage( defaultMessageLevel, messagePart );
+ }
+
+ /**
+ * @param level level.
+ * @param messagePart message part.
+ * @return {@link MessageHolder}
+ */
+ protected MessageHolder addMessage( int level, CharSequence messagePart )
+ {
+ newMessage( level );
+ append( messagePart.toString() );
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addMessage( Throwable error )
+ {
+ return addMessage( defaultMessageLevel, error );
+ }
+
+ /**
+ * @param level level.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ protected MessageHolder addMessage( int level, Throwable error )
+ {
+ newMessage( level );
+ append( error );
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder append( CharSequence messagePart )
+ {
+ if ( currentMessage == null )
+ {
+ newMessage();
+ }
+
+ currentMessage.append( messagePart.toString() );
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder append( Throwable error )
+ {
+ if ( currentMessage == null )
+ {
+ newMessage();
+ }
+
+ currentMessage.setError( error );
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public boolean isEmpty()
+ {
+ return messages.isEmpty();
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder newMessage()
+ {
+ newMessage( defaultMessageLevel );
+
+ return this;
+ }
+
+ /**
+ * @param messageLevel message level.
+ */
+ protected void newMessage( int messageLevel )
+ {
+ if ( onDemandSink != null && currentMessage != null )
+ {
+ renderTo( currentMessage, onDemandSink );
+ }
+
+ currentMessage = new Message( messageLevel, onDemandSink );
+ messages.add( currentMessage );
+ }
+
+ /** {@inheritDoc} */
+ public String render()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ int counter = 1;
+ for ( Iterator<Message> it = messages.iterator(); it.hasNext(); )
+ {
+ Message message = (Message) it.next();
+
+ int ml = message.getMessageLevel();
+
+ if ( ml >= messageLevelStates.length || ml < 0 )
+ {
+ ml = MessageLevels.LEVEL_DEBUG;
+ }
+
+ if ( !messageLevelStates[ml] )
+ {
+ continue;
+ }
+
+ CharSequence content = message.render();
+ String label = MessageLevels.getLevelLabel( message.getMessageLevel() );
+
+ if ( content.length() > label.length() + 3 )
+ {
+ buffer.append( '[' ).append( counter++ ).append( "] " );
+ buffer.append( content.toString() );
+
+ if ( it.hasNext() )
+ {
+ buffer.append( "\n\n" );
+ }
+ }
+ }
+
+ return buffer.toString();
+ }
+
+ /** {@inheritDoc} */
+ public int size()
+ {
+ return messages.size();
+ }
+
+ private static final class Message
+ {
+ private StringBuffer message = new StringBuffer();
+
+ private Throwable error;
+
+ private final int messageLevel;
+
+ private final MessageSink onDemandSink;
+
+ Message( int messageLevel, MessageSink onDemandSink )
+ {
+ this.messageLevel = messageLevel;
+
+ this.onDemandSink = onDemandSink;
+ }
+
+ public Message setError( Throwable pError )
+ {
+ this.error = pError;
+ return this;
+ }
+
+ public Message append( CharSequence pMessage )
+ {
+ this.message.append( pMessage.toString() );
+ return this;
+ }
+
+ /**
+ * @return message level.
+ */
+ public int getMessageLevel()
+ {
+ return messageLevel;
+ }
+
+ /**
+ * @return Sequence.
+ */
+ public CharSequence render()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ if ( onDemandSink == null )
+ {
+ buffer.append( '[' ).append( MessageLevels.getLevelLabel( messageLevel ) ).append( "] " );
+ }
+ if ( message != null && message.length() > 0 )
+ {
+ buffer.append( message );
+
+ if ( error != null )
+ {
+ buffer.append( '\n' );
+ }
+ }
+
+ if ( error != null )
+ {
+ buffer.append( "Error:\n" );
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter( sw );
+ error.printStackTrace( pw );
+
+ buffer.append( sw.toString() );
+ }
+
+ return buffer;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addDebugMessage( CharSequence messagePart, Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_DEBUG, messagePart, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addDebugMessage( CharSequence messagePart )
+ {
+ return addMessage( MessageLevels.LEVEL_DEBUG, messagePart );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addDebugMessage( Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_DEBUG, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addErrorMessage( CharSequence messagePart, Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_ERROR, messagePart, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addErrorMessage( CharSequence messagePart )
+ {
+ return addMessage( MessageLevels.LEVEL_ERROR, messagePart );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addErrorMessage( Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_ERROR, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addInfoMessage( CharSequence messagePart, Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_INFO, messagePart, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addInfoMessage( CharSequence messagePart )
+ {
+ return addMessage( MessageLevels.LEVEL_INFO, messagePart );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addInfoMessage( Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_INFO, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addSevereMessage( CharSequence messagePart, Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_SEVERE, messagePart, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addSevereMessage( CharSequence messagePart )
+ {
+ return addMessage( MessageLevels.LEVEL_SEVERE, messagePart );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addSevereMessage( Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_SEVERE, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addWarningMessage( CharSequence messagePart, Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_WARNING, messagePart, error );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addWarningMessage( CharSequence messagePart )
+ {
+ return addMessage( MessageLevels.LEVEL_WARNING, messagePart );
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder addWarningMessage( Throwable error )
+ {
+ return addMessage( MessageLevels.LEVEL_WARNING, error );
+ }
+
+ /** {@inheritDoc} */
+ public int countDebugMessages()
+ {
+ return countMessagesOfType( MessageLevels.LEVEL_DEBUG );
+ }
+
+ /** {@inheritDoc} */
+ public int countErrorMessages()
+ {
+ return countMessagesOfType( MessageLevels.LEVEL_ERROR );
+ }
+
+ /** {@inheritDoc} */
+ public int countInfoMessages()
+ {
+ return countMessagesOfType( MessageLevels.LEVEL_INFO );
+ }
+
+ /** {@inheritDoc} */
+ public int countMessages()
+ {
+ return size();
+ }
+
+ /** {@inheritDoc} */
+ public int countSevereMessages()
+ {
+ return countMessagesOfType( MessageLevels.LEVEL_SEVERE );
+ }
+
+ /** {@inheritDoc} */
+ public int countWarningMessages()
+ {
+ return countMessagesOfType( MessageLevels.LEVEL_WARNING );
+ }
+
+ /**
+ * @param messageLevel leve.
+ * @return number of messages.
+ */
+ private int countMessagesOfType( int messageLevel )
+ {
+ int count = 0;
+
+ for ( Message message : messages )
+ {
+ if ( messageLevel == message.getMessageLevel() )
+ {
+ count++;
+ }
+ }
+
+ return count;
+ }
+
+ /** {@inheritDoc} */
+ public boolean isDebugEnabled()
+ {
+ return messageLevelStates[MessageLevels.LEVEL_DEBUG];
+ }
+
+ /** {@inheritDoc} */
+ public boolean isErrorEnabled()
+ {
+ return messageLevelStates[MessageLevels.LEVEL_ERROR];
+ }
+
+ /** {@inheritDoc} */
+ public boolean isInfoEnabled()
+ {
+ return messageLevelStates[MessageLevels.LEVEL_INFO];
+ }
+
+ /** {@inheritDoc} */
+ public boolean isSevereEnabled()
+ {
+ return messageLevelStates[MessageLevels.LEVEL_SEVERE];
+ }
+
+ /** {@inheritDoc} */
+ public boolean isWarningEnabled()
+ {
+ return messageLevelStates[MessageLevels.LEVEL_WARNING];
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder newDebugMessage()
+ {
+ if ( isDebugEnabled() )
+ {
+ newMessage( MessageLevels.LEVEL_DEBUG );
+ }
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder newErrorMessage()
+ {
+ if ( isErrorEnabled() )
+ {
+ newMessage( MessageLevels.LEVEL_ERROR );
+ }
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder newInfoMessage()
+ {
+ if ( isInfoEnabled() )
+ {
+ newMessage( MessageLevels.LEVEL_INFO );
+ }
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder newSevereMessage()
+ {
+ if ( isSevereEnabled() )
+ {
+ newMessage( MessageLevels.LEVEL_SEVERE );
+ }
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public MessageHolder newWarningMessage()
+ {
+ if ( isWarningEnabled() )
+ {
+ newMessage( MessageLevels.LEVEL_WARNING );
+ }
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public void setDebugEnabled( boolean enabled )
+ {
+ messageLevelStates[MessageLevels.LEVEL_DEBUG] = enabled;
+ }
+
+ /** {@inheritDoc} */
+ public void setErrorEnabled( boolean enabled )
+ {
+ messageLevelStates[MessageLevels.LEVEL_ERROR] = enabled;
+ }
+
+ /** {@inheritDoc} */
+ public void setInfoEnabled( boolean enabled )
+ {
+ messageLevelStates[MessageLevels.LEVEL_INFO] = enabled;
+ }
+
+ /** {@inheritDoc} */
+ public void setSevereEnabled( boolean enabled )
+ {
+ messageLevelStates[MessageLevels.LEVEL_SEVERE] = enabled;
+ }
+
+ /** {@inheritDoc} */
+ public void setWarningEnabled( boolean enabled )
+ {
+ messageLevelStates[MessageLevels.LEVEL_WARNING] = enabled;
+ }
+
+ /** {@inheritDoc} */
+ public void flush()
+ {
+ if ( onDemandSink != null && currentMessage != null )
+ {
+ renderTo( currentMessage, onDemandSink );
+ currentMessage = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void render( MessageSink sink )
+ {
+ for ( Message message : messages )
+ {
+ renderTo( message, sink );
+ }
+ }
+
+ /**
+ * @param message {@link Message}
+ * @param sink {@link MessageSink}
+ */
+ protected void renderTo( Message message, MessageSink sink )
+ {
+ switch ( message.getMessageLevel() )
+ {
+ case ( MessageLevels.LEVEL_SEVERE ):
+ sink.severe( message.render().toString() );
+ break;
+
+ case ( MessageLevels.LEVEL_ERROR ):
+ sink.error( message.render().toString() );
+ break;
+
+ case ( MessageLevels.LEVEL_WARNING ):
+ sink.warning( message.render().toString() );
+ break;
+
+ case ( MessageLevels.LEVEL_INFO ):
+ sink.info( message.render().toString() );
+ break;
+
+ default:
+ sink.debug( message.render().toString() );
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/FileLocation.java b/src/main/java/org/apache/maven/plugins/assembly/io/FileLocation.java
new file mode 100644
index 0000000..ee13dda
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/FileLocation.java
@@ -0,0 +1,175 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+
+
+/**
+ * file location implementation.
+ *
+ */
+class FileLocation
+ implements Location
+{
+
+ private File file;
+ private FileChannel channel;
+ private final String specification;
+ private FileInputStream stream;
+
+ /**
+ * @param file {@link File}
+ * @param specification spec
+ */
+ FileLocation( File file, String specification )
+ {
+ this.file = file;
+ this.specification = specification;
+ }
+
+ /**
+ * @param specification spec
+ */
+ FileLocation( String specification )
+ {
+ this.specification = specification;
+ }
+
+ /** {@inheritDoc} */
+ public void close()
+ {
+ if ( ( channel != null ) && channel.isOpen() )
+ {
+ try
+ {
+ channel.close();
+ }
+ catch ( IOException e )
+ {
+ //swallow it.
+ }
+ }
+
+ if ( stream != null )
+ {
+ try
+ {
+ stream.close();
+ }
+ catch ( IOException e )
+ {
+ // swallow it.
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public File getFile()
+ throws IOException
+ {
+ initFile();
+
+ return unsafeGetFile();
+ }
+
+ /**
+ * @return {@link File}
+ */
+ File unsafeGetFile()
+ {
+ return file;
+ }
+
+ /**
+ * initialize file.
+ * @throws IOException in case of error
+ */
+ private void initFile()
+ throws IOException
+ {
+ if ( file == null )
+ {
+ file = new File( specification );
+ }
+ }
+
+ /**
+ * @param file {@link File}
+ */
+ protected void setFile( File file )
+ {
+ if ( channel != null )
+ {
+ throw new IllegalStateException( "Location is already open; cannot setFile(..)." );
+ }
+
+ this.file = file;
+ }
+
+ /** {@inheritDoc} */
+ public String getSpecification()
+ {
+ return specification;
+ }
+
+ /** {@inheritDoc} */
+ public void open()
+ throws IOException
+ {
+ if ( stream == null )
+ {
+ initFile();
+
+ stream = new FileInputStream( file );
+ channel = stream.getChannel();
+ }
+ }
+
+ /** {@inheritDoc} */
+ public int read( ByteBuffer buffer )
+ throws IOException
+ {
+ open();
+ return channel.read( buffer );
+ }
+
+ /** {@inheritDoc} */
+ public int read( byte[] buffer )
+ throws IOException
+ {
+ open();
+ return channel.read( ByteBuffer.wrap( buffer ) );
+ }
+
+ /** {@inheritDoc} */
+ public InputStream getInputStream()
+ throws IOException
+ {
+ open();
+ return stream;
+ }
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java b/src/main/java/org/apache/maven/plugins/assembly/io/FileLocatorStrategy.java
similarity index 70%
copy from src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
copy to src/main/java/org/apache/maven/plugins/assembly/io/FileLocatorStrategy.java
index b0062ba..87e5385 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/FileLocatorStrategy.java
@@ -19,32 +19,20 @@ package org.apache.maven.plugins.assembly.io;
* under the License.
*/
-import org.apache.maven.shared.io.location.FileLocation;
-import org.apache.maven.shared.io.location.Location;
-import org.apache.maven.shared.io.location.LocatorStrategy;
-import org.apache.maven.shared.io.logging.MessageHolder;
-
import java.io.File;
/**
+ * file locator strategy.
*
*/
-class RelativeFileLocatorStrategy
+class FileLocatorStrategy
implements LocatorStrategy
{
- private final File basedir;
-
- RelativeFileLocatorStrategy( File basedir )
- {
- this.basedir = basedir;
- }
-
- @Override
+ /** {@inheritDoc} */
public Location resolve( String locationSpecification, MessageHolder messageHolder )
{
- File file = new File( basedir, locationSpecification );
- messageHolder.addInfoMessage( "Searching for file location: " + file.getAbsolutePath() );
+ File file = new File( locationSpecification );
Location location = null;
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/Location.java b/src/main/java/org/apache/maven/plugins/assembly/io/Location.java
new file mode 100644
index 0000000..c30c4d4
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/Location.java
@@ -0,0 +1,77 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * The location interface.
+ *
+ */
+interface Location
+{
+
+ /**
+ * @return {@link File}
+ * @throws IOException in case of an error
+ */
+ File getFile() throws IOException;
+
+ /**
+ * Open the location.
+ *
+ * @throws IOException in case of an error
+ */
+ void open() throws IOException;
+
+ /**
+ * Close the location.
+ */
+ void close();
+
+ /**
+ * @param buffer The buffer
+ * @return number of read bytes
+ * @throws IOException in case of an error
+ */
+ int read( ByteBuffer buffer ) throws IOException;
+
+ /**
+ * @param buffer the buffer
+ * @return number of read bytes
+ * @throws IOException in case of an error
+ */
+ int read( byte[] buffer ) throws IOException;
+
+ /**
+ * @return the resulting input stream.
+ * @throws IOException in case of an error
+ */
+ InputStream getInputStream() throws IOException;
+
+ /**
+ * @return spec
+ */
+ String getSpecification();
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/Locator.java b/src/main/java/org/apache/maven/plugins/assembly/io/Locator.java
new file mode 100644
index 0000000..8f992e3
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/Locator.java
@@ -0,0 +1,114 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * The Locator.
+ *
+ */
+final class Locator
+{
+
+ private List<LocatorStrategy> strategies;
+ private final MessageHolder messageHolder;
+
+ /**
+ * @param strategies List of strategies
+ * @param messageHolder {@link MessageHolder}
+ */
+ Locator( List<LocatorStrategy> strategies, MessageHolder messageHolder )
+ {
+ this.messageHolder = messageHolder;
+ this.strategies = new ArrayList<LocatorStrategy>( strategies );
+ }
+
+ /**
+ * Create instance.
+ */
+ Locator()
+ {
+ this.messageHolder = new DefaultMessageHolder();
+ this.strategies = new ArrayList<LocatorStrategy>();
+ }
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder getMessageHolder()
+ {
+ return messageHolder;
+ }
+
+ /**
+ * @param strategy The strategy to be added.
+ */
+ void addStrategy( LocatorStrategy strategy )
+ {
+ this.strategies.add( strategy );
+ }
+
+ /**
+ * @param strategy the strategy to remove.
+ */
+ void removeStrategy( LocatorStrategy strategy )
+ {
+ this.strategies.remove( strategy );
+ }
+
+ /**
+ * @param strategies the strategies to be set.
+ */
+ void setStrategies( List<LocatorStrategy> strategies )
+ {
+ this.strategies.clear();
+ this.strategies.addAll( strategies );
+ }
+
+ /**
+ * @return list of strategies.
+ */
+ List<LocatorStrategy> getStrategies()
+ {
+ return strategies;
+ }
+
+ /**
+ * @param locationSpecification location spec
+ * @return {@link Location}
+ */
+ Location resolve( String locationSpecification )
+ {
+ Location location = null;
+
+ for ( Iterator<LocatorStrategy> it = strategies.iterator(); location == null && it.hasNext(); )
+ {
+ LocatorStrategy strategy = (LocatorStrategy) it.next();
+
+ location = strategy.resolve( locationSpecification, messageHolder );
+ }
+
+ return location;
+ }
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/LocatorStrategy.java b/src/main/java/org/apache/maven/plugins/assembly/io/LocatorStrategy.java
new file mode 100644
index 0000000..7ef73f8
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/LocatorStrategy.java
@@ -0,0 +1,35 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.
+ */
+
+/**
+ * Locator Strategy interface.
+ */
+interface LocatorStrategy
+{
+
+ /**
+ * @param locationSpecification the specification
+ * @param messageHolder {@link MessageHolder}
+ * @return {@link Location}
+ */
+ Location resolve( String locationSpecification, MessageHolder messageHolder );
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/MessageHolder.java b/src/main/java/org/apache/maven/plugins/assembly/io/MessageHolder.java
new file mode 100644
index 0000000..ff0ba38
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/MessageHolder.java
@@ -0,0 +1,290 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.
+ */
+
+/**
+ * Message Holder class.
+ *
+ */
+interface MessageHolder
+{
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder newMessage();
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder newDebugMessage();
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder newInfoMessage();
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder newWarningMessage();
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder newErrorMessage();
+
+ /**
+ * @return {@link MessageHolder}
+ */
+ MessageHolder newSevereMessage();
+
+ /**
+ * @param messagePart message part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder append( CharSequence messagePart );
+
+ /**
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder append( Throwable error );
+
+ /**
+ * @param messagePart Message Part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addMessage( CharSequence messagePart, Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addMessage( CharSequence messagePart );
+
+ /**
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addMessage( Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addDebugMessage( CharSequence messagePart, Throwable error );
+
+ /**
+ * @param messagePart messages part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addDebugMessage( CharSequence messagePart );
+
+ /**
+ * @param error messages part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addDebugMessage( Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addInfoMessage( CharSequence messagePart, Throwable error );
+
+ /**
+ * @param messagePart messages part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addInfoMessage( CharSequence messagePart );
+
+ /**
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addInfoMessage( Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addWarningMessage( CharSequence messagePart, Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addWarningMessage( CharSequence messagePart );
+
+ /**
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addWarningMessage( Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addErrorMessage( CharSequence messagePart, Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addErrorMessage( CharSequence messagePart );
+
+ /**
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addErrorMessage( Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @param error {@link Throwable}
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addSevereMessage( CharSequence messagePart, Throwable error );
+
+ /**
+ * @param messagePart message part.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addSevereMessage( CharSequence messagePart );
+
+ /**
+ * @param error The error.
+ * @return {@link MessageHolder}
+ */
+ MessageHolder addSevereMessage( Throwable error );
+
+ /**
+ * @return the size.
+ */
+ int size();
+
+ /**
+ * @return count number of messages.
+ */
+ int countMessages();
+
+ /**
+ * @return count number of debug messages.
+ */
+ int countDebugMessages();
+
+ /**
+ * @return count number of info messages
+ */
+ int countInfoMessages();
+
+ /**
+ * @return count number of warning messages
+ */
+ int countWarningMessages();
+
+ /**
+ * @return count number of error messages
+ */
+ int countErrorMessages();
+
+ /**
+ * @return count number of server messages
+ */
+ int countSevereMessages();
+
+ /**
+ * @return true / false.
+ */
+ boolean isDebugEnabled();
+
+ /**
+ * @param enabled enable debug
+ */
+ void setDebugEnabled( boolean enabled );
+
+ /**
+ * @return true if info is enabled false otherwise
+ */
+ boolean isInfoEnabled();
+
+ /**
+ * @param enabled true info enable false otherwise.
+ */
+ void setInfoEnabled( boolean enabled );
+
+ /**
+ * @return true if warning is enabled false otherwise.
+ */
+ boolean isWarningEnabled();
+
+ /**
+ * @param enabled enable warning or disable.
+ */
+ void setWarningEnabled( boolean enabled );
+
+ /**
+ * @return true if error is enabled false otherwise.
+ */
+ boolean isErrorEnabled();
+
+ /**
+ * @param enabled enable error or disable
+ */
+ void setErrorEnabled( boolean enabled );
+
+ /**
+ * @return true if severe is enabled false otherwise.
+ */
+ boolean isSevereEnabled();
+
+ /**
+ * @param enabled enable severe or disable
+ */
+ void setSevereEnabled( boolean enabled );
+
+ /**
+ * @return true if empty, false otherwise
+ */
+ boolean isEmpty();
+
+ /**
+ * @return rendered
+ */
+ String render();
+
+ /**
+ * @param sink {@link MessageSink}
+ */
+ void render( MessageSink sink );
+
+ /**
+ * flush
+ */
+ void flush();
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/MessageLevels.java b/src/main/java/org/apache/maven/plugins/assembly/io/MessageLevels.java
new file mode 100644
index 0000000..fd4e960
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/MessageLevels.java
@@ -0,0 +1,117 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ *
+ */
+final class MessageLevels
+{
+
+ /**
+ * Debug.
+ */
+ public static final int LEVEL_DEBUG = 0;
+ /**
+ * Info
+ */
+ public static final int LEVEL_INFO = 1;
+ /**
+ * Warning.
+ */
+ public static final int LEVEL_WARNING = 2;
+ /**
+ * Error
+ */
+ public static final int LEVEL_ERROR = 3;
+ /**
+ * Severe
+ */
+ public static final int LEVEL_SEVERE = 4;
+ /**
+ * Disabled.
+ */
+ public static final int LEVEL_DISABLED = 5;
+
+ private static final List<String> LEVEL_NAMES;
+
+ static
+ {
+ List<String> names = new ArrayList<String>();
+ names.add( "DEBUG" );
+ names.add( "INFO" );
+ names.add( "WARN" );
+ names.add( "ERROR" );
+ names.add( "SEVERE" );
+
+ LEVEL_NAMES = Collections.unmodifiableList( names );
+ }
+
+ private MessageLevels()
+ {
+ }
+
+ /**
+ * @param maxMessageLevel for which level
+ * @return level states
+ */
+ static boolean[] getLevelStates( int maxMessageLevel )
+ {
+ boolean[] states = new boolean[5];
+
+ Arrays.fill( states, false );
+
+ switch ( maxMessageLevel )
+ {
+ case ( LEVEL_DEBUG ):
+ states[LEVEL_DEBUG] = true;
+ case ( LEVEL_INFO ):
+ states[LEVEL_INFO] = true;
+ case ( LEVEL_WARNING ):
+ states[LEVEL_WARNING] = true;
+ case ( LEVEL_ERROR ):
+ states[LEVEL_ERROR] = true;
+ case ( LEVEL_SEVERE ):
+ states[LEVEL_SEVERE] = true;
+ default:
+ }
+
+ return states;
+ }
+
+ /**
+ * @param messageLevel the message leve.
+ * @return The label.
+ */
+ static String getLevelLabel( int messageLevel )
+ {
+ if ( messageLevel > -1 && LEVEL_NAMES.size() > messageLevel )
+ {
+ return (String) LEVEL_NAMES.get( messageLevel );
+ }
+
+ throw new IllegalArgumentException( "Invalid message level: " + messageLevel );
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/MessageSink.java b/src/main/java/org/apache/maven/plugins/assembly/io/MessageSink.java
new file mode 100644
index 0000000..9d37103
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/MessageSink.java
@@ -0,0 +1,55 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * Message Sink interface.
+ *
+ */
+interface MessageSink
+{
+
+ /**
+ * @param message the message
+ */
+ void debug( String message );
+
+ /**
+ * @param message the message
+ */
+ void info( String message );
+
+ /**
+ * @param message the message
+ */
+ void warning( String message );
+
+ /**
+ * @param message the message
+ */
+ void error( String message );
+
+ /**
+ * @param message the message
+ */
+ void severe( String message );
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategy.java b/src/main/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategy.java
index f6f9cb4..47f3ccf 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategy.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategy.java
@@ -19,10 +19,6 @@ package org.apache.maven.plugins.assembly.io;
* under the License.
*/
-import org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy;
-import org.apache.maven.shared.io.location.Location;
-import org.apache.maven.shared.io.logging.MessageHolder;
-
/**
*
*/
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java b/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
index b0062ba..172eb5e 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/RelativeFileLocatorStrategy.java
@@ -19,11 +19,6 @@ package org.apache.maven.plugins.assembly.io;
* under the License.
*/
-import org.apache.maven.shared.io.location.FileLocation;
-import org.apache.maven.shared.io.location.Location;
-import org.apache.maven.shared.io.location.LocatorStrategy;
-import org.apache.maven.shared.io.logging.MessageHolder;
-
import java.io.File;
/**
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/URLLocation.java b/src/main/java/org/apache/maven/plugins/assembly/io/URLLocation.java
new file mode 100644
index 0000000..faaac78
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/URLLocation.java
@@ -0,0 +1,81 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.maven.shared.utils.io.FileUtils;
+
+/**
+ * The URL Location.
+ *
+ */
+class URLLocation
+ extends FileLocation
+{
+
+ private final URL url;
+
+ private final String tempFilePrefix;
+
+ private final String tempFileSuffix;
+
+ private final boolean tempFileDeleteOnExit;
+
+ /**
+ * @param url the URL
+ * @param specification the spec
+ * @param tempFilePrefix the prefix
+ * @param tempFileSuffix the suffix
+ * @param tempFileDeleteOnExit delete on exit
+ */
+ URLLocation( URL url, String specification, String tempFilePrefix, String tempFileSuffix,
+ boolean tempFileDeleteOnExit )
+ {
+ super( specification );
+
+ this.url = url;
+ this.tempFilePrefix = tempFilePrefix;
+ this.tempFileSuffix = tempFileSuffix;
+ this.tempFileDeleteOnExit = tempFileDeleteOnExit;
+ }
+
+ /** {@inheritDoc} */
+ void initFile()
+ throws IOException
+ {
+ if ( unsafeGetFile() == null )
+ {
+ File tempFile = File.createTempFile( tempFilePrefix, tempFileSuffix );
+
+ if ( tempFileDeleteOnExit )
+ {
+ tempFile.deleteOnExit();
+ }
+
+ FileUtils.copyURLToFile( url, tempFile );
+
+ setFile( tempFile );
+ }
+ }
+
+}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategyTest.java b/src/test/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategyTest.java
index 9e00cd8..22507b7 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategyTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/io/PrefixedClasspathLocatorStrategyTest.java
@@ -20,10 +20,6 @@ package org.apache.maven.plugins.assembly.io;
*/
import junit.framework.TestCase;
-import org.apache.maven.shared.io.location.Location;
-import org.apache.maven.shared.io.location.LocatorStrategy;
-import org.apache.maven.shared.io.logging.DefaultMessageHolder;
-import org.apache.maven.shared.io.logging.MessageHolder;
/**
* @author Benjamin Bentmann
@@ -31,11 +27,11 @@ import org.apache.maven.shared.io.logging.MessageHolder;
public class PrefixedClasspathLocatorStrategyTest
extends TestCase
{
+
+ private MessageHolder mh = new DefaultMessageHolder();
public void testResolvePrefixWithLeadingSlashAndWithTrailingSlash()
{
- MessageHolder mh = new DefaultMessageHolder();
-
LocatorStrategy ls = new PrefixedClasspathLocatorStrategy( "/assemblies/" );
Location location = ls.resolve( "empty.xml", mh );
@@ -45,8 +41,6 @@ public class PrefixedClasspathLocatorStrategyTest
public void testResolvePrefixWithLeadingSlashAndWithoutTrailingSlash()
{
- MessageHolder mh = new DefaultMessageHolder();
-
LocatorStrategy ls = new PrefixedClasspathLocatorStrategy( "/assemblies" );
Location location = ls.resolve( "empty.xml", mh );
@@ -56,8 +50,6 @@ public class PrefixedClasspathLocatorStrategyTest
public void testResolvePrefixWithoutLeadingSlashAndWithTrailingSlash()
{
- MessageHolder mh = new DefaultMessageHolder();
-
LocatorStrategy ls = new PrefixedClasspathLocatorStrategy( "assemblies/" );
Location location = ls.resolve( "empty.xml", mh );
@@ -67,8 +59,6 @@ public class PrefixedClasspathLocatorStrategyTest
public void testResolvePrefixWithoutLeadingSlashAndWithoutTrailingSlash()
{
- MessageHolder mh = new DefaultMessageHolder();
-
LocatorStrategy ls = new PrefixedClasspathLocatorStrategy( "assemblies" );
Location location = ls.resolve( "empty.xml", mh );