+
\ No newline at end of file
From 4a944bf134b9a6dbab78509352b3968f39ddbcd4 Mon Sep 17 00:00:00 2001
From: Igor Fedorenko
Date: Wed, 2 Feb 2011 15:49:42 -0500
Subject: [PATCH 010/133] made Xpp3Dome serializable
Signed-off-by: Igor Fedorenko
---
src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
index 2f2f94e5..d6ae6fef 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
@@ -19,6 +19,7 @@
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
import java.io.IOException;
+import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,7 +33,10 @@
* NOTE: remove all the util code in here when separated, this class should be pure data.
*/
public class Xpp3Dom
+ implements Serializable
{
+ private static final long serialVersionUID = 2567894443061173996L;
+
protected String name;
protected String value;
From 4617e1f1b021a84b820de912131764081f731c8b Mon Sep 17 00:00:00 2001
From: Benjamin Bentmann
Date: Wed, 9 Feb 2011 19:56:26 +0100
Subject: [PATCH 011/133] o Removed obsolete configuration
---
pom.xml | 7 -------
1 file changed, 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8ba6f1f5..bf47430b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,13 +75,6 @@ limitations under the License.
-
- org.apache.maven.plugins
- maven-release-plugin
-
- https://svn.codehaus.org/plexus/plexus-utils/tags/
-
-
From 4c5e6b97645a3523caeb4aa3c5ec5c4d79e2a0dd Mon Sep 17 00:00:00 2001
From: Benjamin Bentmann
Date: Wed, 9 Feb 2011 19:58:56 +0100
Subject: [PATCH 012/133] [maven-release-plugin] prepare release
plexus-utils-2.0.6
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index bf47430b..9cb89d3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
plexus-utils
- 2.0.6-SNAPSHOT
+ 2.0.6Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 0b313b6f8b1e489b80b502189194ac559f748ac2 Mon Sep 17 00:00:00 2001
From: Benjamin Bentmann
Date: Wed, 9 Feb 2011 19:59:02 +0100
Subject: [PATCH 013/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 9cb89d3f..fcd6ab5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
plexus-utils
- 2.0.6
+ 2.0.7-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From e7b92afa33a41656273d888f53bfd7d55aa85bbe Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Sun, 13 Feb 2011 16:08:40 +0100
Subject: [PATCH 014/133] Restored jdk 1.3 compatibility to StringUtils
This implementation is probably also faster than the non 1.3 compat one.
Please note that I do not make any claims as to keeping 1.3 compatibility
for the rest of plexus-utils. But this class is used by everyone and
only contained a few lines of 1.4 code
Improved test coverage on method in question
---
.../org/codehaus/plexus/util/StringUtils.java | 19 ++++++++++++-------
.../codehaus/plexus/util/StringUtilsTest.java | 6 ++++++
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java
index 7e485e46..3b658bd9 100644
--- a/src/main/java/org/codehaus/plexus/util/StringUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/StringUtils.java
@@ -58,8 +58,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
*
Common String manipulation routines.
@@ -2380,11 +2378,18 @@ public static String escape( String source, final char[] escapedChars, char esca
*/
public static String removeDuplicateWhitespace( String s )
{
- String patternStr = "\\s+";
- String replaceStr = " ";
- Pattern pattern = Pattern.compile( patternStr );
- Matcher matcher = pattern.matcher( s );
- return matcher.replaceAll( replaceStr );
+ StringBuffer result = new StringBuffer( );
+ int length = s.length();
+ boolean isPreviousWhiteSpace = false;
+ for (int i = 0; i < length; i++){
+ char c = s.charAt( i );
+ boolean thisCharWhiteSpace = Character.isWhitespace( c );
+ if (!(isPreviousWhiteSpace && thisCharWhiteSpace)){
+ result.append( c );
+ }
+ isPreviousWhiteSpace = thisCharWhiteSpace;
+ }
+ return result.toString();
}
/**
diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
index 1f212129..63e7340f 100644
--- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
@@ -221,6 +221,12 @@ public void testRemoveDuplicateWhitespace()
assertEquals( "this is test ", StringUtils.removeDuplicateWhitespace( s ) );
s = "this \r\n is \n \r test ";
assertEquals( "this is test ", StringUtils.removeDuplicateWhitespace( s ) );
+ s = " this \r\n is \n \r test";
+ assertEquals( " this is test", StringUtils.removeDuplicateWhitespace( s ) );
+ s = "this \r\n is \n \r test \n ";
+ assertEquals( "this is test ", StringUtils.removeDuplicateWhitespace( s ) );
+
+
}
public void testUnifyLineSeparators()
From 8d084c7911dbf98d5531358b408fa4037229b66a Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 1 Mar 2011 08:06:48 +0100
Subject: [PATCH 015/133] Added intelliJ ignores
---
.gitignore | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index 5a78575e..d525fbe3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,8 @@
-target/
-.project
-.classpath
-.settings/
-bin
+target/
+.project
+.classpath
+.settings/
+bin
+*.iml
+*.ipr
+*.iws
\ No newline at end of file
From 401347173783947805458893210afb3d37ade0ae Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 2 Mar 2011 18:32:23 +0100
Subject: [PATCH 016/133] [PLXUTILS-138] Fixed threading issue when timeout
went off in executeCommandLine
Pumpers would be left running even after the timeout interrupt had
gone off
---
.../plexus/util/cli/CommandLineUtils.java | 76 +++++++++----------
.../plexus/util/cli/StreamFeeder.java | 24 +++++-
.../plexus/util/cli/StreamPumper.java | 20 ++++-
3 files changed, 75 insertions(+), 45 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 255a061d..6f9f0d8b 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -16,6 +16,10 @@
* limitations under the License.
*/
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -32,10 +36,6 @@
import java.util.StringTokenizer;
import java.util.Vector;
-import org.codehaus.plexus.util.Os;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.StringUtils;
-
/**
* @author Trygve Laugstøl
* @version $Id$
@@ -122,10 +122,10 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
}
/**
- * @param cl The command line to execute
- * @param systemIn The input to read from, must be thread safe
- * @param systemOut A consumer that receives output, must be thread safe
- * @param systemErr A consumer that receives system error stream output, must be thread safe
+ * @param cl The command line to execute
+ * @param systemIn The input to read from, must be thread safe
+ * @param systemOut A consumer that receives output, must be thread safe
+ * @param systemErr A consumer that receives system error stream output, must be thread safe
* @param timeoutInSeconds Positive integer to specify timeout, zero and negative integers for no timeout.
* @return A return value, see {@link Process#exitValue()}
* @throws CommandLineException or CommandLineTimeOutException if time out occurs
@@ -188,32 +188,7 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
returnValue = p.exitValue();
}
- if ( inputFeeder != null )
- {
- synchronized ( inputFeeder )
- {
- while ( !inputFeeder.isDone() )
- {
- inputFeeder.wait();
- }
- }
- }
-
- synchronized ( outputPumper )
- {
- while ( !outputPumper.isDone() )
- {
- outputPumper.wait();
- }
- }
-
- synchronized ( errorPumper )
- {
- while ( !errorPumper.isDone() )
- {
- errorPumper.wait();
- }
- }
+ waitForAllPumpers( inputFeeder, outputPumper, errorPumper );
processes.remove( new Long( cl.getPid() ) );
@@ -232,6 +207,12 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
catch ( InterruptedException ex )
{
killProcess( cl.getPid() );
+ if ( inputFeeder != null )
+ {
+ inputFeeder.disable();
+ }
+ outputPumper.disable();
+ errorPumper.disable();
throw new CommandLineTimeOutException( "Error while executing external command, process killed.", ex );
}
finally
@@ -254,6 +235,19 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
}
}
+ private static void waitForAllPumpers( StreamFeeder inputFeeder, StreamPumper outputPumper,
+ StreamPumper errorPumper )
+ throws InterruptedException
+ {
+ if ( inputFeeder != null )
+ {
+ inputFeeder.waitUntilDone();
+ }
+
+ outputPumper.waitUntilDone();
+ errorPumper.waitUntilDone();
+ }
+
/**
* Gets the shell environment variables for this process. Note that the returned mapping from variable names to
* values will always be case-sensitive regardless of the platform, i.e. getSystemEnvVars().get("path")
@@ -263,7 +257,7 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
* @return The shell environment variables, can be empty but never null.
* @throws IOException If the environment variables could not be queried from the shell.
* @see System#getenv() System.getenv() API, new in JDK 5.0, to get the same result
- * since 2.0.2 System#getenv() will be used if available in the current running jvm.
+ * since 2.0.2 System#getenv() will be used if available in the current running jvm.
*/
public static Properties getSystemEnvVars()
throws IOException
@@ -279,14 +273,14 @@ public static Properties getSystemEnvVars()
* @return Properties object of (possibly modified) envar keys mapped to their values.
* @throws IOException
* @see System#getenv() System.getenv() API, new in JDK 5.0, to get the same result
- * since 2.0.2 System#getenv() will be used if available in the current running jvm.
+ * since 2.0.2 System#getenv() will be used if available in the current running jvm.
*/
public static Properties getSystemEnvVars( boolean caseSensitive )
throws IOException
{
-
+
// check if it's 1.5+ run
-
+
Method getenvMethod = getEnvMethod();
if ( getenvMethod != null )
{
@@ -307,7 +301,7 @@ public static Properties getSystemEnvVars( boolean caseSensitive )
throw new IOException( e.getMessage() );
}
}
-
+
Process p = null;
try
@@ -627,7 +621,7 @@ public static String toString( String[] line )
}
return result.toString();
}
-
+
private static Method getEnvMethod()
{
try
@@ -643,7 +637,7 @@ private static Method getEnvMethod()
return null;
}
}
-
+
private static Properties getEnvFromSystem( Method method, boolean caseSensitive )
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java b/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
index 4b6ab4cb..9202cf9e 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
@@ -35,6 +35,9 @@ public class StreamFeeder
private boolean done;
+ volatile boolean disabled;
+
+
/**
* Create a new StreamFeeder
*
@@ -66,7 +69,6 @@ public void run()
{
close();
-
synchronized ( this )
{
done = true;
@@ -135,10 +137,28 @@ private void feed()
{
synchronized ( output )
{
- output.write( data );
+ if ( !disabled )
+ {
+ output.write( data );
+ }
data = input.read();
}
}
}
+
+ public synchronized void waitUntilDone()
+ throws InterruptedException
+ {
+ while ( !isDone() )
+ {
+ wait();
+ }
+ }
+
+ public void disable()
+ {
+ disabled = true;
+ }
+
}
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java b/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
index 67d54da6..3a4e0b35 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
@@ -84,8 +84,8 @@
*
* @author Florin Vancea
* @author Paul Julius
- * @since June 11, 2001
* @version $Id$
+ * @since June 11, 2001
*/
public class StreamPumper
extends Thread
@@ -102,6 +102,8 @@ public class StreamPumper
boolean done;
+ volatile boolean disabled;
+
public StreamPumper( InputStream in )
{
this( in, (StreamConsumer) null );
@@ -192,9 +194,23 @@ public Exception getException()
private void consumeLine( String line )
{
- if ( consumer != null )
+ if ( consumer != null && !disabled )
{
consumer.consumeLine( line );
}
}
+
+ public synchronized void waitUntilDone()
+ throws InterruptedException
+ {
+ while ( !isDone() )
+ {
+ wait();
+ }
+ }
+
+ public void disable()
+ {
+ disabled = true;
+ }
}
From ab197741e751b9358febdbe9b1483ab5e4e5ebc5 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 3 Mar 2011 09:23:58 +0100
Subject: [PATCH 017/133] o Extracted common base class and added unit test
---
.../util/cli/AbstractStreamHandler.java | 55 +++++++++++++++++++
.../plexus/util/cli/StreamFeeder.java | 33 ++---------
.../plexus/util/cli/StreamPumper.java | 29 +---------
.../plexus/util/cli/StreamPumperTest.java | 35 +++++++++---
4 files changed, 89 insertions(+), 63 deletions(-)
create mode 100644 src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java
diff --git a/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java b/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java
new file mode 100644
index 00000000..cfe979cd
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java
@@ -0,0 +1,55 @@
+package org.codehaus.plexus.util.cli;
+
+/*
+ * Copyright The Codehaus 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.
+ */
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class AbstractStreamHandler extends Thread {
+ private boolean done;
+ private volatile boolean disabled;
+
+ public boolean isDone()
+ {
+ return done;
+ }
+
+ public synchronized void waitUntilDone()
+ throws InterruptedException
+ {
+ while ( !isDone() )
+ {
+ wait();
+ }
+ }
+
+
+ protected boolean isDisabled() {
+ return disabled;
+ }
+
+ public void disable()
+ {
+ disabled = true;
+ }
+
+ public void setDone()
+ {
+ done = true;
+ }
+
+}
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java b/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
index 9202cf9e..4259b656 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
@@ -26,17 +26,11 @@
* @author Trygve Laugstøl
* @version $Id$
*/
-public class StreamFeeder
- extends Thread
-{
+public class StreamFeeder extends AbstractStreamHandler {
private InputStream input;
private OutputStream output;
- private boolean done;
-
- volatile boolean disabled;
-
/**
* Create a new StreamFeeder
@@ -71,7 +65,7 @@ public void run()
synchronized ( this )
{
- done = true;
+ setDone();
this.notifyAll();
}
@@ -119,11 +113,6 @@ public void close()
}
}
- public boolean isDone()
- {
- return done;
- }
-
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@@ -133,11 +122,11 @@ private void feed()
{
int data = input.read();
- while ( !done && data != -1 )
+ while ( !isDone() && data != -1 )
{
synchronized ( output )
{
- if ( !disabled )
+ if ( !isDisabled())
{
output.write( data );
}
@@ -147,18 +136,4 @@ private void feed()
}
}
- public synchronized void waitUntilDone()
- throws InterruptedException
- {
- while ( !isDone() )
- {
- wait();
- }
- }
-
- public void disable()
- {
- disabled = true;
- }
-
}
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java b/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
index 3a4e0b35..e9d93f31 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
@@ -88,7 +88,7 @@
* @since June 11, 2001
*/
public class StreamPumper
- extends Thread
+ extends AbstractStreamHandler
{
private final BufferedReader in;
@@ -100,10 +100,6 @@ public class StreamPumper
private static final int SIZE = 1024;
- boolean done;
-
- volatile boolean disabled;
-
public StreamPumper( InputStream in )
{
this( in, (StreamConsumer) null );
@@ -162,7 +158,7 @@ public void run()
synchronized ( this )
{
- done = true;
+ setDone();
this.notifyAll();
}
@@ -182,11 +178,6 @@ public void close()
IOUtil.close( out );
}
- public boolean isDone()
- {
- return done;
- }
-
public Exception getException()
{
return exception;
@@ -194,23 +185,9 @@ public Exception getException()
private void consumeLine( String line )
{
- if ( consumer != null && !disabled )
+ if ( consumer != null && !isDisabled() )
{
consumer.consumeLine( line );
}
}
-
- public synchronized void waitUntilDone()
- throws InterruptedException
- {
- while ( !isDone() )
- {
- wait();
- }
- }
-
- public void disable()
- {
- disabled = true;
- }
}
diff --git a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java
index 4d21d810..c9ac1e6a 100644
--- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java
+++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java
@@ -52,6 +52,8 @@
* limitations under the License.
*/
+import junit.framework.TestCase;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -60,12 +62,11 @@
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
/**
* @author Paul Julius
*/
-public class StreamPumperTest extends TestCase
+public class StreamPumperTest
+ extends TestCase
{
private String lineSeparator;
@@ -80,7 +81,8 @@ public StreamPumperTest( String testName )
/*
* @see TestCase#setUp()
*/
- public void setUp() throws Exception
+ public void setUp()
+ throws Exception
{
super.setUp();
lineSeparator = System.getProperty( "line.separator" );
@@ -91,8 +93,7 @@ public void testPumping()
String line1 = "line1";
String line2 = "line2";
String lines = line1 + "\n" + line2;
- ByteArrayInputStream inputStream =
- new ByteArrayInputStream( lines.getBytes() );
+ ByteArrayInputStream inputStream = new ByteArrayInputStream( lines.getBytes() );
TestConsumer consumer = new TestConsumer();
StreamPumper pumper = new StreamPumper( inputStream, consumer );
@@ -188,9 +189,9 @@ static class TestConsumer
/**
* Checks to see if this consumer consumed a particular line. This method will wait up to timeout number of
* milliseconds for the line to get consumed.
- *
+ *
* @param testLine Line to test for.
- * @param timeout Number of milliseconds to wait for the line.
+ * @param timeout Number of milliseconds to wait for the line.
* @return true if the line gets consumed, else false.
*/
public boolean wasLineConsumed( String testLine, long timeout )
@@ -232,4 +233,22 @@ public void consumeLine( String line )
}
}
+ public void testEnabled()
+ {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( "AB\nCE\nEF".getBytes() );
+ TestConsumer streamConsumer = new TestConsumer();
+ StreamPumper streamPumper = new StreamPumper( byteArrayInputStream, streamConsumer );
+ streamPumper.run();
+ assertEquals( 3, streamConsumer.lines.size() );
+ }
+
+ public void testDisabled()
+ {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( "AB\nCE\nEF".getBytes() );
+ TestConsumer streamConsumer = new TestConsumer();
+ StreamPumper streamPumper = new StreamPumper( byteArrayInputStream, streamConsumer );
+ streamPumper.disable();
+ streamPumper.run();
+ assertEquals( 0, streamConsumer.lines.size() );
+ }
}
From a3f0eea4f476ae35073e294dfb7d88f4990aa3c4 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 3 Mar 2011 17:54:23 +0100
Subject: [PATCH 018/133] o Fixed code style.
---
.../codehaus/plexus/util/cli/AbstractStreamHandler.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java b/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java
index cfe979cd..2c7e8967 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/AbstractStreamHandler.java
@@ -19,8 +19,11 @@
/**
* @author Kristian Rosenvold
*/
-public class AbstractStreamHandler extends Thread {
+public class AbstractStreamHandler
+ extends Thread
+{
private boolean done;
+
private volatile boolean disabled;
public boolean isDone()
@@ -38,7 +41,8 @@ public synchronized void waitUntilDone()
}
- protected boolean isDisabled() {
+ protected boolean isDisabled()
+ {
return disabled;
}
From e282b22a3ddbb2ea4ae4d4b429b3b93b89409584 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 3 Mar 2011 18:17:16 +0100
Subject: [PATCH 019/133] [maven-release-plugin] prepare release
plexus-utils-2.0.7
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index fcd6ab5c..83b1cf86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
plexus-utils
- 2.0.7-SNAPSHOT
+ 2.0.7Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 275b2ae60e7a0e3e0671cc19878cb0ae31402312 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 3 Mar 2011 18:17:22 +0100
Subject: [PATCH 020/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 83b1cf86..d5407887 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
plexus-utils
- 2.0.7
+ 2.0.8-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From bf26a7fdf6e744dd1880e0e9613ca8ff4661e990 Mon Sep 17 00:00:00 2001
From: Jason Dillon
Date: Fri, 15 Apr 2011 14:19:28 -0700
Subject: [PATCH 021/133] Use spice-parent
---
pom.xml | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index d5407887..83f84c00 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,12 +20,11 @@ limitations under the License.
4.0.0
- org.codehaus.plexus
- plexus
- 2.0.7
- ../pom/pom.xml
+ org.sonatype.spice
+ spice-parent
+ 16
-
+
plexus-utils2.0.8-SNAPSHOT
@@ -43,6 +42,15 @@ limitations under the License.
http://jira.codehaus.org/browse/PLXUTILS
+
+
+ junit
+ junit
+ 3.8.2
+ test
+
+
+
From 7826e20ebec8242a234f6a5804879623da9c2bc9 Mon Sep 17 00:00:00 2001
From: Olivier Lamy
Date: Thu, 12 May 2011 15:01:11 +0200
Subject: [PATCH 022/133] restore plexus groupId
---
pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 83f84c00..41ffdb0b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,8 @@ limitations under the License.
spice-parent16
-
+
+ org.codehaus.plexusplexus-utils2.0.8-SNAPSHOT
From dff209e5a1f7c1bb4a4de2a19582bbc2cb3c6f0c Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 19 Apr 2011 13:34:48 +0200
Subject: [PATCH 023/133] [PLXUTILS-25] Made shutdown hook local to
executeCommandLine without global singletons
Removed killProcess and isAlive(long) because they did not work, and no-one at mojo/asf were using them
---
.../plexus/util/cli/CommandLineUtils.java | 106 +++++-------------
.../plexus/util/cli/ShutdownHookUtils.java | 62 ++++++++++
2 files changed, 88 insertions(+), 80 deletions(-)
create mode 100644 src/main/java/org/codehaus/plexus/util/cli/ShutdownHookUtils.java
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 6f9f0d8b..849c7a18 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -27,8 +27,6 @@
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
@@ -42,47 +40,6 @@
*/
public abstract class CommandLineUtils
{
- private static Map processes = Collections.synchronizedMap( new HashMap() );
-
- private static Thread shutdownHook = new Thread( "CommandlineUtil shutdown" )
- {
- public void run()
- {
- if ( ( processes != null ) && ( processes.size() > 0 ) )
- {
- System.err.println( "Destroying " + processes.size() + " processes" );
- for ( Iterator it = processes.values().iterator(); it.hasNext(); )
- {
- System.err.println( "Destroying process.." );
- ( (Process) it.next() ).destroy();
-
- }
- System.err.println( "Destroyed " + processes.size() + " processes" );
- }
- }
- };
-
- static
- {
- shutdownHook.setContextClassLoader( null );
- addShutdownHook();
- }
-
- public static void addShutdownHook()
- {
- Runtime.getRuntime().addShutdownHook( shutdownHook );
- }
-
- public static void removeShutdownHook( boolean execute )
- {
- Runtime.getRuntime().removeShutdownHook( shutdownHook );
-
- if ( execute )
- {
- shutdownHook.run();
- }
- }
-
public static class StringStreamConsumer
implements StreamConsumer
{
@@ -101,6 +58,23 @@ public String getOutput()
}
}
+ private static class ProcessHook extends Thread {
+ private final Process process;
+
+ private ProcessHook( Process process )
+ {
+ super("CommandlineUtils process shutdown hook");
+ this.process = process;
+ this.setContextClassLoader( null );
+ }
+
+ public void run()
+ {
+ process.destroy();
+ }
+ }
+
+
public static int executeCommandLine( Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr )
throws CommandLineException
{
@@ -129,6 +103,7 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
* @param timeoutInSeconds Positive integer to specify timeout, zero and negative integers for no timeout.
* @return A return value, see {@link Process#exitValue()}
* @throws CommandLineException or CommandLineTimeOutException if time out occurs
+ * @noinspection ThrowableResultOfMethodCallIgnored
*/
public static int executeCommandLine( Commandline cl, InputStream systemIn, StreamConsumer systemOut,
StreamConsumer systemErr, int timeoutInSeconds )
@@ -143,7 +118,6 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
p = cl.execute();
- processes.put( new Long( cl.getPid() ), p );
StreamFeeder inputFeeder = null;
@@ -165,6 +139,10 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
errorPumper.start();
+ ProcessHook processHook = new ProcessHook( p );
+
+ ShutdownHookUtils.addShutDownHook( processHook );
+
try
{
int returnValue;
@@ -190,8 +168,6 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
waitForAllPumpers( inputFeeder, outputPumper, errorPumper );
- processes.remove( new Long( cl.getPid() ) );
-
if ( outputPumper.getException() != null )
{
throw new CommandLineException( "Error inside systemOut parser", outputPumper.getException() );
@@ -206,7 +182,6 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
}
catch ( InterruptedException ex )
{
- killProcess( cl.getPid() );
if ( inputFeeder != null )
{
inputFeeder.disable();
@@ -217,6 +192,10 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
}
finally
{
+ ShutdownHookUtils.removeShutdownHook( processHook );
+
+ processHook.run();
+
if ( inputFeeder != null )
{
inputFeeder.close();
@@ -226,12 +205,6 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
errorPumper.close();
- p.destroy();
-
- if ( processes.get( new Long( cl.getPid() ) ) != null )
- {
- processes.remove( new Long( cl.getPid() ) );
- }
}
}
@@ -377,33 +350,6 @@ else if ( lastKey != null )
}
}
- /**
- * Kill a process launched by executeCommandLine methods.
- * Doesn't work correctly on windows, only the cmd process will be destroy but not the sub process (Bug ID 4770092)
- *
- * @param pid The pid of command return by Commandline.getPid()
- */
- public static void killProcess( long pid )
- {
- Process p = (Process) processes.get( new Long( pid ) );
-
- if ( p != null )
- {
- p.destroy();
- System.out.println( "Process " + pid + " is killed." );
- processes.remove( new Long( pid ) );
- }
- else
- {
- System.out.println( "don't exist." );
- }
- }
-
- public static boolean isAlive( long pid )
- {
- return ( processes.get( new Long( pid ) ) != null );
- }
-
public static boolean isAlive( Process p )
{
if ( p == null )
diff --git a/src/main/java/org/codehaus/plexus/util/cli/ShutdownHookUtils.java b/src/main/java/org/codehaus/plexus/util/cli/ShutdownHookUtils.java
new file mode 100644
index 00000000..20873b07
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/cli/ShutdownHookUtils.java
@@ -0,0 +1,62 @@
+package org.codehaus.plexus.util.cli;
+
+/*
+ * Copyright The Codehaus 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 java.security.AccessControlException;
+
+/**
+ * A shutdown hook that does not throw any exceptions upon container startup/shutdown or security manager
+ * restrictions.
+ *
+ * Incorrect usage of the hook itself may still throw an exception.
+ *
+ * @author Kristian Rosenvold
+ */
+class ShutdownHookUtils
+{
+
+ public static void addShutDownHook( Thread hook )
+ {
+ try
+ {
+ Runtime.getRuntime().addShutdownHook( hook );
+ }
+ catch ( IllegalStateException ignore )
+ {
+ }
+ catch ( AccessControlException ignore )
+ {
+ }
+
+
+ }
+
+ public static void removeShutdownHook( Thread hook )
+ {
+ try
+ {
+ Runtime.getRuntime().removeShutdownHook( hook );
+ }
+ catch ( IllegalStateException ignore )
+ {
+ }
+ catch ( AccessControlException ignore )
+ {
+ }
+ }
+
+}
From 2e68f9519147eadb2dc27da3bdfe942529f054d4 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 16 May 2011 20:15:13 +0200
Subject: [PATCH 024/133] [PLXUTILS-1] Added reallySleep method
Guarantees miniumum sleep time, even on windows
---
.../codehaus/plexus/util/FileUtilsTest.java | 151 ++++++++++--------
1 file changed, 82 insertions(+), 69 deletions(-)
diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
index 88b59de2..0620ad42 100644
--- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
@@ -29,6 +29,8 @@
import java.net.URL;
import java.util.Properties;
+import sun.awt.windows.ThemeReader;
+
/**
* This is used to test FileUtils for correctness.
*
@@ -127,12 +129,12 @@ public void testToFileNull()
public void testToURLs()
throws Exception
{
- File[] files = new File[]{new File( "file1" ), new File( "file2" ),};
+ File[] files = new File[]{ new File( "file1" ), new File( "file2" ), };
URL[] urls = FileUtils.toURLs( files );
- assertEquals( "The length of the generated URL's is not equals to the length of files. " + "Was " + files
- .length + ", expected " + urls.length, files.length, urls.length );
+ assertEquals( "The length of the generated URL's is not equals to the length of files. " + "Was " + files.length
+ + ", expected " + urls.length, files.length, urls.length );
for ( int i = 0; i < urls.length; i++ )
{
@@ -147,7 +149,7 @@ public void testGetFilesFromExtension()
// Non-existent files
final String[] emptyFileNames =
- FileUtils.getFilesFromExtension( getTestDirectory().getAbsolutePath(), new String[]{"java"} );
+ FileUtils.getFilesFromExtension( getTestDirectory().getAbsolutePath(), new String[]{ "java" } );
assertTrue( emptyFileNames.length == 0 );
// Existing files
@@ -178,7 +180,7 @@ public void testMkdir()
FileUtils.mkdir( winFile.getAbsolutePath() );
assertTrue( false );
}
- catch ( IllegalArgumentException e)
+ catch ( IllegalArgumentException e )
{
assertTrue( true );
}
@@ -307,7 +309,7 @@ public void testForceMkdir()
FileUtils.forceMkdir( winFile );
assertTrue( false );
}
- catch ( IllegalArgumentException e)
+ catch ( IllegalArgumentException e )
{
assertTrue( true );
}
@@ -391,7 +393,7 @@ public void testCopyIfModifiedWhenSourceIsNewer()
FileUtils.copyFile( testFile1, destination );
// Make sure source is newer
- Thread.sleep( 1000 );
+ reallySleep( 1000 );
// Place source
File source = new File( getTestDirectory(), "copy1.txt" );
@@ -412,7 +414,7 @@ public void testCopyIfModifiedWhenSourceIsOlder()
FileUtils.copyFile( testFile1, source );
// Make sure desintation is newer
- Thread.sleep( 1000 );
+ reallySleep( 1000 );
// Place destination
File desintation = new File( getTestDirectory(), "/temp/copy1.txt" );
@@ -556,12 +558,14 @@ public void testResolveFileDot()
public void testNormalize()
throws Exception
{
- final String[] src = {"", "/", "///", "/foo", "/foo//", "/./", "/foo/./", "/foo/./bar", "/foo/../bar",
- "/foo/../bar/../baz", "/foo/bar/../../baz", "/././", "/foo/./../bar", "/foo/.././bar/", "//foo//./bar",
- "/../", "/foo/../../"};
+ final String[] src =
+ { "", "/", "///", "/foo", "/foo//", "/./", "/foo/./", "/foo/./bar", "/foo/../bar", "/foo/../bar/../baz",
+ "/foo/bar/../../baz", "/././", "/foo/./../bar", "/foo/.././bar/", "//foo//./bar", "/../",
+ "/foo/../../" };
- final String[] dest = {"", "/", "/", "/foo", "/foo/", "/", "/foo/", "/foo/bar", "/bar", "/baz", "/baz", "/",
- "/bar", "/bar/", "/foo/bar", null, null};
+ final String[] dest =
+ { "", "/", "/", "/foo", "/foo/", "/", "/foo/", "/foo/bar", "/bar", "/baz", "/baz", "/", "/bar", "/bar/",
+ "/foo/bar", null, null };
assertEquals( "Oops, test writer goofed", src.length, dest.length );
@@ -631,12 +635,8 @@ public void testFileUtils()
public void testGetExtension()
{
final String[][] tests =
- {{"filename.ext", "ext"}
- , {"README", ""}
- , {"domain.dot.com", "com"}
- , {"image.jpeg", "jpeg"}
- , {"folder" + File.separator + "image.jpeg", "jpeg"}
- , {"folder" + File.separator + "README", ""}};
+ { { "filename.ext", "ext" }, { "README", "" }, { "domain.dot.com", "com" }, { "image.jpeg", "jpeg" },
+ { "folder" + File.separator + "image.jpeg", "jpeg" }, { "folder" + File.separator + "README", "" } };
for ( int i = 0; i < tests.length; i++ )
{
@@ -650,14 +650,13 @@ public void testGetExtensionWithPaths()
// Since the utilities are based on the separator for the platform
// running the test, ensure we are using the right separator
final String sep = File.separator;
- final String[][] testsWithPaths = {
- { sep + "tmp" + sep + "foo" + sep + "filename.ext", "ext"}
- , {"C:" + sep + "temp" + sep + "foo" + sep + "filename.ext", "ext"}
- , {"" + sep + "tmp" + sep + "foo.bar" + sep + "filename.ext", "ext"}
- , {"C:" + sep + "temp" + sep + "foo.bar" + sep + "filename.ext", "ext"}
- , {"" + sep + "tmp" + sep + "foo.bar" + sep + "README", ""}
- , {"C:" + sep + "temp" + sep + "foo.bar" + sep + "README", ""}
- , {".." + sep + "filename.ext", "ext"}, {"blabla", ""}};
+ final String[][] testsWithPaths = { { sep + "tmp" + sep + "foo" + sep + "filename.ext", "ext" },
+ { "C:" + sep + "temp" + sep + "foo" + sep + "filename.ext", "ext" },
+ { "" + sep + "tmp" + sep + "foo.bar" + sep + "filename.ext", "ext" },
+ { "C:" + sep + "temp" + sep + "foo.bar" + sep + "filename.ext", "ext" },
+ { "" + sep + "tmp" + sep + "foo.bar" + sep + "README", "" },
+ { "C:" + sep + "temp" + sep + "foo.bar" + sep + "README", "" }, { ".." + sep + "filename.ext", "ext" },
+ { "blabla", "" } };
for ( int i = 0; i < testsWithPaths.length; i++ )
{
assertEquals( testsWithPaths[i][1], FileUtils.getExtension( testsWithPaths[i][0] ) );
@@ -667,8 +666,8 @@ public void testGetExtensionWithPaths()
public void testRemoveExtension()
{
- final String[][] tests = {{"filename.ext", "filename"}, {"first.second.third.ext", "first.second.third"},
- {"README", "README"}, {"domain.dot.com", "domain.dot"}, {"image.jpeg", "image"}};
+ final String[][] tests = { { "filename.ext", "filename" }, { "first.second.third.ext", "first.second.third" },
+ { "README", "README" }, { "domain.dot.com", "domain.dot" }, { "image.jpeg", "image" } };
for ( int i = 0; i < tests.length; i++ )
{
@@ -684,20 +683,17 @@ public void testRemoveExtensionWithPaths()
// running the test, ensure we are using the right separator
final String sep = File.separator;
final String[][] testsWithPaths =
- {{sep + "tmp" + sep + "foo" + sep + "filename.ext"
- , sep + "tmp" + sep + "foo" + sep + "filename"}
- , {"C:" + sep + "temp" + sep + "foo" + sep + "filename.ext"
- , "C:" + sep + "temp" + sep + "foo" + sep + "filename"}
- , {sep + "tmp" + sep + "foo.bar" + sep + "filename.ext"
- , sep + "tmp" + sep + "foo.bar" + sep + "filename"}
- , {"C:" + sep + "temp" + sep + "foo.bar" + sep + "filename.ext"
- , "C:" + sep + "temp" + sep + "foo.bar" + sep + "filename"}
- , {sep + "tmp" + sep + "foo.bar" + sep + "README"
- , sep + "tmp" + sep + "foo.bar" + sep + "README"}
- , {"C:" + sep + "temp" + sep + "foo.bar" + sep + "README"
- , "C:" + sep + "temp" + sep + "foo.bar" + sep + "README"}
- , {".." + sep + "filename.ext"
- , ".." + sep + "filename"}};
+ { { sep + "tmp" + sep + "foo" + sep + "filename.ext", sep + "tmp" + sep + "foo" + sep + "filename" },
+ { "C:" + sep + "temp" + sep + "foo" + sep + "filename.ext",
+ "C:" + sep + "temp" + sep + "foo" + sep + "filename" },
+ { sep + "tmp" + sep + "foo.bar" + sep + "filename.ext",
+ sep + "tmp" + sep + "foo.bar" + sep + "filename" },
+ { "C:" + sep + "temp" + sep + "foo.bar" + sep + "filename.ext",
+ "C:" + sep + "temp" + sep + "foo.bar" + sep + "filename" },
+ { sep + "tmp" + sep + "foo.bar" + sep + "README", sep + "tmp" + sep + "foo.bar" + sep + "README" },
+ { "C:" + sep + "temp" + sep + "foo.bar" + sep + "README",
+ "C:" + sep + "temp" + sep + "foo.bar" + sep + "README" },
+ { ".." + sep + "filename.ext", ".." + sep + "filename" } };
for ( int i = 0; i < testsWithPaths.length; i++ )
{
@@ -825,9 +821,9 @@ public void testCopyDirectoryStructureIfModified()
FileUtils.copyDirectoryStructureIfModified( from, to );
- File files[] = {new File( to, "root.txt" ), new File( to, "2/2.txt" ), new File( to, "2/2_1/2_1.txt" )};
+ File files[] = { new File( to, "root.txt" ), new File( to, "2/2.txt" ), new File( to, "2/2_1/2_1.txt" ) };
- long timestamps[] = {files[0].lastModified(), files[1].lastModified(), files[2].lastModified()};
+ long timestamps[] = { files[0].lastModified(), files[1].lastModified(), files[2].lastModified() };
checkFile( fRoot, files[0] );
@@ -913,13 +909,13 @@ public void testFilteredFileCopy()
filterProperties.setProperty( "s", "sample text" );
// test ${token}
- FileUtils.FilterWrapper[] wrappers1 = new FileUtils.FilterWrapper[]{new FileUtils.FilterWrapper()
+ FileUtils.FilterWrapper[] wrappers1 = new FileUtils.FilterWrapper[]{ new FileUtils.FilterWrapper()
{
public Reader getReader( Reader reader )
{
return new InterpolationFilterReader( reader, filterProperties, "${", "}" );
}
- }};
+ } };
File srcFile = new File( getTestDirectory(), "root.txt" );
FileUtils.fileWrite( srcFile.getAbsolutePath(), "UTF-8", "This is a test. Test ${s}\n" );
@@ -991,7 +987,8 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite()
}
- public void testFileRead() throws IOException
+ public void testFileRead()
+ throws IOException
{
File testFile = new File( getTestDirectory(), "testFileRead.txt" );
String testFileName = testFile.getAbsolutePath();
@@ -1018,7 +1015,8 @@ public void testFileRead() throws IOException
testFile.delete();
}
- public void testFileReadWithEncoding() throws IOException
+ public void testFileReadWithEncoding()
+ throws IOException
{
String encoding = "UTF-8";
File testFile = new File( getTestDirectory(), "testFileRead.txt" );
@@ -1041,7 +1039,8 @@ public void testFileReadWithEncoding() throws IOException
testFile.delete();
}
- public void testFileAppend() throws IOException
+ public void testFileAppend()
+ throws IOException
{
String baseString = "abc";
File testFile = new File( getTestDirectory(), "testFileAppend.txt" );
@@ -1064,7 +1063,8 @@ public void testFileAppend() throws IOException
testFile.delete();
}
- public void testFileAppendWithEncoding() throws IOException
+ public void testFileAppendWithEncoding()
+ throws IOException
{
String baseString = "abc";
String encoding = "UTF-8";
@@ -1088,7 +1088,8 @@ public void testFileAppendWithEncoding() throws IOException
testFile.delete();
}
- public void testFileWrite() throws IOException
+ public void testFileWrite()
+ throws IOException
{
File testFile = new File( getTestDirectory(), "testFileWrite.txt" );
String testFileName = testFile.getAbsolutePath();
@@ -1099,7 +1100,8 @@ public void testFileWrite() throws IOException
testFile.delete();
}
- public void testFileWriteWithEncoding() throws IOException
+ public void testFileWriteWithEncoding()
+ throws IOException
{
String encoding = "UTF-8";
File testFile = new File( getTestDirectory(), "testFileWrite.txt" );
@@ -1114,11 +1116,10 @@ public void testFileWriteWithEncoding() throws IOException
/**
* Workaround for the following Sun bugs. They are fixed in JDK 6u1 and JDK 5u11.
*
+ * @throws Exception
* @see Sun bug id=4403166
* @see Sun bug id=6182812
* @see Sun bug id=6481955
- *
- * @throws Exception
*/
public void testDeleteLongPathOnWindows()
throws Exception
@@ -1177,17 +1178,11 @@ public void testExtensions()
throws Exception
{
- String[][] values = {
- { "fry.frozen", "frozen" },
- { "fry", "" },
- { "fry.", "" },
- { "/turanga/leela/meets.fry", "fry" },
- { "/3000/turanga.leela.fry/zoidberg.helps", "helps" },
- { "/3000/turanga.leela.fry/zoidberg.", "" },
- { "/3000/turanga.leela.fry/zoidberg", "" },
- { "/3000/leela.fry.bender/", "" },
- { "/3000/leela.fry.bdner/.", "" },
- { "/3000/leela.fry.bdner/foo.bar.txt", "txt" } };
+ String[][] values =
+ { { "fry.frozen", "frozen" }, { "fry", "" }, { "fry.", "" }, { "/turanga/leela/meets.fry", "fry" },
+ { "/3000/turanga.leela.fry/zoidberg.helps", "helps" }, { "/3000/turanga.leela.fry/zoidberg.", "" },
+ { "/3000/turanga.leela.fry/zoidberg", "" }, { "/3000/leela.fry.bender/", "" },
+ { "/3000/leela.fry.bdner/.", "" }, { "/3000/leela.fry.bdner/foo.bar.txt", "txt" } };
for ( int i = 0; i < values.length; i++ )
{
@@ -1324,18 +1319,36 @@ public void testcopyDirectoryLayoutWithExcludesIncludes()
/**
* Be sure that {@link FileUtils#createTempFile(String, String, File)} is always unique.
+ *
* @throws Exception if any
*/
public void testCreateTempFile()
throws Exception
{
File last = FileUtils.createTempFile( "unique", ".tmp", null );
- for (int i = 0; i < 10; i ++ )
+ for ( int i = 0; i < 10; i++ )
{
File current = FileUtils.createTempFile( "unique", ".tmp", null );
- assertTrue( "No unique name: " + current.getName(),
- !current.getName().equals( last.getName() ) );
+ assertTrue( "No unique name: " + current.getName(), !current.getName().equals( last.getName() ) );
last = current;
}
}
+
+ /**
+ * Because windows(tm) quite frequently sleeps less than the advertised time
+ *
+ * @param time The amount of time to sleep
+ * @throws InterruptedException
+ */
+ private void reallySleep( int time )
+ throws InterruptedException
+ {
+ long until = System.currentTimeMillis() + time;
+ Thread.sleep( time );
+ while ( System.currentTimeMillis() < until )
+ {
+ Thread.sleep( time / 10 );
+ Thread.yield();
+ }
+ }
}
From 3b455498e62f8bd72fa1f82b022b206de7c983e9 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 16 May 2011 20:25:47 +0200
Subject: [PATCH 025/133] [PLXUTILS-121] Added MKS default exclude
---
src/main/java/org/codehaus/plexus/util/AbstractScanner.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
index 23879e91..685e9181 100644
--- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
@@ -30,6 +30,7 @@ public abstract class AbstractScanner
*
RCS: **/RCS, **/RCS/**
*
SCCS: **/SCCS, **/SCCS/**
*
VSSercer: **/vssver.scc
+ *
MKS: **/project.pj
*
SVN: **/.svn, **/.svn/**
*
GNU: **/.arch-ids, **/.arch-ids/**
*
Bazaar: **/.bzr, **/.bzr/**
@@ -68,6 +69,9 @@ public abstract class AbstractScanner
// Visual SourceSafe
"**/vssver.scc",
+ // MKS
+ "**/project.pj",
+
// Subversion
"**/.svn",
"**/.svn/**",
From 91498db9542cdb832410238eccccd6b5fef45074 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 9 Jun 2011 22:30:48 +0200
Subject: [PATCH 026/133] o Updated plugins for release
---
pom.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/pom.xml b/pom.xml
index 41ffdb0b..b9b229d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,21 @@ limitations under the License.
1.4
+
+ org.apache.maven.plugins
+ maven-release-plugin
+ 2.1
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.1.2
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ 2.6
+ org.apache.maven.pluginsmaven-surefire-plugin
From 972962533b2cfec983796a271242b6c297a617c1 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 9 Jun 2011 22:45:35 +0200
Subject: [PATCH 027/133] o Reverted distributionmanagement to override parent
---
pom.xml | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/pom.xml b/pom.xml
index b9b229d8..4fb0e162 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,23 @@ limitations under the License.
http://jira.codehaus.org/browse/PLXUTILS
+
+
+ plexus-releases
+ Plexus Release Repository
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
+ plexus-snapshots
+ Plexus Snapshot Repository
+ ${plexusDistMgmtSnapshotsUrl}
+
+
+ codehaus.org
+ dav:https://dav.codehaus.org/plexus
+
+
+
junit
From 01d252ac6be7f132d37a632b9ddbdd345b037181 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 9 Jun 2011 22:47:39 +0200
Subject: [PATCH 028/133] [maven-release-plugin] prepare release
plexus-utils-2.1
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4fb0e162..d5ef0b33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 2.0.8-SNAPSHOT
+ 2.1Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 990b8d18556179cc1e1acc6ca30668375ab84e2c Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 9 Jun 2011 22:48:50 +0200
Subject: [PATCH 029/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d5ef0b33..dea9feb1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 2.1
+ 2.1.1-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From c71baa8c55669bfaa4a72b81dfbc5f109a04e1af Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Fri, 17 Jun 2011 21:38:44 +0200
Subject: [PATCH 030/133] o Java 1.5 upgrade. Generified some stuff
---
pom.xml | 5 +-
.../codehaus/plexus/util/CollectionUtils.java | 82 +++++++++----------
.../plexus/util/DirectoryScanner.java | 82 ++++++++++---------
.../util/InterpolationFilterReader.java | 8 +-
.../util/LineOrientedInterpolatingReader.java | 33 ++++----
.../plexus/util/introspection/ClassMap.java | 6 +-
.../plexus/util/introspection/MethodMap.java | 49 ++++++-----
.../plexus/util/io/FileInputStreamFacade.java | 3 -
.../plexus/util/io/RawInputStreamFacade.java | 4 +-
.../plexus/util/io/URLInputStreamFacade.java | 3 -
.../plexus/util/reflection/Reflector.java | 78 ++++++++++--------
.../util/reflection/ReflectorException.java | 4 +-
.../LineOrientedInterpolatingReaderTest.java | 30 +++----
.../plexus/util/cli/CommandLineUtilsTest.java | 17 ++--
14 files changed, 202 insertions(+), 202 deletions(-)
diff --git a/pom.xml b/pom.xml
index dea9feb1..f65c8f06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,9 +74,10 @@ limitations under the License.
org.apache.maven.pluginsmaven-compiler-plugin
+ 2.3.2
- 1.4
- 1.4
+ 1.5
+ 1.5
diff --git a/src/main/java/org/codehaus/plexus/util/CollectionUtils.java b/src/main/java/org/codehaus/plexus/util/CollectionUtils.java
index 4192b79f..1762b9ab 100644
--- a/src/main/java/org/codehaus/plexus/util/CollectionUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/CollectionUtils.java
@@ -55,7 +55,7 @@ public class CollectionUtils
* @param recessiveMap Recessive Map.
* @return The result map with combined dominant and recessive values.
*/
- public static Map mergeMaps( Map dominantMap, Map recessiveMap )
+ public static Map mergeMaps( Map dominantMap, Map recessiveMap )
{
if ( dominantMap == null && recessiveMap == null )
@@ -68,21 +68,21 @@ public static Map mergeMaps( Map dominantMap, Map recessiveMap )
return dominantMap;
}
- if ( dominantMap == null && recessiveMap != null )
+ if ( dominantMap == null)
{
return recessiveMap;
}
- Map result = new HashMap();
+ Map result = new HashMap();
// Grab the keys from the dominant and recessive maps.
- Set dominantMapKeys = dominantMap.keySet();
- Set recessiveMapKeys = recessiveMap.keySet();
+ Set dominantMapKeys = dominantMap.keySet();
+ Set recessiveMapKeys = recessiveMap.keySet();
// Create the set of keys that will be contributed by the
// recessive Map by subtracting the intersection of keys
// from the recessive Map's keys.
- Collection contributingRecessiveKeys =
+ Collection contributingRecessiveKeys =
CollectionUtils.subtract( recessiveMapKeys,
CollectionUtils.intersection( dominantMapKeys, recessiveMapKeys ) );
@@ -90,9 +90,8 @@ public static Map mergeMaps( Map dominantMap, Map recessiveMap )
// Now take the keys we just found and extract the values from
// the recessiveMap and put the key:value pairs into the dominantMap.
- for ( Iterator i = contributingRecessiveKeys.iterator(); i.hasNext(); )
+ for ( K key : contributingRecessiveKeys )
{
- Object key = i.next();
result.put( key, recessiveMap.get( key ) );
}
@@ -107,9 +106,9 @@ public static Map mergeMaps( Map dominantMap, Map recessiveMap )
* @param maps An array of Maps to merge.
* @return Map The result Map produced after the merging process.
*/
- public static Map mergeMaps( Map[] maps )
+ public static Map mergeMaps( Map[] maps )
{
- Map result = null;
+ Map result;
if ( maps.length == 0 )
{
@@ -140,20 +139,21 @@ else if ( maps.length == 1 )
* will be equal to the minimum of the cardinality of that element
* in the two given {@link Collection}s.
*
+ * @param a The first collection
+ * @param b The second collection
* @see Collection#retainAll
+ * @return The intersection of a and b, never null
*/
- public static Collection intersection( final Collection a, final Collection b )
+ public static Collection intersection( final Collection a, final Collection b )
{
- ArrayList list = new ArrayList();
- Map mapa = getCardinalityMap( a );
- Map mapb = getCardinalityMap( b );
- Set elts = new HashSet( a );
+ ArrayList list = new ArrayList();
+ Map mapa = getCardinalityMap( a );
+ Map mapb = getCardinalityMap( b );
+ Set elts = new HashSet( a );
elts.addAll( b );
- Iterator it = elts.iterator();
- while ( it.hasNext() )
+ for ( E obj : elts )
{
- Object obj = it.next();
- for ( int i = 0,m = Math.min( getFreq( obj, mapa ), getFreq( obj, mapb ) ); i < m; i++ )
+ for ( int i = 0, m = Math.min( getFreq( obj, mapa ), getFreq( obj, mapb ) ); i < m; i++ )
{
list.add( obj );
}
@@ -167,15 +167,17 @@ public static Collection intersection( final Collection a, final Collection b )
* will be the cardinality of e in a minus the cardinality
* of e in b, or zero, whichever is greater.
*
+ * @param a The start collection
+ * @param b The collection that will be subtracted
* @see Collection#removeAll
+ * @return The result of the subtraction
*/
- public static Collection subtract( final Collection a, final Collection b )
+ public static Collection subtract( final Collection a, final Collection b )
{
- ArrayList list = new ArrayList( a );
- Iterator it = b.iterator();
- while ( it.hasNext() )
+ ArrayList list = new ArrayList( a );
+ for ( T aB : b )
{
- list.remove( it.next() );
+ list.remove( aB );
}
return list;
}
@@ -187,35 +189,35 @@ public static Collection subtract( final Collection a, final Collection b )
* in the {@link Collection}.
* An entry that maps to null indicates that the
* element does not appear in the given {@link Collection}.
+ * @param col The collection to count cardinalities for
+ * @return A map of counts, indexed on each element in the collection
*/
- public static Map getCardinalityMap( final Collection col )
+ public static Map getCardinalityMap( final Collection col )
{
- HashMap count = new HashMap();
- Iterator it = col.iterator();
- while ( it.hasNext() )
+ HashMap count = new HashMap();
+ for ( E obj : col )
{
- Object obj = it.next();
- Integer c = (Integer) ( count.get( obj ) );
+ Integer c = count.get( obj );
if ( null == c )
{
- count.put( obj, new Integer( 1 ) );
+ count.put( obj, 1 );
}
else
{
- count.put( obj, new Integer( c.intValue() + 1 ) );
+ count.put( obj, c + 1 );
}
}
return count;
}
- public static List iteratorToList( Iterator it )
+ public static List iteratorToList( Iterator it )
{
if ( it == null )
{
throw new NullPointerException( "it cannot be null." );
}
- List list = new ArrayList();
+ List list = new ArrayList();
while ( it.hasNext() )
{
@@ -229,23 +231,21 @@ public static List iteratorToList( Iterator it )
//
// ----------------------------------------------------------------------
- private static final int getFreq( final Object obj, final Map freqMap )
+ private static int getFreq( final E obj, final Map freqMap )
{
try
{
- Object o = freqMap.get( obj );
+ Integer o = freqMap.get( obj );
if ( o != null ) // minimize NullPointerExceptions
{
- return ( (Integer) o ).intValue();
+ return o;
}
}
- catch ( NullPointerException e )
+ catch ( NullPointerException ignore )
{
- // ignored
}
- catch ( NoSuchElementException e )
+ catch ( NoSuchElementException ignore )
{
- // ignored
}
return 0;
}
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
index b7155406..1d22fb29 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
@@ -155,40 +155,40 @@ public class DirectoryScanner extends AbstractScanner
/** The files which matched at least one include and no excludes
* and were selected.
*/
- protected Vector filesIncluded;
+ protected Vector filesIncluded;
/** The files which did not match any includes or selectors. */
- protected Vector filesNotIncluded;
+ protected Vector filesNotIncluded;
/**
* The files which matched at least one include and at least
* one exclude.
*/
- protected Vector filesExcluded;
+ protected Vector filesExcluded;
/** The directories which matched at least one include and no excludes
* and were selected.
*/
- protected Vector dirsIncluded;
+ protected Vector dirsIncluded;
/** The directories which were found and did not match any includes. */
- protected Vector dirsNotIncluded;
+ protected Vector dirsNotIncluded;
/**
* The directories which matched at least one include and at least one
* exclude.
*/
- protected Vector dirsExcluded;
+ protected Vector dirsExcluded;
/** The files which matched at least one include and no excludes and
* which a selector discarded.
*/
- protected Vector filesDeselected;
+ protected Vector filesDeselected;
/** The directories which matched at least one include and no excludes
* but which a selector discarded.
*/
- protected Vector dirsDeselected;
+ protected Vector dirsDeselected;
/** Whether or not our results were built by a slow scan. */
protected boolean haveSlowResults = false;
@@ -219,6 +219,7 @@ public DirectoryScanner()
* @param basedir The base directory to scan.
* Must not be null.
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public void setBasedir( String basedir )
{
setBasedir( new File( basedir.replace( '/', File.separatorChar ).replace(
@@ -253,6 +254,7 @@ public File getBasedir()
*
* @param followSymlinks whether or not symbolic links should be followed
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public void setFollowSymlinks( boolean followSymlinks )
{
this.followSymlinks = followSymlinks;
@@ -265,6 +267,7 @@ public void setFollowSymlinks( boolean followSymlinks )
* @return true if all files and directories which have
* been found so far have been included.
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public boolean isEverythingIncluded()
{
return everythingIncluded;
@@ -298,14 +301,14 @@ public void scan() throws IllegalStateException
setupDefaultFilters();
- filesIncluded = new Vector();
- filesNotIncluded = new Vector();
- filesExcluded = new Vector();
- filesDeselected = new Vector();
- dirsIncluded = new Vector();
- dirsNotIncluded = new Vector();
- dirsExcluded = new Vector();
- dirsDeselected = new Vector();
+ filesIncluded = new Vector();
+ filesNotIncluded = new Vector();
+ filesExcluded = new Vector();
+ filesDeselected = new Vector();
+ dirsIncluded = new Vector();
+ dirsNotIncluded = new Vector();
+ dirsExcluded = new Vector();
+ dirsDeselected = new Vector();
if ( isIncluded( "" ) )
{
@@ -353,21 +356,19 @@ protected void slowScan()
String[] notIncl = new String[dirsNotIncluded.size()];
dirsNotIncluded.copyInto( notIncl );
- for ( int i = 0; i < excl.length; i++ )
+ for ( String anExcl : excl )
{
- if ( !couldHoldIncluded( excl[i] ) )
+ if ( !couldHoldIncluded( anExcl ) )
{
- scandir( new File( basedir, excl[i] ),
- excl[i] + File.separator, false );
+ scandir( new File( basedir, anExcl ), anExcl + File.separator, false );
}
}
- for ( int i = 0; i < notIncl.length; i++ )
+ for ( String aNotIncl : notIncl )
{
- if ( !couldHoldIncluded( notIncl[i] ) )
+ if ( !couldHoldIncluded( aNotIncl ) )
{
- scandir( new File( basedir, notIncl[i] ),
- notIncl[i] + File.separator, false );
+ scandir( new File( basedir, aNotIncl ), aNotIncl + File.separator, false );
}
}
@@ -385,7 +386,6 @@ protected void slowScan()
* prevent problems with an absolute path when using
* dir). Must not be null.
* @param fast Whether or not this call is part of a fast scan.
- * @throws IOException
*
* @see #filesIncluded
* @see #filesNotIncluded
@@ -429,15 +429,15 @@ protected void scandir( File dir, String vpath, boolean fast )
if ( !followSymlinks )
{
- Vector noLinks = new Vector();
- for ( int i = 0; i < newfiles.length; i++ )
+ Vector noLinks = new Vector();
+ for ( String newfile : newfiles )
{
try
{
- if ( isSymbolicLink( dir, newfiles[i] ) )
+ if ( isSymbolicLink( dir, newfile ) )
{
- String name = vpath + newfiles[i];
- File file = new File( dir, newfiles[i] );
+ String name = vpath + newfile;
+ File file = new File( dir, newfile );
if ( file.isDirectory() )
{
dirsExcluded.addElement( name );
@@ -449,26 +449,25 @@ protected void scandir( File dir, String vpath, boolean fast )
}
else
{
- noLinks.addElement( newfiles[i] );
+ noLinks.addElement( newfile );
}
}
catch ( IOException ioe )
{
- String msg = "IOException caught while checking "
- + "for links, couldn't get cannonical path!";
+ String msg = "IOException caught while checking " + "for links, couldn't get cannonical path!";
// will be caught and redirected to Ant's logging system
System.err.println( msg );
- noLinks.addElement( newfiles[i] );
+ noLinks.addElement( newfile );
}
}
newfiles = new String[noLinks.size()];
noLinks.copyInto( newfiles );
}
- for ( int i = 0; i < newfiles.length; i++ )
+ for ( String newfile : newfiles )
{
- String name = vpath + newfiles[i];
- File file = new File( dir, newfiles[i] );
+ String name = vpath + newfile;
+ File file = new File( dir, newfile );
if ( file.isDirectory() )
{
if ( isIncluded( name ) )
@@ -557,6 +556,7 @@ else if ( file.isFile() )
* @return false when the selectors says that the file
* should not be selected, true otherwise.
*/
+ @SuppressWarnings( { "UnusedParameters" } )
protected boolean isSelected( String name, File file )
{
return true;
@@ -587,6 +587,7 @@ public String[] getIncludedFiles()
*
* @see #slowScan
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getNotIncludedFiles()
{
slowScan();
@@ -606,6 +607,7 @@ public String[] getNotIncludedFiles()
*
* @see #slowScan
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getExcludedFiles()
{
slowScan();
@@ -625,6 +627,7 @@ public String[] getExcludedFiles()
*
* @see #slowScan
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getDeselectedFiles()
{
slowScan();
@@ -658,6 +661,7 @@ public String[] getIncludedDirectories()
*
* @see #slowScan
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getNotIncludedDirectories()
{
slowScan();
@@ -677,6 +681,7 @@ public String[] getNotIncludedDirectories()
*
* @see #slowScan
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getExcludedDirectories()
{
slowScan();
@@ -696,6 +701,7 @@ public String[] getExcludedDirectories()
*
* @see #slowScan
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getDeselectedDirectories()
{
slowScan();
@@ -715,6 +721,8 @@ public String[] getDeselectedDirectories()
* @param name the name of the file to test.
*
* @since Ant 1.5
+ * @return true if it's a symbolic link
+ * @throws java.io.IOException .
*/
public boolean isSymbolicLink( File parent, String name )
throws IOException
diff --git a/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java b/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
index 8eec7e44..17b8ee3b 100644
--- a/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
+++ b/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
@@ -90,10 +90,10 @@ public class InterpolationFilterReader
private int endTokenLength;
/** Default begin token. */
- private static String DEFAULT_BEGIN_TOKEN = "${";
+ private static final String DEFAULT_BEGIN_TOKEN = "${";
/** Default end token. */
- private static String DEFAULT_END_TOKEN = "}";
+ private static final String DEFAULT_END_TOKEN = "}";
public InterpolationFilterReader( Reader in, Map variables, String beginToken, String endToken )
{
@@ -201,7 +201,7 @@ public int read() throws IOException
return ch;
}
- int ch = -1;
+ int ch;
if ( previousIndex != -1 && previousIndex < endTokenLength )
{
ch = endToken.charAt( previousIndex++ );
@@ -213,7 +213,7 @@ public int read() throws IOException
if ( ch == beginToken.charAt( 0 ) )
{
- StringBuffer key = new StringBuffer();
+ StringBuilder key = new StringBuilder();
int beginTokenMatchPos = 1;
diff --git a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
index 47a5ba2f..9b892d40 100644
--- a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
+++ b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
@@ -25,7 +25,6 @@
import java.io.Reader;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -48,7 +47,7 @@ public class LineOrientedInterpolatingReader
private final PushbackReader pushbackReader;
- private final Map context;
+ private final Map context;
private final String startDelim;
@@ -64,7 +63,7 @@ public class LineOrientedInterpolatingReader
private String line;
- public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim,
+ public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim,
String escapeSeq )
{
super( reader );
@@ -92,12 +91,12 @@ public LineOrientedInterpolatingReader( Reader reader, Map context, String start
}
}
- public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim )
+ public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim )
{
this( reader, context, startDelim, endDelim, DEFAULT_ESCAPE_SEQ );
}
- public LineOrientedInterpolatingReader( Reader reader, Map context )
+ public LineOrientedInterpolatingReader( Reader reader, Map context )
{
this( reader, context, DEFAULT_START_DELIM, DEFAULT_END_DELIM, DEFAULT_ESCAPE_SEQ );
}
@@ -192,8 +191,8 @@ private void readAndInterpolateLine() throws IOException
private String readLine() throws IOException
{
- StringBuffer lineBuffer = new StringBuffer( 40 ); // half of the "normal" line maxsize
- int next = -1;
+ StringBuilder lineBuffer = new StringBuilder( 40 ); // half of the "normal" line maxsize
+ int next;
boolean lastWasCR = false;
while ( ( next = pushbackReader.read() ) > -1 )
@@ -235,9 +234,9 @@ private String replaceWithInterpolatedValues( String rawLine, Map evaluatedExpre
{
String result = rawLine;
- for ( Iterator it = evaluatedExpressions.entrySet().iterator(); it.hasNext(); )
+ for ( Object o : evaluatedExpressions.entrySet() )
{
- Map.Entry entry = (Map.Entry) it.next();
+ Map.Entry entry = (Map.Entry) o;
String expression = (String) entry.getKey();
@@ -251,14 +250,14 @@ private String replaceWithInterpolatedValues( String rawLine, Map evaluatedExpre
private Map evaluateExpressions( Set expressions )
{
- Map evaluated = new TreeMap();
+ Map evaluated = new TreeMap();
- for ( Iterator it = expressions.iterator(); it.hasNext(); )
+ for ( Object expression : expressions )
{
- String rawExpression = (String) it.next();
+ String rawExpression = (String) expression;
- String realExpression = rawExpression.substring( startDelim.length(), rawExpression.length()
- - endDelim.length() );
+ String realExpression =
+ rawExpression.substring( startDelim.length(), rawExpression.length() - endDelim.length() );
String[] parts = realExpression.split( "\\." );
if ( parts.length > 0 )
@@ -297,7 +296,7 @@ private Map evaluateExpressions( Set expressions )
private Set parseForExpressions( String rawLine )
{
- Set expressions = new HashSet();
+ Set expressions = new HashSet();
if ( rawLine != null )
{
@@ -342,7 +341,7 @@ private int findDelimiter( String rawLine, String delimiter, int lastPos )
{
int placeholder = lastPos;
- int position = -1;
+ int position;
do
{
position = rawLine.indexOf( delimiter, placeholder );
@@ -371,7 +370,7 @@ private int findDelimiter( String rawLine, String delimiter, int lastPos )
private String findAndReplaceUnlessEscaped(String rawLine, String search, String replace)
{
- StringBuffer lineBuffer = new StringBuffer( (int)(rawLine.length() * 1.5) );
+ StringBuilder lineBuffer = new StringBuilder( (int) ( rawLine.length() * 1.5 ) );
int lastReplacement = -1;
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java b/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
index a8b06765..06ff14d8 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
@@ -23,7 +23,7 @@
/**
* A cache of introspection information for a specific class instance.
- * Keys {@link java.lang.Method} objects by a concatenation of the
+ * Keys {@link java.lang.reflect.Method} objects by a concatenation of the
* method name and the names of classes that make up the parameters.
*
* @author Jason van Zyl
@@ -46,7 +46,7 @@ private static final class CacheMiss
* the basis for the Method map.
*/
- private Class clazz;
+ private final Class clazz;
/**
* Cache of Methods, or CACHE_MISS, keyed by method
@@ -426,7 +426,7 @@ public static Method getPublicMethod( Method method )
* Looks up the method with specified name and signature in the first public
* superclass or implemented interface of the class.
*
- * @param class the class whose method is sought
+ * @param clazz the class whose method is sought
* @param name the name of the method
* @param paramTypes the classes of method parameters
*/
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java b/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java
index bf733097..1b6a27e5 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java
@@ -42,28 +42,27 @@ public class MethodMap
/**
* Keep track of all methods with the same name.
*/
- Map methodByNameMap = new Hashtable();
+ Map> methodByNameMap = new Hashtable>();
/**
* Add a method to a list of methods by name.
* For a particular class we are keeping track
* of all the methods with the same name.
+ * @param method The method
*/
public void add(Method method)
{
String methodName = method.getName();
- List l = get( methodName );
+ List l = get( methodName );
if ( l == null)
{
- l = new ArrayList();
+ l = new ArrayList();
methodByNameMap.put(methodName, l);
}
l.add(method);
-
- return;
}
/**
@@ -72,9 +71,9 @@ public void add(Method method)
* @param key The name of the method.
* @return List list of methods
*/
- public List get(String key)
+ public List get(String key)
{
- return (List) methodByNameMap.get(key);
+ return methodByNameMap.get(key);
}
/**
@@ -145,7 +144,7 @@ public static class AmbiguousException extends Exception
private static Method getMostSpecific(List methods, Class[] classes)
throws AmbiguousException
{
- LinkedList applicables = getApplicables(methods, classes);
+ LinkedList applicables = getApplicables(methods, classes);
if(applicables.isEmpty())
{
@@ -154,7 +153,7 @@ private static Method getMostSpecific(List methods, Class[] classes)
if(applicables.size() == 1)
{
- return (Method)applicables.getFirst();
+ return applicables.getFirst();
}
/*
@@ -163,21 +162,18 @@ private static Method getMostSpecific(List methods, Class[] classes)
* (the most specific method) otherwise we have ambiguity.
*/
- LinkedList maximals = new LinkedList();
+ LinkedList maximals = new LinkedList();
- for (Iterator applicable = applicables.iterator();
- applicable.hasNext();)
+ for ( Method app : applicables )
{
- Method app = (Method) applicable.next();
Class[] appArgs = app.getParameterTypes();
boolean lessSpecific = false;
- for (Iterator maximal = maximals.iterator();
- !lessSpecific && maximal.hasNext();)
+ for ( Iterator maximal = maximals.iterator(); !lessSpecific && maximal.hasNext(); )
{
Method max = (Method) maximal.next();
- switch(moreSpecific(appArgs, max.getParameterTypes()))
+ switch ( moreSpecific( appArgs, max.getParameterTypes() ) )
{
case MORE_SPECIFIC:
{
@@ -205,9 +201,9 @@ private static Method getMostSpecific(List methods, Class[] classes)
}
}
- if(!lessSpecific)
+ if ( !lessSpecific )
{
- maximals.addLast(app);
+ maximals.addLast( app );
}
}
@@ -217,7 +213,7 @@ private static Method getMostSpecific(List methods, Class[] classes)
throw new AmbiguousException();
}
- return (Method)maximals.getFirst();
+ return maximals.getFirst();
}
/**
@@ -282,17 +278,17 @@ private static int moreSpecific(Class[] c1, Class[] c2)
* formal and actual arguments matches, and argument types are assignable
* to formal types through a method invocation conversion).
*/
- private static LinkedList getApplicables(List methods, Class[] classes)
+ private static LinkedList getApplicables(List methods, Class[] classes)
{
- LinkedList list = new LinkedList();
+ LinkedList list = new LinkedList();
- for (Iterator imethod = methods.iterator(); imethod.hasNext();)
+ for ( Object method1 : methods )
{
- Method method = (Method) imethod.next();
+ Method method = (Method) method1;
- if(isApplicable(method, classes))
+ if ( isApplicable( method, classes ) )
{
- list.add(method);
+ list.add( method );
}
}
@@ -302,6 +298,9 @@ private static LinkedList getApplicables(List methods, Class[] classes)
/**
* Returns true if the supplied method is applicable to actual
* argument types.
+ * @param method The method to check for applicability
+ * @param classes The arguments
+ * @return true if the method applies to the parameter types
*/
private static boolean isApplicable(Method method, Class[] classes)
{
diff --git a/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java
index 70a452e1..453f080f 100644
--- a/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java
+++ b/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java
@@ -27,9 +27,6 @@
public class FileInputStreamFacade implements InputStreamFacade {
private final File file;
- /**
- * Creates a new instance.
- */
public FileInputStreamFacade( File file )
{
this.file = file;
diff --git a/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java
index 008ce6ac..c982b8fb 100644
--- a/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java
+++ b/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java
@@ -22,12 +22,10 @@
/**
* Implementation of {@link InputStreamFacade} for raw input streams.
*/
+@SuppressWarnings( { "UnusedDeclaration" } )
public class RawInputStreamFacade implements InputStreamFacade {
final InputStream stream;
- /**
- * Creates a new instance.
- */
public RawInputStreamFacade( InputStream stream )
{
this.stream = stream;
diff --git a/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java
index bd09669b..9bd53d9f 100644
--- a/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java
+++ b/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java
@@ -26,9 +26,6 @@
public class URLInputStreamFacade implements InputStreamFacade {
private final URL url;
- /**
- * Creates a new instance.
- */
public URLInputStreamFacade( URL url )
{
this.url = url;
diff --git a/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java b/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java
index 1655803b..199c876a 100644
--- a/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java
+++ b/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java
@@ -56,7 +56,8 @@ public Reflector()
* @throws ReflectorException
* In case anything goes wrong here...
*/
- public Object newInstance( Class theClass, Object[] params )
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ public T newInstance( Class theClass, Object[] params )
throws ReflectorException
{
if ( params == null )
@@ -73,19 +74,19 @@ public Object newInstance( Class theClass, Object[] params )
try
{
- Constructor con = getConstructor( theClass, paramTypes );
+ Constructor con = getConstructor( theClass, paramTypes );
if ( con == null )
{
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append( "Constructor not found for class: " );
buffer.append( theClass.getName() );
buffer.append( " with specified or ancestor parameter classes: " );
- for ( int i = 0; i < paramTypes.length; i++ )
+ for ( Class paramType : paramTypes )
{
- buffer.append( paramTypes[i].getName() );
+ buffer.append( paramType.getName() );
buffer.append( ',' );
}
@@ -123,7 +124,8 @@ public Object newInstance( Class theClass, Object[] params )
* @throws ReflectorException
* In case anything goes wrong here...
*/
- public Object getSingleton( Class theClass, Object[] initParams )
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ public T getSingleton( Class theClass, Object[] initParams )
throws ReflectorException
{
Class[] paramTypes = new Class[initParams.length];
@@ -137,7 +139,8 @@ public Object getSingleton( Class theClass, Object[] initParams )
{
Method method = getMethod( theClass, GET_INSTANCE_METHOD_NAME, paramTypes );
- return method.invoke( null, initParams );
+ //noinspection unchecked
+ return (T) method.invoke( null, initParams );
}
catch ( InvocationTargetException ex )
{
@@ -163,6 +166,7 @@ public Object getSingleton( Class theClass, Object[] initParams )
* @throws ReflectorException
* In case of an error looking up or invoking the method.
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public Object invoke( Object target, String methodName, Object[] params )
throws ReflectorException
{
@@ -184,14 +188,14 @@ public Object invoke( Object target, String methodName, Object[] params )
if ( method == null )
{
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append( "Singleton-producing method named '" ).append( methodName )
.append( "' not found with specified parameter classes: " );
- for ( int i = 0; i < paramTypes.length; i++ )
+ for ( Class paramType : paramTypes )
{
- buffer.append( paramTypes[i].getName() );
+ buffer.append( paramType.getName() );
buffer.append( ',' );
}
@@ -212,6 +216,7 @@ public Object invoke( Object target, String methodName, Object[] params )
}
}
+ @SuppressWarnings( { "UnusedDeclaration" } )
public Object getStaticField( Class targetClass, String fieldName )
throws ReflectorException
{
@@ -239,6 +244,7 @@ public Object getStaticField( Class targetClass, String fieldName )
}
}
+ @SuppressWarnings( { "UnusedDeclaration" } )
public Object getField( Object target, String fieldName )
throws ReflectorException
{
@@ -303,6 +309,7 @@ public Object getField( Object target, String fieldName, boolean breakAccessibil
* @throws ReflectorException
* In case of an error looking up or invoking the method.
*/
+ @SuppressWarnings( { "UnusedDeclaration" } )
public Object invokeStatic( Class targetClass, String methodName, Object[] params )
throws ReflectorException
{
@@ -324,14 +331,15 @@ public Object invokeStatic( Class targetClass, String methodName, Object[] param
if ( method == null )
{
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
- buffer.append( "Singleton-producing method named \'" + methodName
- + "\' not found with specified parameter classes: " );
+ buffer.append( "Singleton-producing method named \'" )
+ .append( methodName )
+ .append( "\' not found with specified parameter classes: " );
- for ( int i = 0; i < paramTypes.length; i++ )
+ for ( Class paramType : paramTypes )
{
- buffer.append( paramTypes[i].getName() );
+ buffer.append( paramType.getName() );
buffer.append( ',' );
}
@@ -365,12 +373,12 @@ public Object invokeStatic( Class targetClass, String methodName, Object[] param
* @throws ReflectorException
* In case we can't retrieve the proper constructor.
*/
- public Constructor getConstructor( Class targetClass, Class[] params )
+ public Constructor getConstructor( Class targetClass, Class[] params )
throws ReflectorException
{
- Map constructorMap = getConstructorMap( targetClass );
+ Map> constructorMap = getConstructorMap( targetClass );
- StringBuffer key = new StringBuffer( 200 );
+ StringBuilder key = new StringBuilder( 200 );
key.append( "(" );
@@ -387,17 +395,18 @@ public Constructor getConstructor( Class targetClass, Class[] params )
key.append( ")" );
- Constructor constructor = null;
+ Constructor constructor;
String paramKey = key.toString();
synchronized ( paramKey.intern() )
{
- constructor = (Constructor) constructorMap.get( paramKey );
+ constructor = constructorMap.get( paramKey );
if ( constructor == null )
{
- Constructor[] cands = targetClass.getConstructors();
+ @SuppressWarnings( { "unchecked" } )
+ Constructor[] cands = (Constructor[]) targetClass.getConstructors();
for ( int i = 0, len = cands.length; i < len; i++ )
{
@@ -435,7 +444,7 @@ public Constructor getConstructor( Class targetClass, Class[] params )
public Object getObjectProperty( Object target, String propertyName )
throws ReflectorException
{
- Object returnValue = null;
+ Object returnValue;
if ( propertyName == null || propertyName.trim().length() < 1 )
{
@@ -494,7 +503,7 @@ public Object getObjectProperty( Object target, String propertyName )
else
{
returnValue = getField( target, propertyName, true );
- if ( method == null && returnValue == null )
+ if ( returnValue == null )
{
// TODO: Check if exception is the right action! Field exists, but contains null
throw new ReflectorException( "Neither method: \'" + propertyName + "\' nor bean accessor: \'"
@@ -535,9 +544,9 @@ public Method getMethod( Class targetClass, String methodName, Class[] params )
private Method _getMethod( Class targetClass, String methodName, Class[] params )
throws ReflectorException
{
- Map methodMap = getMethodMap( targetClass, methodName );
+ Map methodMap = (Map) getMethodMap( targetClass, methodName );
- StringBuffer key = new StringBuffer( 200 );
+ StringBuilder key = new StringBuilder( 200 );
key.append( "(" );
@@ -549,7 +558,7 @@ private Method _getMethod( Class targetClass, String methodName, Class[] params
key.append( ")" );
- Method method = null;
+ Method method;
String paramKey = key.toString();
@@ -604,10 +613,10 @@ private Method _getMethod( Class targetClass, String methodName, Class[] params
* @throws ReflectorException
* in case of a lookup error.
*/
- private Map getConstructorMap( Class theClass )
+ private Map> getConstructorMap( Class theClass )
throws ReflectorException
{
- return getMethodMap( theClass, CONSTRUCTOR_METHOD_NAME );
+ return (Map>) getMethodMap( theClass, CONSTRUCTOR_METHOD_NAME );
}
/**
@@ -621,10 +630,10 @@ private Map getConstructorMap( Class theClass )
* @throws ReflectorException
* in case of a lookup error.
*/
- private Map getMethodMap( Class theClass, String methodName )
+ private Map getMethodMap( Class theClass, String methodName )
throws ReflectorException
{
- Map methodMap = null;
+ Map methodMap;
if ( theClass == null )
{
@@ -635,14 +644,13 @@ private Map getMethodMap( Class theClass, String methodName )
synchronized ( className.intern() )
{
- Map classMethods = (Map) classMaps.get( className );
+ Map> classMethods = (Map>) classMaps.get( className );
if ( classMethods == null )
{
classMethods = new HashMap();
- methodMap = new HashMap();
+ methodMap = new HashMap();
classMethods.put( methodName, methodMap );
-
classMaps.put( className, classMethods );
}
else
@@ -651,11 +659,11 @@ private Map getMethodMap( Class theClass, String methodName )
synchronized ( key.intern() )
{
- methodMap = (Map) classMethods.get( methodName );
+ methodMap = classMethods.get( methodName );
if ( methodMap == null )
{
- methodMap = new HashMap();
+ methodMap = new HashMap();
classMethods.put( methodName, methodMap );
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/reflection/ReflectorException.java b/src/main/java/org/codehaus/plexus/util/reflection/ReflectorException.java
index de564e2f..567b060c 100644
--- a/src/main/java/org/codehaus/plexus/util/reflection/ReflectorException.java
+++ b/src/main/java/org/codehaus/plexus/util/reflection/ReflectorException.java
@@ -26,9 +26,7 @@
public class ReflectorException
extends Exception
{
- /**
- * Create a new ReflectorException.
- */
+ @SuppressWarnings( { "UnusedDeclaration" } )
public ReflectorException()
{
}
diff --git a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java
index 9852b5bd..66ae435e 100644
--- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java
+++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java
@@ -75,9 +75,7 @@ public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() thro
public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception
{
- Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ Map m = getStandardMap();
String foo = "${name} is an ${noun}. ${not.interpolated}";
@@ -90,11 +88,17 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep
assertEquals( "jason is an asshole. ${not.interpolated}", bar );
}
- public void testDefaultInterpolationWithEscapedExpression() throws Exception
+ private Map getStandardMap()
{
- Map m = new HashMap();
+ Map m = new HashMap();
m.put( "name", "jason" );
m.put( "noun", "asshole" );
+ return m;
+ }
+
+ public void testDefaultInterpolationWithEscapedExpression() throws Exception
+ {
+ Map m = getStandardMap();
String foo = "${name} is an ${noun}. \\${noun} value";
@@ -109,9 +113,7 @@ public void testDefaultInterpolationWithEscapedExpression() throws Exception
public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception
{
- Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ Map m = getStandardMap();
String foo = "${name} is an ${noun}";
@@ -126,9 +128,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio
public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception
{
- Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ Map m = getStandardMap();
String foo = "@name@ is an @noun@. @not.interpolated@ baby @foo@. @bar@";
@@ -144,9 +144,7 @@ public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception
public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception
{
- Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ Map m = getStandardMap();
String foo = "@name@ is an @foobarred@";
@@ -162,9 +160,7 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue
public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception
{
- Map m = new HashMap();
- m.put( "name", "jason" );
- m.put( "noun", "asshole" );
+ Map m = getStandardMap();
String foo = "@name@ is an @noun@";
diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java
index e37268fe..6e333870 100644
--- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java
@@ -16,15 +16,14 @@
* limitations under the License.
*/
+import junit.framework.TestCase;
+import org.codehaus.plexus.util.Os;
+
import java.util.Arrays;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
-import org.codehaus.plexus.util.Os;
-
-import junit.framework.TestCase;
-
+@SuppressWarnings( { "JavaDoc", "deprecation" } )
public class CommandLineUtilsTest
extends TestCase
{
@@ -64,9 +63,9 @@ public void testGetSystemEnvVarsCaseInsensitive()
throws Exception
{
Properties vars = CommandLineUtils.getSystemEnvVars( false );
- for ( Iterator it = vars.keySet().iterator(); it.hasNext(); )
+ for ( Object o : vars.keySet() )
{
- String variable = (String) it.next();
+ String variable = (String) o;
assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable );
}
}
@@ -82,9 +81,9 @@ public void testGetSystemEnvVarsWindows()
return;
}
Properties vars = CommandLineUtils.getSystemEnvVars();
- for ( Iterator it = vars.keySet().iterator(); it.hasNext(); )
+ for ( Object o : vars.keySet() )
{
- String variable = (String) it.next();
+ String variable = (String) o;
assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable );
}
}
From 0de92b1259d4182fc9245db2dfa0b0fee356d425 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Sun, 19 Jun 2011 16:43:48 +0200
Subject: [PATCH 031/133] o Added asynch executeCommandLine
---
.../plexus/util/cli/CommandLineUtils.java | 195 +++++++++++-------
1 file changed, 115 insertions(+), 80 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 849c7a18..303d8f8d 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -27,12 +27,12 @@
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
+import java.util.concurrent.Callable;
/**
* @author Trygve Laugstøl
@@ -88,6 +88,7 @@ public static int executeCommandLine( Commandline cl, StreamConsumer systemOut,
return executeCommandLine( cl, null, systemOut, systemErr, timeoutInSeconds );
}
+ @SuppressWarnings( { "UnusedDeclaration" } )
public static int executeCommandLine( Commandline cl, InputStream systemIn, StreamConsumer systemOut,
StreamConsumer systemErr )
throws CommandLineException
@@ -108,27 +109,54 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
public static int executeCommandLine( Commandline cl, InputStream systemIn, StreamConsumer systemOut,
StreamConsumer systemErr, int timeoutInSeconds )
throws CommandLineException
+ {
+ final Callable future =
+ executeCommandLineAsCallable( cl, systemIn, systemOut, systemErr, timeoutInSeconds );
+ try
+ {
+ return future.call();
+ }
+ catch ( Exception e )
+ {
+ if (e instanceof CommandLineException){
+ throw (CommandLineException) e.getCause();
+ }
+ throw new RuntimeException( e );
+ }
+ }
+
+ /**
+ * Immediately forks a process, returns a callable that will block until process is complete.
+ * @param cl The command line to execute
+ * @param systemIn The input to read from, must be thread safe
+ * @param systemOut A consumer that receives output, must be thread safe
+ * @param systemErr A consumer that receives system error stream output, must be thread safe
+ * @param timeoutInSeconds Positive integer to specify timeout, zero and negative integers for no timeout.
+ * @return A Callable that provides the process return value, see {@link Process#exitValue()}. "call" must be called on
+ * this to be sure the forked process has terminated, no guarantees is made about
+ * any internal state before after the completion of the call statements
+ * @throws CommandLineException or CommandLineTimeOutException if time out occurs
+ * @noinspection ThrowableResultOfMethodCallIgnored
+ */
+ public static Callable executeCommandLineAsCallable( final Commandline cl, final InputStream systemIn,
+ final StreamConsumer systemOut,
+ final StreamConsumer systemErr,
+ final int timeoutInSeconds )
+ throws CommandLineException
{
if ( cl == null )
{
throw new IllegalArgumentException( "cl cannot be null." );
}
- Process p;
-
- p = cl.execute();
-
+ final Process p = cl.execute();
- StreamFeeder inputFeeder = null;
+ final StreamFeeder inputFeeder = systemIn != null ?
+ new StreamFeeder( systemIn, p.getOutputStream() ) : null;
- if ( systemIn != null )
- {
- inputFeeder = new StreamFeeder( systemIn, p.getOutputStream() );
- }
+ final StreamPumper outputPumper = new StreamPumper( p.getInputStream(), systemOut );
- StreamPumper outputPumper = new StreamPumper( p.getInputStream(), systemOut );
-
- StreamPumper errorPumper = new StreamPumper( p.getErrorStream(), systemErr );
+ final StreamPumper errorPumper = new StreamPumper( p.getErrorStream(), systemErr );
if ( inputFeeder != null )
{
@@ -139,73 +167,79 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
errorPumper.start();
- ProcessHook processHook = new ProcessHook( p );
+ final ProcessHook processHook = new ProcessHook( p );
ShutdownHookUtils.addShutDownHook( processHook );
- try
+ return new Callable()
{
- int returnValue;
- if ( timeoutInSeconds <= 0 )
+ public Integer call()
+ throws Exception
{
- returnValue = p.waitFor();
- }
- else
- {
- long now = System.currentTimeMillis();
- long timeoutInMillis = 1000L * timeoutInSeconds;
- long finish = now + timeoutInMillis;
- while ( isAlive( p ) && ( System.currentTimeMillis() < finish ) )
- {
- Thread.sleep( 10 );
- }
- if ( isAlive( p ) )
+ try
{
- throw new InterruptedException( "Process timeout out after " + timeoutInSeconds + " seconds" );
- }
- returnValue = p.exitValue();
- }
-
- waitForAllPumpers( inputFeeder, outputPumper, errorPumper );
+ int returnValue;
+ if ( timeoutInSeconds <= 0 )
+ {
+ returnValue = p.waitFor();
+ }
+ else
+ {
+ long now = System.currentTimeMillis();
+ long timeoutInMillis = 1000L * timeoutInSeconds;
+ long finish = now + timeoutInMillis;
+ while ( isAlive( p ) && ( System.currentTimeMillis() < finish ) )
+ {
+ Thread.sleep( 10 );
+ }
+ if ( isAlive( p ) )
+ {
+ throw new InterruptedException( "Process timeout out after " + timeoutInSeconds + " seconds" );
+ }
+ returnValue = p.exitValue();
+ }
- if ( outputPumper.getException() != null )
- {
- throw new CommandLineException( "Error inside systemOut parser", outputPumper.getException() );
- }
+ waitForAllPumpers( inputFeeder, outputPumper, errorPumper );
- if ( errorPumper.getException() != null )
- {
- throw new CommandLineException( "Error inside systemErr parser", errorPumper.getException() );
- }
+ if ( outputPumper.getException() != null )
+ {
+ throw new CommandLineException( "Error inside systemOut parser", outputPumper.getException() );
+ }
- return returnValue;
- }
- catch ( InterruptedException ex )
- {
- if ( inputFeeder != null )
- {
- inputFeeder.disable();
- }
- outputPumper.disable();
- errorPumper.disable();
- throw new CommandLineTimeOutException( "Error while executing external command, process killed.", ex );
- }
- finally
- {
- ShutdownHookUtils.removeShutdownHook( processHook );
+ if ( errorPumper.getException() != null )
+ {
+ throw new CommandLineException( "Error inside systemErr parser", errorPumper.getException() );
+ }
- processHook.run();
+ return returnValue;
+ }
+ catch ( InterruptedException ex )
+ {
+ if ( inputFeeder != null )
+ {
+ inputFeeder.disable();
+ }
+ outputPumper.disable();
+ errorPumper.disable();
+ throw new CommandLineTimeOutException( "Error while executing external command, process killed.", ex );
+ }
+ finally
+ {
+ ShutdownHookUtils.removeShutdownHook( processHook );
- if ( inputFeeder != null )
- {
- inputFeeder.close();
- }
+ processHook.run();
- outputPumper.close();
+ if ( inputFeeder != null )
+ {
+ inputFeeder.close();
+ }
- errorPumper.close();
+ outputPumper.close();
- }
+ errorPumper.close();
+ }
+ }
+ };
}
private static void waitForAllPumpers( StreamFeeder inputFeeder, StreamPumper outputPumper,
@@ -244,7 +278,7 @@ public static Properties getSystemEnvVars()
*
* @param caseSensitive Whether environment variable keys should be treated case-sensitively.
* @return Properties object of (possibly modified) envar keys mapped to their values.
- * @throws IOException
+ * @throws IOException .
* @see System#getenv() System.getenv() API, new in JDK 5.0, to get the same result
* since 2.0.2 System#getenv() will be used if available in the current running jvm.
*/
@@ -383,8 +417,8 @@ public static String[] translateCommandline( String toProcess )
final int inDoubleQuote = 2;
int state = normal;
StringTokenizer tok = new StringTokenizer( toProcess, "\"\' ", true );
- Vector v = new Vector();
- StringBuffer current = new StringBuffer();
+ Vector v = new Vector();
+ StringBuilder current = new StringBuilder();
while ( tok.hasMoreTokens() )
{
@@ -463,6 +497,7 @@ else if ( " ".equals( nextTok ) )
* {@link StringUtils#quoteAndEscape(String, char, char[], char, boolean)}, or
* {@link StringUtils#quoteAndEscape(String, char)} instead.
*/
+ @SuppressWarnings( { "JavaDoc", "deprecation" } )
public static String quote( String argument )
throws CommandLineException
{
@@ -481,6 +516,7 @@ public static String quote( String argument )
* {@link StringUtils#quoteAndEscape(String, char, char[], char, boolean)}, or
* {@link StringUtils#quoteAndEscape(String, char)} instead.
*/
+ @SuppressWarnings( { "JavaDoc", "UnusedDeclaration", "deprecation" } )
public static String quote( String argument, boolean wrapExistingQuotes )
throws CommandLineException
{
@@ -492,13 +528,14 @@ public static String quote( String argument, boolean wrapExistingQuotes )
* {@link StringUtils#quoteAndEscape(String, char, char[], char, boolean)}, or
* {@link StringUtils#quoteAndEscape(String, char)} instead.
*/
+ @SuppressWarnings( { "JavaDoc" } )
public static String quote( String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes,
boolean wrapExistingQuotes )
throws CommandLineException
{
- if ( argument.indexOf( "\"" ) > -1 )
+ if ( argument.contains( "\"" ) )
{
- if ( argument.indexOf( "\'" ) > -1 )
+ if ( argument.contains( "\'" ) )
{
throw new CommandLineException( "Can't handle single and double quotes in same argument" );
}
@@ -514,7 +551,7 @@ else if ( wrapExistingQuotes )
}
}
}
- else if ( argument.indexOf( "\'" ) > -1 )
+ else if ( argument.contains( "\'" ) )
{
if ( escapeDoubleQuotes )
{
@@ -525,7 +562,7 @@ else if ( wrapExistingQuotes )
return '\"' + argument + '\"';
}
}
- else if ( argument.indexOf( " " ) > -1 )
+ else if ( argument.contains( " " ) )
{
if ( escapeDoubleQuotes )
{
@@ -549,7 +586,7 @@ public static String toString( String[] line )
}
// path containing one or more elements
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
for ( int i = 0; i < line.length; i++ )
{
if ( i > 0 )
@@ -572,7 +609,7 @@ private static Method getEnvMethod()
{
try
{
- return System.class.getMethod( "getenv", null );
+ return System.class.getMethod( "getenv");
}
catch ( NoSuchMethodException e )
{
@@ -588,12 +625,10 @@ private static Properties getEnvFromSystem( Method method, boolean caseSensitive
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
Properties envVars = new Properties();
- Map envs = (Map) method.invoke( null, null );
- Iterator iterator = envs.keySet().iterator();
- while ( iterator.hasNext() )
+ @SuppressWarnings( { "unchecked" } ) Map envs = (Map) method.invoke( null );
+ for ( String key : envs.keySet() )
{
- String key = (String) iterator.next();
- String value = (String) envs.get( key );
+ String value = envs.get( key );
if ( !caseSensitive )
{
key = key.toUpperCase( Locale.ENGLISH );
From efae8034ae3ce0b85dd77f67bfa242555a37379d Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 22 Jun 2011 16:29:43 +0200
Subject: [PATCH 032/133] [maven-release-plugin] prepare release
plexus-utils-3.0
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f65c8f06..f38e1fd3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 2.1.1-SNAPSHOT
+ 3.0Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 8e38ad4624aad25f7f96fa0d74054bbc341dab99 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 22 Jun 2011 16:29:48 +0200
Subject: [PATCH 033/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f38e1fd3..ddbf4037 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 3.0
+ 3.0.1-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From fc21469bf1e33c06db30d7bf3c533dca6a085a95 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 23 Jun 2011 23:42:52 +0200
Subject: [PATCH 034/133] o Slight adjustment to asynch interface
---
.../plexus/util/cli/CommandLineCallable.java | 28 +++++++++++++++++
.../plexus/util/cli/CommandLineUtils.java | 30 ++++++-------------
2 files changed, 37 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java
new file mode 100644
index 00000000..8a451607
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java
@@ -0,0 +1,28 @@
+package org.codehaus.plexus.util.cli;
+
+/*
+ * Copyright The Codehaus 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 java.util.concurrent.Callable;
+
+/**
+ * Callable wrapper that exposes the proper exeception type to the client.
+ * @author Kristian Rosenvold
+ */
+public interface CommandLineCallable extends Callable
+{
+ public Integer call() throws CommandLineException;
+}
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 303d8f8d..3ebcba66 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -16,10 +16,6 @@
* limitations under the License.
*/
-import org.codehaus.plexus.util.Os;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.StringUtils;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -32,7 +28,9 @@
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
-import java.util.concurrent.Callable;
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
/**
* @author Trygve Laugstøl
@@ -110,19 +108,9 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
StreamConsumer systemErr, int timeoutInSeconds )
throws CommandLineException
{
- final Callable future =
+ final CommandLineCallable future =
executeCommandLineAsCallable( cl, systemIn, systemOut, systemErr, timeoutInSeconds );
- try
- {
- return future.call();
- }
- catch ( Exception e )
- {
- if (e instanceof CommandLineException){
- throw (CommandLineException) e.getCause();
- }
- throw new RuntimeException( e );
- }
+ return future.call();
}
/**
@@ -132,13 +120,13 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
* @param systemOut A consumer that receives output, must be thread safe
* @param systemErr A consumer that receives system error stream output, must be thread safe
* @param timeoutInSeconds Positive integer to specify timeout, zero and negative integers for no timeout.
- * @return A Callable that provides the process return value, see {@link Process#exitValue()}. "call" must be called on
+ * @return A CommandLineCallable that provides the process return value, see {@link Process#exitValue()}. "call" must be called on
* this to be sure the forked process has terminated, no guarantees is made about
* any internal state before after the completion of the call statements
* @throws CommandLineException or CommandLineTimeOutException if time out occurs
* @noinspection ThrowableResultOfMethodCallIgnored
*/
- public static Callable executeCommandLineAsCallable( final Commandline cl, final InputStream systemIn,
+ public static CommandLineCallable executeCommandLineAsCallable( final Commandline cl, final InputStream systemIn,
final StreamConsumer systemOut,
final StreamConsumer systemErr,
final int timeoutInSeconds )
@@ -171,10 +159,10 @@ public static Callable executeCommandLineAsCallable( final Commandline
ShutdownHookUtils.addShutDownHook( processHook );
- return new Callable()
+ return new CommandLineCallable()
{
public Integer call()
- throws Exception
+ throws CommandLineException
{
try
{
From 12bb5ae874b48bcffcadc4aafb376034feced124 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 23 Jun 2011 23:47:18 +0200
Subject: [PATCH 035/133] o Reverted release
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index ddbf4037..f65c8f06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 3.0.1-SNAPSHOT
+ 2.1.1-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From b0e8713ff665f7fb5c8fcf6ae40d1ee03147db97 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 23 Jun 2011 23:48:15 +0200
Subject: [PATCH 036/133] [maven-release-plugin] prepare release
plexus-utils-3.0
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f65c8f06..f38e1fd3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 2.1.1-SNAPSHOT
+ 3.0Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 5c59e85020103c74eefe0b531d00e04959c545f5 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 23 Jun 2011 23:48:46 +0200
Subject: [PATCH 037/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f38e1fd3..ddbf4037 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
org.codehaus.plexusplexus-utils
- 3.0
+ 3.0.1-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 69fe0e89edb5f2a57cbbaf62864e50b7c7e22c8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sat, 2 Jul 2011 22:56:53 +0200
Subject: [PATCH 038/133] updated parent to org.codehaus.plexus:plexus
---
pom.xml | 48 +++---------------------------------------------
1 file changed, 3 insertions(+), 45 deletions(-)
diff --git a/pom.xml b/pom.xml
index ddbf4037..a4c8ff7b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,12 +20,11 @@ limitations under the License.
4.0.0
- org.sonatype.spice
- spice-parent
- 16
+ org.codehaus.plexus
+ plexus
+ 3.0-SNAPSHOT
- org.codehaus.plexusplexus-utils3.0.1-SNAPSHOT
@@ -43,23 +42,6 @@ limitations under the License.
http://jira.codehaus.org/browse/PLXUTILS
-
-
- plexus-releases
- Plexus Release Repository
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
- plexus-snapshots
- Plexus Snapshot Repository
- ${plexusDistMgmtSnapshotsUrl}
-
-
- codehaus.org
- dav:https://dav.codehaus.org/plexus
-
-
-
junit
@@ -71,30 +53,6 @@ limitations under the License.
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.5
- 1.5
-
-
-
- org.apache.maven.plugins
- maven-release-plugin
- 2.1
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.1.2
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
- 2.6
- org.apache.maven.pluginsmaven-surefire-plugin
From a9786dcd82d3df0f3d28baf812221d1e7554c139 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sat, 2 Jul 2011 23:03:10 +0200
Subject: [PATCH 039/133] improved site structure
---
src/site/site.xml | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/site/site.xml b/src/site/site.xml
index d339cb1b..38cbad8a 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -1,4 +1,17 @@
-
+
+
-
+
+
+
+
+
+
+
\ No newline at end of file
From f3888692f862a9ea30de409452217a7956698953 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sat, 2 Jul 2011 23:32:20 +0200
Subject: [PATCH 040/133] more generics
---
.../plexus/util/DirectoryScanner.java | 10 ----
.../org/codehaus/plexus/util/FileUtils.java | 58 +++++++++----------
.../java/org/codehaus/plexus/util/Os.java | 17 +++---
.../codehaus/plexus/util/ReflectionUtils.java | 36 +++++-------
.../org/codehaus/plexus/util/StringUtils.java | 8 +--
.../plexus/util/cli/CommandLineUtils.java | 1 -
.../plexus/util/cli/shell/BourneShell.java | 6 +-
.../plexus/util/cli/shell/CmdShell.java | 2 +-
.../codehaus/plexus/util/cli/shell/Shell.java | 16 ++---
.../org/codehaus/plexus/util/xml/Xpp3Dom.java | 27 +++++----
10 files changed, 77 insertions(+), 104 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
index 1d22fb29..835bb69a 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
@@ -219,7 +219,6 @@ public DirectoryScanner()
* @param basedir The base directory to scan.
* Must not be null.
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public void setBasedir( String basedir )
{
setBasedir( new File( basedir.replace( '/', File.separatorChar ).replace(
@@ -254,7 +253,6 @@ public File getBasedir()
*
* @param followSymlinks whether or not symbolic links should be followed
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public void setFollowSymlinks( boolean followSymlinks )
{
this.followSymlinks = followSymlinks;
@@ -267,7 +265,6 @@ public void setFollowSymlinks( boolean followSymlinks )
* @return true if all files and directories which have
* been found so far have been included.
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public boolean isEverythingIncluded()
{
return everythingIncluded;
@@ -556,7 +553,6 @@ else if ( file.isFile() )
* @return false when the selectors says that the file
* should not be selected, true otherwise.
*/
- @SuppressWarnings( { "UnusedParameters" } )
protected boolean isSelected( String name, File file )
{
return true;
@@ -587,7 +583,6 @@ public String[] getIncludedFiles()
*
* @see #slowScan
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getNotIncludedFiles()
{
slowScan();
@@ -607,7 +602,6 @@ public String[] getNotIncludedFiles()
*
* @see #slowScan
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getExcludedFiles()
{
slowScan();
@@ -627,7 +621,6 @@ public String[] getExcludedFiles()
*
* @see #slowScan
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getDeselectedFiles()
{
slowScan();
@@ -661,7 +654,6 @@ public String[] getIncludedDirectories()
*
* @see #slowScan
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getNotIncludedDirectories()
{
slowScan();
@@ -681,7 +673,6 @@ public String[] getNotIncludedDirectories()
*
* @see #slowScan
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getExcludedDirectories()
{
slowScan();
@@ -701,7 +692,6 @@ public String[] getExcludedDirectories()
*
* @see #slowScan
*/
- @SuppressWarnings( { "UnusedDeclaration" } )
public String[] getDeselectedDirectories()
{
slowScan();
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 98fe5e79..1d226e0c 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -73,10 +73,8 @@
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import java.util.Random;
-import java.util.Vector;
import org.codehaus.plexus.util.io.FileInputStreamFacade;
import org.codehaus.plexus.util.io.InputStreamFacade;
@@ -165,7 +163,7 @@ public static String[] getDefaultExcludes()
* @return the default excludes pattern as list.
* @see #getDefaultExcludes()
*/
- public static List getDefaultExcludesAsList()
+ public static List getDefaultExcludesAsList()
{
return Arrays.asList( getDefaultExcludes() );
}
@@ -599,7 +597,7 @@ public static File getFile( String fileName )
*/
public static String[] getFilesFromExtension( String directory, String[] extensions )
{
- Vector files = new Vector();
+ List files = new ArrayList();
File currentDir = new File( directory );
@@ -636,14 +634,14 @@ public static String[] getFilesFromExtension( String directory, String[] extensi
String add = currentFile.getAbsolutePath();
if ( isValidFile( add, extensions ) )
{
- files.addElement( add );
+ files.add( add );
}
}
}
//ok... move the Vector into the files list...
String[] foundFiles = new String[files.size()];
- files.copyInto( foundFiles );
+ files.toArray( foundFiles );
return foundFiles;
}
@@ -651,11 +649,11 @@ public static String[] getFilesFromExtension( String directory, String[] extensi
/**
* Private helper method for getFilesFromExtension()
*/
- private static Vector blendFilesToVector( Vector v, String[] files )
+ private static List blendFilesToVector( List v, String[] files )
{
for ( int i = 0; i < files.length; ++i )
{
- v.addElement( files[i] );
+ v.add( files[i] );
}
return v;
@@ -1698,7 +1696,7 @@ public static long sizeOfDirectory( final File directory )
* @throws IOException
* @see #getFileNames( File, String, String, boolean )
*/
- public static List getFiles( File directory, String includes, String excludes )
+ public static List getFiles( File directory, String includes, String excludes )
throws IOException
{
return getFiles( directory, includes, excludes, true );
@@ -1715,16 +1713,16 @@ public static List getFiles( File directory, String includes, String excludes )
* @throws IOException
* @see #getFileNames( File, String, String, boolean )
*/
- public static List getFiles( File directory, String includes, String excludes, boolean includeBasedir )
+ public static List getFiles( File directory, String includes, String excludes, boolean includeBasedir )
throws IOException
{
- List fileNames = getFileNames( directory, includes, excludes, includeBasedir );
+ List fileNames = getFileNames( directory, includes, excludes, includeBasedir );
- List files = new ArrayList();
+ List files = new ArrayList();
- for ( Iterator i = fileNames.iterator(); i.hasNext(); )
+ for ( String filename : fileNames )
{
- files.add( new File( (String) i.next() ) );
+ files.add( new File( filename ) );
}
return files;
@@ -1741,7 +1739,7 @@ public static List getFiles( File directory, String includes, String excludes, b
* @return a list of files as String
* @throws IOException
*/
- public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir )
+ public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir )
throws IOException
{
return getFileNames( directory, includes, excludes, includeBasedir, true );
@@ -1758,7 +1756,7 @@ public static List getFileNames( File directory, String includes, String exclude
* @return a list of files as String
* @throws IOException
*/
- public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir,
+ public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir,
boolean isCaseSensitive )
throws IOException
{
@@ -1776,7 +1774,7 @@ public static List getFileNames( File directory, String includes, String exclude
* @return a list of directories as String
* @throws IOException
*/
- public static List getDirectoryNames( File directory, String includes, String excludes, boolean includeBasedir )
+ public static List getDirectoryNames( File directory, String includes, String excludes, boolean includeBasedir )
throws IOException
{
return getDirectoryNames( directory, includes, excludes, includeBasedir, true );
@@ -1793,7 +1791,7 @@ public static List getDirectoryNames( File directory, String includes, String ex
* @return a list of directories as String
* @throws IOException
*/
- public static List getDirectoryNames( File directory, String includes, String excludes, boolean includeBasedir,
+ public static List getDirectoryNames( File directory, String includes, String excludes, boolean includeBasedir,
boolean isCaseSensitive )
throws IOException
{
@@ -1813,7 +1811,7 @@ public static List getDirectoryNames( File directory, String includes, String ex
* @return a list of files as String
* @throws IOException
*/
- public static List getFileAndDirectoryNames( File directory, String includes, String excludes,
+ public static List getFileAndDirectoryNames( File directory, String includes, String excludes,
boolean includeBasedir, boolean isCaseSensitive, boolean getFiles,
boolean getDirectories )
throws IOException
@@ -1836,7 +1834,7 @@ public static List getFileAndDirectoryNames( File directory, String includes, St
scanner.scan();
- List list = new ArrayList();
+ List list = new ArrayList();
if ( getFiles )
{
@@ -1907,12 +1905,10 @@ public static void copyDirectory( File sourceDirectory, File destinationDirector
return;
}
- List files = getFiles( sourceDirectory, includes, excludes );
+ List files = getFiles( sourceDirectory, includes, excludes );
- for ( Iterator i = files.iterator(); i.hasNext(); )
+ for ( File file : files )
{
- File file = (File) i.next();
-
copyFileToDirectory( file, destinationDirectory );
}
}
@@ -1977,20 +1973,18 @@ public static void copyDirectoryLayout( File sourceDirectory, File destinationDi
scanner.addDefaultExcludes();
scanner.scan();
- List includedDirectories = Arrays.asList( scanner.getIncludedDirectories() );
+ List includedDirectories = Arrays.asList( scanner.getIncludedDirectories() );
- for (Iterator i = includedDirectories.iterator();i.hasNext();)
+ for ( String name : includedDirectories )
{
- String name = (String)i.next();
-
- File source = new File(sourceDirectory, name);
+ File source = new File( sourceDirectory, name );
if ( source.equals( sourceDirectory ) )
{
continue;
}
- File destination = new File(destinationDirectory, name);
+ File destination = new File( destinationDirectory, name );
destination.mkdirs();
}
}
@@ -2278,10 +2272,10 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[
* @return a List containing every every line not starting with # and not empty
* @throws IOException if any
*/
- public static List loadFile( File file )
+ public static List loadFile( File file )
throws IOException
{
- List lines = new ArrayList();
+ List lines = new ArrayList();
if ( file.exists() )
{
diff --git a/src/main/java/org/codehaus/plexus/util/Os.java b/src/main/java/org/codehaus/plexus/util/Os.java
index c8fc6b42..2f3af267 100644
--- a/src/main/java/org/codehaus/plexus/util/Os.java
+++ b/src/main/java/org/codehaus/plexus/util/Os.java
@@ -55,7 +55,6 @@
package org.codehaus.plexus.util;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
@@ -94,7 +93,7 @@ public class Os
public static final String FAMILY_OPENVMS = "openvms";
// store the valid families
- private static final Set validFamilies = setValidFamilies();
+ private static final Set validFamilies = setValidFamilies();
// get the current info
private static final String PATH_SEP = System.getProperty( "path.separator" );
@@ -136,9 +135,9 @@ public Os( String family )
/**
* Initializes the set of valid families.
*/
- private static Set setValidFamilies()
+ private static Set setValidFamilies()
{
- Set valid = new HashSet();
+ Set valid = new HashSet();
valid.add( FAMILY_DOS );
valid.add( FAMILY_MAC );
valid.add( FAMILY_NETWARE );
@@ -381,7 +380,7 @@ private static String getOsFamily()
// in case the order of static initialization is
// wrong, get the list
// safely.
- Set families = null;
+ Set families = null;
if ( !validFamilies.isEmpty() )
{
families = validFamilies;
@@ -390,10 +389,8 @@ private static String getOsFamily()
{
families = setValidFamilies();
}
- Iterator iter = families.iterator();
- while ( iter.hasNext() )
+ for ( String fam : families )
{
- String fam = (String) iter.next();
if ( Os.isFamily( fam ) )
{
return fam;
@@ -432,8 +429,8 @@ public static boolean isValidFamily( String theFamily )
* @return a copy of the valid families
* @since 1.4.2
*/
- public static Set getValidFamilies()
+ public static Set getValidFamilies()
{
- return new HashSet( validFamilies );
+ return new HashSet( validFamilies );
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
index f19d4e19..69872874 100644
--- a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
@@ -38,7 +38,7 @@ public final class ReflectionUtils
// Field utils
// ----------------------------------------------------------------------
- public static Field getFieldByNameIncludingSuperclasses( String fieldName, Class clazz )
+ public static Field getFieldByNameIncludingSuperclasses( String fieldName, Class> clazz )
{
Field retValue = null;
@@ -48,7 +48,7 @@ public static Field getFieldByNameIncludingSuperclasses( String fieldName, Class
}
catch ( NoSuchFieldException e )
{
- Class superclass = clazz.getSuperclass();
+ Class> superclass = clazz.getSuperclass();
if ( superclass != null )
{
@@ -59,11 +59,11 @@ public static Field getFieldByNameIncludingSuperclasses( String fieldName, Class
return retValue;
}
- public static List getFieldsIncludingSuperclasses( Class clazz )
+ public static List getFieldsIncludingSuperclasses( Class> clazz )
{
- List fields = new ArrayList( Arrays.asList( clazz.getDeclaredFields() ) );
+ List fields = new ArrayList( Arrays.asList( clazz.getDeclaredFields() ) );
- Class superclass = clazz.getSuperclass();
+ Class> superclass = clazz.getSuperclass();
if ( superclass != null )
{
@@ -85,16 +85,14 @@ public static List getFieldsIncludingSuperclasses( Class clazz )
* @param clazz The class to find the method in.
* @return null or the method found.
*/
- public static Method getSetter( String fieldName, Class clazz )
+ public static Method getSetter( String fieldName, Class> clazz )
{
- Method [] methods = clazz.getMethods();
+ Method[] methods = clazz.getMethods();
fieldName = "set" + StringUtils.capitalizeFirstLetter( fieldName );
- for ( int i = 0; i < methods.length; i++ )
+ for ( Method method : methods )
{
- Method method = methods[i];
-
if ( method.getName().equals( fieldName ) && isSetter( method ) )
{
return method;
@@ -107,16 +105,14 @@ public static Method getSetter( String fieldName, Class clazz )
/**
* Finds all setters in the given class and super classes.
*/
- public static List getSetters( Class clazz )
+ public static List getSetters( Class> clazz )
{
Method[] methods = clazz.getMethods();
- List list = new ArrayList();
+ List list = new ArrayList();
- for ( int i = 0; i < methods.length; i++ )
+ for ( Method method : methods )
{
- Method method = methods[i];
-
if ( isSetter( method ) )
{
list.add( method );
@@ -131,7 +127,7 @@ public static List getSetters( Class clazz )
*
* Will throw an RuntimeException if the method isn't a setter.
*/
- public static Class getSetterType( Method method )
+ public static Class> getSetterType( Method method )
{
if ( !isSetter( method ) )
{
@@ -191,9 +187,9 @@ public static Object getValueIncludingSuperclasses( String variable, Object obje
public static Map getVariablesAndValuesIncludingSuperclasses( Object object )
throws IllegalAccessException
{
- HashMap map = new HashMap ();
+ HashMap map = new HashMap();
- gatherVariablesAndValuesIncludingSuperclasses(object, map);
+ gatherVariablesAndValuesIncludingSuperclasses( object, map );
return map;
}
@@ -220,7 +216,7 @@ private static void gatherVariablesAndValuesIncludingSuperclasses( Object object
throws IllegalAccessException
{
- Class clazz = object.getClass();
+ Class> clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
@@ -234,7 +230,7 @@ private static void gatherVariablesAndValuesIncludingSuperclasses( Object object
}
- Class superclass = clazz.getSuperclass();
+ Class> superclass = clazz.getSuperclass();
if ( !Object.class.equals( superclass ) )
{
diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java
index 3b658bd9..0bb6875e 100644
--- a/src/main/java/org/codehaus/plexus/util/StringUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/StringUtils.java
@@ -678,7 +678,7 @@ public static String join( Object[] array, String separator )
* @param separator the separator character to use
* @return the joined String
*/
- public static String join( Iterator iterator, String separator )
+ public static String join( Iterator> iterator, String separator )
{
if ( separator == null )
{
@@ -2130,9 +2130,9 @@ public static int differenceAt( String s1, String s2 )
return -1;
}
- public static String interpolate( String text, Map namespace )
+ public static String interpolate( String text, Map, ?> namespace )
{
- Iterator keys = namespace.keySet().iterator();
+ Iterator> keys = namespace.keySet().iterator();
while ( keys.hasNext() )
{
@@ -2350,7 +2350,6 @@ public static String escape( String source, final char[] escapedChars, char esca
StringBuffer buffer = new StringBuffer( source.length() );
- int escapeCount = 0;
for ( int i = 0; i < source.length(); i++ )
{
final char c = source.charAt( i );
@@ -2359,7 +2358,6 @@ public static String escape( String source, final char[] escapedChars, char esca
if ( result > -1 )
{
buffer.append( escapeChar );
- escapeCount++;
}
buffer.append( c );
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 3ebcba66..0243a850 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -86,7 +86,6 @@ public static int executeCommandLine( Commandline cl, StreamConsumer systemOut,
return executeCommandLine( cl, null, systemOut, systemErr, timeoutInSeconds );
}
- @SuppressWarnings( { "UnusedDeclaration" } )
public static int executeCommandLine( Commandline cl, InputStream systemIn, StreamConsumer systemOut,
StreamConsumer systemErr )
throws CommandLineException
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
index 18e52838..f33f5037 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
@@ -78,10 +78,10 @@ public String getExecutable()
return unifyQuotes( super.getExecutable());
}
- public List getShellArgsList()
+ public List getShellArgsList()
{
- List shellArgs = new ArrayList();
- List existingShellArgs = super.getShellArgsList();
+ List shellArgs = new ArrayList();
+ List existingShellArgs = super.getShellArgsList();
if ( ( existingShellArgs != null ) && !existingShellArgs.isEmpty() )
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
index 28a2149f..bbe44728 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
@@ -77,7 +77,7 @@ public CmdShell()
* appears to make Windows processes invoke successfully.
*
*/
- public List getCommandLine( String executable, String[] arguments )
+ public List getCommandLine( String executable, String[] arguments )
{
StringBuffer sb = new StringBuffer();
sb.append( "\"" );
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
index 6e264cef..c8100670 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
@@ -44,7 +44,7 @@ public class Shell
private String shellCommand;
- private List shellArgs = new ArrayList();
+ private List shellArgs = new ArrayList();
private boolean quotedArgumentsEnabled = true;
@@ -122,14 +122,14 @@ public String[] getShellArgs()
* @param arguments arguments for the executable, not the shell
* @return List with one String object with executable and arguments quoted as needed
*/
- public List getCommandLine( String executable, String[] arguments )
+ public List getCommandLine( String executable, String[] arguments )
{
return getRawCommandLine( executable, arguments );
}
- protected List getRawCommandLine( String executable, String[] arguments )
+ protected List getRawCommandLine( String executable, String[] arguments )
{
- List commandLine = new ArrayList();
+ List commandLine = new ArrayList();
StringBuffer sb = new StringBuffer();
if ( executable != null )
@@ -252,10 +252,10 @@ protected char getExecutableQuoteDelimiter()
* @return List of String objects, whose array version is suitable to be used as argument
* of Runtime.getRuntime().exec()
*/
- public List getShellCommandLine( String[] arguments )
+ public List getShellCommandLine( String[] arguments )
{
- List commandLine = new ArrayList();
+ List commandLine = new ArrayList();
if ( getShellCommand() != null )
{
@@ -273,7 +273,7 @@ public List getShellCommandLine( String[] arguments )
}
- public List getShellArgsList()
+ public List getShellArgsList()
{
return shellArgs;
}
@@ -371,7 +371,7 @@ public String getOriginalExecutable()
return executable;
}
- public List getOriginalCommandLine( String executable, String[] arguments )
+ public List getOriginalCommandLine( String executable, String[] arguments )
{
return getRawCommandLine( executable, arguments );
}
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
index d6ae6fef..b3cd0452 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
@@ -41,11 +41,11 @@ public class Xpp3Dom
protected String value;
- protected Map attributes;
+ protected Map attributes;
- protected final List childList;
+ protected final List childList;
- protected final Map childMap;
+ protected final Map childMap;
protected Xpp3Dom parent;
@@ -85,8 +85,8 @@ public class Xpp3Dom
public Xpp3Dom( String name )
{
this.name = name;
- childList = new ArrayList();
- childMap = new HashMap();
+ childList = new ArrayList();
+ childMap = new HashMap();
}
/**
@@ -106,8 +106,8 @@ public Xpp3Dom( Xpp3Dom src, String name )
int childCount = src.getChildCount();
- childList = new ArrayList( childCount );
- childMap = new HashMap( childCount << 1 );
+ childList = new ArrayList( childCount );
+ childMap = new HashMap( childCount << 1 );
setValue( src.getValue() );
@@ -183,7 +183,7 @@ public void setAttribute( String name, String value )
}
if ( null == attributes )
{
- attributes = new HashMap();
+ attributes = new HashMap();
}
attributes.put( name, value );
@@ -230,7 +230,7 @@ public Xpp3Dom[] getChildren( String name )
}
else
{
- ArrayList children = new ArrayList();
+ ArrayList children = new ArrayList();
int size = childList.size();
for ( int i = 0; i < size; i++ )
@@ -408,11 +408,10 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
}
else
{
- Map commonChildren = new HashMap();
+ Map> commonChildren = new HashMap>();
- for ( Iterator it = recessive.childMap.keySet().iterator(); it.hasNext(); )
+ for ( String childName : recessive.childMap.keySet() )
{
- String childName = (String) it.next();
Xpp3Dom[] dominantChildren = dominant.getChildren( childName );
if ( dominantChildren.length > 0 )
{
@@ -423,14 +422,14 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
for ( int i = 0, recessiveChildCount = recessive.getChildCount(); i < recessiveChildCount; i++ )
{
Xpp3Dom recessiveChild = recessive.getChild( i );
- Iterator it = (Iterator) commonChildren.get( recessiveChild.getName() );
+ Iterator it = commonChildren.get( recessiveChild.getName() );
if ( it == null )
{
dominant.addChild( new Xpp3Dom( recessiveChild ) );
}
else if ( it.hasNext() )
{
- Xpp3Dom dominantChild = (Xpp3Dom) it.next();
+ Xpp3Dom dominantChild = it.next();
mergeIntoXpp3Dom( dominantChild, recessiveChild, childMergeOverride );
}
}
From 0c34c0598d6fb63759af9660e41767b776934f74 Mon Sep 17 00:00:00 2001
From: Benjamin Bentmann
Date: Fri, 5 Aug 2011 21:47:46 +0200
Subject: [PATCH 041/133] o Fixed POM to use released parent
---
pom.xml | 48 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index a4c8ff7b..88e1160b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,11 +20,12 @@ limitations under the License.
4.0.0
- org.codehaus.plexus
- plexus
- 3.0-SNAPSHOT
+ org.sonatype.spice
+ spice-parent
+ 16
+ org.codehaus.plexusplexus-utils3.0.1-SNAPSHOT
@@ -42,6 +43,23 @@ limitations under the License.
http://jira.codehaus.org/browse/PLXUTILS
+
+
+ plexus-releases
+ Plexus Release Repository
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
+ plexus-snapshots
+ Plexus Snapshot Repository
+ ${plexusDistMgmtSnapshotsUrl}
+
+
+ codehaus.org
+ dav:https://dav.codehaus.org/plexus
+
+
+
junit
@@ -53,6 +71,30 @@ limitations under the License.
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.5
+ 1.5
+
+
+
+ org.apache.maven.plugins
+ maven-release-plugin
+ 2.1
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.1.2
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ 2.6
+ org.apache.maven.pluginsmaven-surefire-plugin
From dc2af9ae0dd58b8be58bee29cd52d7a75ccab047 Mon Sep 17 00:00:00 2001
From: Benjamin Bentmann
Date: Fri, 5 Aug 2011 21:50:41 +0200
Subject: [PATCH 042/133] [PLXUTILS-140] default excludes of scanner should
include .gitignore and .gitattributes
---
src/main/java/org/codehaus/plexus/util/AbstractScanner.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
index 685e9181..9036720d 100644
--- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
@@ -38,7 +38,7 @@ public abstract class AbstractScanner
*
Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mail
*
@@ -100,6 +100,8 @@ public abstract class AbstractScanner
// git
"**/.git",
+ "**/.gitignore",
+ "**/.gitattributes",
"**/.git/**",
// BitKeeper
From 808551a59694bab5739d4934b5eb7a1d8d839336 Mon Sep 17 00:00:00 2001
From: Benjamin Bentmann
Date: Sun, 7 Aug 2011 15:07:36 +0200
Subject: [PATCH 043/133] [PLXUTILS-141] More and better? Javadoc Submitted by:
Mark Wood
---
.../codehaus/plexus/util/AbstractScanner.java | 3 +
.../plexus/util/DirectoryWalkListener.java | 3 +-
.../util/InterpolationFilterReader.java | 35 +++++++++++
.../util/LineOrientedInterpolatingReader.java | 58 +++++++++++++++++++
.../codehaus/plexus/util/PropertyUtils.java | 2 +-
.../codehaus/plexus/util/ReflectionUtils.java | 2 +
.../org/codehaus/plexus/util/Scanner.java | 3 +
.../org/codehaus/plexus/util/io/package.html | 26 +++++++++
.../org/codehaus/plexus/util/package.html | 4 +-
9 files changed, 132 insertions(+), 4 deletions(-)
create mode 100644 src/main/javadoc/org/codehaus/plexus/util/io/package.html
diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
index 9036720d..2912e7c1 100644
--- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
@@ -19,6 +19,9 @@
import java.io.File;
+/**
+ * Scan a directory tree for files, with specified inclusions and exclusions.
+ */
public abstract class AbstractScanner
implements Scanner
{
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java b/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java
index a3bb5e2c..a4af2527 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java
@@ -19,8 +19,9 @@
import java.io.File;
/**
- * DirectoryWalkListener
+ * Observes the actions of a {@link DirectoryWalker}.
* @version $Id$
+ * @see DirectoryWalker
*/
public interface DirectoryWalkListener
{
diff --git a/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java b/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
index 17b8ee3b..d765c0d5 100644
--- a/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
+++ b/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
@@ -61,6 +61,25 @@
import java.util.Map;
/**
+ * A FilterReader which interpolates keyword values into a character stream.
+ * Keywords are recognized when enclosed between starting and ending delimiter
+ * strings. The keywords themselves, and their values, are fetched from a Map
+ * supplied to the constructor.
+ *
+ * When a possible keyword token is recognized (by detecting the starting and
+ * ending token delimiters):
+ *
+ *
+ *
if the enclosed string is found in the keyword Map, the delimiters and
+ * the keyword are effectively replaced by the keyword's value;
+ *
if the enclosed string is found in the keyword Map, but its value has
+ * zero length, then the token (delimiters and keyword) is effectively removed
+ * from the character stream;
+ *
if the enclosed string is not found in the keyword Map, then
+ * no substitution is made; the token text is passed through unaltered.
+ *
+ * @see LineOrientedInterpolatingReader
+ * @see org.codehaus.plexus.interpolation
*/
public class InterpolationFilterReader
extends FilterReader
@@ -95,6 +114,15 @@ public class InterpolationFilterReader
/** Default end token. */
private static final String DEFAULT_END_TOKEN = "}";
+ /**
+ * Construct a Reader to interpolate values enclosed between the given
+ * delimiter tokens.
+ *
+ * @param in a Reader to be wrapped for interpolation.
+ * @param variables name/value pairs to be interpolated into the character stream.
+ * @param beginToken an interpolation target begins with this.
+ * @param endToken an interpolation target ends with this.
+ */
public InterpolationFilterReader( Reader in, Map variables, String beginToken, String endToken )
{
super( in );
@@ -107,6 +135,13 @@ public InterpolationFilterReader( Reader in, Map variables, String beginToken, S
endTokenLength = endToken.length();
}
+ /**
+ * Construct a Reader using the default interpolation delimiter tokens
+ * "${" and "}".
+ *
+ * @param in a Reader to be wrapped for interpolation.
+ * @param variables name/value pairs to be interpolated into the character stream.
+ */
public InterpolationFilterReader( Reader in, Map variables )
{
this( in, variables, DEFAULT_BEGIN_TOKEN, DEFAULT_END_TOKEN );
diff --git a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
index 9b892d40..7a2a6212 100644
--- a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
+++ b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
@@ -30,7 +30,35 @@
import java.util.TreeMap;
/**
+ * A FilterReader which interpolates keyword values into a character stream.
+ * Keywords are recognized when enclosed between starting and ending delimiter
+ * strings. The keywords themselves, and their values, are fetched from a Map
+ * supplied to the constructor.
+ *
+ * When a possible keyword token is recognized (by detecting the starting and
+ * ending token delimiters):
+ *
+ *
+ *
if the enclosed string is found in the keyword Map, the delimiters and
+ * the keyword are effectively replaced by the keyword's value;
+ *
if the enclosed string is found in the keyword Map, but its value has
+ * zero length, then the token (delimiters and keyword) is effectively removed
+ * from the character stream;
+ *
if the enclosed string is not found in the keyword Map, then
+ * no substitution is made; the token text is passed through unaltered.
+ *
+ *
+ * A token in the incoming character stream may be escaped by
+ * prepending an "escape sequence" which is specified to the constructor. An
+ * escaped token is passed through as written, with the escape sequence removed.
+ * This allows things which would look like tokens to be read literally rather
+ * than interpolated.
+ *
+ *
* @author jdcasey Created on Feb 3, 2005
+ *
+ * @see InterpolationFilterReader
+ * @see org.codehaus.plexus.interpolation
*/
public class LineOrientedInterpolatingReader
extends FilterReader
@@ -63,6 +91,16 @@ public class LineOrientedInterpolatingReader
private String line;
+ /**
+ * Construct an interpolating Reader, specifying token delimiters and the
+ * escape sequence.
+ *
+ * @param reader the Reader to be filtered.
+ * @param context keyword/value pairs for interpolation.
+ * @param startDelim character sequence which (possibly) begins a token.
+ * @param endDelim character sequence which ends a token.
+ * @param escapeSeq
+ */
public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim,
String escapeSeq )
{
@@ -91,11 +129,26 @@ public LineOrientedInterpolatingReader( Reader reader, Map context, S
}
}
+ /**
+ * Filters a Reader using the default escape sequence "\".
+ *
+ * @param reader the Reader to be filtered.
+ * @param context keyword/value pairs for interpolation.
+ * @param startDelim the character sequence which (possibly) begins a token.
+ * @param endDelim the character sequence which ends a token.
+ */
public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim )
{
this( reader, context, startDelim, endDelim, DEFAULT_ESCAPE_SEQ );
}
+ /**
+ * Filters a Reader using the default escape sequence "\" and token
+ * delimiters "${", "}".
+ *
+ * @param reader the Reader to be filtered.
+ * @param context keyword/value pairs for interpolation.
+ */
public LineOrientedInterpolatingReader( Reader reader, Map context )
{
this( reader, context, DEFAULT_START_DELIM, DEFAULT_END_DELIM, DEFAULT_ESCAPE_SEQ );
@@ -189,6 +242,11 @@ private void readAndInterpolateLine() throws IOException
}
}
+ /*
+ * Read one line from the wrapped Reader. A line is a sequence of characters
+ * ending in CRLF, CR, or LF. The terminating character(s) will be included
+ * in the returned line.
+ */
private String readLine() throws IOException
{
StringBuilder lineBuffer = new StringBuilder( 40 ); // half of the "normal" line maxsize
diff --git a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java
index f327fd8a..0ed1aa48 100644
--- a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java
@@ -24,7 +24,7 @@
import java.net.URL;
/**
- *
+ * Static methods to create Properties loaded from various sources.
*
* @author Jason van Zyl
* @author Michal Maczka
diff --git a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
index 69872874..53b2a24f 100644
--- a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
@@ -27,6 +27,8 @@
import java.util.Arrays;
/**
+ * Operations on a class' fields and their setters.
+ *
* @author Michal Maczka
* @author Jesse McConnell
* @author Trygve Laugstøl
diff --git a/src/main/java/org/codehaus/plexus/util/Scanner.java b/src/main/java/org/codehaus/plexus/util/Scanner.java
index efd96e11..d2af7b4d 100644
--- a/src/main/java/org/codehaus/plexus/util/Scanner.java
+++ b/src/main/java/org/codehaus/plexus/util/Scanner.java
@@ -18,6 +18,9 @@
import java.io.File;
+/**
+ * Scan a directory tree for files, with specified inclusions and exclusions.
+ */
public interface Scanner
{
diff --git a/src/main/javadoc/org/codehaus/plexus/util/io/package.html b/src/main/javadoc/org/codehaus/plexus/util/io/package.html
new file mode 100644
index 00000000..616b7bc2
--- /dev/null
+++ b/src/main/javadoc/org/codehaus/plexus/util/io/package.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+ Facades to create {@code InputStream}s representing various kinds of
+ data sources, identically.
+
+
diff --git a/src/main/javadoc/org/codehaus/plexus/util/package.html b/src/main/javadoc/org/codehaus/plexus/util/package.html
index 79bf2c28..e4ff4b2c 100644
--- a/src/main/javadoc/org/codehaus/plexus/util/package.html
+++ b/src/main/javadoc/org/codehaus/plexus/util/package.html
@@ -1,3 +1,3 @@
-Misc. utilities.
-
\ No newline at end of file
+Miscellaneous utilities, mainly dealing with I/O, strings, and filesystems.
+
From 285ea2cfddee961092e9fb57f2f5aaae2cd9982c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sun, 7 Aug 2011 21:50:23 +0200
Subject: [PATCH 044/133] use last released plexus parent pom
---
pom.xml | 57 +++------------------------------------------------------
1 file changed, 3 insertions(+), 54 deletions(-)
diff --git a/pom.xml b/pom.xml
index 88e1160b..646c1fe2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,12 +20,11 @@ limitations under the License.
4.0.0
- org.sonatype.spice
- spice-parent
- 16
+ org.codehaus.plexus
+ plexus
+ 3.0
- org.codehaus.plexusplexus-utils3.0.1-SNAPSHOT
@@ -43,58 +42,8 @@ limitations under the License.
http://jira.codehaus.org/browse/PLXUTILS
-
-
- plexus-releases
- Plexus Release Repository
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
- plexus-snapshots
- Plexus Snapshot Repository
- ${plexusDistMgmtSnapshotsUrl}
-
-
- codehaus.org
- dav:https://dav.codehaus.org/plexus
-
-
-
-
-
- junit
- junit
- 3.8.2
- test
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.5
- 1.5
-
-
-
- org.apache.maven.plugins
- maven-release-plugin
- 2.1
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.1.2
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
- 2.6
- org.apache.maven.pluginsmaven-surefire-plugin
From 7541e13a11952a205ec334c28a6aa96a94e0a491 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sun, 7 Aug 2011 22:08:01 +0200
Subject: [PATCH 045/133] updated parent to 3.0.1, which declared dav wagon
provider to deploy site
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 646c1fe2..cb58562a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@ limitations under the License.
org.codehaus.plexusplexus
- 3.0
+ 3.0.1plexus-utils
From 7f8d80f4feb8b7f9b83652839c9643b2c7b47644 Mon Sep 17 00:00:00 2001
From: ajayk
Date: Tue, 3 Jan 2012 16:35:19 +0530
Subject: [PATCH 046/133] Minor Java cleanup
---
src/main/java/org/codehaus/plexus/util/FileUtils.java | 5 +----
.../java/org/codehaus/plexus/util/xml/pull/MXParser.java | 4 ++--
.../java/org/codehaus/plexus/util/FileBasedTestCase.java | 1 -
src/test/java/org/codehaus/plexus/util/FileUtilsTest.java | 2 --
.../java/org/codehaus/plexus/util/TestThreadManager.java | 2 +-
.../org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java | 8 ++++----
6 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 1d226e0c..c7dcb200 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -698,14 +698,11 @@ public static void mkdir( String dir )
{
File file = new File( dir );
- if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+ if ( Os.isFamily( Os.FAMILY_WINDOWS ) && !isValidWindowsFileName( file ) )
{
- if ( !isValidWindowsFileName( file ) )
- {
throw new IllegalArgumentException( "The file (" + dir
+ ") cannot contain any of the following characters: \n"
+ StringUtils.join( INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME, " " ) );
- }
}
if ( !file.exists() )
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
index bbf43fab..f19a2702 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
@@ -2703,11 +2703,11 @@ protected void parseXmlDeclWithVersion(int versionStart, int versionEnd)
if(ch == 'y') {
ch = requireInput(ch, YES);
//Boolean standalone = new Boolean(true);
- xmlDeclStandalone = new Boolean(true);
+ xmlDeclStandalone = Boolean.valueOf(true);
} else if(ch == 'n') {
ch = requireInput(ch, NO);
//Boolean standalone = new Boolean(false);
- xmlDeclStandalone = new Boolean(false);
+ xmlDeclStandalone = Boolean.valueOf(false);
} else {
throw new XmlPullParserException(
"expected 'yes' or 'no' after standalone and not "
diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java
index 84ea3aba..c7151e78 100644
--- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java
+++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java
@@ -32,7 +32,6 @@
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-import org.codehaus.plexus.util.FileUtils;
/**
* Base class for testcases doing tests with files.
diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
index 0620ad42..27892abf 100644
--- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
@@ -29,8 +29,6 @@
import java.net.URL;
import java.util.Properties;
-import sun.awt.windows.ThemeReader;
-
/**
* This is used to test FileUtils for correctness.
*
diff --git a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java
index 20a24e06..bf80f370 100644
--- a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java
+++ b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java
@@ -99,7 +99,7 @@ public Object getNotifyObject()
public boolean hasFailedThreads()
{
- if ( failedThreads.size() == 0 )
+ if ( failedThreads.isEmpty() )
{
return false;
}
diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
index 2a40417f..4671f858 100644
--- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
@@ -86,7 +86,7 @@ public void testBuildFromXpp3Dom()
{
String rawName = parser.getName();
- if ( rawName.equals( "root" ) )
+ if ( "root".equals( rawName ) )
{
dom = Xpp3DomBuilder.build( parser );
}
@@ -95,15 +95,15 @@ else if ( eventType == XmlPullParser.END_TAG )
{
String rawName = parser.getName();
- if ( rawName.equals( "configuration" ) )
+ if ( "configuration".equals( rawName ) )
{
configurationClosed = true;
}
- else if ( rawName.equals( "newRoot" ) )
+ else if ( "newRoot".equals( rawName ) )
{
newRootClosed = true;
}
- else if ( rawName.equals( "root" ) )
+ else if ( "root".equals( rawName ) )
{
rootClosed = true;
}
From 5479734d6250b09e0205e892a94e81b76e66140c Mon Sep 17 00:00:00 2001
From: Andrew Williams
Date: Tue, 28 Feb 2012 08:01:24 +0000
Subject: [PATCH 047/133] tidy up process after getting env vars
---
.../java/org/codehaus/plexus/util/cli/CommandLineUtils.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 0243a850..283785eb 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -32,6 +32,8 @@
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.IOUtil;
+
/**
* @author Trygve Laugstøl
* @version $Id$
@@ -366,6 +368,10 @@ else if ( lastKey != null )
{
if ( p != null )
{
+ IOUtil.close( p.getOutputStream() );
+ IOUtil.close( p.getErrorStream() );
+ IOUtil.close( p.getInputStream() );
+
p.destroy();
}
}
From 2071163a005a84142dbc9c5a7f6ed02ba5ab826d Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Tue, 28 Feb 2012 09:33:13 +0100
Subject: [PATCH 048/133] ignore .idea
---
.gitignore | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index d525fbe3..761f7ded 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@ target/
bin
*.iml
*.ipr
-*.iws
\ No newline at end of file
+*.iws
+*.idea
From 7a1e58ff7b6309b56e1abe395666683e42e086b5 Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sat, 3 Mar 2012 23:27:17 +0100
Subject: [PATCH 049/133] use last parent 3.1
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index cb58562a..f4f71aeb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@ limitations under the License.
org.codehaus.plexusplexus
- 3.0.1
+ 3.1plexus-utils
From ec0763d88e0cc4c4ed9700fd9bfe2b075d6c254b Mon Sep 17 00:00:00 2001
From: vladt
Date: Tue, 10 Apr 2012 10:00:15 -0400
Subject: [PATCH 050/133] Allow to specify the file separator for
SelectorUtils.matchPath
---
.../codehaus/plexus/util/SelectorUtils.java | 25 +++++++++++--------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
index ecdd40ce..2f1f6de5 100644
--- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
@@ -252,6 +252,11 @@ public static boolean matchPath( String pattern, String str )
*/
public static boolean matchPath( String pattern, String str,
boolean isCaseSensitive )
+ {
+ return matchPath( pattern, str, File.separator, isCaseSensitive );
+ }
+
+ public static boolean matchPath( String pattern, String str, String separator, boolean isCaseSensitive )
{
if ( pattern.length() > ( REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
&& pattern.startsWith( REGEX_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
@@ -270,24 +275,24 @@ public static boolean matchPath( String pattern, String str,
pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
}
- return matchAntPathPattern( pattern, str, isCaseSensitive );
+ return matchAntPathPattern( pattern, str, separator, isCaseSensitive );
}
}
- private static boolean matchAntPathPattern( String pattern, String str, boolean isCaseSensitive )
+ private static boolean matchAntPathPattern( String pattern, String str, String separator, boolean isCaseSensitive )
{
- // When str starts with a File.separator, pattern has to start with a
- // File.separator.
- // When pattern starts with a File.separator, str has to start with a
- // File.separator.
- if ( str.startsWith( File.separator ) !=
- pattern.startsWith( File.separator ) )
+ // When str starts with a separator, pattern has to start with a
+ // separator.
+ // When pattern starts with a separator, str has to start with a
+ // separator.
+ if ( str.startsWith( separator ) !=
+ pattern.startsWith( separator ) )
{
return false;
}
- Vector patDirs = tokenizePath( pattern, File.separator );
- Vector strDirs = tokenizePath( str, File.separator );
+ Vector patDirs = tokenizePath( pattern, separator );
+ Vector strDirs = tokenizePath( str, separator );
int patIdxStart = 0;
int patIdxEnd = patDirs.size() - 1;
From 6905c00395fcfb68e39dc0e270c4299f6b6b66ea Mon Sep 17 00:00:00 2001
From: vladt
Date: Wed, 11 Apr 2012 10:49:27 -0400
Subject: [PATCH 051/133] Unit tests for "allow to specify the file separator
for SelectorUtils.matchPath"
---
.../plexus/util/SelectorUtilsTest.java | 74 +++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java
diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java
new file mode 100644
index 00000000..aeef7a6f
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java
@@ -0,0 +1,74 @@
+package org.codehaus.plexus.util;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/*
+ * Copyright The Codehaus 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.
+ */
+
+public class SelectorUtilsTest
+ extends TestCase
+{
+ public void testMatchPath_DefaultFileSeparator()
+ {
+ String separator = File.separator;
+
+ // Pattern and target start with file separator
+ assertTrue( SelectorUtils.matchPath( separator + "*" + separator + "a.txt", separator + "b" + separator
+ + "a.txt" ) );
+ // Pattern starts with file separator, target doesn't
+ assertFalse( SelectorUtils.matchPath( separator + "*" + separator + "a.txt", "b" + separator + "a.txt" ) );
+ // Pattern doesn't start with file separator, target does
+ assertFalse( SelectorUtils.matchPath( "*" + separator + "a.txt", separator + "b" + separator + "a.txt" ) );
+ // Pattern and target don't start with file separator
+ assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt" ) );
+ }
+
+ public void testMatchPath_UnixFileSeparator()
+ {
+ String separator = "/";
+
+ // Pattern and target start with file separator
+ assertTrue( SelectorUtils.matchPath( separator + "*" + separator + "a.txt", separator + "b" + separator
+ + "a.txt", separator, false ) );
+ // Pattern starts with file separator, target doesn't
+ assertFalse( SelectorUtils.matchPath( separator + "*" + separator + "a.txt", "b" + separator + "a.txt",
+ separator, false ) );
+ // Pattern doesn't start with file separator, target does
+ assertFalse( SelectorUtils.matchPath( "*" + separator + "a.txt", separator + "b" + separator + "a.txt",
+ separator, false ) );
+ // Pattern and target don't start with file separator
+ assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false ) );
+ }
+
+ public void testMatchPath_WindowsFileSeparator()
+ {
+ String separator = "\\";
+
+ // Pattern and target start with file separator
+ assertTrue( SelectorUtils.matchPath( separator + "*" + separator + "a.txt", separator + "b" + separator
+ + "a.txt", separator, false ) );
+ // Pattern starts with file separator, target doesn't
+ assertFalse( SelectorUtils.matchPath( separator + "*" + separator + "a.txt", "b" + separator + "a.txt",
+ separator, false ) );
+ // Pattern doesn't start with file separator, target does
+ assertFalse( SelectorUtils.matchPath( "*" + separator + "a.txt", separator + "b" + separator + "a.txt",
+ separator, false ) );
+ // Pattern and target don't start with file separator
+ assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false ) );
+ }
+}
From f1ee873df4113eae791face1984e14e2b37440ad Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sun, 6 May 2012 00:35:52 +0200
Subject: [PATCH 052/133] [maven-release-plugin] prepare release
plexus-utils-3.0.1
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f4f71aeb..734c7fa0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.1-SNAPSHOT
+ 3.0.1Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 008275f86b5824fa530ec7666b1ae4c4c346304c Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sun, 6 May 2012 00:36:01 +0200
Subject: [PATCH 053/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 734c7fa0..9136cc74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.1
+ 3.0.2-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 4305d47b13c97bfddbef11d684e882261a292e3a Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Wed, 6 Jun 2012 00:54:55 +0200
Subject: [PATCH 054/133] [PLXUTILS-151] FileUtils.deleteDirectory() attempts
to traverse symlinks, then fails when it encounters a file it can't delete
---
src/main/java/org/codehaus/plexus/util/FileUtils.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index c7dcb200..5784393a 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -1562,6 +1562,14 @@ public static void deleteDirectory( final File directory )
return;
}
+ /* try delete the directory before its contents, which will take
+ * care of any directories that are really symbolic links.
+ */
+ if ( directory.delete() )
+ {
+ return;
+ }
+
cleanDirectory( directory );
if ( !directory.delete() )
{
From a976c5231c14707ff7241634673f6ed528e67c4b Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Mon, 9 Jul 2012 16:52:45 +0200
Subject: [PATCH 055/133] prevent NPE if null replace values with an empty
String
---
.../org/codehaus/plexus/util/PathTool.java | 101 ++++++++++--------
1 file changed, 54 insertions(+), 47 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/PathTool.java b/src/main/java/org/codehaus/plexus/util/PathTool.java
index de52db8d..78677a20 100644
--- a/src/main/java/org/codehaus/plexus/util/PathTool.java
+++ b/src/main/java/org/codehaus/plexus/util/PathTool.java
@@ -51,26 +51,26 @@ public class PathTool
* PathTool.getRelativePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = ""
*
*
- * @param basedir The base directory.
+ * @param basedir The base directory.
* @param filename The filename that is relative to the base
- * directory.
+ * directory.
* @return The relative path of the filename from the base
- * directory. This value is not terminated with a forward slash.
- * A zero-length string is returned if: the filename is not relative to
- * the base directory, basedir is null or zero-length,
- * or filename is null or zero-length.
+ * directory. This value is not terminated with a forward slash.
+ * A zero-length string is returned if: the filename is not relative to
+ * the base directory, basedir is null or zero-length,
+ * or filename is null or zero-length.
*/
public static final String getRelativePath( String basedir, String filename )
{
- basedir = uppercaseDrive(basedir);
- filename = uppercaseDrive(filename);
+ basedir = uppercaseDrive( basedir );
+ filename = uppercaseDrive( filename );
/*
* Verify the arguments and make sure the filename is relative
* to the base directory.
*/
- if ( basedir == null || basedir.length() == 0 || filename == null
- || filename.length() == 0 || !filename.startsWith( basedir ) )
+ if ( basedir == null || basedir.length() == 0 || filename == null || filename.length() == 0
+ || !filename.startsWith( basedir ) )
{
return "";
}
@@ -108,13 +108,13 @@ public static final String getRelativePath( String basedir, String filename )
*
* @param filename The filename to be parsed.
* @return The relative path of the filename. This value is not
- * terminated with a forward slash. A zero-length string is
- * returned if: filename is null or zero-length.
+ * terminated with a forward slash. A zero-length string is
+ * returned if: filename is null or zero-length.
* @see #getRelativeFilePath(String, String)
*/
public static final String getRelativePath( String filename )
{
- filename = uppercaseDrive(filename);
+ filename = uppercaseDrive( filename );
if ( filename == null || filename.length() == 0 )
{
@@ -155,8 +155,8 @@ public static final String getRelativePath( String filename )
*
* @param filename The filename to be parsed.
* @return The directory portion of the filename. If
- * the filename does not contain a directory component, "." is
- * returned.
+ * the filename does not contain a directory component, "." is
+ * returned.
*/
public static final String getDirectoryComponent( String filename )
{
@@ -191,44 +191,52 @@ public static final String getDirectoryComponent( String filename )
* @param relativePath
* @return String
*/
- public static final String calculateLink(String link, String relativePath)
+ public static final String calculateLink( String link, String relativePath )
{
+ if ( link == null )
+ {
+ link = "";
+ }
+ if ( relativePath == null )
+ {
+ relativePath = "";
+ }
//This must be some historical feature
- if (link.startsWith("/site/"))
+ if ( link.startsWith( "/site/" ) )
{
- return link.substring(5);
+ return link.substring( 5 );
}
//Allows absolute links in nav-bars etc
- if (link.startsWith("/absolute/"))
+ if ( link.startsWith( "/absolute/" ) )
{
- return link.substring(10);
+ return link.substring( 10 );
}
// This traps urls like http://
- if (link.indexOf(":") >= 0)
+ if ( link.indexOf( ":" ) >= 0 )
{
return link;
}
//If relativepath is current directory, just pass the link through
- if (relativePath.equals("."))
+ if ( StringUtils.equals( relativePath, "." ) )
{
- if (link.startsWith("/"))
+ if ( link.startsWith( "/" ) )
{
- return link.substring(1);
+ return link.substring( 1 );
}
return link;
}
//If we don't do this, you can end up with ..//bob.html rather than ../bob.html
- if (relativePath.endsWith("/") && link.startsWith("/"))
+ if ( relativePath.endsWith( "/" ) && link.startsWith( "/" ) )
{
- return relativePath + "." + link.substring(1);
+ return relativePath + "." + link.substring( 1 );
}
- if (relativePath.endsWith("/") || link.startsWith("/"))
+ if ( relativePath.endsWith( "/" ) || link.startsWith( "/" ) )
{
return relativePath + link;
}
@@ -324,16 +332,16 @@ public static final String getRelativeFilePath( final String oldPath, final Stri
// check for the presence of windows drives. No relative way of
// traversing from one to the other.
- if ( ( toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) )
- && ( !toPath.substring( 0, 1 ).equals( fromPath.substring( 0, 1 ) ) ) )
+ if ( ( toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) ) && ( !toPath.substring( 0, 1 ).equals(
+ fromPath.substring( 0, 1 ) ) ) )
{
// they both have drive path element but they dont match, no
// relative path
return null;
}
- if ( ( toPath.startsWith( ":", 1 ) && !fromPath.startsWith( ":", 1 ) )
- || ( !toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) ) )
+ if ( ( toPath.startsWith( ":", 1 ) && !fromPath.startsWith( ":", 1 ) ) || ( !toPath.startsWith( ":", 1 )
+ && fromPath.startsWith( ":", 1 ) ) )
{
// one has a drive path element and the other doesnt, no relative
// path.
@@ -359,26 +367,24 @@ public static final String getRelativeFilePath( final String oldPath, final Stri
* within the filename (except the leading if present), append the
* "../" string to the return value.
*
- * @param filename The filename to parse.
+ * @param filename The filename to parse.
* @param separator The separator used within the filename.
* @return The relative path of the filename. This value is not
- * terminated with a forward slash. A zero-length string is
- * returned if: the filename is zero-length.
+ * terminated with a forward slash. A zero-length string is
+ * returned if: the filename is zero-length.
*/
- private static final String determineRelativePath( String filename,
- String separator )
+ private static final String determineRelativePath( String filename, String separator )
{
if ( filename.length() == 0 )
{
return "";
}
-
/*
- * Count the slashes in the relative filename, but exclude the
- * leading slash. If the path has no slashes, then the filename
- * is relative to the current directory.
- */
+ * Count the slashes in the relative filename, but exclude the
+ * leading slash. If the path has no slashes, then the filename
+ * is relative to the current directory.
+ */
int slashCount = StringUtils.countMatches( filename, separator ) - 1;
if ( slashCount <= 0 )
{
@@ -409,9 +415,9 @@ private static final String determineRelativePath( String filename,
* often is returned as the separator.
*
* @param filename The filename parsed to determine the file
- * separator.
+ * separator.
* @return The file separator used within filename.
- * This value is either a forward or backward slash.
+ * This value is either a forward or backward slash.
*/
private static final String determineSeparator( String filename )
{
@@ -423,23 +429,24 @@ private static final String determineSeparator( String filename )
/**
* Cygwin prefers lowercase drive letters, but other parts of maven use uppercase
+ *
* @param path
* @return String
*/
- static final String uppercaseDrive(String path)
+ static final String uppercaseDrive( String path )
{
- if (path == null)
+ if ( path == null )
{
return null;
}
- if (path.length() >= 2 && path.charAt(1) == ':')
+ if ( path.length() >= 2 && path.charAt( 1 ) == ':' )
{
path = Character.toUpperCase( path.charAt( 0 ) ) + path.substring( 1 );
}
return path;
}
- private static final String buildRelativePath( String toPath, String fromPath, final char separatorChar )
+ private static final String buildRelativePath( String toPath, String fromPath, final char separatorChar )
{
// use tokeniser to traverse paths and for lazy checking
StringTokenizer toTokeniser = new StringTokenizer( toPath, String.valueOf( separatorChar ) );
From 2b5a6c3645602fd19932d6a6bce07e9c9bf9b29f Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Mon, 9 Jul 2012 17:03:07 +0200
Subject: [PATCH 056/133] [maven-release-plugin] prepare release
plexus-utils-3.0.2
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 9136cc74..216481ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.2-SNAPSHOT
+ 3.0.2Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 4734a0cae9e9ec32c1a04241c0287d881d5a1048 Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Mon, 9 Jul 2012 17:03:18 +0200
Subject: [PATCH 057/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 216481ad..846f725c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.2
+ 3.0.3-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From ef26d83d3b6638ebfc0ac550e413c89ab98723ff Mon Sep 17 00:00:00 2001
From: Robert Elliot
Date: Wed, 1 Aug 2012 00:16:04 +0100
Subject: [PATCH 058/133] Fixed copy and paste bug where wrong escape chars for
arguments were being retrieved
---
.../org/codehaus/plexus/util/cli/shell/Shell.java | 2 +-
.../plexus/util/cli/shell/BourneShellTest.java | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
index c8100670..23cf9524 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
@@ -160,7 +160,7 @@ protected List getRawCommandLine( String executable, String[] arguments
if ( isQuotedArgumentsEnabled() )
{
- char[] escapeChars = getEscapeChars( isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped() );
+ char[] escapeChars = getEscapeChars( isSingleQuotedArgumentEscaped(), isDoubleQuotedArgumentEscaped() );
sb.append( StringUtils.quoteAndEscape( arguments[i], getArgumentQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), '\\', false ) );
}
diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java
index a4072495..51db9c1e 100644
--- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java
+++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java
@@ -101,6 +101,17 @@ public void testAddSingleQuotesOnArgumentWithSpaces()
assertTrue( cli.endsWith( "\'" + args[0] + "\'" ) );
}
+ public void testAddSingleQuotesAndEscapeSingleQuotesOnArgumentWithSpaces()
+ {
+ Shell sh = newShell();
+
+ String[] args = { "some 'arg' with spaces and quotes" };
+
+ List shellCommandLine = sh.getCommandLine("chmod", args );
+
+ assertEquals("null \'some \\'arg\\' with spaces and quotes\'", shellCommandLine.get(shellCommandLine.size() - 1));
+ }
+
public void testArgumentsWithsemicolon()
{
From c07eb85ab8a59dd73d00449f33e3bc57924123e2 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 1 Aug 2012 23:05:35 +0200
Subject: [PATCH 059/133] [maven-release-plugin] prepare release
plexus-utils-3.0.3
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 846f725c..5bd59e84 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.3-SNAPSHOT
+ 3.0.3Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From c628a025b6dace0622c7007a93cc952ba7a55058 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 1 Aug 2012 23:05:44 +0200
Subject: [PATCH 060/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5bd59e84..50fbc4ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.3
+ 3.0.4-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 920f43fffe99ccb93176c558bb9bb8267a0c01a9 Mon Sep 17 00:00:00 2001
From: Robert Elliot
Date: Fri, 3 Aug 2012 00:15:40 +0100
Subject: [PATCH 061/133] Allowed Shell to take an escape pattern (in Java
MessageFormat) to allow correct escaping of quotes in arguments - bourne
shell requires a ' in an argument to be escaped as '\''
---
.../org/codehaus/plexus/util/StringUtils.java | 43 ++++++++++++++++---
.../plexus/util/cli/shell/BourneShell.java | 1 +
.../codehaus/plexus/util/cli/shell/Shell.java | 14 +++++-
.../codehaus/plexus/util/StringUtilsTest.java | 11 +++++
.../util/cli/shell/BourneShellTest.java | 13 ++++--
5 files changed, 71 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java
index 0bb6875e..873cad09 100644
--- a/src/main/java/org/codehaus/plexus/util/StringUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/StringUtils.java
@@ -2288,18 +2288,37 @@ public static String quoteAndEscape( String source,
char escapeChar,
boolean force )
{
+ return quoteAndEscape(source, quoteChar, escapedChars, quotingTriggers, escapeChar + "%s", force);
+ }
+
+ /**
+ * @param source
+ * @param quoteChar
+ * @param escapedChars
+ * @param quotingTriggers
+ * @param escapePattern
+ * @param force
+ * @return the String quoted and escaped
+ * @since 3.0.4
+ */
+ public static String quoteAndEscape(String source,
+ char quoteChar,
+ final char[] escapedChars,
+ final char[] quotingTriggers,
+ String escapePattern,
+ boolean force) {
if ( source == null )
{
return null;
}
if ( !force && source.startsWith( Character.toString( quoteChar ) )
- && source.endsWith( Character.toString( quoteChar ) ) )
+ && source.endsWith( Character.toString( quoteChar ) ) )
{
return source;
}
- String escaped = escape( source, escapedChars, escapeChar );
+ String escaped = escape( source, escapedChars, escapePattern );
boolean quote = false;
if ( force )
@@ -2338,6 +2357,18 @@ else if ( !escaped.equals( source ) )
* @since 1.5.1
*/
public static String escape( String source, final char[] escapedChars, char escapeChar )
+ {
+ return escape(source, escapedChars, escapeChar + "%s");
+ }
+
+ /**
+ * @param source
+ * @param escapedChars
+ * @param escapePattern
+ * @return the String escaped
+ * @since 3.0.4
+ */
+ public static String escape( String source, final char[] escapedChars, String escapePattern )
{
if ( source == null )
{
@@ -2357,10 +2388,12 @@ public static String escape( String source, final char[] escapedChars, char esca
if ( result > -1 )
{
- buffer.append( escapeChar );
+ buffer.append( String.format(escapePattern, c) );
+ }
+ else
+ {
+ buffer.append( c );
}
-
- buffer.append( c );
}
return buffer.toString();
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
index f33f5037..e4b4cde4 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
@@ -60,6 +60,7 @@ public BourneShell( boolean isLoginShell )
setSingleQuotedArgumentEscaped( true );
setSingleQuotedExecutableEscaped( false );
setQuotedExecutableEnabled( true );
+ setArgumentEscapePattern("'\\%s'");
if ( isLoginShell )
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
index 23cf9524..571b249d 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
@@ -66,6 +66,8 @@ public class Shell
private char exeQuoteDelimiter = '\"';
+ private String argumentEscapePattern = "\\%s";
+
/**
* Set the command to execute the shell (eg. COMMAND.COM, /bin/bash,...)
*
@@ -162,7 +164,7 @@ protected List getRawCommandLine( String executable, String[] arguments
{
char[] escapeChars = getEscapeChars( isSingleQuotedArgumentEscaped(), isDoubleQuotedArgumentEscaped() );
- sb.append( StringUtils.quoteAndEscape( arguments[i], getArgumentQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), '\\', false ) );
+ sb.append( StringUtils.quoteAndEscape( arguments[i], getArgumentQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), getArgumentEscapePattern(), false ) );
}
else
{
@@ -244,6 +246,15 @@ protected char getExecutableQuoteDelimiter()
return exeQuoteDelimiter;
}
+ protected void setArgumentEscapePattern(String argumentEscapePattern)
+ {
+ this.argumentEscapePattern = argumentEscapePattern;
+ }
+
+ protected String getArgumentEscapePattern() {
+ return argumentEscapePattern;
+ }
+
/**
* Get the full command line to execute, including shell command, shell arguments,
* executable and executable arguments
@@ -395,5 +406,4 @@ protected void setSingleQuotedExecutableEscaped( boolean singleQuotedExecutableE
{
this.singleQuotedExecutableEscaped = singleQuotedExecutableEscaped;
}
-
}
diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
index 63e7340f..e7c505ef 100644
--- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
@@ -123,6 +123,17 @@ public void testQuote_EscapeEmbeddedSingleQuotes()
assertEquals( check, result );
}
+ public void testQuote_EscapeEmbeddedSingleQuotesWithPattern()
+ {
+ String src = "This \'is a\' test";
+ String check = "\'This pre'postis apre'post test\'";
+
+ char[] escaped = { '\'', '\"' };
+ String result = StringUtils.quoteAndEscape( src, '\'', escaped, new char[]{ ' ' }, "pre%spost", false );
+
+ assertEquals( check, result );
+ }
+
public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces()
{
String src = "This \"is a\" test";
diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java
index 51db9c1e..2a987eda 100644
--- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java
+++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java
@@ -101,15 +101,20 @@ public void testAddSingleQuotesOnArgumentWithSpaces()
assertTrue( cli.endsWith( "\'" + args[0] + "\'" ) );
}
- public void testAddSingleQuotesAndEscapeSingleQuotesOnArgumentWithSpaces()
+ public void testEscapeSingleQuotesOnArgument()
{
Shell sh = newShell();
- String[] args = { "some 'arg' with spaces and quotes" };
+ sh.setWorkingDirectory( "/usr/bin" );
+ sh.setExecutable( "chmod" );
+
+ String[] args = { "arg'withquote" };
- List shellCommandLine = sh.getCommandLine("chmod", args );
+ List shellCommandLine = sh.getShellCommandLine( args );
- assertEquals("null \'some \\'arg\\' with spaces and quotes\'", shellCommandLine.get(shellCommandLine.size() - 1));
+ String cli = StringUtils.join( shellCommandLine.iterator(), " " );
+ System.out.println( cli );
+ assertEquals("cd /usr/bin && chmod 'arg'\\''withquote'", shellCommandLine.get(shellCommandLine.size() - 1));
}
public void testArgumentsWithsemicolon()
From 76880d4187130c8142b887c55d05c1cb349e2dc2 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 6 Aug 2012 20:34:29 +0200
Subject: [PATCH 062/133] [maven-release-plugin] prepare release
plexus-utils-3.0.4
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 50fbc4ac..85569279 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.4-SNAPSHOT
+ 3.0.4Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 97601113fcc349aec60e937c3dca886a2f75d01d Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 6 Aug 2012 20:34:38 +0200
Subject: [PATCH 063/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 85569279..ecbef109 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.4
+ 3.0.5-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From e7b72534b3f68b9e75331a2badbd421bc65395ac Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 20 Aug 2012 16:15:07 +0200
Subject: [PATCH 064/133] o Added significantly faster MatchPatterns to
SelectorUtils
Using matchpattarns reduces string tokenizing immensely, enough to actually speed up some plugins quite
a lot
---
.../codehaus/plexus/util/AbstractScanner.java | 218 +++++--------
.../plexus/util/DirectoryScanner.java | 133 ++++----
.../codehaus/plexus/util/MatchPattern.java | 125 ++++++++
.../codehaus/plexus/util/MatchPatterns.java | 81 +++++
.../codehaus/plexus/util/SelectorUtils.java | 301 +++++++++---------
.../plexus/util/MatchPatternTest.java | 32 ++
.../plexus/util/MatchPatternsTest.java | 32 ++
7 files changed, 576 insertions(+), 346 deletions(-)
create mode 100644 src/main/java/org/codehaus/plexus/util/MatchPattern.java
create mode 100644 src/main/java/org/codehaus/plexus/util/MatchPatterns.java
create mode 100644 src/test/java/org/codehaus/plexus/util/MatchPatternTest.java
create mode 100644 src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java
diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
index 2912e7c1..1a1858dc 100644
--- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
@@ -22,8 +22,8 @@
/**
* Scan a directory tree for files, with specified inclusions and exclusions.
*/
-public abstract class AbstractScanner
- implements Scanner
+public abstract class AbstractScanner
+ implements Scanner
{
/**
* Patterns which should be excluded by default, like SCM files
@@ -50,90 +50,73 @@ public abstract class AbstractScanner
*/
public static final String[] DEFAULTEXCLUDES = {
// Miscellaneous typical temporary files
- "**/*~",
- "**/#*#",
- "**/.#*",
- "**/%*%",
- "**/._*",
-
+ "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
+
// CVS
- "**/CVS",
- "**/CVS/**",
- "**/.cvsignore",
-
+ "**/CVS", "**/CVS/**", "**/.cvsignore",
+
// RCS
- "**/RCS",
- "**/RCS/**",
-
+ "**/RCS", "**/RCS/**",
+
// SCCS
- "**/SCCS",
- "**/SCCS/**",
-
+ "**/SCCS", "**/SCCS/**",
+
// Visual SourceSafe
"**/vssver.scc",
-
+
// MKS
"**/project.pj",
// Subversion
- "**/.svn",
- "**/.svn/**",
-
+ "**/.svn", "**/.svn/**",
+
// Arch
- "**/.arch-ids",
- "**/.arch-ids/**",
-
+ "**/.arch-ids", "**/.arch-ids/**",
+
//Bazaar
- "**/.bzr",
- "**/.bzr/**",
-
+ "**/.bzr", "**/.bzr/**",
+
//SurroundSCM
"**/.MySCMServerInfo",
-
+
// Mac
"**/.DS_Store",
-
+
// Serena Dimensions Version 10
- "**/.metadata",
- "**/.metadata/**",
-
+ "**/.metadata", "**/.metadata/**",
+
// Mercurial
- "**/.hg",
- "**/.hg/**",
-
+ "**/.hg", "**/.hg/**",
+
// git
- "**/.git",
- "**/.gitignore",
- "**/.gitattributes",
- "**/.git/**",
-
+ "**/.git", "**/.gitignore", "**/.gitattributes", "**/.git/**",
+
// BitKeeper
- "**/BitKeeper",
- "**/BitKeeper/**",
- "**/ChangeSet",
- "**/ChangeSet/**",
-
+ "**/BitKeeper", "**/BitKeeper/**", "**/ChangeSet", "**/ChangeSet/**",
+
// darcs
- "**/_darcs",
- "**/_darcs/**",
- "**/.darcsrepo",
- "**/.darcsrepo/**",
- "**/-darcs-backup*",
- "**/.darcs-temp-mail"
- };
-
- /** The patterns for the files to be included. */
+ "**/_darcs", "**/_darcs/**", "**/.darcsrepo", "**/.darcsrepo/**", "**/-darcs-backup*", "**/.darcs-temp-mail" };
+
+ /**
+ * The patterns for the files to be included.
+ */
protected String[] includes;
-
- /** The patterns for the files to be excluded. */
+
+ private MatchPatterns includesPatterns;
+
+ /**
+ * The patterns for the files to be excluded.
+ */
protected String[] excludes;
-
+
+ private MatchPatterns excludesPatterns;
+
/**
* Whether or not the file system should be treated as a case sensitive
* one.
*/
protected boolean isCaseSensitive = true;
-
+
/**
* Sets whether or not the file system should be regarded as case sensitive.
*
@@ -144,11 +127,11 @@ public void setCaseSensitive( boolean isCaseSensitive )
{
this.isCaseSensitive = isCaseSensitive;
}
-
+
/**
* Tests whether or not a given path matches the start of a given
* pattern up to the first "**".
- *
+ *
* This is not a general purpose test and should only be used if you
* can live with false positives. For example, pattern=**\a
* and str=b will yield true.
@@ -157,39 +140,36 @@ public void setCaseSensitive( boolean isCaseSensitive )
* null.
* @param str The path to match, as a String. Must not be
* null.
- *
* @return whether or not a given path matches the start of a given
- * pattern up to the first "**".
+ * pattern up to the first "**".
*/
protected static boolean matchPatternStart( String pattern, String str )
{
return SelectorUtils.matchPatternStart( pattern, str );
}
-
+
/**
* Tests whether or not a given path matches the start of a given
* pattern up to the first "**".
- *
+ *
* This is not a general purpose test and should only be used if you
* can live with false positives. For example, pattern=**\a
* and str=b will yield true.
*
- * @param pattern The pattern to match against. Must not be
- * null.
- * @param str The path to match, as a String. Must not be
- * null.
+ * @param pattern The pattern to match against. Must not be
+ * null.
+ * @param str The path to match, as a String. Must not be
+ * null.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
- *
* @return whether or not a given path matches the start of a given
- * pattern up to the first "**".
+ * pattern up to the first "**".
*/
- protected static boolean matchPatternStart( String pattern, String str,
- boolean isCaseSensitive )
+ protected static boolean matchPatternStart( String pattern, String str, boolean isCaseSensitive )
{
return SelectorUtils.matchPatternStart( pattern, str, isCaseSensitive );
}
-
+
/**
* Tests whether or not a given path matches a given pattern.
*
@@ -197,7 +177,6 @@ protected static boolean matchPatternStart( String pattern, String str,
* null.
* @param str The path to match, as a String. Must not be
* null.
- *
* @return true if the pattern matches against the string,
* or false otherwise.
*/
@@ -205,26 +184,24 @@ protected static boolean matchPath( String pattern, String str )
{
return SelectorUtils.matchPath( pattern, str );
}
-
+
/**
* Tests whether or not a given path matches a given pattern.
*
- * @param pattern The pattern to match against. Must not be
- * null.
- * @param str The path to match, as a String. Must not be
- * null.
+ * @param pattern The pattern to match against. Must not be
+ * null.
+ * @param str The path to match, as a String. Must not be
+ * null.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
- *
* @return true if the pattern matches against the string,
* or false otherwise.
*/
- protected static boolean matchPath( String pattern, String str,
- boolean isCaseSensitive )
+ protected static boolean matchPath( String pattern, String str, boolean isCaseSensitive )
{
return SelectorUtils.matchPath( pattern, str, isCaseSensitive );
}
-
+
/**
* Tests whether or not a string matches against a pattern.
* The pattern may contain two special characters:
@@ -235,7 +212,6 @@ protected static boolean matchPath( String pattern, String str,
* Must not be null.
* @param str The string which must be matched against the pattern.
* Must not be null.
- *
* @return true if the string matches against the pattern,
* or false otherwise.
*/
@@ -243,43 +219,40 @@ public static boolean match( String pattern, String str )
{
return SelectorUtils.match( pattern, str );
}
-
+
/**
* Tests whether or not a string matches against a pattern.
* The pattern may contain two special characters:
* '*' means zero or more characters
* '?' means one and only one character
*
- * @param pattern The pattern to match against.
- * Must not be null.
- * @param str The string which must be matched against the pattern.
- * Must not be null.
+ * @param pattern The pattern to match against.
+ * Must not be null.
+ * @param str The string which must be matched against the pattern.
+ * Must not be null.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
- *
- *
* @return true if the string matches against the pattern,
* or false otherwise.
*/
- protected static boolean match( String pattern, String str,
- boolean isCaseSensitive )
+ protected static boolean match( String pattern, String str, boolean isCaseSensitive )
{
return SelectorUtils.match( pattern, str, isCaseSensitive );
}
-
-
+
+
/**
* Sets the list of include patterns to use. All '/' and '\' characters
* are replaced by File.separatorChar, so the separator used
* need not match File.separatorChar.
- *
+ *
* When a pattern ends with a '/' or '\', "**" is appended.
*
* @param includes A list of include patterns.
* May be null, indicating that all files
* should be included. If a non-null
* list is given, all elements must be
- * non-null.
+ * non-null.
*/
public void setIncludes( String[] includes )
{
@@ -296,12 +269,12 @@ public void setIncludes( String[] includes )
}
}
}
-
+
/**
* Sets the list of exclude patterns to use. All '/' and '\' characters
* are replaced by File.separatorChar, so the separator used
* need not match File.separatorChar.
- *
+ *
* When a pattern ends with a '/' or '\', "**" is appended.
*
* @param excludes A list of exclude patterns.
@@ -327,7 +300,7 @@ public void setExcludes( String[] excludes )
/**
* Normalizes the pattern, e.g. converts forward and backward slashes to the platform-specific file separator.
- *
+ *
* @param pattern The pattern to normalize, must not be null.
* @return The normalized pattern, never null.
*/
@@ -369,16 +342,9 @@ private String normalizePattern( String pattern )
*/
protected boolean isIncluded( String name )
{
- for ( int i = 0; i < includes.length; i++ )
- {
- if ( matchPath( includes[i], name, isCaseSensitive ) )
- {
- return true;
- }
- }
- return false;
+ return includesPatterns.matches( name, isCaseSensitive );
}
-
+
/**
* Tests whether or not a name matches the start of at least one include
* pattern.
@@ -389,16 +355,9 @@ protected boolean isIncluded( String name )
*/
protected boolean couldHoldIncluded( String name )
{
- for ( int i = 0; i < includes.length; i++ )
- {
- if ( matchPatternStart( includes[i], name, isCaseSensitive ) )
- {
- return true;
- }
- }
- return false;
+ return includesPatterns.matchesPatternStart(name, isCaseSensitive);
}
-
+
/**
* Tests whether or not a name matches against at least one exclude
* pattern.
@@ -409,16 +368,9 @@ protected boolean couldHoldIncluded( String name )
*/
protected boolean isExcluded( String name )
{
- for ( int i = 0; i < excludes.length; i++ )
- {
- if ( matchPath( excludes[i], name, isCaseSensitive ) )
- {
- return true;
- }
- }
- return false;
+ return excludesPatterns.matches( name, isCaseSensitive );
}
-
+
/**
* Adds default exclusions to the current exclusions set.
*/
@@ -437,8 +389,8 @@ public void addDefaultExcludes()
}
excludes = newExcludes;
}
-
- protected void setupDefaultFilters()
+
+ protected void setupDefaultFilters()
{
if ( includes == null )
{
@@ -451,4 +403,10 @@ protected void setupDefaultFilters()
excludes = new String[0];
}
}
+
+ protected void setupMatchPatterns()
+ {
+ includesPatterns = MatchPatterns.from( includes );
+ excludesPatterns = MatchPatterns.from( excludes );
+ }
}
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
index 835bb69a..33e114ad 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
@@ -61,12 +61,12 @@
/**
* Class for scanning a directory for files/directories which match certain
* criteria.
- *
+ *
* These criteria consist of selectors and patterns which have been specified.
* With the selectors you can select which files you want to have included.
* Files which are not selected are excluded. With patterns you can include
* or exclude files based on their filename.
- *
+ *
* The idea is simple. A given directory is recursively scanned for all files
* and directories. Each file/directory is matched against a set of selectors,
* including special support for matching against filenames with include and
@@ -74,12 +74,12 @@
* pattern of the include pattern list or other file selector, and don't match
* any pattern of the exclude pattern list or fail to match against a required
* selector will be placed in the list of files/directories found.
- *
+ *
* When no list of include patterns is supplied, "**" will be used, which
* means that everything will be matched. When no list of exclude patterns is
* supplied, an empty list is used, such that nothing will be excluded. When
* no selectors are supplied, none are applied.
- *
+ *
* The filename pattern matching is done as follows:
* The name to be matched is split up in path segments. A path segment is the
* name of a directory or file, which is bounded by
@@ -87,11 +87,11 @@
* For example, "abc/def/ghi/xyz.java" is split up in the segments "abc",
* "def","ghi" and "xyz.java".
* The same is done for the pattern against which should be matched.
- *
+ *
* The segments of the name and the pattern are then matched against each
* other. When '**' is used for a path segment in the pattern, it matches
* zero or more path segments of the name.
- *
+ *
* There is a special case regarding the use of File.separators
* at the beginning of the pattern and the string to match:
* When a pattern starts with a File.separator, the string
@@ -100,27 +100,27 @@
* string to match may not start with a File.separator.
* When one of these rules is not obeyed, the string will not
* match.
- *
+ *
* When a name path segment is matched against a pattern path segment, the
* following special characters can be used:
* '*' matches zero or more characters
* '?' matches one character.
- *
+ *
* Examples:
- *
+ *
* "**\*.class" matches all .class files/dirs in a directory tree.
- *
+ *
* "test\a??.java" matches all files/dirs which start with an 'a', then two
* more characters and then ".java", in a directory called test.
- *
+ *
* "**" matches everything in a directory tree.
- *
+ *
* "**\test\**\XYZ*" matches all files/dirs which start with "XYZ" and where
* there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123").
- *
+ *
* Case sensitivity may be turned off if necessary. By default, it is
* turned on.
- *
+ *
* Example of usage:
*
* String[] includes = {"**\\*.class"};
@@ -141,23 +141,29 @@
* files in all proper subdirectories of a directory called "modules"
*
* @author Arnout J. Kuiper
- * ajkuiper@wxs.nl
+ * ajkuiper@wxs.nl
* @author Magesh Umasankar
* @author Bruce Atherton
* @author Antoine Levy-Lambert
*/
-public class DirectoryScanner extends AbstractScanner
+public class DirectoryScanner
+ extends AbstractScanner
{
- /** The base directory to be scanned. */
+ /**
+ * The base directory to be scanned.
+ */
protected File basedir;
- /** The files which matched at least one include and no excludes
- * and were selected.
+ /**
+ * The files which matched at least one include and no excludes
+ * and were selected.
*/
protected Vector filesIncluded;
- /** The files which did not match any includes or selectors. */
+ /**
+ * The files which did not match any includes or selectors.
+ */
protected Vector filesNotIncluded;
/**
@@ -166,12 +172,15 @@ public class DirectoryScanner extends AbstractScanner
*/
protected Vector filesExcluded;
- /** The directories which matched at least one include and no excludes
- * and were selected.
+ /**
+ * The directories which matched at least one include and no excludes
+ * and were selected.
*/
protected Vector dirsIncluded;
- /** The directories which were found and did not match any includes. */
+ /**
+ * The directories which were found and did not match any includes.
+ */
protected Vector dirsNotIncluded;
/**
@@ -180,17 +189,21 @@ public class DirectoryScanner extends AbstractScanner
*/
protected Vector dirsExcluded;
- /** The files which matched at least one include and no excludes and
- * which a selector discarded.
+ /**
+ * The files which matched at least one include and no excludes and
+ * which a selector discarded.
*/
protected Vector filesDeselected;
- /** The directories which matched at least one include and no excludes
- * but which a selector discarded.
+ /**
+ * The directories which matched at least one include and no excludes
+ * but which a selector discarded.
*/
protected Vector dirsDeselected;
- /** Whether or not our results were built by a slow scan. */
+ /**
+ * Whether or not our results were built by a slow scan.
+ */
protected boolean haveSlowResults = false;
/**
@@ -200,7 +213,9 @@ public class DirectoryScanner extends AbstractScanner
*/
private boolean followSymlinks = true;
- /** Whether or not everything tested so far has been included. */
+ /**
+ * Whether or not everything tested so far has been included.
+ */
protected boolean everythingIncluded = true;
/**
@@ -221,8 +236,7 @@ public DirectoryScanner()
*/
public void setBasedir( String basedir )
{
- setBasedir( new File( basedir.replace( '/', File.separatorChar ).replace(
- '\\', File.separatorChar ) ) );
+ setBasedir( new File( basedir.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ) ) );
}
/**
@@ -275,11 +289,12 @@ public boolean isEverythingIncluded()
* pattern and don't match any exclude patterns. If there are selectors
* then the files must pass muster there, as well.
*
- * @exception IllegalStateException if the base directory was set
- * incorrectly (i.e. if it is null, doesn't exist,
- * or isn't a directory).
+ * @throws IllegalStateException if the base directory was set
+ * incorrectly (i.e. if it is null, doesn't exist,
+ * or isn't a directory).
*/
- public void scan() throws IllegalStateException
+ public void scan()
+ throws IllegalStateException
{
if ( basedir == null )
{
@@ -287,16 +302,15 @@ public void scan() throws IllegalStateException
}
if ( !basedir.exists() )
{
- throw new IllegalStateException( "basedir " + basedir
- + " does not exist" );
+ throw new IllegalStateException( "basedir " + basedir + " does not exist" );
}
if ( !basedir.isDirectory() )
{
- throw new IllegalStateException( "basedir " + basedir
- + " is not a directory" );
+ throw new IllegalStateException( "basedir " + basedir + " is not a directory" );
}
setupDefaultFilters();
+ setupMatchPatterns();
filesIncluded = new Vector();
filesNotIncluded = new Vector();
@@ -337,7 +351,7 @@ public void scan() throws IllegalStateException
* list of excluded/included files/directories, whereas a fast scan
* will only have full results for included files, as it ignores
* directories which can't possibly hold any included files/directories.
- *
+ *
* Returns immediately if a slow scan has already been completed.
*/
protected void slowScan()
@@ -383,7 +397,6 @@ protected void slowScan()
* prevent problems with an absolute path when using
* dir). Must not be null.
* @param fast Whether or not this call is part of a fast scan.
- *
* @see #filesIncluded
* @see #filesNotIncluded
* @see #filesExcluded
@@ -406,15 +419,14 @@ protected void scandir( File dir, String vpath, boolean fast )
* then???)
*/
-
/*
- * [jdcasey] (2) is apparently happening to me, as this is killing one of my tests...
- * this is affecting the assembly plugin, fwiw. I will initialize the newfiles array as
- * zero-length for now.
- *
- * NOTE: I can't find the problematic code, as it appears to come from a native method
- * in UnixFileSystem...
- */
+ * [jdcasey] (2) is apparently happening to me, as this is killing one of my tests...
+ * this is affecting the assembly plugin, fwiw. I will initialize the newfiles array as
+ * zero-length for now.
+ *
+ * NOTE: I can't find the problematic code, as it appears to come from a native method
+ * in UnixFileSystem...
+ */
/*
* [bentmann] A null array will also be returned from list() on NTFS when dir refers to a soft link or
* junction point whose target is not existent.
@@ -580,7 +592,6 @@ public String[] getIncludedFiles()
*
* @return the names of the files which matched none of the include
* patterns.
- *
* @see #slowScan
*/
public String[] getNotIncludedFiles()
@@ -599,7 +610,6 @@ public String[] getNotIncludedFiles()
*
* @return the names of the files which matched at least one of the
* include patterns and at at least one of the exclude patterns.
- *
* @see #slowScan
*/
public String[] getExcludedFiles()
@@ -613,12 +623,11 @@ public String[] getExcludedFiles()
/**
*
Returns the names of the files which were selected out and
* therefore not ultimately included.
- *
+ *
*
The names are relative to the base directory. This involves
* performing a slow scan if one has not already been completed.
*
* @return the names of the files which were deselected.
- *
* @see #slowScan
*/
public String[] getDeselectedFiles()
@@ -635,7 +644,7 @@ public String[] getDeselectedFiles()
* The names are relative to the base directory.
*
* @return the names of the directories which matched at least one of the
- * include patterns and none of the exclude patterns.
+ * include patterns and none of the exclude patterns.
*/
public String[] getIncludedDirectories()
{
@@ -650,8 +659,7 @@ public String[] getIncludedDirectories()
* performing a slow scan if one has not already been completed.
*
* @return the names of the directories which matched none of the include
- * patterns.
- *
+ * patterns.
* @see #slowScan
*/
public String[] getNotIncludedDirectories()
@@ -669,8 +677,7 @@ public String[] getNotIncludedDirectories()
* performing a slow scan if one has not already been completed.
*
* @return the names of the directories which matched at least one of the
- * include patterns and at least one of the exclude patterns.
- *
+ * include patterns and at least one of the exclude patterns.
* @see #slowScan
*/
public String[] getExcludedDirectories()
@@ -684,12 +691,11 @@ public String[] getExcludedDirectories()
/**
*
Returns the names of the directories which were selected out and
* therefore not ultimately included.
- *
+ *
*
The names are relative to the base directory. This involves
* performing a slow scan if one has not already been completed.
*
* @return the names of the directories which were deselected.
- *
* @see #slowScan
*/
public String[] getDeselectedDirectories()
@@ -702,17 +708,16 @@ public String[] getDeselectedDirectories()
/**
* Checks whether a given file is a symbolic link.
- *
+ *
*
It doesn't really test for symbolic links but whether the
* canonical and absolute paths of the file are identical - this
* may lead to false positives on some platforms.
*
* @param parent the parent directory of the file to test
- * @param name the name of the file to test.
- *
- * @since Ant 1.5
+ * @param name the name of the file to test.
* @return true if it's a symbolic link
* @throws java.io.IOException .
+ * @since Ant 1.5
*/
public boolean isSymbolicLink( File parent, String name )
throws IOException
diff --git a/src/main/java/org/codehaus/plexus/util/MatchPattern.java b/src/main/java/org/codehaus/plexus/util/MatchPattern.java
new file mode 100644
index 00000000..930bda38
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/MatchPattern.java
@@ -0,0 +1,125 @@
+package org.codehaus.plexus.util;
+/*
+ * Copyright The Codehaus 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 java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * Describes a match target for SelectorUtils.
+ *
+ * Significantly more efficient than using strings, since re-evaluation and re-tokenizing is avoided.
+ *
+ * @author Kristian Rosenvold
+ */
+public class MatchPattern
+{
+ private final String source;
+
+ private final String regexPattern;
+
+ private final String separator;
+
+ private final String[] tokenized;
+
+ private MatchPattern( String source, String separator )
+ {
+ regexPattern = SelectorUtils.isRegexPrefixedPattern( source ) ? source.substring(
+ SelectorUtils.REGEX_HANDLER_PREFIX.length(),
+ source.length() - SelectorUtils.PATTERN_HANDLER_SUFFIX.length() ) : null;
+ this.source =
+ SelectorUtils.isAntPrefixedPattern( source )
+ ? source.substring( SelectorUtils.ANT_HANDLER_PREFIX.length(), source.length()
+ - SelectorUtils.PATTERN_HANDLER_SUFFIX.length() )
+ : source;
+ this.separator = separator;
+ tokenized = tokenizePathToString( this.source, separator );
+ }
+
+
+
+ public boolean matchPath( String str, boolean isCaseSensitive )
+ {
+ if ( regexPattern != null )
+ {
+ return str.matches( regexPattern );
+ }
+ else
+ {
+ return SelectorUtils.matchAntPathPattern( this, str, separator, isCaseSensitive );
+ }
+ }
+
+ boolean matchPath( String str, String[] strDirs, boolean isCaseSensitive )
+ {
+ if ( regexPattern != null )
+ {
+ return str.matches( regexPattern );
+ }
+ else
+ {
+ return SelectorUtils.matchAntPathPattern( getTokenizedPathString(), strDirs, isCaseSensitive );
+ }
+ }
+
+ public boolean matchPatternStart( String str, boolean isCaseSensitive )
+ {
+ if ( regexPattern != null )
+ {
+ // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgement until we have
+ // a file to deal with, or we can definitely say this is an exclusion...
+ return true;
+ }
+ else
+ {
+ String altStr = source.replace( '\\', '/' );
+
+ return SelectorUtils.matchAntPathPatternStart( this, str, File.separator, isCaseSensitive )
+ || SelectorUtils.matchAntPathPatternStart( this, altStr, "/", isCaseSensitive );
+ }
+ }
+
+ public String[] getTokenizedPathString()
+ {
+ return tokenized;
+ }
+
+
+ public boolean startsWith( String string )
+ {
+ return source.startsWith( string );
+ }
+
+
+ static String[] tokenizePathToString( String path, String separator )
+ {
+ List ret = new ArrayList();
+ StringTokenizer st = new StringTokenizer( path, separator );
+ while ( st.hasMoreTokens() )
+ {
+ ret.add( st.nextToken() );
+ }
+ return ret.toArray( new String[ret.size()] );
+ }
+
+ public static MatchPattern fromString( String source )
+ {
+ return new MatchPattern( source, File.separator );
+ }
+
+}
diff --git a/src/main/java/org/codehaus/plexus/util/MatchPatterns.java b/src/main/java/org/codehaus/plexus/util/MatchPatterns.java
new file mode 100644
index 00000000..e72505cf
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/MatchPatterns.java
@@ -0,0 +1,81 @@
+package org.codehaus.plexus.util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A list of patterns to be matched
+ *
+ * @author Kristian Rosenvold
+ */
+public class MatchPatterns
+{
+ private final MatchPattern[] patterns;
+
+ private MatchPatterns( MatchPattern[] patterns )
+ {
+ this.patterns = patterns;
+ }
+
+ /**
+ * Checks these MatchPatterns against a specified string.
+ *
+ * Uses far less string tokenization than any of the alternatives.
+ *
+ * @param name The name to look for
+ * @param isCaseSensitive If the comparison is case sensitive
+ * @return true if any of the supplied patterns match
+ */
+ public boolean matches( String name, boolean isCaseSensitive )
+ {
+ String[] tokenized = MatchPattern.tokenizePathToString( name, File.separator );
+ for ( MatchPattern pattern : patterns )
+ {
+ if ( pattern.matchPath( name, tokenized, isCaseSensitive ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean matchesPatternStart( String name, boolean isCaseSensitive )
+ {
+ for ( MatchPattern includesPattern : patterns )
+ {
+ if ( includesPattern.matchPatternStart( name, isCaseSensitive ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static MatchPatterns from( String... sources )
+ {
+ final int length = sources.length;
+ MatchPattern[] result = new MatchPattern[length];
+ for ( int i = 0; i < length; i++ )
+ {
+ result[i] = MatchPattern.fromString( sources[i] );
+ }
+ return new MatchPatterns( result );
+ }
+
+ public static MatchPatterns from( Iterable strings )
+ {
+ return new MatchPatterns( getMatchPatterns( strings ) );
+ }
+
+ private static MatchPattern[] getMatchPatterns( Iterable items )
+ {
+ List result = new ArrayList();
+ for ( String string : items )
+ {
+ result.add( MatchPattern.fromString( string ) );
+ }
+ return result.toArray( new MatchPattern[result.size()] );
+ }
+
+}
diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
index 2f1f6de5..6309c570 100644
--- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
@@ -55,6 +55,8 @@
package org.codehaus.plexus.util;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -67,23 +69,23 @@
*
This is a Singleton.
*
* @author Arnout J. Kuiper
- * ajkuiper@wxs.nl
+ * ajkuiper@wxs.nl
* @author Magesh Umasankar
* @author Bruce Atherton
- * @since 1.5
* @version $Id$
+ * @since 1.5
*/
public final class SelectorUtils
{
public static final String PATTERN_HANDLER_PREFIX = "[";
-
+
public static final String PATTERN_HANDLER_SUFFIX = "]";
-
+
public static final String REGEX_HANDLER_PREFIX = "%regex" + PATTERN_HANDLER_PREFIX;
-
+
public static final String ANT_HANDLER_PREFIX = "%ant" + PATTERN_HANDLER_PREFIX;
-
+
private static SelectorUtils instance = new SelectorUtils();
/**
@@ -104,7 +106,7 @@ public static SelectorUtils getInstance()
/**
* Tests whether or not a given path matches the start of a given
* pattern up to the first "**".
- *
+ *
* This is not a general purpose test and should only be used if you
* can live with false positives. For example, pattern=**\a
* and str=b will yield true.
@@ -113,9 +115,8 @@ public static SelectorUtils getInstance()
* null.
* @param str The path to match, as a String. Must not be
* null.
- *
* @return whether or not a given path matches the start of a given
- * pattern up to the first "**".
+ * pattern up to the first "**".
*/
public static boolean matchPatternStart( String pattern, String str )
{
@@ -125,26 +126,23 @@ public static boolean matchPatternStart( String pattern, String str )
/**
* Tests whether or not a given path matches the start of a given
* pattern up to the first "**".
- *
+ *
* This is not a general purpose test and should only be used if you
* can live with false positives. For example, pattern=**\a
* and str=b will yield true.
*
- * @param pattern The pattern to match against. Must not be
- * null.
- * @param str The path to match, as a String. Must not be
- * null.
+ * @param pattern The pattern to match against. Must not be
+ * null.
+ * @param str The path to match, as a String. Must not be
+ * null.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
- *
* @return whether or not a given path matches the start of a given
- * pattern up to the first "**".
+ * pattern up to the first "**".
*/
- public static boolean matchPatternStart( String pattern, String str,
- boolean isCaseSensitive )
+ public static boolean matchPatternStart( String pattern, String str, boolean isCaseSensitive )
{
- if ( pattern.length() > ( REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
- && pattern.startsWith( REGEX_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ if ( isRegexPrefixedPattern( pattern ) )
{
// FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgement until we have
// a file to deal with, or we can definitely say this is an exclusion...
@@ -152,50 +150,85 @@ public static boolean matchPatternStart( String pattern, String str,
}
else
{
- if ( pattern.length() > ( ANT_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
- && pattern.startsWith( ANT_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ if ( isAntPrefixedPattern( pattern ) )
{
- pattern =
- pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
+ pattern = pattern.substring( ANT_HANDLER_PREFIX.length(),
+ pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
}
String altStr = str.replace( '\\', '/' );
-
+
return matchAntPathPatternStart( pattern, str, File.separator, isCaseSensitive )
|| matchAntPathPatternStart( pattern, altStr, "/", isCaseSensitive );
}
}
-
- private static boolean matchAntPathPatternStart( String pattern, String str, String separator, boolean isCaseSensitive )
+
+ static boolean isAntPrefixedPattern( String pattern )
+ {
+ return pattern.length() > ( ANT_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
+ && pattern.startsWith( ANT_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX );
+ }
+
+ @SuppressWarnings( "SimplifiableIfStatement" )
+ static boolean matchAntPathPatternStart( MatchPattern pattern, String str, String separator,
+ boolean isCaseSensitive )
+ {
+ if ( separatorPatternStartSlashMismatch( pattern, str, separator ) )
+ {
+ return false;
+ }
+
+ return matchAntPathPatternStart( pattern.getTokenizedPathString(), str, separator, isCaseSensitive );
+ }
+
+ static boolean matchAntPathPatternStart( String pattern, String str, String separator, boolean isCaseSensitive )
{
// When str starts with a File.separator, pattern has to start with a
// File.separator.
// When pattern starts with a File.separator, str has to start with a
// File.separator.
- if ( str.startsWith( separator ) !=
- pattern.startsWith( separator ) )
+ if ( separatorPatternStartSlashMismatch( pattern, str, separator ) )
{
return false;
}
- Vector patDirs = tokenizePath( pattern, separator );
- Vector strDirs = tokenizePath( str, separator );
+ String[] patDirs = tokenizePathToString( pattern, separator );
+ return matchAntPathPatternStart( patDirs, str, separator, isCaseSensitive );
+ }
+
+ // When str starts with a File.separator, pattern has to start with a
+ // File.separator.
+ // When pattern starts with a File.separator, str has to start with a
+ // File.separator.
+ private static boolean separatorPatternStartSlashMismatch( String pattern, String str, String separator )
+ {
+ return str.startsWith( separator ) != pattern.startsWith( separator );
+ }
+
+ private static boolean separatorPatternStartSlashMismatch( MatchPattern matchPattern, String str, String separator )
+ {
+ return str.startsWith( separator ) != matchPattern.startsWith( separator );
+ }
+
+
+ static boolean matchAntPathPatternStart( String[] patDirs, String str, String separator, boolean isCaseSensitive )
+ {
+ String[] strDirs = tokenizePathToString( str, separator );
int patIdxStart = 0;
- int patIdxEnd = patDirs.size() - 1;
+ int patIdxEnd = patDirs.length - 1;
int strIdxStart = 0;
- int strIdxEnd = strDirs.size() - 1;
+ int strIdxEnd = strDirs.length - 1;
// up to first '**'
while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
{
- String patDir = (String) patDirs.elementAt( patIdxStart );
+ String patDir = patDirs[patIdxStart];
if ( patDir.equals( "**" ) )
{
break;
}
- if ( !match( patDir, (String) strDirs.elementAt( strIdxStart ),
- isCaseSensitive ) )
+ if ( !match( patDir, strDirs[strIdxStart], isCaseSensitive ) )
{
return false;
}
@@ -203,22 +236,7 @@ private static boolean matchAntPathPatternStart( String pattern, String str, Str
strIdxStart++;
}
- if ( strIdxStart > strIdxEnd )
- {
- // String is exhausted
- return true;
- }
- else if ( patIdxStart > patIdxEnd )
- {
- // String not exhausted, but pattern is. Failure.
- return false;
- }
- else
- {
- // pattern now holds ** while string is not exhausted
- // this will generate false positives but we can live with that.
- return true;
- }
+ return strIdxStart > strIdxEnd || patIdxStart <= patIdxEnd;
}
/**
@@ -228,7 +246,6 @@ else if ( patIdxStart > patIdxEnd )
* null.
* @param str The path to match, as a String. Must not be
* null.
- *
* @return true if the pattern matches against the string,
* or false otherwise.
*/
@@ -240,78 +257,88 @@ public static boolean matchPath( String pattern, String str )
/**
* Tests whether or not a given path matches a given pattern.
*
- * @param pattern The pattern to match against. Must not be
- * null.
- * @param str The path to match, as a String. Must not be
- * null.
+ * @param pattern The pattern to match against. Must not be
+ * null.
+ * @param str The path to match, as a String. Must not be
+ * null.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
- *
* @return true if the pattern matches against the string,
* or false otherwise.
*/
- public static boolean matchPath( String pattern, String str,
- boolean isCaseSensitive )
+ public static boolean matchPath( String pattern, String str, boolean isCaseSensitive )
{
return matchPath( pattern, str, File.separator, isCaseSensitive );
}
public static boolean matchPath( String pattern, String str, String separator, boolean isCaseSensitive )
{
- if ( pattern.length() > ( REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
- && pattern.startsWith( REGEX_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ if ( isRegexPrefixedPattern( pattern ) )
{
- pattern = pattern.substring( REGEX_HANDLER_PREFIX.length(), pattern.length()
- - PATTERN_HANDLER_SUFFIX.length() );
+ pattern =
+ pattern.substring( REGEX_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
return str.matches( pattern );
}
else
{
- if ( pattern.length() > ( ANT_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
- && pattern.startsWith( ANT_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ if ( isAntPrefixedPattern( pattern ) )
{
- pattern =
- pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
+ pattern = pattern.substring( ANT_HANDLER_PREFIX.length(),
+ pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
}
-
+
return matchAntPathPattern( pattern, str, separator, isCaseSensitive );
}
}
- private static boolean matchAntPathPattern( String pattern, String str, String separator, boolean isCaseSensitive )
+ static boolean isRegexPrefixedPattern( String pattern )
{
- // When str starts with a separator, pattern has to start with a
- // separator.
- // When pattern starts with a separator, str has to start with a
- // separator.
- if ( str.startsWith( separator ) !=
- pattern.startsWith( separator ) )
+ return pattern.length() > ( REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
+ && pattern.startsWith( REGEX_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX );
+ }
+
+ static boolean matchAntPathPattern( MatchPattern matchPattern, String str, String separator,
+ boolean isCaseSensitive )
+ {
+ if ( separatorPatternStartSlashMismatch( matchPattern, str, separator ) )
{
return false;
}
+ String[] patDirs = matchPattern.getTokenizedPathString();
+ String[] strDirs = tokenizePathToString( str, separator );
+ return matchAntPathPattern( patDirs, strDirs, isCaseSensitive );
+ }
- Vector patDirs = tokenizePath( pattern, separator );
- Vector strDirs = tokenizePath( str, separator );
+ static boolean matchAntPathPattern( String pattern, String str, String separator, boolean isCaseSensitive )
+ {
+ if ( separatorPatternStartSlashMismatch( pattern, str, separator ) )
+ {
+ return false;
+ }
+ String[] patDirs = tokenizePathToString( pattern, separator );
+ String[] strDirs = tokenizePathToString( str, separator );
+ return matchAntPathPattern( patDirs, strDirs, isCaseSensitive );
+ }
+
+ static boolean matchAntPathPattern( String[] patDirs, String[] strDirs, boolean isCaseSensitive )
+ {
int patIdxStart = 0;
- int patIdxEnd = patDirs.size() - 1;
+ int patIdxEnd = patDirs.length - 1;
int strIdxStart = 0;
- int strIdxEnd = strDirs.size() - 1;
+ int strIdxEnd = strDirs.length - 1;
// up to first '**'
while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
{
- String patDir = (String) patDirs.elementAt( patIdxStart );
+ String patDir = patDirs[patIdxStart];
if ( patDir.equals( "**" ) )
{
break;
}
- if ( !match( patDir, (String) strDirs.elementAt( strIdxStart ),
- isCaseSensitive ) )
+ if ( !match( patDir, strDirs[strIdxStart], isCaseSensitive ) )
{
- patDirs = null;
- strDirs = null;
return false;
}
patIdxStart++;
@@ -322,10 +349,8 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
// String is exhausted
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
{
- if ( !patDirs.elementAt( i ).equals( "**" ) )
+ if ( !patDirs[i].equals( "**" ) )
{
- patDirs = null;
- strDirs = null;
return false;
}
}
@@ -336,8 +361,6 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
if ( patIdxStart > patIdxEnd )
{
// String not exhausted, but pattern is. Failure.
- patDirs = null;
- strDirs = null;
return false;
}
}
@@ -345,16 +368,13 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
// up to last '**'
while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
{
- String patDir = (String) patDirs.elementAt( patIdxEnd );
+ String patDir = patDirs[patIdxEnd];
if ( patDir.equals( "**" ) )
{
break;
}
- if ( !match( patDir, (String) strDirs.elementAt( strIdxEnd ),
- isCaseSensitive ) )
+ if ( !match( patDir, strDirs[strIdxEnd], isCaseSensitive ) )
{
- patDirs = null;
- strDirs = null;
return false;
}
patIdxEnd--;
@@ -365,10 +385,8 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
// String is exhausted
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
{
- if ( !patDirs.elementAt( i ).equals( "**" ) )
+ if ( !patDirs[i].equals( "**" ) )
{
- patDirs = null;
- strDirs = null;
return false;
}
}
@@ -380,7 +398,7 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
int patIdxTmp = -1;
for ( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
{
- if ( patDirs.elementAt( i ).equals( "**" ) )
+ if ( patDirs[i].equals( "**" ) )
{
patIdxTmp = i;
break;
@@ -398,26 +416,24 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
int strLength = ( strIdxEnd - strIdxStart + 1 );
int foundIdx = -1;
strLoop:
- for ( int i = 0; i <= strLength - patLength; i++ )
- {
- for ( int j = 0; j < patLength; j++ )
- {
- String subPat = (String) patDirs.elementAt( patIdxStart + j + 1 );
- String subStr = (String) strDirs.elementAt( strIdxStart + i + j );
- if ( !match( subPat, subStr, isCaseSensitive ) )
- {
- continue strLoop;
- }
- }
-
- foundIdx = strIdxStart + i;
- break;
- }
+ for ( int i = 0; i <= strLength - patLength; i++ )
+ {
+ for ( int j = 0; j < patLength; j++ )
+ {
+ String subPat = patDirs[patIdxStart + j + 1];
+ String subStr = strDirs[strIdxStart + i + j];
+ if ( !match( subPat, subStr, isCaseSensitive ) )
+ {
+ continue strLoop;
+ }
+ }
+
+ foundIdx = strIdxStart + i;
+ break;
+ }
if ( foundIdx == -1 )
{
- patDirs = null;
- strDirs = null;
return false;
}
@@ -427,10 +443,8 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
{
- if ( !patDirs.elementAt( i ).equals( "**" ) )
+ if ( !patDirs[i].equals( "**" ) )
{
- patDirs = null;
- strDirs = null;
return false;
}
}
@@ -448,7 +462,6 @@ private static boolean matchAntPathPattern( String pattern, String str, String s
* Must not be null.
* @param str The string which must be matched against the pattern.
* Must not be null.
- *
* @return true if the string matches against the pattern,
* or false otherwise.
*/
@@ -463,19 +476,16 @@ public static boolean match( String pattern, String str )
* '*' means zero or more characters
* '?' means one and only one character
*
- * @param pattern The pattern to match against.
- * Must not be null.
- * @param str The string which must be matched against the pattern.
- * Must not be null.
+ * @param pattern The pattern to match against.
+ * Must not be null.
+ * @param str The string which must be matched against the pattern.
+ * Must not be null.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
- *
- *
* @return true if the string matches against the pattern,
* or false otherwise.
*/
- public static boolean match( String pattern, String str,
- boolean isCaseSensitive )
+ public static boolean match( String pattern, String str, boolean isCaseSensitive )
{
char[] patArr = pattern.toCharArray();
char[] strArr = str.toCharArray();
@@ -486,9 +496,9 @@ public static boolean match( String pattern, String str,
char ch;
boolean containsStar = false;
- for ( int i = 0; i < patArr.length; i++ )
+ for ( char aPatArr : patArr )
{
- if ( patArr[i] == '*' )
+ if ( aPatArr == '*' )
{
containsStar = true;
break;
@@ -639,8 +649,8 @@ private static boolean equals( char c1, char c2, boolean isCaseSensitive )
if ( !isCaseSensitive )
{
// NOTE: Try both upper case and lower case as done by String.equalsIgnoreCase()
- if ( Character.toUpperCase( c1 ) == Character.toUpperCase( c2 ) ||
- Character.toLowerCase( c1 ) == Character.toLowerCase( c2 ) )
+ if ( Character.toUpperCase( c1 ) == Character.toUpperCase( c2 )
+ || Character.toLowerCase( c1 ) == Character.toLowerCase( c2 ) )
{
return true;
}
@@ -648,28 +658,15 @@ private static boolean equals( char c1, char c2, boolean isCaseSensitive )
return false;
}
- /**
- * Breaks a path up into a Vector of path elements, tokenizing on
- * File.separator.
- *
- * @param path Path to tokenize. Must not be null.
- *
- * @return a Vector of path elements from the tokenized path
- */
- public static Vector tokenizePath( String path )
- {
- return tokenizePath( path, File.separator );
- }
-
- public static Vector tokenizePath( String path, String separator )
+ private static String[] tokenizePathToString( String path, String separator )
{
- Vector ret = new Vector();
+ List ret = new ArrayList();
StringTokenizer st = new StringTokenizer( path, separator );
while ( st.hasMoreTokens() )
{
- ret.addElement( st.nextToken() );
+ ret.add( st.nextToken() );
}
- return ret;
+ return ret.toArray( new String[ret.size()] );
}
@@ -681,10 +678,10 @@ public static Vector tokenizePath( String path, String separator )
* false if the src file doesn't even exist, since how could the
* target then be out of date.
*
- * @param src the original file
- * @param target the file being compared against
+ * @param src the original file
+ * @param target the file being compared against
* @param granularity the amount in seconds of slack we will give in
- * determining out of dateness
+ * determining out of dateness
* @return whether the target is out of date
*/
public static boolean isOutOfDate( File src, File target, int granularity )
diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java
new file mode 100644
index 00000000..ded393ea
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java
@@ -0,0 +1,32 @@
+package org.codehaus.plexus.util;
+/*
+ * Copyright The Codehaus 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 junit.framework.TestCase;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class MatchPatternTest extends TestCase
+{
+ public void testMatchPath()
+ throws Exception
+ {
+ MatchPattern mp = MatchPattern.fromString( "ABC*" );
+ assertTrue(mp.matchPath( "ABCD", true ));
+
+ }
+}
diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java
new file mode 100644
index 00000000..b75b5b54
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java
@@ -0,0 +1,32 @@
+package org.codehaus.plexus.util;
+/*
+ * Copyright The Codehaus 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 junit.framework.TestCase;
+
+public class MatchPatternsTest
+ extends TestCase
+{
+ public void testMatches()
+ throws Exception
+ {
+ MatchPatterns from = MatchPatterns.from( "ABC**", "CDE**" );
+ assertTrue( from.matches( "ABCDE", true ) );
+ assertTrue( from.matches( "CDEF", true ) );
+ assertFalse( from.matches( "XYZ", true ) );
+
+ }
+}
From b50fe89cfb368e06dabc340b851504a2a2f25c47 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 20 Aug 2012 16:20:50 +0200
Subject: [PATCH 065/133] [maven-release-plugin] prepare release
plexus-utils-3.0.5
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index ecbef109..282b590e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.5-SNAPSHOT
+ 3.0.5Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From f39264673198dd21a24b783a50e9df4cbadc8b23 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 20 Aug 2012 16:20:58 +0200
Subject: [PATCH 066/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 282b590e..127cc53d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.5
+ 3.0.6-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From a5b09677d9fdb82512edfb80e14f53ae03025e83 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Sat, 15 Sep 2012 12:35:51 +0200
Subject: [PATCH 067/133] [PLXUTILS-153] Updated file copy to use nio
Patch with functionality from commons-io by Ryszard Perkowski
---
.../org/codehaus/plexus/util/FileUtils.java | 300 ++++++++++--------
.../java/org/codehaus/plexus/util/IOUtil.java | 23 ++
.../plexus/util/io/FileInputStreamFacade.java | 40 ---
3 files changed, 198 insertions(+), 165 deletions(-)
delete mode 100644 src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 5784393a..520abe13 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -57,6 +57,7 @@
import java.io.BufferedReader;
import java.io.File;
+import java.nio.channels.FileChannel;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
@@ -76,7 +77,6 @@
import java.util.List;
import java.util.Random;
-import org.codehaus.plexus.util.io.FileInputStreamFacade;
import org.codehaus.plexus.util.io.InputStreamFacade;
import org.codehaus.plexus.util.io.URLInputStreamFacade;
@@ -139,14 +139,21 @@ public class FileUtils
*/
public static final int ONE_GB = ONE_KB * ONE_MB;
- /** The vm line separator */
+ /**
+ * The file copy buffer size (30 MB)
+ */
+ private static final long FILE_COPY_BUFFER_SIZE = ONE_MB * 30;
+
+ /**
+ * The vm line separator
+ */
public static String FS = System.getProperty( "file.separator" );
/**
* Non-valid Characters for naming files, folders under Windows: ":", "*", "?", "\"", "<", ">", "|"
*
* @see
- * http://support.microsoft.com/?scid=kb%3Ben-us%3B177506&x=12&y=13
+ * http://support.microsoft.com/?scid=kb%3Ben-us%3B177506&x=12&y=13
*/
private static final String[] INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME = { ":", "*", "?", "\"", "<", ">", "|" };
@@ -251,7 +258,7 @@ public static String basename( String filename )
* Matches the equally named unix command.
*
* @param filename the file path
- * @param suffix the file suffix
+ * @param suffix the file suffix
* @return the basename of the file
*/
public static String basename( String filename, String suffix )
@@ -299,7 +306,7 @@ public static String extension( String filename )
}
}
- if ( lastDot >= 0 && lastDot > lastSep)
+ if ( lastDot >= 0 && lastDot > lastSep )
{
return filename.substring( lastDot + 1 );
}
@@ -333,7 +340,7 @@ public static String fileRead( String file )
}
/**
- * @param file the file path
+ * @param file the file path
* @param encoding the wanted encoding
* @return the file content using the specified encoding.
* @throws IOException if any
@@ -354,11 +361,11 @@ public static String fileRead( String file, String encoding )
public static String fileRead( File file )
throws IOException
{
- return fileRead( file, null);
+ return fileRead( file, null );
}
/**
- * @param file the file path
+ * @param file the file path
* @param encoding the wanted encoding
* @return the file content using the specified encoding.
* @throws IOException if any
@@ -400,13 +407,13 @@ public static String fileRead( File file, String encoding )
* Note: the data is written with platform encoding
*
* @param fileName The path of the file to write.
- * @param data The content to write to the file.
+ * @param data The content to write to the file.
* @throws IOException if any
*/
public static void fileAppend( String fileName, String data )
throws IOException
{
- fileAppend( fileName, null, data);
+ fileAppend( fileName, null, data );
}
/**
@@ -414,7 +421,7 @@ public static void fileAppend( String fileName, String data )
*
* @param fileName The path of the file to write.
* @param encoding The encoding of the file.
- * @param data The content to write to the file.
+ * @param data The content to write to the file.
* @throws IOException if any
*/
public static void fileAppend( String fileName, String encoding, String data )
@@ -424,7 +431,8 @@ public static void fileAppend( String fileName, String encoding, String data )
try
{
out = new FileOutputStream( fileName, true );
- if ( encoding != null ) {
+ if ( encoding != null )
+ {
out.write( data.getBytes( encoding ) );
}
else
@@ -443,7 +451,7 @@ public static void fileAppend( String fileName, String encoding, String data )
* Note: the data is written with platform encoding
*
* @param fileName The path of the file to write.
- * @param data The content to write to the file.
+ * @param data The content to write to the file.
* @throws IOException if any
*/
public static void fileWrite( String fileName, String data )
@@ -457,7 +465,7 @@ public static void fileWrite( String fileName, String data )
*
* @param fileName The path of the file to write.
* @param encoding The encoding of the file.
- * @param data The content to write to the file.
+ * @param data The content to write to the file.
* @throws IOException if any
*/
public static void fileWrite( String fileName, String encoding, String data )
@@ -472,9 +480,8 @@ public static void fileWrite( String fileName, String encoding, String data )
* Note: the data is written with platform encoding
*
* @param fileName The path of the file to write.
- * @param data The content to write to the file.
+ * @param data The content to write to the file.
* @throws IOException if any
- *
* @since 2.0.6
*/
public static void fileWrite( File file, String data )
@@ -488,9 +495,8 @@ public static void fileWrite( File file, String data )
*
* @param fileName The path of the file to write.
* @param encoding The encoding of the file.
- * @param data The content to write to the file.
+ * @param data The content to write to the file.
* @throws IOException if any
- *
* @since 2.0.6
*/
public static void fileWrite( File file, String encoding, String data )
@@ -542,8 +548,8 @@ public static boolean waitFor( String fileName, int seconds )
/**
* Waits for NFS to propagate a file creation, imposing a timeout.
*
- * @param file The file.
- * @param seconds The maximum time in seconds to wait.
+ * @param file The file.
+ * @param seconds The maximum time in seconds to wait.
* @return True if file exists.
*/
public static boolean waitFor( File file, int seconds )
@@ -591,7 +597,7 @@ public static File getFile( String fileName )
*
* The given extensions should be like "java" and not like ".java"
*
- * @param directory The path of the directory.
+ * @param directory The path of the directory.
* @param extensions an array of expected extensions.
* @return An array of files for the wanted extensions.
*/
@@ -700,9 +706,9 @@ public static void mkdir( String dir )
if ( Os.isFamily( Os.FAMILY_WINDOWS ) && !isValidWindowsFileName( file ) )
{
- throw new IllegalArgumentException( "The file (" + dir
- + ") cannot contain any of the following characters: \n"
- + StringUtils.join( INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME, " " ) );
+ throw new IllegalArgumentException(
+ "The file (" + dir + ") cannot contain any of the following characters: \n" + StringUtils.join(
+ INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME, " " ) );
}
if ( !file.exists() )
@@ -818,9 +824,9 @@ public static URL[] toURLs( final File[] files )
*/
public static String removeExtension( final String filename )
{
- String ext = extension(filename);
+ String ext = extension( filename );
- if ( "".equals(ext) )
+ if ( "".equals( ext ) )
{
return filename;
}
@@ -843,7 +849,7 @@ public static String removeExtension( final String filename )
*/
public static String getExtension( final String filename )
{
- return extension(filename);
+ return extension( filename );
}
/**
@@ -870,7 +876,7 @@ public static String removePath( final String filepath )
* a.txt --> a.txt
*
*
- * @param filepath the path of the file
+ * @param filepath the path of the file
* @param fileSeparatorChar the file separator character like / on Unix plateforms.
* @return the filename minus path
*/
@@ -910,7 +916,7 @@ public static String getPath( final String filepath )
* a.txt --> ""
*
*
- * @param filepath the filepath
+ * @param filepath the filepath
* @param fileSeparatorChar the file separator character like / on Unix plateforms.
* @return the filename minus path
*/
@@ -1040,7 +1046,7 @@ public static void copyFile( final File source, final File destination )
return;
}
- copyStreamToFile( new FileInputStreamFacade( source ), destination);
+ doCopyFile( source, destination );
if ( source.length() != destination.length() )
{
@@ -1049,19 +1055,50 @@ public static void copyFile( final File source, final File destination )
}
}
+ private static void doCopyFile( File source, File destination )
+ throws IOException
+ {
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
+ FileChannel input = null;
+ FileChannel output = null;
+ try
+ {
+ fis = new FileInputStream( source );
+ fos = new FileOutputStream( destination );
+ input = fis.getChannel();
+ output = fos.getChannel();
+ long size = input.size();
+ long pos = 0;
+ long count = 0;
+ while ( pos < size )
+ {
+ count = size - pos > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : size - pos;
+ pos += output.transferFrom( input, pos, count );
+ }
+ }
+ finally
+ {
+ IOUtil.close( output );
+ IOUtil.close( fos );
+ IOUtil.close( input );
+ IOUtil.close( fis );
+ }
+ }
+
/**
* 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 source An existing non-directory File to copy bytes from.
* @param destination A non-directory File to write bytes to (possibly
- * overwriting).
+ * overwriting).
* @return true if no problem occured
- * @throws IOException if source does not exist, destination cannot be
- * written to, or an IO error occurs during copying.
+ * @throws IOException if source does not exist, destination cannot be
+ * written to, or an IO error occurs during copying.
* @throws FileNotFoundException if destination is a directory
- * (use {@link #copyFileToDirectory}).
+ * (use {@link #copyFileToDirectory}).
*/
public static boolean copyFileIfModified( final File source, final File destination )
throws IOException
@@ -1081,20 +1118,20 @@ public static boolean copyFileIfModified( final File source, final File destinat
* The directories up to destination will be created if they don't already exist.
* destination will be overwritten if it already exists.
*
- * @param source A URL to copy bytes from.
+ * @param source A URL to copy bytes from.
* @param destination A non-directory File to write bytes to (possibly
- * overwriting).
+ * overwriting).
* @throws IOException if
- *
- *
source URL cannot be opened
- *
destination cannot be written to
- *
an IO error occurs during copying
- *
+ *
+ *
source URL cannot be opened
+ *
destination cannot be written to
+ *
an IO error occurs during copying
+ *
*/
public static void copyURLToFile( final URL source, final File destination )
throws IOException
{
- copyStreamToFile( new URLInputStreamFacade( source ) , destination);
+ copyStreamToFile( new URLInputStreamFacade( source ), destination );
}
/**
@@ -1102,32 +1139,22 @@ public static void copyURLToFile( final URL source, final File destination )
* 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 {@link InputStream} to copy bytes from. This stream is
- * guaranteed to be closed.
+ * @param source An {@link InputStream} to copy bytes from. This stream is
+ * guaranteed to be closed.
* @param destination A non-directory File to write bytes to (possibly
- * overwriting).
+ * overwriting).
* @throws IOException if
- *
- *
source URL cannot be opened
- *
destination cannot be written to
- *
an IO error occurs during copying
- *
+ *
+ *
source URL cannot be opened
+ *
destination cannot be written to
+ *
an IO error occurs during copying
+ *
*/
public static void copyStreamToFile( final InputStreamFacade source, final File destination )
throws IOException
{
- //does destination directory exist ?
- if ( destination.getParentFile() != null && !destination.getParentFile().exists() )
- {
- destination.getParentFile().mkdirs();
- }
-
- //make sure we can write to destination
- if ( destination.exists() && !destination.canWrite() )
- {
- final String message = "Unable to open file " + destination + " for writing.";
- throw new IOException( message );
- }
+ mkdirsFor( destination );
+ checkCanWrite( destination );
InputStream input = null;
FileOutputStream output = null;
@@ -1144,6 +1171,26 @@ public static void copyStreamToFile( final InputStreamFacade source, final File
}
}
+ private static void checkCanWrite( File destination )
+ throws IOException
+ {
+ //make sure we can write to destination
+ if ( destination.exists() && !destination.canWrite() )
+ {
+ final String message = "Unable to open file " + destination + " for writing.";
+ throw new IOException( message );
+ }
+ }
+
+ private static void mkdirsFor( File destination )
+ {
+ //does destination directory exist ?
+ if ( destination.getParentFile() != null && !destination.getParentFile().exists() )
+ {
+ destination.getParentFile().mkdirs();
+ }
+ }
+
/**
* Normalize a path.
* Eliminates "/../" and "/./" in a string. Returns null if the ..'s went past the
@@ -1218,7 +1265,7 @@ public static String normalize( final String path )
* Thieved from Tomcat sources...
*
* @param lookupPath a path
- * @param path the path to concatenate
+ * @param path the path to concatenate
* @return The concatenated paths, or null if error occurs
*/
public static String catPath( final String lookupPath, final String path )
@@ -1255,7 +1302,7 @@ public static String catPath( final String lookupPath, final String path )
* baseFile, otherwise it is treated as a normal root-relative path.
*
* @param baseFile Where to resolve filename from, if filename is
- * relative.
+ * relative.
* @param filename Absolute or relative file path to resolve.
* @return The canonical File of filename.
*/
@@ -1499,8 +1546,8 @@ private static void cleanDirectoryOnExit( final File directory )
* Make a directory.
*
* @param file not null
- * @throws IOException If there already exists a file with specified name or
- * the directory is unable to be created
+ * @throws IOException If there already exists a file with specified name or
+ * the directory is unable to be created
* @throws IllegalArgumentException if the file contains illegal Windows characters under Windows OS.
* @see #INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
*/
@@ -1511,9 +1558,9 @@ public static void forceMkdir( final File file )
{
if ( !isValidWindowsFileName( file ) )
{
- throw new IllegalArgumentException( "The file (" + file.getAbsolutePath()
- + ") cannot contain any of the following characters: \n"
- + StringUtils.join( INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME, " " ) );
+ throw new IllegalArgumentException(
+ "The file (" + file.getAbsolutePath() + ") cannot contain any of the following characters: \n"
+ + StringUtils.join( INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME, " " ) );
}
}
@@ -1567,7 +1614,7 @@ public static void deleteDirectory( final File directory )
*/
if ( directory.delete() )
{
- return;
+ return;
}
cleanDirectory( directory );
@@ -1695,11 +1742,11 @@ public static long sizeOfDirectory( final File directory )
* including the directory name in each of the files
*
* @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @return a list of File objects
* @throws IOException
- * @see #getFileNames( File, String, String, boolean )
+ * @see #getFileNames(File, String, String, boolean)
*/
public static List getFiles( File directory, String includes, String excludes )
throws IOException
@@ -1710,13 +1757,13 @@ public static List getFiles( File directory, String includes, String exclu
/**
* Return the files contained in the directory, using inclusion and exclusion Ant patterns
*
- * @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param directory the directory to scan
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each file
* @return a list of File objects
* @throws IOException
- * @see #getFileNames( File, String, String, boolean )
+ * @see #getFileNames(File, String, String, boolean)
*/
public static List getFiles( File directory, String includes, String excludes, boolean includeBasedir )
throws IOException
@@ -1737,9 +1784,9 @@ public static List getFiles( File directory, String includes, String exclu
* Return a list of files as String depending options.
* This method use case sensitive file name.
*
- * @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param directory the directory to scan
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @return a list of files as String
* @throws IOException
@@ -1753,16 +1800,16 @@ public static List getFileNames( File directory, String includes, String
/**
* Return a list of files as String depending options.
*
- * @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param directory the directory to scan
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @param isCaseSensitive true if case sensitive
* @return a list of files as String
* @throws IOException
*/
public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir,
- boolean isCaseSensitive )
+ boolean isCaseSensitive )
throws IOException
{
return getFileAndDirectoryNames( directory, includes, excludes, includeBasedir, isCaseSensitive, true, false );
@@ -1772,14 +1819,15 @@ public static List getFileNames( File directory, String includes, String
* Return a list of directories as String depending options.
* This method use case sensitive file name.
*
- * @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param directory the directory to scan
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @return a list of directories as String
* @throws IOException
*/
- public static List getDirectoryNames( File directory, String includes, String excludes, boolean includeBasedir )
+ public static List getDirectoryNames( File directory, String includes, String excludes,
+ boolean includeBasedir )
throws IOException
{
return getDirectoryNames( directory, includes, excludes, includeBasedir, true );
@@ -1788,16 +1836,16 @@ public static List getDirectoryNames( File directory, String includes, S
/**
* Return a list of directories as String depending options.
*
- * @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param directory the directory to scan
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @param isCaseSensitive true if case sensitive
* @return a list of directories as String
* @throws IOException
*/
- public static List getDirectoryNames( File directory, String includes, String excludes, boolean includeBasedir,
- boolean isCaseSensitive )
+ public static List getDirectoryNames( File directory, String includes, String excludes,
+ boolean includeBasedir, boolean isCaseSensitive )
throws IOException
{
return getFileAndDirectoryNames( directory, includes, excludes, includeBasedir, isCaseSensitive, false, true );
@@ -1806,19 +1854,19 @@ public static List getDirectoryNames( File directory, String includes, S
/**
* Return a list of files as String depending options.
*
- * @param directory the directory to scan
- * @param includes the includes pattern, comma separated
- * @param excludes the excludes pattern, comma separated
+ * @param directory the directory to scan
+ * @param includes the includes pattern, comma separated
+ * @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @param isCaseSensitive true if case sensitive
- * @param getFiles true if get files
+ * @param getFiles true if get files
* @param getDirectories true if get directories
* @return a list of files as String
* @throws IOException
*/
public static List getFileAndDirectoryNames( File directory, String includes, String excludes,
- boolean includeBasedir, boolean isCaseSensitive, boolean getFiles,
- boolean getDirectories )
+ boolean includeBasedir, boolean isCaseSensitive,
+ boolean getFiles, boolean getDirectories )
throws IOException
{
DirectoryScanner scanner = new DirectoryScanner();
@@ -1881,7 +1929,7 @@ public static List getFileAndDirectoryNames( File directory, String incl
/**
* Copy a directory to an other one.
*
- * @param sourceDirectory the source dir
+ * @param sourceDirectory the source dir
* @param destinationDirectory the target dir
* @throws IOException if any
*/
@@ -1894,10 +1942,10 @@ public static void copyDirectory( File sourceDirectory, File destinationDirector
/**
* Copy a directory to an other one.
*
- * @param sourceDirectory the source dir
+ * @param sourceDirectory the source dir
* @param destinationDirectory the target dir
- * @param includes include pattern
- * @param excludes exlucde pattern
+ * @param includes include pattern
+ * @param excludes exlucde pattern
* @throws IOException if any
* @see #getFiles(File, String, String)
*/
@@ -1927,15 +1975,15 @@ public static void copyDirectory( File sourceDirectory, File destinationDirector
*
The sourceDirectory must exists.
*
*
- * @param sourceDirectory the source dir
+ * @param sourceDirectory the source dir
* @param destinationDirectory the target dir
- * @param includes include pattern
- * @param excludes exlucde pattern
- * @since 1.5.7
+ * @param includes include pattern
+ * @param excludes exlucde pattern
* @throws IOException if any
+ * @since 1.5.7
*/
public static void copyDirectoryLayout( File sourceDirectory, File destinationDirectory, String[] includes,
- String[] excludes )
+ String[] excludes )
throws IOException
{
if ( sourceDirectory == null )
@@ -1968,7 +2016,7 @@ public static void copyDirectoryLayout( File sourceDirectory, File destinationDi
}
else
{
- scanner.setIncludes( new String[] { "**" } );
+ scanner.setIncludes( new String[]{ "**" } );
}
if ( excludes != null && excludes.length >= 1 )
@@ -2003,7 +2051,7 @@ public static void copyDirectoryLayout( File sourceDirectory, File destinationDi
*
The sourceDirectory must exists.
*
*
- * @param sourceDirectory the source dir
+ * @param sourceDirectory the source dir
* @param destinationDirectory the target dir
* @throws IOException if any
*/
@@ -2022,7 +2070,7 @@ public static void copyDirectoryStructure( File sourceDirectory, File destinatio
*
The sourceDirectory must exists.
*
*
- * @param sourceDirectory the source dir
+ * @param sourceDirectory the source dir
* @param destinationDirectory the target dir
* @throws IOException if any
*/
@@ -2117,7 +2165,7 @@ else if ( file.isDirectory() )
* @param from the file to move
* @param to the new file name
* @throws IOException if anything bad happens during this process.
- * Note that to may have been deleted already when this happens.
+ * Note that to may have been deleted already when this happens.
*/
public static void rename( File from, File to )
throws IOException
@@ -2160,10 +2208,10 @@ public static void rename( File from, File to )
*
To delete automatically the file created by this method, use the
* {@link File#deleteOnExit()} method.
*
- * @param prefix prefix before the random number
- * @param suffix file extension; include the '.'
+ * @param prefix prefix before the random number
+ * @param suffix file extension; include the '.'
* @param parentDir Directory to create the temporary file in -java.io.tmpdir
- * used if not specificed
+ * used if not specificed
* @return a File reference to the new temporary file.
*/
public static File createTempFile( String prefix, String suffix, File parentDir )
@@ -2192,8 +2240,9 @@ public static File createTempFile( String prefix, String suffix, File parentDir
/**
* If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified()
- * @param from the file to copy
- * @param to the destination file
+ *
+ * @param from the file to copy
+ * @param to the destination file
* @param encoding the file output encoding (only if wrappers is not empty)
* @param wrappers array of {@link FilterWrapper}
* @throws IOException if an IO error occurs during copying or filtering
@@ -2211,12 +2260,13 @@ public static abstract class FilterWrapper
/**
* If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if overwrite is true
- * @param from the file to copy
- * @param to the destination file
- * @param encoding the file output encoding (only if wrappers is not empty)
- * @param wrappers array of {@link FilterWrapper}
+ *
+ * @param from the file to copy
+ * @param to the destination file
+ * @param encoding the file output encoding (only if wrappers is not empty)
+ * @param wrappers array of {@link FilterWrapper}
* @param overwrite if true and f wrappers is null or empty, the file will be copy
- * enven if to.lastModified() < from.lastModified()
+ * enven if to.lastModified() < from.lastModified()
* @throws IOException if an IO error occurs during copying or filtering
* @since 1.5.2
*/
@@ -2311,7 +2361,7 @@ public static List loadFile( File file )
*
* @param f not null file
* @return false if the file path contains any of forbidden Windows characters,
- * true if the Os is not Windows or if the file path respect the Windows constraints.
+ * true if the Os is not Windows or if the file path respect the Windows constraints.
* @see #INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
* @since 1.5.2
*/
@@ -2324,7 +2374,7 @@ public static boolean isValidWindowsFileName( File f )
return false;
}
- if ( f.getParentFile()!= null)
+ if ( f.getParentFile() != null )
{
return isValidWindowsFileName( f.getParentFile() );
}
diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java
index 20cab90d..633c1b2e 100644
--- a/src/main/java/org/codehaus/plexus/util/IOUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java
@@ -67,6 +67,7 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.channels.Channel;
/**
* General IO Stream manipulation.
@@ -745,6 +746,28 @@ public static void close( InputStream inputStream )
}
}
+ /**
+ * Closes a channel. Channel can be null and any IOException's will be swallowed.
+ *
+ * @param channel The stream to close.
+ */
+ public static void close( Channel channel )
+ {
+ if ( channel == null )
+ {
+ return;
+ }
+
+ try
+ {
+ channel.close();
+ }
+ catch( IOException ex )
+ {
+ // ignore
+ }
+ }
+
/**
* Closes the output stream. The output stream can be null and any IOException's will be swallowed.
*
diff --git a/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java
deleted file mode 100644
index 453f080f..00000000
--- a/src/main/java/org/codehaus/plexus/util/io/FileInputStreamFacade.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.codehaus.plexus.util.io;
-
-/*
- * Copyright The Codehaus 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 java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Implementation of {@link InputStreamFacade} for files.
- */
-public class FileInputStreamFacade implements InputStreamFacade {
- private final File file;
-
- public FileInputStreamFacade( File file )
- {
- this.file = file;
- }
-
- public InputStream getInputStream() throws IOException {
- return new FileInputStream( file );
- }
-
-
-}
From 4332f7bd3c51ff3496998fdcb2d00a38e067630d Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Sat, 15 Sep 2012 12:50:33 +0200
Subject: [PATCH 068/133] [maven-release-plugin] prepare release
plexus-utils-3.0.6
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 127cc53d..c8c352c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.6-SNAPSHOT
+ 3.0.6Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 93ca53f2e588e2a277c3c61b26a91c813be07822 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Sat, 15 Sep 2012 12:50:42 +0200
Subject: [PATCH 069/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c8c352c4..61d243f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.6
+ 3.0.7-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From 74eba576223fd231404d7019b9368e69614b760e Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sat, 15 Sep 2012 22:04:58 +0200
Subject: [PATCH 070/133] javadoc fix
---
src/main/java/org/codehaus/plexus/util/FileUtils.java | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 520abe13..3450ec05 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -479,7 +479,7 @@ public static void fileWrite( String fileName, String encoding, String data )
* Writes data to a file. The file will be created if it does not exist.
* Note: the data is written with platform encoding
*
- * @param fileName The path of the file to write.
+ * @param file The file to write.
* @param data The content to write to the file.
* @throws IOException if any
* @since 2.0.6
@@ -493,7 +493,7 @@ public static void fileWrite( File file, String data )
/**
* Writes data to a file. The file will be created if it does not exist.
*
- * @param fileName The path of the file to write.
+ * @param file The file to write.
* @param encoding The encoding of the file.
* @param data The content to write to the file.
* @throws IOException if any
@@ -1097,8 +1097,6 @@ private static void doCopyFile( File source, File destination )
* @return true if no problem occured
* @throws IOException if source does not exist, destination cannot be
* written to, or an IO error occurs during copying.
- * @throws FileNotFoundException if destination is a directory
- * (use {@link #copyFileToDirectory}).
*/
public static boolean copyFileIfModified( final File source, final File destination )
throws IOException
@@ -1483,7 +1481,7 @@ public static void forceDeleteOnExit( final File file )
/**
* Recursively schedule directory for deletion on JVM exit.
*
- * @param file a directory
+ * @param directory a directory
* @throws IOException if any
*/
private static void deleteDirectoryOnExit( final File directory )
@@ -1501,7 +1499,7 @@ private static void deleteDirectoryOnExit( final File directory )
/**
* Clean a directory without deleting it.
*
- * @param file a directory
+ * @param directory a directory
* @throws IOException if any
*/
private static void cleanDirectoryOnExit( final File directory )
From 66ef487d7f2d82f0b136b8112967050d939c8a1e Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sat, 15 Sep 2012 22:05:35 +0200
Subject: [PATCH 071/133] format code
---
.../java/org/codehaus/plexus/util/FileUtils.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 3450ec05..d7717178 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -55,9 +55,11 @@
*
*/
+import org.codehaus.plexus.util.io.InputStreamFacade;
+import org.codehaus.plexus.util.io.URLInputStreamFacade;
+
import java.io.BufferedReader;
import java.io.File;
-import java.nio.channels.FileChannel;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
@@ -70,6 +72,7 @@
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
+import java.nio.channels.FileChannel;
import java.security.SecureRandom;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -77,9 +80,6 @@
import java.util.List;
import java.util.Random;
-import org.codehaus.plexus.util.io.InputStreamFacade;
-import org.codehaus.plexus.util.io.URLInputStreamFacade;
-
/**
* This class provides basic facilities for manipulating files and file paths.
*
@@ -479,8 +479,8 @@ public static void fileWrite( String fileName, String encoding, String data )
* Writes data to a file. The file will be created if it does not exist.
* Note: the data is written with platform encoding
*
- * @param file The file to write.
- * @param data The content to write to the file.
+ * @param file The file to write.
+ * @param data The content to write to the file.
* @throws IOException if any
* @since 2.0.6
*/
@@ -1095,8 +1095,8 @@ private static void doCopyFile( File source, File destination )
* @param destination A non-directory File to write bytes to (possibly
* overwriting).
* @return true if no problem occured
- * @throws IOException if source does not exist, destination cannot be
- * written to, or an IO error occurs during copying.
+ * @throws IOException if source does not exist, destination cannot be
+ * written to, or an IO error occurs during copying.
*/
public static boolean copyFileIfModified( final File source, final File destination )
throws IOException
From 7834a317d0b9ca4c6dc4d89bb0c0fad8d81e8897 Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sat, 15 Sep 2012 22:24:32 +0200
Subject: [PATCH 072/133] directory for destination must be created if not
exits
---
src/main/java/org/codehaus/plexus/util/FileUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index d7717178..f0e040bb 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -1045,7 +1045,7 @@ public static void copyFile( final File source, final File destination )
//if they are equal, we can exit the method without doing any work
return;
}
-
+ mkdirsFor( destination );
doCopyFile( source, destination );
if ( source.length() != destination.length() )
From 0e99794fbaf156a281ccbceea7cd3660c5d4d376 Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sat, 15 Sep 2012 22:38:53 +0200
Subject: [PATCH 073/133] add unit to ensure directory of destination for
copyFile is created
---
.../codehaus/plexus/util/FileUtilsTest.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
index 27892abf..93b3a425 100644
--- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
@@ -379,6 +379,25 @@ public void testCopyFile2()
assertTrue( "Check Full copy", destination.length() == testFile2Size );
}
+ /**
+ * ensure we create directory tree for destination
+ *
+ * @throws Exception
+ */
+ public void testCopyFile3()
+ throws Exception
+ {
+ File destDirectory = new File( getTestDirectory(), "foo/bar/testcopy" );
+ if ( destDirectory.exists() )
+ {
+ destDirectory.delete();
+ }
+ final File destination = new File( destDirectory, "copy2.txt" );
+ FileUtils.copyFile( testFile1, destination );
+ assertTrue( "Check Exist", destination.exists() );
+ assertTrue( "Check Full copy", destination.length() == testFile2Size );
+ }
+
// copyFileIfModified
public void testCopyIfModifiedWhenSourceIsNewer()
From 23cb9cba9d7ba020547802a45b2991dee99dbcb1 Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sun, 16 Sep 2012 09:15:45 +0200
Subject: [PATCH 074/133] [maven-release-plugin] prepare release
plexus-utils-3.0.7
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 61d243f9..f922ce0d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.7-SNAPSHOT
+ 3.0.7Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From aef9a6924ef3c942fbce3422a9aab2f2f85d530c Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sun, 16 Sep 2012 09:15:58 +0200
Subject: [PATCH 075/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f922ce0d..f8805558 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.7
+ 3.0.8-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and more.
From d854834f4c0d33ea95df373ea966b3d3770f90ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Wed, 19 Sep 2012 22:54:41 +0200
Subject: [PATCH 076/133] updated parent pom
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f8805558..4dddf322 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@ limitations under the License.
org.codehaus.plexusplexus
- 3.1
+ 3.2plexus-utils
From 6397c3e439528cd1c319c7e3eae448768f7a4552 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 20 Sep 2012 21:29:07 +0200
Subject: [PATCH 077/133] o Added support for java7 isSymlink
---
pom.xml | 27 ++++++++++-
.../plexus/util/DirectoryScanner.java | 4 ++
.../codehaus/plexus/util/Java7Detector.java | 48 +++++++++++++++++++
.../codehaus/plexus/util/Java7FileUtil.java | 32 +++++++++++++
4 files changed, 109 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/org/codehaus/plexus/util/Java7Detector.java
create mode 100644 src/main/java/org/codehaus/plexus/util/Java7FileUtil.java
diff --git a/pom.xml b/pom.xml
index 4dddf322..07e9278b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,8 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
-
+4.0.0
@@ -29,7 +30,9 @@ limitations under the License.
3.0.8-SNAPSHOTPlexus Common Utilities
- A collection of various utility classes to ease working with strings, files, command lines, XML and more.
+ A collection of various utility classes to ease working with strings, files, command lines, XML and
+ more.
+ http://plexus.codehaus.org/plexus-utils
@@ -66,6 +69,26 @@ limitations under the License.
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.1.1
+
+
+ enforce-java
+
+ enforce
+
+
+
+
+ 1.7.0
+
+
+
+
+
+
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
index 33e114ad..11fb8324 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
@@ -722,6 +722,10 @@ public String[] getDeselectedDirectories()
public boolean isSymbolicLink( File parent, String name )
throws IOException
{
+ if ( Java7Detector.isJava7() )
+ {
+ return Java7FileUtil.isSymLink( new File( parent, name ) );
+ }
File resolvedParent = new File( parent.getCanonicalPath() );
File toTest = new File( resolvedParent, name );
return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
diff --git a/src/main/java/org/codehaus/plexus/util/Java7Detector.java b/src/main/java/org/codehaus/plexus/util/Java7Detector.java
new file mode 100644
index 00000000..64f71e4a
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/Java7Detector.java
@@ -0,0 +1,48 @@
+package org.codehaus.plexus.util;
+
+/*
+ * Copyright 2011 The Codehaus 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.
+ */
+
+/**
+ * Java7 feature detection
+ *
+ * @author Kristian Rosenvold
+ */
+class Java7Detector
+{
+
+ private static final boolean isJava7;
+
+ static
+ {
+ boolean isJava7x = true;
+ try
+ {
+ Class.forName( "java.nio.file.Files" );
+ }
+ catch ( Exception e )
+ {
+ isJava7x = false;
+ }
+ isJava7 = isJava7x;
+ }
+
+
+ public static boolean isJava7()
+ {
+ return isJava7;
+ }
+}
diff --git a/src/main/java/org/codehaus/plexus/util/Java7FileUtil.java b/src/main/java/org/codehaus/plexus/util/Java7FileUtil.java
new file mode 100644
index 00000000..df4d9ec3
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/Java7FileUtil.java
@@ -0,0 +1,32 @@
+package org.codehaus.plexus.util;
+
+/*
+ * Copyright 2007 The Codehaus 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 java.io.File;
+import java.nio.file.Files;
+
+/**
+ * Encapsulates use of java7 features
+ */
+public class Java7FileUtil
+{
+ public static boolean isSymLink( File file )
+ {
+ return Files.isSymbolicLink( file.toPath() );
+ }
+
+}
\ No newline at end of file
From b0c708017f813ec9b7799fe82b4bc4bfd1631c53 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 20 Sep 2012 21:32:09 +0200
Subject: [PATCH 078/133] [maven-release-plugin] prepare release
plexus-utils-3.0.8
---
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 07e9278b..c46b3a17 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,8 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
-
+4.0.0
@@ -27,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.8-SNAPSHOT
+ 3.0.8Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -39,6 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
+ plexus-utils-3.0.8JIRA
From f500a607fb3479496a02e09a0f9fe2ff89e88871 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Thu, 20 Sep 2012 21:32:17 +0200
Subject: [PATCH 079/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index c46b3a17..6975f055 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.8
+ 3.0.9-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- plexus-utils-3.0.8
+ HEADJIRA
From acf8cd8d1d35afa78f39cfd61a6ebebc06b2b069 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Wed, 31 Oct 2012 16:04:46 +0100
Subject: [PATCH 080/133] updated parent pom
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 6975f055..de7ee91a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@ limitations under the License.
org.codehaus.plexusplexus
- 3.2
+ 3.3plexus-utils
From d7b3c8ae2bd8947f5fce395c87324030d3d0497c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sun, 18 Nov 2012 13:10:56 +0100
Subject: [PATCH 081/133] [PLXUTILS-154] added xml:space="preserve" support to
Xpp3DomBuilder
---
.../codehaus/plexus/util/xml/Xpp3DomBuilder.java | 16 +++++++++++-----
.../plexus/util/xml/Xpp3DomBuilderTest.java | 7 ++++++-
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
index f021730a..d2ca058e 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
@@ -89,16 +89,20 @@ public static Xpp3Dom build( XmlPullParser parser )
public static Xpp3Dom build( XmlPullParser parser, boolean trim )
throws XmlPullParserException, IOException
{
- List elements = new ArrayList();
+ List elements = new ArrayList();
- List values = new ArrayList();
+ List values = new ArrayList();
int eventType = parser.getEventType();
+ boolean spacePreserve = false;
+
while ( eventType != XmlPullParser.END_DOCUMENT )
{
if ( eventType == XmlPullParser.START_TAG )
{
+ spacePreserve = false;
+
String rawName = parser.getName();
Xpp3Dom childConfiguration = new Xpp3Dom( rawName );
@@ -107,7 +111,7 @@ public static Xpp3Dom build( XmlPullParser parser, boolean trim )
if ( depth > 0 )
{
- Xpp3Dom parent = (Xpp3Dom) elements.get( depth - 1 );
+ Xpp3Dom parent = elements.get( depth - 1 );
parent.addChild( childConfiguration );
}
@@ -132,17 +136,19 @@ public static Xpp3Dom build( XmlPullParser parser, boolean trim )
String value = parser.getAttributeValue( i );
childConfiguration.setAttribute( name, value );
+
+ spacePreserve = spacePreserve || ( "xml:space".equals( name ) && "preserve".equals( value ) );
}
}
else if ( eventType == XmlPullParser.TEXT )
{
int depth = values.size() - 1;
- StringBuffer valueBuffer = (StringBuffer) values.get( depth );
+ StringBuffer valueBuffer = values.get( depth );
String text = parser.getText();
- if ( trim )
+ if ( trim && !spacePreserve )
{
text = text.trim();
}
diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
index 4671f858..2096d6b6 100644
--- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
@@ -35,7 +35,7 @@ public class Xpp3DomBuilderTest
extends TestCase
{
- private static final String LS = System.getProperty("line.separator");
+ private static final String LS = System.getProperty( "line.separator" );
public void testBuildFromReader()
throws Exception
@@ -221,6 +221,7 @@ private static String createDomString()
buf.append( " \n" );
buf.append( " \n" );
buf.append( " \n" );
+ buf.append( " do not trim \n" );
buf.append( "\n" );
return buf.toString();
@@ -244,6 +245,10 @@ private static Xpp3Dom createExpectedDom()
expectedDom.addChild( el4 );
Xpp3Dom el5 = new Xpp3Dom( "el5" );
expectedDom.addChild( el5 );
+ Xpp3Dom el6 = new Xpp3Dom( "el6" );
+ el6.setAttribute( "xml:space", "preserve" );
+ el6.setValue( " do not trim " );
+ expectedDom.addChild( el6 );
return expectedDom;
}
}
From 244226d693f6a816fdba0f33f269e9e71f3e8984 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sun, 18 Nov 2012 21:47:43 +0100
Subject: [PATCH 082/133] [maven-release-plugin] prepare release
plexus-utils-3.0.9
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index de7ee91a..990c2697 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.9-SNAPSHOT
+ 3.0.9Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- HEAD
+ plexus-utils-3.0.9JIRA
From 4b4d7c22b2ae790c8a0ea5cce5f69919cca22cc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Mon, 19 Nov 2012 00:02:41 +0100
Subject: [PATCH 083/133] prepare next version
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 990c2697..98907938 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.9
+ 3.1-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- plexus-utils-3.0.9
+ HEADJIRA
From ccc7b11dc7c35e3226e279ff612d879beb28a055 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 27 Nov 2012 08:53:00 +0100
Subject: [PATCH 084/133] o Added testcase for xpp3 dom duplicate children
behaviour
---
src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java
index f49cc85b..446f3a46 100644
--- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java
+++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java
@@ -269,4 +269,10 @@ public void testShouldCopyRecessiveChildrenNotPresentInTarget()
assertNotSame( result.getChild( "bar" ), recessiveConfig.getChild( "bar" ) );
}
+ public void testDupeChildren() throws IOException, XmlPullParserException {
+ String dupes = "xy";
+ Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( dupes ) );
+ assertNotNull( dom);
+ assertEquals("y", dom.getChild("foo").getValue());
+ }
}
From 0ffb38a98e13b0ffa3957e9e093db5eb567bd406 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 27 Nov 2012 08:54:57 +0100
Subject: [PATCH 085/133] [PLXCOMP-194] WeakHashMap used incorrectly in cache
---
.../introspection/ReflectionValueExtractor.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java b/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
index 2be103b5..09f785ba 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -50,7 +52,7 @@ public class ReflectionValueExtractor
* This approach prevents permgen space overflows due to retention of discarded
* classloaders.
*/
- private static final Map classMaps = new WeakHashMap();
+ private static final Map> classMaps = new WeakHashMap>();
/**
* Indexed properties pattern, ie (\\w+)\\[(\\d+)\\]
@@ -234,13 +236,16 @@ public static Object evaluate( String expression, Object root, boolean trimRootT
private static ClassMap getClassMap( Class clazz )
{
- ClassMap classMap = (ClassMap) classMaps.get( clazz );
- if ( classMap == null )
+ SoftReference softRef = classMaps.get( clazz);
+
+ ClassMap classMap;
+
+ if ( softRef == null || (classMap = softRef.get() ) == null)
{
classMap = new ClassMap( clazz );
- classMaps.put( clazz, classMap );
+ classMaps.put( clazz, new SoftReference(classMap) );
}
return classMap;
From edeb37d624a2cee66ab09e5b9cefc92e14e0492a Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 27 Nov 2012 09:01:43 +0100
Subject: [PATCH 086/133] o Changed to WeakReference
---
.../introspection/ReflectionValueExtractor.java | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java b/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
index 09f785ba..96cdfbab 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
@@ -16,20 +16,15 @@
* limitations under the License.
*/
-import java.lang.ref.SoftReference;
+import org.codehaus.plexus.util.StringUtils;
+
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.WeakHashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.codehaus.plexus.util.StringUtils;
-
/**
*
Using simple dotted expressions to extract the values from an Object instance,
* For example we might want to extract a value like: project.build.sourceDirectory
@@ -52,7 +47,7 @@ public class ReflectionValueExtractor
* This approach prevents permgen space overflows due to retention of discarded
* classloaders.
*/
- private static final Map> classMaps = new WeakHashMap>();
+ private static final Map> classMaps = new WeakHashMap>();
/**
* Indexed properties pattern, ie (\\w+)\\[(\\d+)\\]
@@ -237,7 +232,7 @@ public static Object evaluate( String expression, Object root, boolean trimRootT
private static ClassMap getClassMap( Class clazz )
{
- SoftReference softRef = classMaps.get( clazz);
+ WeakReference softRef = classMaps.get( clazz);
ClassMap classMap;
@@ -245,7 +240,7 @@ private static ClassMap getClassMap( Class clazz )
{
classMap = new ClassMap( clazz );
- classMaps.put( clazz, new SoftReference(classMap) );
+ classMaps.put( clazz, new WeakReference(classMap) );
}
return classMap;
From 6a2ad293e18e9ab51d686377be6314d2c5143301 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 28 Nov 2012 11:50:24 +0100
Subject: [PATCH 087/133] [PLXUTILS-155] Removed pre-1.5 code for forking to
get system environment
---
.../plexus/util/cli/CommandLineUtils.java | 128 ++----------------
1 file changed, 8 insertions(+), 120 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 283785eb..d00c4ce3 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -16,12 +16,8 @@
* limitations under the License.
*/
-import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
import java.util.Map;
@@ -29,11 +25,8 @@
import java.util.StringTokenizer;
import java.util.Vector;
import org.codehaus.plexus.util.Os;
-import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.IOUtil;
-
/**
* @author Trygve Laugstøl
* @version $Id$
@@ -274,107 +267,18 @@ public static Properties getSystemEnvVars()
public static Properties getSystemEnvVars( boolean caseSensitive )
throws IOException
{
-
- // check if it's 1.5+ run
-
- Method getenvMethod = getEnvMethod();
- if ( getenvMethod != null )
- {
- try
- {
- return getEnvFromSystem( getenvMethod, caseSensitive );
- }
- catch ( IllegalAccessException e )
- {
- throw new IOException( e.getMessage() );
- }
- catch ( IllegalArgumentException e )
- {
- throw new IOException( e.getMessage() );
- }
- catch ( InvocationTargetException e )
- {
- throw new IOException( e.getMessage() );
- }
- }
-
- Process p = null;
-
- try
- {
- Properties envVars = new Properties();
-
- Runtime r = Runtime.getRuntime();
-
- //If this is windows set the shell to command.com or cmd.exe with correct arguments.
- boolean overriddenEncoding = false;
- if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
- {
- if ( Os.isFamily( Os.FAMILY_WIN9X ) )
- {
- p = r.exec( "command.com /c set" );
- }
- else
- {
- overriddenEncoding = true;
- // /U = change stdout encoding to UTF-16LE to avoid encoding inconsistency
- // between command-line/DOS and GUI/Windows, see PLXUTILS-124
- p = r.exec( "cmd.exe /U /c set" );
- }
- }
- else
- {
- p = r.exec( "env" );
- }
-
- Reader reader = overriddenEncoding
- ? new InputStreamReader( p.getInputStream(), ReaderFactory.UTF_16LE )
- : new InputStreamReader( p.getInputStream() );
- BufferedReader br = new BufferedReader( reader );
-
- String line;
-
- String lastKey = null;
- String lastVal = null;
-
- while ( ( line = br.readLine() ) != null )
- {
- int idx = line.indexOf( '=' );
-
- if ( idx > 0 )
- {
- lastKey = line.substring( 0, idx );
-
- if ( !caseSensitive )
- {
- lastKey = lastKey.toUpperCase( Locale.ENGLISH );
- }
-
- lastVal = line.substring( idx + 1 );
-
- envVars.setProperty( lastKey, lastVal );
- }
- else if ( lastKey != null )
- {
- lastVal += "\n" + line;
-
- envVars.setProperty( lastKey, lastVal );
- }
- }
-
- return envVars;
- }
- finally
+ Properties envVars = new Properties();
+ Map envs = System.getenv();
+ for ( String key : envs.keySet() )
{
- if ( p != null )
+ String value = envs.get( key );
+ if ( !caseSensitive)
{
- IOUtil.close( p.getOutputStream() );
- IOUtil.close( p.getErrorStream() );
- IOUtil.close( p.getInputStream() );
-
- p.destroy();
+ key = key.toUpperCase( Locale.ENGLISH );
}
+ envVars.put( key, value );
}
+ return envVars;
}
public static boolean isAlive( Process p )
@@ -614,20 +518,4 @@ private static Method getEnvMethod()
}
}
- private static Properties getEnvFromSystem( Method method, boolean caseSensitive )
- throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
- {
- Properties envVars = new Properties();
- @SuppressWarnings( { "unchecked" } ) Map envs = (Map) method.invoke( null );
- for ( String key : envs.keySet() )
- {
- String value = envs.get( key );
- if ( !caseSensitive )
- {
- key = key.toUpperCase( Locale.ENGLISH );
- }
- envVars.put( key, value );
- }
- return envVars;
- }
}
From f787a5a5f5577f7c743987158d95fecf1278f47b Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Wed, 28 Nov 2012 11:56:39 +0100
Subject: [PATCH 088/133] remove not anymore used private method
---
.../plexus/util/cli/CommandLineUtils.java | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index d00c4ce3..fc73e515 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -502,20 +502,4 @@ public static String toString( String[] line )
return result.toString();
}
- private static Method getEnvMethod()
- {
- try
- {
- return System.class.getMethod( "getenv");
- }
- catch ( NoSuchMethodException e )
- {
- return null;
- }
- catch ( SecurityException e )
- {
- return null;
- }
- }
-
}
From a09697db5ee87f97180b1c84b5bbdef47ba28658 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 28 Nov 2012 23:44:39 +0100
Subject: [PATCH 089/133] [maven-release-plugin] prepare release
plexus-utils-3.0.10
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 98907938..4856ee9d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.1-SNAPSHOT
+ 3.0.10Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- HEAD
+ plexus-utils-3.0.10JIRA
From ccb7af9bc8ae340ef9269b759a1b5797924da726 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 28 Nov 2012 23:44:46 +0100
Subject: [PATCH 090/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4856ee9d..98907938 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.10
+ 3.1-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- plexus-utils-3.0.10
+ HEADJIRA
From 8474758efb9847cd6478a49dd118fac086ceb49b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sun, 2 Dec 2012 00:52:32 +0100
Subject: [PATCH 091/133] updated parent pom
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 98907938..777b3498 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@ limitations under the License.
org.codehaus.plexusplexus
- 3.3
+ 3.3.1plexus-utils
From 763d6bc011a23334dbf126a43f2db0561dab417f Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Fri, 11 Jan 2013 07:28:46 +0100
Subject: [PATCH 092/133] [IO-276] deleteDirectoryOnExit does not work
---
src/main/java/org/codehaus/plexus/util/FileUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index f0e040bb..7bac8d67 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -1491,9 +1491,9 @@ private static void deleteDirectoryOnExit( final File directory )
{
return;
}
+ directory.deleteOnExit(); // The hook reverses the list
cleanDirectoryOnExit( directory );
- directory.deleteOnExit();
}
/**
From 286a5980977d154392853a54035f2c16e38f29fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sat, 27 Jul 2013 22:50:39 +0200
Subject: [PATCH 093/133] added generics
---
.../util/dag/CycleDetectedException.java | 9 ++-
.../plexus/util/dag/CycleDetector.java | 64 +++++++------------
.../org/codehaus/plexus/util/dag/DAG.java | 30 ++++-----
.../plexus/util/dag/TopologicalSorter.java | 43 ++++---------
.../org/codehaus/plexus/util/dag/Vertex.java | 27 +++-----
.../util/dag/CycleDetectedExceptionTest.java | 2 +-
.../plexus/util/dag/CycleDetectorTest.java | 6 +-
.../org/codehaus/plexus/util/dag/DAGTest.java | 6 +-
.../util/dag/TopologicalSorterTest.java | 16 ++---
9 files changed, 80 insertions(+), 123 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
index 55287d0d..ae5e6c07 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
@@ -22,9 +22,9 @@
public class CycleDetectedException
extends Exception
{
- private List cycle;
+ private List cycle;
- public CycleDetectedException( final String message, final List cycle )
+ public CycleDetectedException( final String message, final List cycle )
{
super( message );
@@ -32,8 +32,7 @@ public CycleDetectedException( final String message, final List cycle )
}
-
- public List getCycle()
+ public List getCycle()
{
return cycle;
}
@@ -45,7 +44,7 @@ public String cycleToString()
{
final StringBuffer buffer = new StringBuffer();
- for ( Iterator iterator = cycle.iterator(); iterator.hasNext(); )
+ for ( Iterator iterator = cycle.iterator(); iterator.hasNext(); )
{
buffer.append( iterator.next() );
diff --git a/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java b/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java
index 4f26c61b..ea285883 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java
@@ -18,7 +18,6 @@
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -37,18 +36,16 @@ public class CycleDetector
private final static Integer VISITED = new Integer( 2 );
- public static List hasCycle( final DAG graph )
+ public static List hasCycle( final DAG graph )
{
- final List verticies = graph.getVerticies();
+ final List verticies = graph.getVerticies();
- final Map vertexStateMap = new HashMap();
+ final Map vertexStateMap = new HashMap();
- List retValue = null;
+ List retValue = null;
- for ( final Iterator iter = verticies.iterator(); iter.hasNext(); )
+ for ( Vertex vertex : verticies )
{
- final Vertex vertex = ( Vertex ) iter.next();
-
if ( isNotVisited( vertex, vertexStateMap ) )
{
retValue = introducesCycle( vertex, vertexStateMap );
@@ -61,12 +58,10 @@ public static List hasCycle( final DAG graph )
}
return retValue;
-
}
-
/**
- * This method will be called when an egde leading to given vertex was added
+ * This method will be called when an edge leading to given vertex was added
* and we want to check if introduction of this edge has not resulted
* in apparition of cycle in the graph
*
@@ -74,9 +69,9 @@ public static List hasCycle( final DAG graph )
* @param vertexStateMap
* @return
*/
- public static List introducesCycle( final Vertex vertex, final Map vertexStateMap )
+ public static List introducesCycle( final Vertex vertex, final Map vertexStateMap )
{
- final LinkedList cycleStack = new LinkedList();
+ final LinkedList cycleStack = new LinkedList();
final boolean hasCycle = dfsVisit( vertex, cycleStack, vertexStateMap );
@@ -84,15 +79,15 @@ public static List introducesCycle( final Vertex vertex, final Map vertexStateMa
{
// we have a situation like: [b, a, c, d, b, f, g, h].
// Label of Vertex which introduced the cycle is at the first position in the list
- // We have to find second occurence of this label and use its position in the list
- // for getting the sublist of vertex labels of cycle paricipants
+ // We have to find second occurrence of this label and use its position in the list
+ // for getting the sublist of vertex labels of cycle participants
//
- // So in our case we are seraching for [b, a, c, d, b]
- final String label = ( String ) cycleStack.getFirst();
+ // So in our case we are searching for [b, a, c, d, b]
+ final String label = cycleStack.getFirst();
final int pos = cycleStack.lastIndexOf( label );
- final List cycle = cycleStack.subList( 0, pos + 1 );
+ final List cycle = cycleStack.subList( 0, pos + 1 );
Collections.reverse( cycle );
@@ -103,13 +98,11 @@ public static List introducesCycle( final Vertex vertex, final Map vertexStateMa
}
- public static List introducesCycle( final Vertex vertex )
+ public static List introducesCycle( final Vertex vertex )
{
-
- final Map vertexStateMap = new HashMap();
+ final Map vertexStateMap = new HashMap();
return introducesCycle( vertex, vertexStateMap );
-
}
/**
@@ -117,16 +110,11 @@ public static List introducesCycle( final Vertex vertex )
* @param vertexStateMap
* @return
*/
- private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
+ private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
{
- if ( !vertexStateMap.containsKey( vertex ) )
- {
- return true;
- }
+ final Integer state = vertexStateMap.get( vertex );
- final Integer state = ( Integer ) vertexStateMap.get( vertex );
-
- return NOT_VISTITED.equals( state );
+ return ( state == null ) || NOT_VISTITED.equals( state );
}
/**
@@ -134,25 +122,22 @@ private static boolean isNotVisited( final Vertex vertex, final Map vertexStateM
* @param vertexStateMap
* @return
*/
- private static boolean isVisiting( final Vertex vertex, final Map vertexStateMap )
+ private static boolean isVisiting( final Vertex vertex, final Map vertexStateMap )
{
- final Integer state = ( Integer ) vertexStateMap.get( vertex );
+ final Integer state = vertexStateMap.get( vertex );
return VISITING.equals( state );
}
- private static boolean dfsVisit( final Vertex vertex, final LinkedList cycle, final Map vertexStateMap )
+ private static boolean dfsVisit( final Vertex vertex, final LinkedList cycle,
+ final Map vertexStateMap )
{
cycle.addFirst( vertex.getLabel() );
vertexStateMap.put( vertex, VISITING );
- final List verticies = vertex.getChildren();
-
- for ( final Iterator iter = verticies.iterator(); iter.hasNext(); )
+ for ( Vertex v : vertex.getChildren() )
{
- final Vertex v = ( Vertex ) iter.next();
-
if ( isNotVisited( v, vertexStateMap ) )
{
final boolean hasCycle = dfsVisit( v, cycle, vertexStateMap );
@@ -174,9 +159,6 @@ else if ( isVisiting( v, vertexStateMap ) )
cycle.removeFirst();
return false;
-
}
-
-
}
\ No newline at end of file
diff --git a/src/main/java/org/codehaus/plexus/util/dag/DAG.java b/src/main/java/org/codehaus/plexus/util/dag/DAG.java
index 89c23b68..715f7624 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/DAG.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/DAG.java
@@ -28,7 +28,7 @@
*
* @author Michal Maczka
* @version $Id$
- * @todo this class should be reanmed from DAG to Dag
+ * @todo this class should be renamed from DAG to Dag
*/
public class DAG implements Cloneable, Serializable
{
@@ -36,18 +36,18 @@ public class DAG implements Cloneable, Serializable
//Fields
//------------------------------------------------------------
/**
- * Nodes will be kept in two data strucures at the same time
+ * Nodes will be kept in two data structures at the same time
* for faster processing
*/
/**
* Maps vertex's label to vertex
*/
- private Map vertexMap = new HashMap();
+ private Map vertexMap = new HashMap();
/**
* Conatin list of all verticies
*/
- private List vertexList = new ArrayList();
+ private List vertexList = new ArrayList();
// ------------------------------------------------------------
// Constructors
@@ -68,17 +68,15 @@ public DAG()
/**
* @return
*/
- public List getVerticies()
+ public List getVerticies()
{
return vertexList;
}
- public Set getLabels()
+ public Set getLabels()
{
- final Set retValue = vertexMap.keySet();
-
- return retValue;
+ return vertexMap.keySet();
}
// ------------------------------------------------------------
@@ -100,7 +98,7 @@ public Vertex addVertex( final String label )
// check if vertex is alredy in DAG
if ( vertexMap.containsKey( label ) )
{
- retValue = ( Vertex ) vertexMap.get( label );
+ retValue = vertexMap.get( label );
}
else
{
@@ -130,7 +128,7 @@ public void addEdge( final Vertex from, final Vertex to ) throws CycleDetectedEx
to.addEdgeFrom( from );
- final List cycle = CycleDetector.introducesCycle( to );
+ final List cycle = CycleDetector.introducesCycle( to );
if ( cycle != null )
{
@@ -185,7 +183,7 @@ public boolean hasEdge( final String label1, final String label2 )
* @param label
* @return
*/
- public List getChildLabels( final String label )
+ public List getChildLabels( final String label )
{
final Vertex vertex = getVertex( label );
@@ -196,7 +194,7 @@ public List getChildLabels( final String label )
* @param label
* @return
*/
- public List getParentLabels( final String label )
+ public List getParentLabels( final String label )
{
final Vertex vertex = getVertex( label );
@@ -241,16 +239,16 @@ public boolean isConnected( final String label )
* the label passed as parameter to this method. This label should
* always be the last item in the list.
*/
- public List getSuccessorLabels( final String label )
+ public List getSuccessorLabels( final String label )
{
final Vertex vertex = getVertex( label );
- final List retValue;
+ final List retValue;
//optimization.
if ( vertex.isLeaf() )
{
- retValue = new ArrayList( 1 );
+ retValue = new ArrayList( 1 );
retValue.add( label );
}
diff --git a/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java b/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java
index 4a5f30d1..6c570a50 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java
@@ -17,7 +17,6 @@
*/
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -40,37 +39,30 @@ public class TopologicalSorter
* @return List of String (vertex labels)
*/
- public static List sort( final DAG graph )
+ public static List sort( final DAG graph )
{
return dfs( graph );
}
- public static List sort( final Vertex vertex )
+ public static List sort( final Vertex vertex )
{
// we need to use addFirst method so we will use LinkedList explicitly
- final LinkedList retValue = new LinkedList();
+ final List retValue = new LinkedList();
- final Map vertexStateMap = new HashMap();
-
- dfsVisit( vertex, vertexStateMap, retValue );
+ dfsVisit( vertex, new HashMap(), retValue );
return retValue;
}
- private static List dfs( final DAG graph )
+ private static List dfs( final DAG graph )
{
- final List verticies = graph.getVerticies();
-
// we need to use addFirst method so we will use LinkedList explicitly
- final LinkedList retValue = new LinkedList();
+ final List retValue = new LinkedList();
+ final Map vertexStateMap = new HashMap();
- final Map vertexStateMap = new HashMap();
-
- for ( final Iterator iter = verticies.iterator(); iter.hasNext(); )
+ for ( Vertex vertex : graph.getVerticies() )
{
- final Vertex vertex = ( Vertex ) iter.next();
-
if ( isNotVisited( vertex, vertexStateMap ) )
{
dfsVisit( vertex, vertexStateMap, retValue );
@@ -85,28 +77,21 @@ private static List dfs( final DAG graph )
* @param vertexStateMap
* @return
*/
- private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
+ private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
{
- if ( !vertexStateMap.containsKey( vertex ) )
- {
- return true;
- }
- final Integer state = ( Integer ) vertexStateMap.get( vertex );
+ final Integer state = vertexStateMap.get( vertex );
- return NOT_VISTITED.equals( state );
+ return ( state == null ) || NOT_VISTITED.equals( state );
}
- private static void dfsVisit( final Vertex vertex, final Map vertexStateMap, final LinkedList list )
+ private static void dfsVisit( final Vertex vertex, final Map vertexStateMap,
+ final List list )
{
vertexStateMap.put( vertex, VISITING );
- final List verticies = vertex.getChildren();
-
- for ( final Iterator iter = verticies.iterator(); iter.hasNext(); )
+ for ( Vertex v : vertex.getChildren() )
{
- final Vertex v = ( Vertex ) iter.next();
-
if ( isNotVisited( v, vertexStateMap ) )
{
dfsVisit( v, vertexStateMap, list );
diff --git a/src/main/java/org/codehaus/plexus/util/dag/Vertex.java b/src/main/java/org/codehaus/plexus/util/dag/Vertex.java
index 873c430c..a9f1324b 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/Vertex.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/Vertex.java
@@ -18,7 +18,6 @@
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
/**
@@ -32,9 +31,9 @@ public class Vertex implements Cloneable, Serializable
//------------------------------------------------------------
private String label = null;
- List children = new ArrayList();
+ List children = new ArrayList();
- List parents = new ArrayList();
+ List parents = new ArrayList();
// ------------------------------------------------------------
@@ -90,13 +89,11 @@ public void addEdgeFrom( final Vertex vertex )
public void removeEdgeFrom( final Vertex vertex )
{
-
parents.remove( vertex );
-
}
- public List getChildren()
+ public List getChildren()
{
return children;
}
@@ -107,14 +104,12 @@ public List getChildren()
*
* @return the labels used by the most direct children.
*/
- public List getChildLabels()
+ public List getChildLabels()
{
- final List retValue = new ArrayList( children.size() );
+ final List retValue = new ArrayList( children.size() );
- for ( final Iterator iter = children.iterator(); iter.hasNext(); )
+ for ( Vertex vertex : children )
{
- final Vertex vertex = ( Vertex ) iter.next();
-
retValue.add( vertex.getLabel() );
}
return retValue;
@@ -126,7 +121,7 @@ public List getChildLabels()
*
* @return list of parents
*/
- public List getParents()
+ public List getParents()
{
return parents;
}
@@ -137,14 +132,12 @@ public List getParents()
*
* @return the labels used parents
*/
- public List getParentLabels()
+ public List getParentLabels()
{
- final List retValue = new ArrayList( parents.size() );
+ final List retValue = new ArrayList( parents.size() );
- for ( final Iterator iter = parents.iterator(); iter.hasNext(); )
+ for ( Vertex vertex : parents )
{
- final Vertex vertex = ( Vertex ) iter.next();
-
retValue.add( vertex.getLabel() );
}
return retValue;
diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java
index 46942fb3..77f1d470 100644
--- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java
+++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java
@@ -30,7 +30,7 @@ public class CycleDetectedExceptionTest
{
public void testException()
{
- final List cycle = new ArrayList();
+ final List cycle = new ArrayList();
cycle.add( "a" );
diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java
index 7caaf933..bfa9424f 100644
--- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java
+++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java
@@ -70,7 +70,7 @@ public void testCycyleDetection()
catch ( CycleDetectedException e )
{
- final List cycle = e.getCycle();
+ final List cycle = e.getCycle();
assertNotNull( "Cycle should be not null", cycle );
@@ -129,7 +129,7 @@ public void testCycyleDetection()
}
catch ( CycleDetectedException e )
{
- final List cycle = e.getCycle();
+ final List cycle = e.getCycle();
assertNotNull( "Cycle should be not null", cycle );
@@ -177,7 +177,7 @@ public void testCycyleDetection()
}
catch ( CycleDetectedException e )
{
- final List cycle = e.getCycle();
+ final List cycle = e.getCycle();
assertNotNull( "Cycle should be not null", cycle );
diff --git a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java
index 50c1e50f..de599ad4 100644
--- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java
+++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java
@@ -98,7 +98,7 @@ public void testDAG()
assertFalse( dag.hasEdge( "d", "c" ) );
- final Set labels = dag.getLabels();
+ final Set labels = dag.getLabels();
assertEquals( 4, labels.size() );
@@ -168,9 +168,9 @@ public void testGetPredessors()
dag.addEdge( "f", "g" );
- final List actual = dag.getSuccessorLabels( "b" );
+ final List actual = dag.getSuccessorLabels( "b" );
- final List expected = new ArrayList();
+ final List expected = new ArrayList();
expected.add( "d" );
diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java
index 67a45722..a081b653 100644
--- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java
+++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java
@@ -40,7 +40,7 @@ public void testDfs()
dag1.addEdge( "b", "c" );
- final List expected1 = new ArrayList();
+ final List expected1 = new ArrayList();
expected1.add( "c" );
@@ -48,7 +48,7 @@ public void testDfs()
expected1.add( "a" );
- final List actual1 = TopologicalSorter.sort( dag1 );
+ final List actual1 = TopologicalSorter.sort( dag1 );
assertEquals( "Order is different then expected", expected1, actual1 );
@@ -68,7 +68,7 @@ public void testDfs()
dag2.addEdge( "c", "b" );
- final List expected2 = new ArrayList();
+ final List expected2 = new ArrayList();
expected2.add( "a" );
@@ -76,7 +76,7 @@ public void testDfs()
expected2.add( "c" );
- final List actual2 = TopologicalSorter.sort( dag2 );
+ final List actual2 = TopologicalSorter.sort( dag2 );
assertEquals( "Order is different then expected", expected2, actual2 );
@@ -117,7 +117,7 @@ public void testDfs()
dag3.addEdge( "f", "g" );
- final List expected3 = new ArrayList();
+ final List expected3 = new ArrayList();
expected3.add( "d" );
@@ -133,7 +133,7 @@ public void testDfs()
expected3.add( "a" );
- final List actual3 = TopologicalSorter.sort( dag3 );
+ final List actual3 = TopologicalSorter.sort( dag3 );
assertEquals( "Order is different then expected", expected3, actual3 );
@@ -172,7 +172,7 @@ public void testDfs()
dag4.addEdge( "e", "f" );
- final List expected4 = new ArrayList();
+ final List expected4 = new ArrayList();
expected4.add( "d" );
@@ -186,7 +186,7 @@ public void testDfs()
expected4.add( "a" );
- final List actual4 = TopologicalSorter.sort( dag4 );
+ final List actual4 = TopologicalSorter.sort( dag4 );
assertEquals( "Order is different then expected", expected4, actual4 );
}
From 3217c5d2c9d56a3a849d9325ebeaebfa6a583eb4 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 31 Jul 2013 13:20:00 +0200
Subject: [PATCH 094/133] Added buffering of FileInputStream
---
src/main/java/org/codehaus/plexus/util/ReaderFactory.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
index c9fe9927..eab0af1c 100644
--- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -200,7 +201,9 @@ public static Reader newReader( InputStream in, String encoding )
public static Reader newReader( File file, String encoding )
throws FileNotFoundException, UnsupportedEncodingException
{
- return new InputStreamReader( new FileInputStream(file), encoding );
+ FileInputStream in = new FileInputStream( file );
+ BufferedInputStream bis = new BufferedInputStream( in, 32768 );
+ return new InputStreamReader( bis, encoding );
}
/**
From 25fc3a2059275be83d25626064ca826848485797 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 11 Mar 2013 14:17:27 +0100
Subject: [PATCH 095/133] Added string instrumentationQ
---
.../plexus/util/xml/pull/MXParser.java | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
index f19a2702..5ddfbcca 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
@@ -13,6 +13,8 @@
import java.io.IOException;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.plexus.util.ReaderFactory;
@@ -741,6 +743,33 @@ public boolean isWhitespace() throws XmlPullParserException
throw new XmlPullParserException("no content available to check for whitespaces");
}
+ private static final ConcurrentHashMap counts = new ConcurrentHashMap();
+
+ static {
+ Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+ public void run() {
+ int overallDuped = 0;
+ int largeDuped = 0;
+ int totalOverall = 0;
+ int totalLarge = 0;
+ System.out.println("String usage report");
+ for (Map.Entry entry : counts.entrySet()) {
+ if (entry.getValue() > 200){
+ System.out.println(entry.getKey() + ":" + entry.getValue());
+ totalLarge += entry.getKey().length() * entry.getValue();
+ largeDuped += entry.getValue();
+ }
+ totalOverall += entry.getKey().length() * entry.getValue();
+ overallDuped += entry.getValue();
+ }
+ System.out.println("totalLarge = " + totalLarge);
+ System.out.println("totalOverall = " + totalOverall);
+ System.out.println("overallDuped = " + overallDuped);
+ System.out.println("largeDuped = " + largeDuped);
+ }
+ }));
+ }
+
public String getText()
{
if(eventType == START_DOCUMENT || eventType == END_DOCUMENT) {
@@ -759,10 +788,16 @@ public String getText()
} else {
text = new String(pc, pcStart, pcEnd - pcStart);
}
+ Integer current = counts.get( text);
+ if (current == null) current = 0;
+ counts.put( text, current + 1);
}
return text;
}
+
+
+
public char[] getTextCharacters(int [] holderForStartAndLength)
{
if( eventType == TEXT ) {
From 5572436a9f5e20f90bc61ca9f3cc901fe7df452d Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Wed, 31 Jul 2013 14:52:23 +0200
Subject: [PATCH 096/133] Java5 conversion, generate less garbage for
operations matching append.*substring
---
.../codehaus/plexus/util/DirectoryWalker.java | 2 +-
.../org/codehaus/plexus/util/FileUtils.java | 4 +-
.../util/LineOrientedInterpolatingReader.java | 4 +-
.../org/codehaus/plexus/util/PathTool.java | 2 +-
.../codehaus/plexus/util/SelectorUtils.java | 2 +-
.../org/codehaus/plexus/util/StringUtils.java | 69 +++++++++----------
.../plexus/util/cli/shell/BourneShell.java | 2 +-
.../plexus/util/cli/shell/CmdShell.java | 2 +-
.../codehaus/plexus/util/cli/shell/Shell.java | 4 +-
.../util/dag/CycleDetectedException.java | 2 +-
.../plexus/util/introspection/ClassMap.java | 49 ++++++++-----
.../plexus/util/xml/XmlWriterUtil.java | 15 ++--
.../plexus/util/xml/Xpp3DomBuilder.java | 9 +--
.../plexus/util/xml/pull/MXParser.java | 6 +-
.../plexus/util/xml/pull/MXSerializer.java | 8 +--
.../plexus/util/DirectoryScannerTest.java | 2 +-
.../codehaus/plexus/util/FileUtilsTest.java | 4 +-
.../plexus/util/cli/CommandlineTest.java | 2 +-
.../util/cli/EnhancedStringTokenizerTest.java | 2 +-
.../util/xml/PrettyPrintXMLWriterTest.java | 2 +-
.../plexus/util/xml/Xpp3DomBuilderTest.java | 8 +--
.../plexus/util/xml/Xpp3DomWriterTest.java | 2 +-
22 files changed, 108 insertions(+), 94 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java b/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java
index 6f621b09..0d7c76cb 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java
@@ -320,7 +320,7 @@ public void scan()
if ( debugEnabled )
{
Iterator it;
- StringBuffer dbg = new StringBuffer();
+ StringBuilder dbg = new StringBuilder();
dbg.append( "DirectoryWalker Scan" );
dbg.append( "\n Base Dir: " ).append( this.baseDir.getAbsolutePath() );
dbg.append( "\n Includes: " );
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 7bac8d67..6d00ce62 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -373,7 +373,7 @@ public static String fileRead( File file )
public static String fileRead( File file, String encoding )
throws IOException
{
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
Reader reader = null;
@@ -1336,7 +1336,7 @@ public static File resolveFile( final File baseFile, String filename )
// FIXME: I'm almost certain this // removal is unnecessary, as getAbsoluteFile() strips
// them. However, I'm not sure about this UNC stuff. (JT)
final char[] chars = filename.toCharArray();
- final StringBuffer sb = new StringBuffer();
+ final StringBuilder sb = new StringBuilder();
//remove duplicate file separators in succession - except
//on win32 at start of filename as UNC filenames can
diff --git a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
index 7a2a6212..29b81acc 100644
--- a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
+++ b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
@@ -442,7 +442,7 @@ private String findAndReplaceUnlessEscaped(String rawLine, String search, String
lastReplacement = 0;
}
- lineBuffer.append( rawLine.substring( lastReplacement, nextReplacement ) );
+ lineBuffer.append( rawLine, lastReplacement, nextReplacement );
int escIdx = rawLine.indexOf( escapeSeq, lastReplacement + 1 );
if(escIdx > -1 && escIdx + escapeSeq.length() == nextReplacement)
@@ -466,7 +466,7 @@ private String findAndReplaceUnlessEscaped(String rawLine, String search, String
if( lastReplacement < rawLine.length() )
{
- lineBuffer.append( rawLine.substring( lastReplacement ) );
+ lineBuffer.append( rawLine, lastReplacement, rawLine.length() );
}
return lineBuffer.toString();
diff --git a/src/main/java/org/codehaus/plexus/util/PathTool.java b/src/main/java/org/codehaus/plexus/util/PathTool.java
index 78677a20..76301862 100644
--- a/src/main/java/org/codehaus/plexus/util/PathTool.java
+++ b/src/main/java/org/codehaus/plexus/util/PathTool.java
@@ -396,7 +396,7 @@ private static final String determineRelativePath( String filename, String separ
* that the file is within one or more directories. Thus, each
* slash represents a "../" in the relative path.
*/
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for ( int i = 0; i < slashCount; i++ )
{
sb.append( "../" );
diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
index 6309c570..621b04e4 100644
--- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
@@ -711,7 +711,7 @@ public static boolean isOutOfDate( File src, File target, int granularity )
*/
public static String removeWhitespace( String input )
{
- StringBuffer result = new StringBuffer();
+ StringBuilder result = new StringBuilder();
if ( input != null )
{
StringTokenizer st = new StringTokenizer( input );
diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java
index 873cad09..846f491f 100644
--- a/src/main/java/org/codehaus/plexus/util/StringUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/StringUtils.java
@@ -137,7 +137,7 @@ public static String trim( String str )
*/
public static String deleteWhitespace( String str )
{
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
int sz = str.length();
for ( int i = 0; i < sz; i++ )
{
@@ -292,10 +292,10 @@ public static int indexOfAny( String str, String[] searchStrs )
// String's can't have a MAX_VALUEth index.
int ret = Integer.MAX_VALUE;
- int tmp = 0;
- for ( int i = 0; i < sz; i++ )
+ int tmp;
+ for ( String searchStr : searchStrs )
{
- tmp = str.indexOf( searchStrs[i] );
+ tmp = str.indexOf( searchStr );
if ( tmp == -1 )
{
continue;
@@ -326,12 +326,11 @@ public static int lastIndexOfAny( String str, String[] searchStrs )
{
return -1;
}
- int sz = searchStrs.length;
int ret = -1;
- int tmp = 0;
- for ( int i = 0; i < sz; i++ )
+ int tmp;
+ for ( String searchStr : searchStrs )
{
- tmp = str.lastIndexOf( searchStrs[i] );
+ tmp = str.lastIndexOf( searchStr );
if ( tmp > ret )
{
ret = tmp;
@@ -574,7 +573,7 @@ public static String[] split( String text, String separator )
*/
public static String[] split( String str, String separator, int max )
{
- StringTokenizer tok = null;
+ StringTokenizer tok;
if ( separator == null )
{
// Null separator means we're using StringTokenizer's default
@@ -594,7 +593,7 @@ public static String[] split( String str, String separator, int max )
String[] list = new String[listSize];
int i = 0;
- int lastTokenBegin = 0;
+ int lastTokenBegin;
int lastTokenEnd = 0;
while ( tok.hasMoreTokens() )
{
@@ -654,7 +653,7 @@ public static String join( Object[] array, String separator )
int arraySize = array.length;
int bufSize = ( arraySize == 0 ? 0 : ( array[0].toString().length() +
separator.length() ) * arraySize );
- StringBuffer buf = new StringBuffer( bufSize );
+ StringBuilder buf = new StringBuilder( bufSize );
for ( int i = 0; i < arraySize; i++ )
{
@@ -684,7 +683,7 @@ public static String join( Iterator> iterator, String separator )
{
separator = "";
}
- StringBuffer buf = new StringBuffer( 256 ); // Java default is 16, probably too small
+ StringBuilder buf = new StringBuilder( 256 ); // Java default is 16, probably too small
while ( iterator.hasNext() )
{
buf.append( iterator.next() );
@@ -801,11 +800,11 @@ public static String replace( String text, String repl, String with, int max )
return text;
}
- StringBuffer buf = new StringBuffer( text.length() );
- int start = 0, end = 0;
+ StringBuilder buf = new StringBuilder( text.length() );
+ int start = 0, end;
while ( ( end = text.indexOf( repl, start ) ) != -1 )
{
- buf.append( text.substring( start, end ) ).append( with );
+ buf.append( text, start, end ).append( with );
start = end + repl.length();
if ( --max == 0 )
@@ -813,7 +812,7 @@ public static String replace( String text, String repl, String with, int max )
break;
}
}
- buf.append( text.substring( start ) );
+ buf.append( text, start, text.length());
return buf.toString();
}
@@ -830,9 +829,9 @@ public static String replace( String text, String repl, String with, int max )
public static String overlayString( String text, String overlay, int start, int end )
{
return new StringBuffer( start + overlay.length() + text.length() - end + 1 )
- .append( text.substring( 0, start ) )
+ .append( text, 0, start )
.append( overlay )
- .append( text.substring( end ) )
+ .append( text, end, text.length() )
.toString();
}
@@ -1107,7 +1106,7 @@ public static String escape( String str )
// improved with code from cybertiger@cyberiantiger.org
// unicode from him, and defaul for < 32's.
int sz = str.length();
- StringBuffer buffer = new StringBuffer( 2 * sz );
+ StringBuilder buffer = new StringBuilder( 2 * sz );
for ( int i = 0; i < sz; i++ )
{
char ch = str.charAt( i );
@@ -1201,7 +1200,7 @@ else if ( ch < 32 )
*/
public static String repeat( String str, int repeat )
{
- StringBuffer buffer = new StringBuffer( repeat * str.length() );
+ StringBuilder buffer = new StringBuilder( repeat * str.length() );
for ( int i = 0; i < repeat; i++ )
{
buffer.append( str );
@@ -1478,7 +1477,7 @@ else if ( str.length() == 0 )
{
return new StringBuffer( str.length() )
.append( Character.toLowerCase( str.charAt( 0 ) ) )
- .append( str.substring( 1 ) )
+ .append( str, 1, str.length() )
.toString();
}
}
@@ -1504,9 +1503,9 @@ else if ( str.length() == 0 )
}
else
{
- return new StringBuffer( str.length() )
+ return new StringBuilder( str.length() )
.append( Character.toTitleCase( str.charAt( 0 ) ) )
- .append( str.substring( 1 ) )
+ .append( str, 1, str.length() )
.toString();
}
}
@@ -1529,11 +1528,11 @@ public static String swapCase( String str )
return null;
}
int sz = str.length();
- StringBuffer buffer = new StringBuffer( sz );
+ StringBuilder buffer = new StringBuilder( sz );
boolean whitespace = false;
- char ch = 0;
- char tmp = 0;
+ char ch;
+ char tmp;
for ( int i = 0; i < sz; i++ )
{
@@ -1586,7 +1585,7 @@ public static String capitaliseAllWords( String str )
return null;
}
int sz = str.length();
- StringBuffer buffer = new StringBuffer( sz );
+ StringBuilder buffer = new StringBuilder( sz );
boolean space = true;
for ( int i = 0; i < sz; i++ )
{
@@ -1627,7 +1626,7 @@ public static String uncapitaliseAllWords( String str )
return null;
}
int sz = str.length();
- StringBuffer buffer = new StringBuffer( sz );
+ StringBuilder buffer = new StringBuilder( sz );
boolean space = true;
for ( int i = 0; i < sz; i++ )
{
@@ -2161,7 +2160,7 @@ public static String removeAndHump( String data, String replaceThis )
{
String temp;
- StringBuffer out = new StringBuffer();
+ StringBuilder out = new StringBuilder();
temp = data;
@@ -2197,7 +2196,7 @@ public static String lowercaseFirstLetter( String data )
public static String addAndDeHump( String view )
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for ( int i = 0; i < view.length(); i++ )
{
@@ -2331,9 +2330,9 @@ else if ( !escaped.equals( source ) )
}
else
{
- for ( int i = 0; i < quotingTriggers.length; i++ )
+ for ( char quotingTrigger : quotingTriggers )
{
- if ( escaped.indexOf( quotingTriggers[i] ) > -1 )
+ if ( escaped.indexOf( quotingTrigger ) > -1 )
{
quote = true;
break;
@@ -2379,7 +2378,7 @@ public static String escape( String source, final char[] escapedChars, String es
System.arraycopy( escapedChars, 0, eqc, 0, escapedChars.length );
Arrays.sort( eqc );
- StringBuffer buffer = new StringBuffer( source.length() );
+ StringBuilder buffer = new StringBuilder( source.length() );
for ( int i = 0; i < source.length(); i++ )
{
@@ -2409,7 +2408,7 @@ public static String escape( String source, final char[] escapedChars, String es
*/
public static String removeDuplicateWhitespace( String s )
{
- StringBuffer result = new StringBuffer( );
+ StringBuilder result = new StringBuilder( );
int length = s.length();
boolean isPreviousWhiteSpace = false;
for (int i = 0; i < length; i++){
@@ -2466,7 +2465,7 @@ public static String unifyLineSeparators( String s, String ls )
int length = s.length();
- StringBuffer buffer = new StringBuffer( length );
+ StringBuilder buffer = new StringBuilder( length );
for ( int i = 0; i < length; i++ )
{
if ( s.charAt( i ) == '\r' )
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
index e4b4cde4..d3432820 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
@@ -123,7 +123,7 @@ protected String getExecutionPreamble()
}
String dir = getWorkingDirectoryAsString();
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append( "cd " );
sb.append( unifyQuotes( dir ) );
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
index bbe44728..a96bb68a 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
@@ -79,7 +79,7 @@ public CmdShell()
*/
public List getCommandLine( String executable, String[] arguments )
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append( "\"" );
sb.append( super.getCommandLine( executable, arguments ).get( 0 ) );
sb.append( "\"" );
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
index 571b249d..6d748fb2 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
@@ -132,7 +132,7 @@ public List getCommandLine( String executable, String[] arguments )
protected List getRawCommandLine( String executable, String[] arguments )
{
List commandLine = new ArrayList();
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if ( executable != null )
{
@@ -189,7 +189,7 @@ protected String getExecutionPreamble()
protected char[] getEscapeChars( boolean includeSingleQuote, boolean includeDoubleQuote )
{
- StringBuffer buf = new StringBuffer( 2 );
+ StringBuilder buf = new StringBuilder( 2 );
if ( includeSingleQuote )
{
buf.append( '\'' );
diff --git a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
index ae5e6c07..76dd1883 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
@@ -42,7 +42,7 @@ public List getCycle()
*/
public String cycleToString()
{
- final StringBuffer buffer = new StringBuffer();
+ final StringBuilder buffer = new StringBuilder();
for ( Iterator iterator = cycle.iterator(); iterator.hasNext(); )
{
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java b/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
index 06ff14d8..1fb667c1 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
@@ -187,9 +187,9 @@ private String makeMethodKey( Method method )
{
Class[] parameterTypes = method.getParameterTypes();
- StringBuffer methodKey = new StringBuffer( method.getName() );
+ StringBuilder methodKey = new StringBuilder( method.getName() );
- for ( int j = 0; j < parameterTypes.length; j++ )
+ for ( Class parameterType : parameterTypes )
{
/*
* If the argument type is primitive then we want
@@ -197,28 +197,44 @@ private String makeMethodKey( Method method )
* corresponding Object type so introspection for
* methods with primitive types will work correctly.
*/
- if ( parameterTypes[j].isPrimitive() )
+ if ( parameterType.isPrimitive() )
{
- if ( parameterTypes[j].equals( Boolean.TYPE ) )
+ if ( parameterType.equals( Boolean.TYPE ) )
+ {
methodKey.append( "java.lang.Boolean" );
- else if ( parameterTypes[j].equals( Byte.TYPE ) )
+ }
+ else if ( parameterType.equals( Byte.TYPE ) )
+ {
methodKey.append( "java.lang.Byte" );
- else if ( parameterTypes[j].equals( Character.TYPE ) )
+ }
+ else if ( parameterType.equals( Character.TYPE ) )
+ {
methodKey.append( "java.lang.Character" );
- else if ( parameterTypes[j].equals( Double.TYPE ) )
+ }
+ else if ( parameterType.equals( Double.TYPE ) )
+ {
methodKey.append( "java.lang.Double" );
- else if ( parameterTypes[j].equals( Float.TYPE ) )
+ }
+ else if ( parameterType.equals( Float.TYPE ) )
+ {
methodKey.append( "java.lang.Float" );
- else if ( parameterTypes[j].equals( Integer.TYPE ) )
+ }
+ else if ( parameterType.equals( Integer.TYPE ) )
+ {
methodKey.append( "java.lang.Integer" );
- else if ( parameterTypes[j].equals( Long.TYPE ) )
+ }
+ else if ( parameterType.equals( Long.TYPE ) )
+ {
methodKey.append( "java.lang.Long" );
- else if ( parameterTypes[j].equals( Short.TYPE ) )
+ }
+ else if ( parameterType.equals( Short.TYPE ) )
+ {
methodKey.append( "java.lang.Short" );
+ }
}
else
{
- methodKey.append( parameterTypes[j].getName() );
+ methodKey.append( parameterType.getName() );
}
}
@@ -227,11 +243,11 @@ else if ( parameterTypes[j].equals( Short.TYPE ) )
private static String makeMethodKey( String method, Object[] params )
{
- StringBuffer methodKey = new StringBuffer().append( method );
+ StringBuilder methodKey = new StringBuilder().append( method );
- for ( int j = 0; j < params.length; j++ )
+ for ( Object param : params )
{
- Object arg = params[j];
+ Object arg = param;
if ( arg == null )
{
@@ -287,9 +303,8 @@ private static Method[] getAccessibleMethods( Class clazz )
}
int j = 0;
- for ( int i = 0; i < methodInfos.length; ++i )
+ for ( MethodInfo methodInfo : methodInfos )
{
- MethodInfo methodInfo = methodInfos[i];
if ( methodInfo.upcast )
{
methods[j++] = methodInfo.method;
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java b/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
index c1a90c7a..913b5f27 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
@@ -206,17 +206,16 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i
String[] sentences = StringUtils.split( comment, LS );
StringBuffer line = new StringBuffer( indentation + "
+
+
+ 4.0.0
+
+
+ org.codehaus.plexus
+ plexus
+ 3.3.1
+
+
+ plexus-utils
+ 3.0.14-SNAPSHOT
+
+ Plexus Common Utilities
+ A collection of various utility classes to ease working with strings, files, command lines, XML and
+ more.
+
+ http://plexus.codehaus.org/plexus-utils
+
+
+ scm:git:git@github.com:sonatype/plexus-utils.git
+ scm:git:git@github.com:sonatype/plexus-utils.git
+ http://github.com/sonatype/plexus-utils
+ HEAD
+
+
+ JIRA
+ http://jira.codehaus.org/browse/PLXUTILS
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ true
+
+ org/codehaus/plexus/util/FileBasedTestCase.java
+ **/Test*.java
+
+
+
+ JAVA_HOME
+ ${JAVA_HOME}
+
+
+ M2_HOME
+ ${M2_HOME}
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.1.1
+
+
+ enforce-java
+
+ enforce
+
+
+
+
+ 1.7.0
+
+
+
+
+
+
+
+
+
diff --git a/release.properties b/release.properties
new file mode 100644
index 00000000..52276bb2
--- /dev/null
+++ b/release.properties
@@ -0,0 +1,18 @@
+#release configuration
+#Tue Aug 06 21:40:26 CEST 2013
+project.scm.org.codehaus.plexus\:plexus-utils.tag=HEAD
+scm.tagNameFormat=@{project.artifactId}-@{project.version}
+scm.tag=plexus-utils-3.0.14
+project.scm.org.codehaus.plexus\:plexus-utils.url=http\://github.com/sonatype/plexus-utils
+pushChanges=true
+scm.url=scm\:git\:git@github.com\:sonatype/plexus-utils.git
+preparationGoals=clean verify
+project.scm.org.codehaus.plexus\:plexus-utils.developerConnection=scm\:git\:git@github.com\:sonatype/plexus-utils.git
+project.scm.org.codehaus.plexus\:plexus-utils.connection=scm\:git\:git@github.com\:sonatype/plexus-utils.git
+project.rel.org.codehaus.plexus\:plexus-utils=3.0.14
+project.dev.org.codehaus.plexus\:plexus-utils=3.0.15-SNAPSHOT
+remoteTagging=true
+scm.commentPrefix=[maven-release-plugin]
+exec.additionalArguments=-Pplexus-release
+exec.snapshotReleasePluginAllowed=false
+completedPhase=generate-release-poms
diff --git a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
index d7054af0..fae43373 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
@@ -224,16 +224,18 @@ private static String escapeXml( String text )
text = gt.matcher( text ).replaceAll( ">" );
}
if (text.indexOf('"') >= 0){
- text = dqoute.matcher( text ).replaceAll( "\"" );
+ text = dqoute.matcher( text ).replaceAll( """ );
}
if (text.indexOf('\'') >= 0){
- text = sqoute.matcher( text ).replaceAll( "\'" );
+ text = sqoute.matcher( text ).replaceAll( "'" );
}
return text;
}
- private static final Pattern crlf = Pattern.compile( "\r\n" );
+ private static final String crlf_str = "\r\n";
+
+ private static final Pattern crlf = Pattern.compile( crlf_str );
private static final Pattern lowers = Pattern.compile( "([\000-\037])" );
@@ -242,10 +244,10 @@ private static String escapeXmlAttribute( String text )
text = escapeXml( text );
// Windows
- Matcher matcher = crlf.matcher( text );
- if (matcher.matches())
+ Matcher crlfmatcher = crlf.matcher( text );
+ if (text.contains( crlf_str ))
{
- text = matcher.replaceAll( "
" );
+ text = crlfmatcher.replaceAll( "
" );
}
Matcher m = lowers.matcher( text );
From f9df68c1529f172e1e2a4145777c4e66d8d6a4d1 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 6 Aug 2013 21:53:20 +0200
Subject: [PATCH 114/133] Removed files that shouldnt be there
---
.gitignore | 2 ++
pom.xml | 2 +-
release.properties | 18 ------------------
3 files changed, 3 insertions(+), 19 deletions(-)
delete mode 100644 release.properties
diff --git a/.gitignore b/.gitignore
index 761f7ded..b17b6d7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@ bin
*.ipr
*.iws
*.idea
+release.properties
+
diff --git a/pom.xml b/pom.xml
index 2d18f38f..2366ba11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.14
+ 3.0.14-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
diff --git a/release.properties b/release.properties
deleted file mode 100644
index 52276bb2..00000000
--- a/release.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-#release configuration
-#Tue Aug 06 21:40:26 CEST 2013
-project.scm.org.codehaus.plexus\:plexus-utils.tag=HEAD
-scm.tagNameFormat=@{project.artifactId}-@{project.version}
-scm.tag=plexus-utils-3.0.14
-project.scm.org.codehaus.plexus\:plexus-utils.url=http\://github.com/sonatype/plexus-utils
-pushChanges=true
-scm.url=scm\:git\:git@github.com\:sonatype/plexus-utils.git
-preparationGoals=clean verify
-project.scm.org.codehaus.plexus\:plexus-utils.developerConnection=scm\:git\:git@github.com\:sonatype/plexus-utils.git
-project.scm.org.codehaus.plexus\:plexus-utils.connection=scm\:git\:git@github.com\:sonatype/plexus-utils.git
-project.rel.org.codehaus.plexus\:plexus-utils=3.0.14
-project.dev.org.codehaus.plexus\:plexus-utils=3.0.15-SNAPSHOT
-remoteTagging=true
-scm.commentPrefix=[maven-release-plugin]
-exec.additionalArguments=-Pplexus-release
-exec.snapshotReleasePluginAllowed=false
-completedPhase=generate-release-poms
From e434f28f0a2f9175a493be39c47176aeb3d00469 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 6 Aug 2013 21:54:07 +0200
Subject: [PATCH 115/133] [maven-release-plugin] prepare release
plexus-utils-3.0.14
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 2366ba11..2d18f38f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.14-SNAPSHOT
+ 3.0.14Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
From d5fdf54d84dba41ac54d50974b8ddbedf374c9d3 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 6 Aug 2013 21:54:15 +0200
Subject: [PATCH 116/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 2d18f38f..14d3df6e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.14
+ 3.0.15-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
From 02eed78e4abcfad06de8014f5f7623cb26ad34f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Boutemy?=
Date: Sun, 18 Aug 2013 22:19:09 +0200
Subject: [PATCH 117/133] fixed javadoc
---
src/main/java/org/codehaus/plexus/util/FileUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 59ac1186..e1100162 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -145,7 +145,7 @@ public class FileUtils
private static final long FILE_COPY_BUFFER_SIZE = ONE_MB * 30;
/**
- * The vm line separator
+ * The vm file separator
*/
public static String FS = System.getProperty( "file.separator" );
From 1267e1b1126bb3d89b1fd60901370c8b6bcd3d60 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 19 Aug 2013 21:29:20 +0200
Subject: [PATCH 118/133] Revert "Added buffering of FileInputStream"
This reverts commit 3217c5d2c9d56a3a849d9325ebeaebfa6a583eb4.
Unsure about overall effect of this, tests seem inconclusive.
---
src/main/java/org/codehaus/plexus/util/ReaderFactory.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
index eab0af1c..c9fe9927 100644
--- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
@@ -16,7 +16,6 @@
* limitations under the License.
*/
-import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -201,9 +200,7 @@ public static Reader newReader( InputStream in, String encoding )
public static Reader newReader( File file, String encoding )
throws FileNotFoundException, UnsupportedEncodingException
{
- FileInputStream in = new FileInputStream( file );
- BufferedInputStream bis = new BufferedInputStream( in, 32768 );
- return new InputStreamReader( bis, encoding );
+ return new InputStreamReader( new FileInputStream(file), encoding );
}
/**
From ad6d1ad6b3edbc4b4a2f26e31ae94babbb07513c Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 19 Aug 2013 21:35:53 +0200
Subject: [PATCH 119/133] Added comments about unbuffered reader
---
src/main/java/org/codehaus/plexus/util/ReaderFactory.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
index c9fe9927..8eddfdf9 100644
--- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
@@ -190,6 +190,8 @@ public static Reader newReader( InputStream in, String encoding )
/**
* Create a new Reader with specified encoding.
*
+ * Note that there is no buffering on this reader, which favours clients that read into large buffers (8K+).
+ *
* @param file not null file.
* @param encoding not null supported encoding.
* @return a reader instance for the input file using the given encoding.
From 3b271b43f9e5021b4232fc2ffdfb4e469c7f8685 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 19 Aug 2013 21:55:42 +0200
Subject: [PATCH 120/133] [maven-release-plugin] prepare release
plexus-utils-3.0.15
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 14d3df6e..70967027 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.15-SNAPSHOT
+ 3.0.15Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- plexus-utils-3.0.14
+ plexus-utils-3.0.15JIRA
From f2beca21c75084986b49b3ab7b5f0f988021dcea Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 19 Aug 2013 21:55:50 +0200
Subject: [PATCH 121/133] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 70967027..7ded25f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ limitations under the License.
plexus-utils
- 3.0.15
+ 3.0.16-SNAPSHOTPlexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -38,7 +38,7 @@ limitations under the License.
scm:git:git@github.com:sonatype/plexus-utils.gitscm:git:git@github.com:sonatype/plexus-utils.githttp://github.com/sonatype/plexus-utils
- plexus-utils-3.0.15
+ plexus-utils-3.0.14JIRA
From 86c37983bb2bd92b1df43fe73f321ffbfa155070 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Mon, 19 Aug 2013 22:06:31 +0200
Subject: [PATCH 122/133] Upped buffer size
---
src/main/java/org/codehaus/plexus/util/IOUtil.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java
index 633c1b2e..4045a7f4 100644
--- a/src/main/java/org/codehaus/plexus/util/IOUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java
@@ -153,7 +153,7 @@
public final class IOUtil
{
- private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 16;
/**
* Private constructor to prevent instantiation.
From b38a1b3a4352303e4312b2bb601a0d7ec6e28f41 Mon Sep 17 00:00:00 2001
From: Kristian Rosenvold
Date: Tue, 8 Oct 2013 18:21:04 +0200
Subject: [PATCH 123/133] [PLXUTILS-161] Commandline shell injection problems
Patch by Charles Duffy, applied unmodified
---
.../codehaus/plexus/util/cli/Commandline.java | 38 +++++++++---
.../plexus/util/cli/shell/BourneShell.java | 60 ++++++-------------
.../codehaus/plexus/util/cli/shell/Shell.java | 35 ++++++++---
.../plexus/util/cli/CommandlineTest.java | 37 +++++++-----
.../util/cli/shell/BourneShellTest.java | 19 +++---
5 files changed, 107 insertions(+), 82 deletions(-)
diff --git a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
index 5e0d5af4..7346c7ef 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
@@ -139,6 +139,8 @@ public class Commandline
* Create a new command line object.
* Shell is autodetected from operating system
*
+ * Shell usage is only desirable when generating code for remote execution.
+ *
* @param toProcess
*/
public Commandline( String toProcess, Shell shell )
@@ -167,6 +169,8 @@ public Commandline( String toProcess, Shell shell )
/**
* Create a new command line object.
* Shell is autodetected from operating system
+ *
+ * Shell usage is only desirable when generating code for remote execution.
*/
public Commandline( Shell shell )
{
@@ -174,8 +178,7 @@ public Commandline( Shell shell )
}
/**
- * Create a new command line object.
- * Shell is autodetected from operating system
+ * Create a new command line object, given a command following POSIX sh quoting rules
*
* @param toProcess
*/
@@ -203,7 +206,6 @@ public Commandline( String toProcess )
/**
* Create a new command line object.
- * Shell is autodetected from operating system
*/
public Commandline()
{
@@ -253,7 +255,7 @@ public int getPosition()
{
if ( realPos == -1 )
{
- realPos = ( getExecutable() == null ? 0 : 1 );
+ realPos = ( getLiteralExecutable() == null ? 0 : 1 );
for ( int i = 0; i < position; i++ )
{
Arg arg = (Arg) arguments.elementAt( i );
@@ -404,6 +406,21 @@ public void setExecutable( String executable )
this.executable = executable;
}
+ /**
+ * @return Executable to be run, as a literal string (no shell quoting/munging)
+ */
+ public String getLiteralExecutable()
+ {
+ return executable;
+ }
+
+ /**
+ * Return an executable name, quoted for shell use.
+ *
+ * Shell usage is only desirable when generating code for remote execution.
+ *
+ * @return Executable to be run, quoted for shell interpretation
+ */
public String getExecutable()
{
String exec = shell.getExecutable();
@@ -483,7 +500,7 @@ public String[] getEnvironmentVariables()
public String[] getCommandline()
{
final String[] args = getArguments();
- String executable = getExecutable();
+ String executable = getLiteralExecutable();
if ( executable == null )
{
@@ -497,6 +514,8 @@ public String[] getCommandline()
/**
* Returns the shell, executable and all defined arguments.
+ *
+ * Shell usage is only desirable when generating code for remote execution.
*/
public String[] getShellCommandline()
{
@@ -633,7 +652,7 @@ public Process execute()
{
if ( workingDir == null )
{
- process = Runtime.getRuntime().exec( getShellCommandline(), environment );
+ process = Runtime.getRuntime().exec( getCommandline(), environment, workingDir );
}
else
{
@@ -648,7 +667,7 @@ else if ( !workingDir.isDirectory() )
+ "\" does not specify a directory." );
}
- process = Runtime.getRuntime().exec( getShellCommandline(), environment, workingDir );
+ process = Runtime.getRuntime().exec( getCommandline(), environment, workingDir );
}
}
catch ( IOException ex )
@@ -669,7 +688,7 @@ private void verifyShellState()
shell.setWorkingDirectory( workingDir );
}
- if ( shell.getExecutable() == null )
+ if ( shell.getOriginalExecutable() == null )
{
shell.setExecutable( executable );
}
@@ -684,6 +703,8 @@ public Properties getSystemEnvVars()
/**
* Allows to set the shell to be used in this command line.
*
+ * Shell usage is only desirable when generating code for remote execution.
+ *
* @param shell
* @since 1.2
*/
@@ -695,6 +716,7 @@ public void setShell( Shell shell )
/**
* Get the shell to be used in this command line.
*
+ * Shell usage is only desirable when generating code for remote execution.
* @since 1.2
*/
public Shell getShell()
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
index d3432820..9bf3a09f 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
@@ -17,7 +17,6 @@
*/
import org.codehaus.plexus.util.Os;
-import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@@ -29,34 +28,18 @@
public class BourneShell
extends Shell
{
- private static final char[] BASH_QUOTING_TRIGGER_CHARS = {
- ' ',
- '$',
- ';',
- '&',
- '|',
- '<',
- '>',
- '*',
- '?',
- '(',
- ')',
- '[',
- ']',
- '{',
- '}',
- '`' };
public BourneShell()
{
- this( false );
+ this(false);
}
public BourneShell( boolean isLoginShell )
{
+ setUnconditionalQuoting( true );
setShellCommand( "/bin/sh" );
setArgumentQuoteDelimiter( '\'' );
- setExecutableQuoteDelimiter( '\"' );
+ setExecutableQuoteDelimiter( '\'' );
setSingleQuotedArgumentEscaped( true );
setSingleQuotedExecutableEscaped( false );
setQuotedExecutableEnabled( true );
@@ -76,7 +59,7 @@ public String getExecutable()
return super.getExecutable();
}
- return unifyQuotes( super.getExecutable());
+ return quoteOneItem( super.getOriginalExecutable(), true );
}
public List getShellArgsList()
@@ -126,46 +109,41 @@ protected String getExecutionPreamble()
StringBuilder sb = new StringBuilder();
sb.append( "cd " );
- sb.append( unifyQuotes( dir ) );
+ sb.append( quoteOneItem( dir, false ) );
sb.append( " && " );
return sb.toString();
}
- protected char[] getQuotingTriggerChars()
- {
- return BASH_QUOTING_TRIGGER_CHARS;
- }
-
/**
*
Using simple dotted expressions to extract the values from an Object instance,
- * For example we might want to extract a value like: project.build.sourceDirectory
- *
- *
The implementation supports indexed, nested and mapped properties similar to the JSP way.
- *
+ *
+ * Using simple dotted expressions to extract the values from an Object instance, For example we might want to extract a
+ * value like: project.build.sourceDirectory
+ *
+ *
+ * The implementation supports indexed, nested and mapped properties similar to the JSP way.
+ *
+ *
* @author Jason van Zyl
* @author Vincent Siveton
* @version $Id$
- * @see http://struts.apache.org/1.x/struts-taglib/indexedprops.html
+ * @see http://struts.apache.org/1.x/struts-taglib/indexedprops.html
*/
public class ReflectionValueExtractor
{
- private static final Class[] CLASS_ARGS = new Class[0];
+ private static final Class>[] CLASS_ARGS = new Class[0];
private static final Object[] OBJECT_ARGS = new Object[0];
/**
- * Use a WeakHashMap here, so the keys (Class objects) can be garbage collected.
- * This approach prevents permgen space overflows due to retention of discarded
- * classloaders.
+ * Use a WeakHashMap here, so the keys (Class objects) can be garbage collected. This approach prevents permgen
+ * space overflows due to retention of discarded classloaders.
*/
- private static final Map> classMaps = new WeakHashMap>();
+ private static final Map, WeakReference> classMaps =
+ new WeakHashMap, WeakReference>();
- /**
- * Indexed properties pattern, ie (\\w+)\\[(\\d+)\\]
- */
- private static final Pattern INDEXED_PROPS = Pattern.compile( "(\\w+)\\[(\\d+)\\]" );
+ static final int EOF = -1;
- /**
- * Indexed properties pattern, ie (\\w+)\\((.+)\\)
- */
- private static final Pattern MAPPED_PROPS = Pattern.compile( "(\\w+)\\((.+)\\)" );
+ static final char PROPERTY_START = '.';
+
+ static final char INDEXED_START = '[';
+
+ static final char INDEXED_END = ']';
+
+ static final char MAPPED_START = '(';
+
+ static final char MAPPED_END = ')';
+
+ static class Tokenizer
+ {
+ final String expression;
+
+ int idx;
+
+ public Tokenizer( String expression )
+ {
+ this.expression = expression;
+ }
+
+ public int peekChar()
+ {
+ return idx < expression.length() ? expression.charAt( idx ) : EOF;
+ }
+
+ public int skipChar()
+ {
+ return idx < expression.length() ? expression.charAt( idx++ ) : EOF;
+ }
+
+ public String nextToken( char delimiter )
+ {
+ int start = idx;
+
+ while ( idx < expression.length() && delimiter != expression.charAt( idx ) )
+ {
+ idx++;
+ }
+
+ // delimiter MUST be present
+ if ( idx <= start || idx >= expression.length() )
+ {
+ return null;
+ }
+
+ return expression.substring( start, idx++ );
+ }
+
+ public String nextPropertyName()
+ {
+ final int start = idx;
+
+ while ( idx < expression.length() && Character.isJavaIdentifierPart( expression.charAt( idx ) ) )
+ {
+ idx++;
+ }
+
+ // property name does not require delimiter
+ if ( idx <= start || idx > expression.length() )
+ {
+ return null;
+ }
+
+ return expression.substring( start, idx );
+ }
+
+ public int getPosition()
+ {
+ return idx < expression.length() ? idx : EOF;
+ }
+
+ // to make tokenizer look pretty in debugger
+ @Override
+ public String toString()
+ {
+ return idx < expression.length() ? expression.substring( idx ) : "";
+ }
+ }
private ReflectionValueExtractor()
{
}
/**
- *
The implementation supports indexed, nested and mapped properties.
- *
+ *
+ * The implementation supports indexed, nested and mapped properties.
+ *
*
*
nested properties should be defined by a dot, i.e. "user.address.street"
*
indexed properties (java.util.List or array instance) should be contains (\\w+)\\[(\\d+)\\]
* pattern, i.e. "user.addresses[1].street"
- *
mapped properties should be contains (\\w+)\\((.+)\\) pattern, i.e. "user.addresses(myAddress).street"
+ *
mapped properties should be contains (\\w+)\\((.+)\\) pattern, i.e.
+ * "user.addresses(myAddress).street"
*
- *
+ *
* @param expression not null expression
* @param root not null object
* @return the object defined by the expression
@@ -85,30 +164,26 @@ public static Object evaluate( String expression, Object root )
}
/**
- *
The implementation supports indexed, nested and mapped properties.
- *
+ *
+ * The implementation supports indexed, nested and mapped properties.
+ *
*
*
nested properties should be defined by a dot, i.e. "user.address.street"
*
indexed properties (java.util.List or array instance) should be contains (\\w+)\\[(\\d+)\\]
* pattern, i.e. "user.addresses[1].street"
- *
mapped properties should be contains (\\w+)\\((.+)\\) pattern, i.e. "user.addresses(myAddress).street"
+ *
mapped properties should be contains (\\w+)\\((.+)\\) pattern, i.e.
+ * "user.addresses(myAddress).street"
*
- *
+ *
* @param expression not null expression
* @param root not null object
* @return the object defined by the expression
* @throws Exception if any
*/
// TODO: don't throw Exception
- public static Object evaluate( String expression, Object root, boolean trimRootToken )
+ public static Object evaluate( final String expression, final Object root, final boolean trimRootToken )
throws Exception
{
- // if the root token refers to the supplied root object parameter, remove it.
- if ( trimRootToken )
- {
- expression = expression.substring( expression.indexOf( '.' ) + 1 );
- }
-
Object value = root;
// ----------------------------------------------------------------------
@@ -116,131 +191,166 @@ public static Object evaluate( String expression, Object root, boolean trimRootT
// MavenProject instance.
// ----------------------------------------------------------------------
- StringTokenizer parser = new StringTokenizer( expression, "." );
+ if ( StringUtils.isEmpty( expression ) || !Character.isJavaIdentifierStart( expression.charAt( 0 ) ) )
+ {
+ return null;
+ }
- while ( parser.hasMoreTokens() )
+ final Tokenizer tokenizer;
+ if ( trimRootToken )
{
- // if we have nothing, stop now
- if ( value == null )
+ tokenizer = new Tokenizer( expression );
+ tokenizer.nextPropertyName();
+ }
+ else
+ {
+ tokenizer = new Tokenizer( "." + expression );
+ }
+
+ int propertyPosition = tokenizer.getPosition();
+ while ( value != null && tokenizer.peekChar() != EOF )
+ {
+ switch ( tokenizer.skipChar() )
{
- return null;
+ case INDEXED_START:
+ value =
+ getIndexedValue( expression, propertyPosition, tokenizer.getPosition(), value,
+ tokenizer.nextToken( INDEXED_END ) );
+ break;
+ case MAPPED_START:
+ value =
+ getMappedValue( expression, propertyPosition, tokenizer.getPosition(), value,
+ tokenizer.nextToken( MAPPED_END ) );
+ break;
+ case PROPERTY_START:
+ propertyPosition = tokenizer.getPosition();
+ value = getPropertyValue( value, tokenizer.nextPropertyName() );
+ break;
+ default:
+ // could not parse expression
+ return null;
}
+ }
- String token = parser.nextToken();
+ return value;
+ }
+ private static Object getMappedValue( final String expression, final int from, final int to, final Object value,
+ final String key )
+ throws Exception
+ {
+ if ( value == null || key == null )
+ {
+ return null;
+ }
+
+ if ( value instanceof Map )
+ {
+ Object[] localParams = new Object[] { key };
ClassMap classMap = getClassMap( value.getClass() );
+ Method method = classMap.findMethod( "get", localParams );
+ return method.invoke( value, localParams );
+ }
+
+ final String message =
+ String.format( "The token '%s' at position '%d' refers to a java.util.Map, but the value seems is an instance of '%s'",
+ expression.subSequence( from, to ), from, value.getClass() );
- Method method;
- Object[] localParams = OBJECT_ARGS;
+ throw new Exception( message );
+ }
- // do we have an indexed property?
- Matcher matcher = INDEXED_PROPS.matcher( token );
- if ( matcher.find() )
+ private static Object getIndexedValue( final String expression, final int from, final int to, final Object value,
+ final String indexStr )
+ throws Exception
+ {
+ try
+ {
+ int index = Integer.parseInt( indexStr );
+
+ if ( value.getClass().isArray() )
{
- String methodBase = StringUtils.capitalizeFirstLetter( matcher.group( 1 ) );
- String methodName = "get" + methodBase;
- method = classMap.findMethod( methodName, CLASS_ARGS );
- value = method.invoke( value, OBJECT_ARGS );
- classMap = getClassMap( value.getClass() );
-
- if ( classMap.getCachedClass().isArray() )
- {
- value = Arrays.asList( (Object[]) value );
- classMap = getClassMap( value.getClass() );
- }
-
- if ( value instanceof List )
- {
- // use get method on List interface
- localParams = new Object[1];
- localParams[0] = Integer.valueOf( matcher.group( 2 ) );
- method = classMap.findMethod( "get", localParams );
- }
- else
- {
- throw new Exception( "The token '" + token
- + "' refers to a java.util.List or an array, but the value seems is an instance of '"
- + value.getClass() + "'." );
- }
+ return Array.get( value, index );
}
- else
+
+ if ( value instanceof List )
{
- // do we have a mapped property?
- matcher = MAPPED_PROPS.matcher( token );
- if ( matcher.find() )
- {
- String methodBase = StringUtils.capitalizeFirstLetter( matcher.group( 1 ) );
- String methodName = "get" + methodBase;
- method = classMap.findMethod( methodName, CLASS_ARGS );
- value = method.invoke( value, OBJECT_ARGS );
- classMap = getClassMap( value.getClass() );
-
- if ( value instanceof Map )
- {
- // use get method on List interface
- localParams = new Object[1];
- localParams[0] = matcher.group( 2 );
- method = classMap.findMethod( "get", localParams );
- }
- else
- {
- throw new Exception( "The token '" + token
- + "' refers to a java.util.Map, but the value seems is an instance of '"
- + value.getClass() + "'." );
- }
- }
- else
- {
- String methodBase = StringUtils.capitalizeFirstLetter( token );
- String methodName = "get" + methodBase;
- method = classMap.findMethod( methodName, CLASS_ARGS );
-
- if ( method == null )
- {
- // perhaps this is a boolean property??
- methodName = "is" + methodBase;
-
- method = classMap.findMethod( methodName, CLASS_ARGS );
- }
- }
+ ClassMap classMap = getClassMap( value.getClass() );
+ // use get method on List interface
+ Object[] localParams = new Object[] { index };
+ Method method = classMap.findMethod( "get", localParams );
+ return method.invoke( value, localParams );
}
-
- if ( method == null )
+ }
+ catch ( NumberFormatException e )
+ {
+ return null;
+ }
+ catch ( InvocationTargetException e )
+ {
+ // catch array index issues gracefully, otherwise release
+ if ( e.getCause() instanceof IndexOutOfBoundsException )
{
return null;
}
- try
- {
- value = method.invoke( value, localParams );
- }
- catch ( InvocationTargetException e )
- {
- // catch array index issues gracefully, otherwise release
- if ( e.getCause() instanceof IndexOutOfBoundsException )
- {
- return null;
- }
+ throw e;
+ }
- throw e;
- }
+ final String message =
+ String.format( "The token '%s' at position '%d' refers to a java.util.List or an array, but the value seems is an instance of '%s'",
+ expression.subSequence( from, to ), from, value.getClass() );
+
+ throw new Exception( message );
+ }
+
+ private static Object getPropertyValue( Object value, String property )
+ throws Exception
+ {
+ if ( value == null || property == null )
+ {
+ return null;
}
- return value;
+ ClassMap classMap = getClassMap( value.getClass() );
+ String methodBase = StringUtils.capitalizeFirstLetter( property );
+ String methodName = "get" + methodBase;
+ Method method = classMap.findMethod( methodName, CLASS_ARGS );
+
+ if ( method == null )
+ {
+ // perhaps this is a boolean property??
+ methodName = "is" + methodBase;
+
+ method = classMap.findMethod( methodName, CLASS_ARGS );
+ }
+
+ if ( method == null )
+ {
+ return null;
+ }
+
+ try
+ {
+ return method.invoke( value, OBJECT_ARGS );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw e;
+ }
}
- private static ClassMap getClassMap( Class clazz )
+ private static ClassMap getClassMap( Class> clazz )
{
- WeakReference softRef = classMaps.get( clazz);
+ WeakReference softRef = classMaps.get( clazz );
ClassMap classMap;
- if ( softRef == null || (classMap = softRef.get() ) == null)
+ if ( softRef == null || ( classMap = softRef.get() ) == null )
{
classMap = new ClassMap( clazz );
- classMaps.put( clazz, new WeakReference(classMap) );
+ classMaps.put( clazz, new WeakReference( classMap ) );
}
return classMap;
diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java
index d09bce95..f620176a 100644
--- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java
+++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java
@@ -16,15 +16,15 @@
* limitations under the License.
*/
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.ArrayList;
import java.util.Map;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
/**
* @author Jason van Zyl
* @version $Id$
@@ -40,9 +40,9 @@ protected void setUp()
super.setUp();
Dependency dependency1 = new Dependency();
- dependency1.setArtifactId("dep1");
+ dependency1.setArtifactId( "dep1" );
Dependency dependency2 = new Dependency();
- dependency2.setArtifactId("dep2");
+ dependency2.setArtifactId( "dep2" );
project = new Project();
project.setModelVersion( "4.0.0" );
@@ -95,39 +95,39 @@ public void testValueExtraction()
// ----------------------------------------------------------------------
// List
- Dependency dependency = (Dependency)ReflectionValueExtractor.evaluate( "project.dependencies[0]", project );
+ Dependency dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependencies[0]", project );
Assert.assertNotNull( dependency );
- Assert.assertTrue( "dep1".equals(dependency.getArtifactId()) );
+ Assert.assertTrue( "dep1".equals( dependency.getArtifactId() ) );
- String artifactId = (String)ReflectionValueExtractor.evaluate( "project.dependencies[1].artifactId", project );
+ String artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependencies[1].artifactId", project );
- Assert.assertTrue( "dep2".equals(artifactId) );
+ Assert.assertTrue( "dep2".equals( artifactId ) );
// Array
- dependency = (Dependency)ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[0]", project );
+ dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[0]", project );
Assert.assertNotNull( dependency );
- Assert.assertTrue( "dep1".equals(dependency.getArtifactId()) );
+ Assert.assertTrue( "dep1".equals( dependency.getArtifactId() ) );
- artifactId = (String)ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[1].artifactId", project );
+ artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[1].artifactId", project );
- Assert.assertTrue( "dep2".equals(artifactId) );
+ Assert.assertTrue( "dep2".equals( artifactId ) );
// Map
- dependency = (Dependency)ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep1)", project );
+ dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep1)", project );
Assert.assertNotNull( dependency );
- Assert.assertTrue( "dep1".equals(dependency.getArtifactId()) );
+ Assert.assertTrue( "dep1".equals( dependency.getArtifactId() ) );
- artifactId = (String)ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep2).artifactId", project );
+ artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep2).artifactId", project );
- Assert.assertTrue( "dep2".equals(artifactId) );
+ Assert.assertTrue( "dep2".equals( artifactId ) );
// ----------------------------------------------------------------------
// Build
@@ -146,6 +146,112 @@ public void testValueExtractorWithAInvalidExpression()
Assert.assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[0].foo", project ) );
}
+ public void testMappedDottedKey()
+ throws Exception
+ {
+ Map map = new HashMap();
+ map.put( "a.b", "a.b-value" );
+
+ Assert.assertEquals( "a.b-value", ReflectionValueExtractor.evaluate( "h.value(a.b)", new ValueHolder( map ) ) );
+ }
+
+ public void testIndexedMapped()
+ throws Exception
+ {
+ Map