Author: carlos
Date: Tue Jul 25 09:00:44 2006
New Revision: 425435

URL: http://svn.apache.org/viewvc?rev=425435&view=rev
Log:
Merged rev# 425101, 425102 from trunk. Avoid code duplication

Added:
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
   (with props)
    
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/
    
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
   (with props)
    
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
   (with props)
    
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
   (with props)
Modified:
    maven/components/branches/maven-2.0.x/maven-core/   (props changed)
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java

Propchange: maven/components/branches/maven-2.0.x/maven-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jul 25 09:00:44 2006
@@ -11,3 +11,4 @@
 .classpath
 .project
 build.xml
+cobertura.ser

Added: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java?rev=425435&view=auto
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
 (added)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
 Tue Jul 25 09:00:44 2006
@@ -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.wagon.WagonConstants;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.apache.maven.wagon.events.TransferListener;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * Abstract console download progress meter.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a>
+ * @version $Id$
+ * @since 2.0.5
+ */
+public abstract class AbstractConsoleDownloadMonitor
+    extends AbstractLogEnabled
+    implements TransferListener
+{
+
+    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 );
+    }
+
+}

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java?rev=425435&r1=425434&r2=425435&view=diff
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
 Tue Jul 25 09:00:44 2006
@@ -1,79 +1,39 @@
-package org.apache.maven.cli;
-
-/*
- * Copyright 2001-2005 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.wagon.WagonConstants;
-import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-/**
- * Console download progress meter.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
- * @version $Id: ConsoleDownloadMonitor.java 169548 2005-05-11 01:04:50Z brett 
$
- */
-public class BatchModeDownloadMonitor
-    extends AbstractLogEnabled
-    implements TransferListener
-{
-    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() );
-    }
-
-    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 );
-    }
-}
-
-
-
+package org.apache.maven.cli;
+
+/*
+ * 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.
+ * 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.wagon.events.TransferEvent;
+
+/**
+ * Console download progress meter.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ * @version $Id: ConsoleDownloadMonitor.java 169548 2005-05-11 01:04:50Z brett 
$
+ */
+public class BatchModeDownloadMonitor
+    extends AbstractConsoleDownloadMonitor
+{
+    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() );
+    }
+}

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java?rev=425435&r1=425434&r2=425435&view=diff
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
 Tue Jul 25 09:00:44 2006
@@ -18,8 +18,6 @@
 
 import org.apache.maven.wagon.WagonConstants;
 import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 /**
  * Console download progress meter.
@@ -28,8 +26,7 @@
  * @version $Id$
  */
 public class ConsoleDownloadMonitor
-    extends AbstractLogEnabled
-    implements TransferListener
+    extends AbstractConsoleDownloadMonitor
 {
     private long complete;
 
@@ -66,30 +63,5 @@
             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 );
-    }
 }
-
-
 

Added: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java?rev=425435&view=auto
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
 (added)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
 Tue Jul 25 09:00:44 2006
@@ -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 [EMAIL PROTECTED] AbstractConsoleDownloadMonitor}
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a>
+ * @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 );
+        }
+    }
+}

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java?rev=425435&view=auto
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
 (added)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
 Tue Jul 25 09:00:44 2006
@@ -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 [EMAIL PROTECTED] BatchModeDownloadMonitor}
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class BatchModeDownloadMonitorTest
+    extends AbstractConsoleDownloadMonitorTest
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setMonitor( new BatchModeDownloadMonitor() );
+        super.setUp();
+    }
+}

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java?rev=425435&view=auto
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
 (added)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
 Tue Jul 25 09:00:44 2006
@@ -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 [EMAIL PROTECTED] ConsoleDownloadMonitor}
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class ConsoleDownloadMonitorTest
+    extends AbstractConsoleDownloadMonitorTest
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setMonitor( new ConsoleDownloadMonitor() );
+        super.setUp();
+    }
+}

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/maven-2.0.x/maven-core/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"


Reply via email to