You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/01/04 15:18:33 UTC
[maven-javadoc-plugin] branch MJAVADOC-527 updated: Few improvements
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch MJAVADOC-527
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/MJAVADOC-527 by this push:
new 5d7e2cf Few improvements
5d7e2cf is described below
commit 5d7e2cf528d127ab20c3d838f352d4f66a446b7d
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Fri Jan 4 16:18:22 2019 +0100
Few improvements
---
.../apache/maven/plugins/javadoc/JavadocUtil.java | 58 ++++++++++------------
.../plugins/javadoc/AbstractJavadocMojoTest.java | 6 +--
2 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index 7b21981..8c4f4f9 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -33,13 +33,10 @@ import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.client.RedirectLocations;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpContext;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Proxy;
@@ -130,7 +127,7 @@ public class JavadocUtil
public static Collection<Path> pruneDirs( MavenProject project, Collection<String> dirs )
{
final Path projectBasedir = project.getBasedir().toPath();
-
+
Set<Path> pruned = new LinkedHashSet<>( dirs.size() );
for ( String dir : dirs )
{
@@ -174,7 +171,7 @@ public class JavadocUtil
/**
* Determine whether a file should be excluded from the provided list of paths, based on whether it exists and is
* already present in the list.
- *
+ *
* @param f The files.
* @param pruned The list of pruned files..
* @return true if the file could be pruned false otherwise.
@@ -346,7 +343,7 @@ public class JavadocUtil
Collection<String> excludePackages )
{
List<String> files = new ArrayList<>();
-
+
List<Pattern> excludePackagePatterns = new ArrayList<>( excludePackages.size() );
for ( String excludePackage : excludePackages )
{
@@ -368,7 +365,7 @@ public class JavadocUtil
break;
}
}
-
+
if ( !excluded )
{
files.add( file );
@@ -390,9 +387,9 @@ public class JavadocUtil
Collection<String> excludePackagenames )
{
final String regexFileSeparator = File.separator.replace( "\\", "\\\\" );
-
+
final Collection<String> fileList = new ArrayList<>();
-
+
try
{
Files.walkFileTree( sourceDirectory, new SimpleFileVisitor<Path>()
@@ -417,15 +414,15 @@ public class JavadocUtil
List<String> files = new ArrayList<>();
for ( String excludePackagename : excludePackagenames )
{
- // Usage of wildcard was bad specified and bad implemented, i.e. using String.contains()
+ // Usage of wildcard was bad specified and bad implemented, i.e. using String.contains()
// without respecting surrounding context
- // Following implementation should match requirements as defined in the examples:
+ // Following implementation should match requirements as defined in the examples:
// - A wildcard at the beginning should match 1 or more folders
// - Any other wildcard must match exactly one folder
Pattern p = Pattern.compile( excludePackagename.replace( ".", regexFileSeparator )
.replaceFirst( "^\\*", ".+" )
.replace( "*", "[^" + regexFileSeparator + "]+" ) );
-
+
for ( String aFileList : fileList )
{
if ( p.matcher( aFileList ).matches() )
@@ -479,7 +476,7 @@ public class JavadocUtil
/**
* Call the Javadoc tool and parse its output to find its version, i.e.:
- *
+ *
* <pre>
* javadoc.exe( or.sh ) - J - version
* </pre>
@@ -948,7 +945,7 @@ public class JavadocUtil
/**
* Split the given path with colon and semi-colon, to support Solaris and Windows path. Examples:
- *
+ *
* <pre>
* splitPath( "/home:/tmp" ) = ["/home", "/tmp"]
* splitPath( "/home;/tmp" ) = ["/home", "/tmp"]
@@ -980,7 +977,7 @@ public class JavadocUtil
/**
* Unify the given path with the current System path separator, to be platform independent. Examples:
- *
+ *
* <pre>
* unifyPathSeparator( "/home:/tmp" ) = "/home:/tmp" (Solaris box)
* unifyPathSeparator( "/home:/tmp" ) = "/home;/tmp" (Windows box)
@@ -1428,7 +1425,7 @@ public class JavadocUtil
/**
* Ignores line like 'Picked up JAVA_TOOL_OPTIONS: ...' as can happen on CI servers.
- *
+ *
* @author Robert Scholte
* @since 3.0.1
*/
@@ -1635,7 +1632,7 @@ public class JavadocUtil
return true;
}
}
-
+
protected static boolean isValidElementList( URL url, Settings settings, boolean validateContent )
throws IOException
{
@@ -1654,7 +1651,7 @@ public class JavadocUtil
{
continue;
}
-
+
if ( !isValidPackageName( line ) )
{
return false;
@@ -1664,11 +1661,11 @@ public class JavadocUtil
return true;
}
}
-
+
private static BufferedReader getReader( URL url, Settings settings ) throws IOException
{
BufferedReader reader = null;
-
+
if ( "file".equals( url.getProtocol() ) )
{
// Intentionally using the platform default encoding here since this is what Javadoc uses internally.
@@ -1680,17 +1677,17 @@ public class JavadocUtil
final HttpClient httpClient = createHttpClient( settings, url );
final HttpGet httpMethod = new HttpGet( url.toString() );
-
+
HttpResponse response;
- HttpContext context = new BasicHttpContext();
+ HttpClientContext httpContext = HttpClientContext.create();
try
{
- response = httpClient.execute( httpMethod, context );
+ response = httpClient.execute( httpMethod, httpContext );
}
catch ( SocketTimeoutException e )
{
// could be a sporadic failure, one more retry before we give up
- response = httpClient.execute( httpMethod, context );
+ response = httpClient.execute( httpMethod, httpContext );
}
int status = response.getStatusLine().getStatusCode();
@@ -1702,14 +1699,13 @@ public class JavadocUtil
else
{
int pos = url.getPath().lastIndexOf( '/' );
- RedirectLocations redirects = (RedirectLocations)
- context.getAttribute( "http.protocol.redirect-locations" );
- if ( pos >= 0 && redirects != null )
+ List<URI> redirects = httpContext.getRedirectLocations();
+ if ( pos >= 0 && isNotEmpty( redirects ) )
{
URI location = redirects.get( redirects.size() - 1 );
String suffix = url.getPath().substring( pos );
// Redirections shall point to the same file, e.g. /package-list
- if ( !location.toURL().getPath().endsWith( suffix ) )
+ if ( !location.getPath().endsWith( suffix ) )
{
throw new FileNotFoundException( url.toExternalForm() + " redirects to "
+ location.toURL().toExternalForm() + "." );
@@ -1718,14 +1714,14 @@ public class JavadocUtil
}
// Intentionally using the platform default encoding here since this is what Javadoc uses internally.
- reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent() ) )
+ reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent() ) )
{
@Override
public void close()
throws IOException
{
super.close();
-
+
if ( httpMethod != null )
{
httpMethod.releaseConnection();
@@ -1737,7 +1733,7 @@ public class JavadocUtil
}
};
}
-
+
return reader;
}
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
index 83dbb3d..1432492 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
@@ -39,7 +39,7 @@ public class AbstractJavadocMojoTest
extends TestCase
{
AbstractJavadocMojo mojo;
-
+
@Override
protected void setUp()
throws Exception
@@ -54,7 +54,7 @@ public class AbstractJavadocMojoTest
}
};
}
-
+
public void testMJAVADOC432_DetectLinksMessages()
{
Log log = mock( Log.class );
@@ -76,7 +76,7 @@ public class AbstractJavadocMojoTest
verify( log, times( 4 ) ).error( anyString() );
verify( log, times( 4 ) ).warn( anyString() ); // no extra warnings
}
-
+
public void testMJAVADOC527_DetectLinksRecursion()
{
Log log = mock( Log.class );