Author: vsiveton
Date: Wed Sep  9 12:40:59 2009
New Revision: 812926

URL: http://svn.apache.org/viewvc?rev=812926&view=rev
Log:
o try to prevent Hudson build errors when java.sun.com is down (like this 
morning)

Modified:
    
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
    
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java

Modified: 
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java?rev=812926&r1=812925&r2=812926&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
 (original)
+++ 
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
 Wed Sep  9 12:40:59 2009
@@ -24,6 +24,7 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -427,9 +428,12 @@
         }
 
         assertTrue( contentOptions != null );
-        assertTrue( contentOptions.indexOf( "-link" ) != -1 );
-        assertTrue( contentOptions.indexOf( "http://java.sun.com/j2se/"; ) != -1
-            || contentOptions.indexOf( "http://java.sun.com/javase/"; ) != -1 );
+        if ( JavadocUtilTest.isWebSiteOnline( null, 
getContainer().getLogger(), "http://java.sun.com"; ) )
+        {
+            assertTrue( contentOptions.indexOf( "-link" ) != -1 );
+            assertTrue( contentOptions.indexOf( "http://java.sun.com/j2se/"; ) 
!= -1
+                || contentOptions.indexOf( "http://java.sun.com/javase/"; ) != 
-1 );
+        }
     }
 
     /**
@@ -934,7 +938,10 @@
         assertTrue( FileUtils.fileExists( options.getAbsolutePath() ) );
         String optionsContent = readFile( options );
         // NO -link http://java.sun.com/j2se/1.5.0/docs/api/package-list
-        assertTrue( optionsContent.indexOf( "-link" ) == -1 );
+        if ( JavadocUtilTest.isWebSiteOnline( null, 
getContainer().getLogger(), "http://java.sun.com"; ) )
+        {
+            assertTrue( optionsContent.indexOf( "-link" ) == -1 );
+        }
 
         // real proxy
         ProxyServer proxyServer = null;
@@ -962,7 +969,10 @@
 
             optionsContent = readFile( options );
             // -link http://java.sun.com/j2se/1.5.0/docs/api/package-list
-            assertTrue( optionsContent.indexOf( "-link" ) != -1 );
+            if ( JavadocUtilTest.isWebSiteOnline( null, 
getContainer().getLogger(), "http://java.sun.com"; ) )
+            {
+                assertTrue( optionsContent.indexOf( "-link" ) != -1 );
+            }
             assertTrue( true );
         }
         catch ( Exception e )
@@ -1007,7 +1017,10 @@
 
             optionsContent = readFile( options );
             // -link http://java.sun.com/j2se/1.5.0/docs/api/package-list
-            assertTrue( optionsContent.indexOf( "-link" ) != -1 );
+            if ( JavadocUtilTest.isWebSiteOnline( null, 
getContainer().getLogger(), "http://java.sun.com"; ) )
+            {
+                assertTrue( optionsContent.indexOf( "-link" ) != -1 );
+            }
             assertTrue( true );
         }
         catch ( Exception e )

Modified: 
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java?rev=812926&r1=812925&r2=812926&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java
 (original)
+++ 
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java
 Wed Sep  9 12:40:59 2009
@@ -35,6 +35,7 @@
 import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -288,6 +289,11 @@
         JavadocUtil.fetchURL( settings, url );
         assertTrue( true );
 
+        if ( isWebSiteOnline( settings, getContainer().getLogger(), 
"http://maven.apache.org"; ) )
+        {
+            return;
+        }
+
         url = new URL( 
"http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list"; );
         JavadocUtil.fetchURL( settings, url );
         assertTrue( true );
@@ -531,4 +537,32 @@
 
         assertTrue( EqualsBuilder.reflectionEquals( expected, 
JavadocUtil.pruneDirs( null, list ) ) );
     }
+
+    /**
+     * @param settings could be null
+     * @param logger could be null
+     * @param websiteUrl not null
+     * @return <code>true</code> if we are able to fetch websiteUrl, 
<code>false</code> otherwise.
+     * @since 2.6.1
+     */
+    protected static boolean isWebSiteOnline( Settings settings, Logger 
logger, String websiteUrl )
+    {
+        try
+        {
+            JavadocUtil.fetchURL( settings, new URL( websiteUrl ) );
+            return true;
+        }
+        catch ( IOException e )
+        {
+            if ( logger == null )
+            {
+                e.printStackTrace();
+            }
+            else
+            {
+                logger.fatalError( "Error when fetching " + websiteUrl + ". Is 
it available?" );
+            }
+            return false;
+        }
+    }
 }


Reply via email to