diff --git a/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java b/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
new file mode 100644
index 0000000000..29519c83e5
--- /dev/null
+++ b/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
@@ -0,0 +1,88 @@
+package org.apache.maven.cli;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.MavenTransferListener;
+import org.apache.maven.wagon.WagonConstants;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * Abstract console download progress meter.
+ *
+ * @author Carlos Sanchez
+ * @version $Id$
+ * @since 2.0.5
+ */
+public abstract class AbstractConsoleDownloadMonitor
+ extends AbstractLogEnabled
+ implements MavenTransferListener
+{
+
+ public void transferInitiated( TransferEvent transferEvent )
+ {
+ String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
+
+ String url = transferEvent.getWagon().getRepository().getUrl();
+
+ // TODO: can't use getLogger() because this isn't currently instantiated as a component
+ System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
+ }
+
+ /**
+ * Do nothing
+ */
+ public void transferStarted( TransferEvent transferEvent )
+ {
+ // This space left intentionally blank
+ }
+
+ /**
+ * Do nothing
+ */
+ public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
+ {
+ // This space left intentionally blank
+ }
+
+ public void transferCompleted( TransferEvent transferEvent )
+ {
+ long contentLength = transferEvent.getResource().getContentLength();
+ if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
+ {
+ String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
+ String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
+ System.out.println( l + " " + type );
+ }
+ }
+
+ public void transferError( TransferEvent transferEvent )
+ {
+ // TODO: can't use getLogger() because this isn't currently instantiated as a component
+ transferEvent.getException().printStackTrace();
+ }
+
+ /**
+ * Do nothing
+ */
+ public void debug( String message )
+ {
+ // TODO: can't use getLogger() because this isn't currently instantiated as a component
+// getLogger().debug( message );
+ }
+
+}
\ No newline at end of file
diff --git a/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java b/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
index 9a71cdaae9..ba1a34463d 100644
--- a/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
+++ b/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
@@ -1,7 +1,7 @@
package org.apache.maven.cli;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,7 @@ package org.apache.maven.cli;
* limitations under the License.
*/
-import org.apache.maven.wagon.WagonConstants;
import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.MavenTransferListener;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
* Console download progress meter.
@@ -29,8 +25,7 @@ import org.codehaus.plexus.logging.AbstractLogEnabled;
* @version $Id$
*/
public class BatchModeDownloadMonitor
- extends AbstractLogEnabled
- implements MavenTransferListener
+ extends AbstractConsoleDownloadMonitor
{
public void transferInitiated( TransferEvent transferEvent )
{
@@ -41,40 +36,4 @@ public class BatchModeDownloadMonitor
// TODO: can't use getLogger() because this isn't currently instantiated as a component
System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
}
-
- public void transferStarted( TransferEvent transferEvent )
- {
- // This space left intentionally blank
- }
-
- public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
- {
- // This space left intentionally blank
- }
-
- public void transferCompleted( TransferEvent transferEvent )
- {
- long contentLength = transferEvent.getResource().getContentLength();
- if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
- {
- String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
- String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
- System.out.println( l + " " + type );
- }
- }
-
- public void transferError( TransferEvent transferEvent )
- {
- // TODO: can't use getLogger() because this isn't currently instantiated as a component
- transferEvent.getException().printStackTrace();
- }
-
- public void debug( String message )
- {
- // TODO: can't use getLogger() because this isn't currently instantiated as a component
-// getLogger().debug( message );
- }
}
-
-
-
diff --git a/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java b/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
index b3a29242a1..e76a72d6be 100644
--- a/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
+++ b/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
@@ -18,9 +18,6 @@ package org.apache.maven.cli;
import org.apache.maven.wagon.WagonConstants;
import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.MavenTransferListener;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
* Console download progress meter.
@@ -29,28 +26,17 @@ import org.codehaus.plexus.logging.AbstractLogEnabled;
* @version $Id$
*/
public class ConsoleDownloadMonitor
- extends AbstractLogEnabled
- implements MavenTransferListener
+ extends AbstractConsoleDownloadMonitor
{
private long complete;
public void transferInitiated( TransferEvent transferEvent )
{
- String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
-
- String url = transferEvent.getWagon().getRepository().getUrl();
-
- // TODO: can't use getLogger() because this isn't currently instantiated as a component
- System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
+ super.transferInitiated( transferEvent );
complete = 0;
}
- public void transferStarted( TransferEvent transferEvent )
- {
- // This space left intentionally blank
- }
-
public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
{
long total = transferEvent.getResource().getContentLength();
@@ -67,30 +53,5 @@ public class ConsoleDownloadMonitor
System.out.print( complete + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : total + "b" ) + "\r" );
}
}
-
- public void transferCompleted( TransferEvent transferEvent )
- {
- long contentLength = transferEvent.getResource().getContentLength();
- if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
- {
- String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
- String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
- System.out.println( l + " " + type );
- }
- }
-
- public void transferError( TransferEvent transferEvent )
- {
- // TODO: can't use getLogger() because this isn't currently instantiated as a component
- transferEvent.getException().printStackTrace();
- }
-
- public void debug( String message )
- {
- // TODO: can't use getLogger() because this isn't currently instantiated as a component
-// getLogger().debug( message );
- }
}
-
-
diff --git a/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java b/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
new file mode 100644
index 0000000000..a69459c064
--- /dev/null
+++ b/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
@@ -0,0 +1,113 @@
+package org.apache.maven.cli;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.apache.maven.wagon.providers.file.FileWagon;
+import org.apache.maven.wagon.repository.Repository;
+import org.apache.maven.wagon.resource.Resource;
+
+/**
+ * Test for {@link AbstractConsoleDownloadMonitor}
+ *
+ * @author Carlos Sanchez
+ * @version $Id$
+ */
+public abstract class AbstractConsoleDownloadMonitorTest
+ extends TestCase
+{
+
+ private AbstractConsoleDownloadMonitor monitor;
+
+ public AbstractConsoleDownloadMonitorTest()
+ {
+ super();
+ }
+
+ public void setMonitor( AbstractConsoleDownloadMonitor monitor )
+ {
+ this.monitor = monitor;
+ }
+
+ public AbstractConsoleDownloadMonitor getMonitor()
+ {
+ return monitor;
+ }
+
+ public void testTransferInitiated()
+ throws Exception
+ {
+ monitor.transferInitiated( new TransferEventMock() );
+ }
+
+ public void testTransferStarted()
+ throws Exception
+ {
+ monitor.transferStarted( new TransferEventMock() );
+ }
+
+ public void testTransferProgress()
+ throws Exception
+ {
+ byte[] buffer = new byte[1000];
+ monitor.transferProgress( new TransferEventMock(), buffer, 1000 );
+ }
+
+ public void testTransferCompleted()
+ throws Exception
+ {
+ monitor.transferCompleted( new TransferEventMock() );
+ }
+
+ public void testTransferError()
+ throws Exception
+ {
+ monitor.transferError( new TransferEventMock( new RuntimeException() ) );
+ }
+
+ public void testDebug()
+ throws Exception
+ {
+ monitor.debug( "msg" );
+ }
+
+ private class TransferEventMock
+ extends TransferEvent
+ {
+ public TransferEventMock()
+ throws ConnectionException, AuthenticationException
+ {
+ super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
+ getResource().setContentLength( 100000 );
+ Repository repository = new Repository();
+ getWagon().connect( repository );
+ }
+
+ public TransferEventMock( Exception exception )
+ throws ConnectionException, AuthenticationException
+ {
+ super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
+ getResource().setContentLength( 100000 );
+ Repository repository = new Repository();
+ getWagon().connect( repository );
+ }
+ }
+}
\ No newline at end of file
diff --git a/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java b/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
new file mode 100644
index 0000000000..c3f13c6952
--- /dev/null
+++ b/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
@@ -0,0 +1,35 @@
+package org.apache.maven.cli;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Test for {@link BatchModeDownloadMonitor}
+ *
+ * @author Carlos Sanchez
+ * @version $Id$
+ */
+public class BatchModeDownloadMonitorTest
+ extends AbstractConsoleDownloadMonitorTest
+{
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setMonitor( new BatchModeDownloadMonitor() );
+ super.setUp();
+ }
+}
diff --git a/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java b/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
new file mode 100644
index 0000000000..9e58ea24a9
--- /dev/null
+++ b/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
@@ -0,0 +1,35 @@
+package org.apache.maven.cli;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Test for {@link ConsoleDownloadMonitor}
+ *
+ * @author Carlos Sanchez
+ * @version $Id$
+ */
+public class ConsoleDownloadMonitorTest
+ extends AbstractConsoleDownloadMonitorTest
+{
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setMonitor( new ConsoleDownloadMonitor() );
+ super.setUp();
+ }
+}