maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r425102 - in /maven/components/trunk/maven-cli/src: main/java/org/apache/maven/cli/ test/java/org/apache/maven/cli/
Date Mon, 24 Jul 2006 16:01:08 GMT
Author: carlos
Date: Mon Jul 24 09:01:07 2006
New Revision: 425102

URL: http://svn.apache.org/viewvc?rev=425102&view=rev
Log:
Added AbstractConsoleDownloadMonitor to avoid code duplication 

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

Added: maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java?rev=425102&view=auto
==============================================================================
--- maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
(added)
+++ maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
Mon Jul 24 09:01:07 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.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 <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @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

Propchange: maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/AbstractConsoleDownloadMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java?rev=425102&r1=425101&r2=425102&view=diff
==============================================================================
--- maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
(original)
+++ maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/BatchModeDownloadMonitor.java
Mon Jul 24 09:01:07 2006
@@ -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 @@
  * 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 @@
  * @version $Id$
  */
 public class BatchModeDownloadMonitor
-    extends AbstractLogEnabled
-    implements MavenTransferListener
+    extends AbstractConsoleDownloadMonitor
 {
     public void transferInitiated( TransferEvent transferEvent )
     {
@@ -41,40 +36,4 @@
         // 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 );
-    }
 }
-
-
-

Modified: maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java?rev=425102&r1=425101&r2=425102&view=diff
==============================================================================
--- maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
(original)
+++ maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
Mon Jul 24 09:01:07 2006
@@ -18,9 +18,6 @@
 
 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 @@
  * @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 @@
             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/trunk/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java?rev=425102&view=auto
==============================================================================
--- maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
(added)
+++ maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
Mon Jul 24 09:01:07 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 {@link AbstractConsoleDownloadMonitor}
+ * 
+ * @author <a href="mailto:carlos@apache.org">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 );
+        }
+    }
+}
\ No newline at end of file

Propchange: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/AbstractConsoleDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java?rev=425102&view=auto
==============================================================================
--- maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
(added)
+++ maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
Mon Jul 24 09:01:07 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 {@link BatchModeDownloadMonitor}
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class BatchModeDownloadMonitorTest
+    extends AbstractConsoleDownloadMonitorTest
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setMonitor( new BatchModeDownloadMonitor() );
+        super.setUp();
+    }
+}

Propchange: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java?rev=425102&view=auto
==============================================================================
--- maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
(added)
+++ maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
Mon Jul 24 09:01:07 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 {@link ConsoleDownloadMonitor}
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class ConsoleDownloadMonitorTest
+    extends AbstractConsoleDownloadMonitorTest
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setMonitor( new ConsoleDownloadMonitor() );
+        super.setUp();
+    }
+}

Propchange: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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



Mime
View raw message