Skip to content

Commit

Permalink
Code cleanup, drop dependency to xalan
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Feb 6, 2021
1 parent 1596b81 commit 38a4bfd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 106 deletions.
5 changes: 0 additions & 5 deletions maven-jxr-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.2</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected String getOutputEncoding()
*/
protected List<String> pruneSourceDirs( List<String> sourceDirs )
{
List<String> pruned = new ArrayList<String>( sourceDirs.size() );
List<String> pruned = new ArrayList<>( sourceDirs.size() );
for ( String dir : sourceDirs )
{
if ( !pruned.contains( dir ) && hasSources( new File( dir ) ) )
Expand Down Expand Up @@ -265,7 +265,7 @@ && hasSources( currentFile ) )
* @throws org.apache.maven.jxr.JxrException
*/
private void createXref( Locale locale, String destinationDirectory, List<String> sourceDirs )
throws IOException, JxrException, MavenReportException
throws IOException, JxrException
{
FileManager fileManager = new FileManager();
PackageManager packageManager = new PackageManager( fileManager );
Expand Down Expand Up @@ -549,11 +549,7 @@ protected void executeReport( Locale locale )
{
createXref( locale, getDestinationDirectory(), sourceDirs );
}
catch ( JxrException e )
{
throw new MavenReportException( "Error while generating the HTML source code of the project.", e );
}
catch ( IOException e )
catch ( JxrException | IOException e )
{
throw new MavenReportException( "Error while generating the HTML source code of the project.", e );
}
Expand All @@ -565,7 +561,6 @@ protected void executeReport( Locale locale )
* Determine the templateDir to use, given javadocTemplatesVersion
*
* @return
* @throws org.apache.maven.reporting.MavenReportException if javadocTemplatesVersion cannot be parsed
*/
private String getTemplateDir()
{
Expand Down Expand Up @@ -618,7 +613,7 @@ private void setJavadocTemplatesVersion()
*/
protected List<String> constructSourceDirs()
{
List<String> sourceDirs = new ArrayList<String>( getSourceRoots() );
List<String> sourceDirs = new ArrayList<>( getSourceRoots() );
if ( isAggregate() )
{
for ( MavenProject project : reactorProjects )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,17 @@
*/

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Site;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.repository.Repository;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XObject;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* Utility class for the jxr report.
*
Expand All @@ -69,10 +56,8 @@ protected static boolean isJavadocAggregated( MavenProject project )
throws IOException
{
// first check conf for obsolete aggregate param.
// CHECKSTYLE_OFF: LineLength
boolean javadocAggregate =
Boolean.valueOf( JxrReportUtil.getMavenJavadocPluginBasicOption( project, "aggregate", "false" ) ).booleanValue();
// CHECKSTYLE_ON: LineLength
boolean javadocAggregate = Boolean.parseBoolean(
JxrReportUtil.getMavenJavadocPluginBasicOption( project, "aggregate", "false" ) );

if ( javadocAggregate )
{
Expand Down Expand Up @@ -113,15 +98,9 @@ protected static String getMavenJavadocPluginBasicOption( MavenProject project,
String defaultValue )
throws IOException
{
List<Object> plugins = new ArrayList<Object>();
for ( Iterator<?> it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext(); )
{
plugins.add( it.next() );
}
for ( Iterator<?> it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); )
{
plugins.add( it.next() );
}
List<Object> plugins = new ArrayList<>();
plugins.addAll( project.getModel().getReporting().getPlugins() );
plugins.addAll( project.getModel().getBuild().getPlugins() );

String pluginArtifactId = MAVEN_JAVADOC_PLUGIN_ARTIFACT_ID;
for ( Object next : plugins )
Expand All @@ -132,10 +111,8 @@ protected static String getMavenJavadocPluginBasicOption( MavenProject project,
{
Plugin plugin = (Plugin) next;

// CHECKSTYLE_OFF: LineLength
// using out-of-box Maven plugins
if ( !isReportPluginMavenJavadoc( pluginArtifactId, plugin ) )
// CHECKSTYLE_ON: LineLength
{
continue;
}
Expand All @@ -161,34 +138,10 @@ protected static String getMavenJavadocPluginBasicOption( MavenProject project,
continue;
}

try
{
StringReader reader = new StringReader( pluginConf.toString() );
InputSource source = new InputSource( reader );
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( source );

XObject obj = XPathAPI.eval( doc, "//configuration/" + optionName );

if ( StringUtils.isNotEmpty( obj.toString() ) )
{
return obj.toString();
}
}
catch ( SAXException e )
{
throw new IOException( "SAXException: " + e.getMessage() );
}
catch ( ParserConfigurationException e )
String attribute = pluginConf.getAttribute( optionName );
if ( StringUtils.isNotEmpty( attribute ) )
{
throw new IOException( "ParserConfigurationException: " + e.getMessage() );
}
catch ( FactoryConfigurationError e )
{
throw new IOException( "FactoryConfigurationError: " + e.getMessage() );
}
catch ( TransformerException e )
{
throw new IOException( "TransformerException: " + e.getMessage() );
return attribute;
}
}

Expand All @@ -204,17 +157,11 @@ protected static String getMavenJavadocPluginBasicOption( MavenProject project,
protected static List<?> getMavenJavadocPlugins( MavenProject project )
throws IOException
{
List<Object> plugins = new ArrayList<Object>();
for ( Iterator<?> it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext(); )
{
plugins.add( it.next() );
}
for ( Iterator<?> it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); )
{
plugins.add( it.next() );
}
List<Object> plugins = new ArrayList<>();
plugins.addAll( project.getModel().getReporting().getPlugins() );
plugins.addAll( project.getModel().getBuild().getPlugins() );

List<Object> result = new ArrayList<Object>();
List<Object> result = new ArrayList<>();

String pluginArtifactId = MAVEN_JAVADOC_PLUGIN_ARTIFACT_ID;
for ( Object next : plugins )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class JxrTestReport
@Override
protected List<String> getSourceRoots()
{
List<String> l = new ArrayList<String>();
List<String> l = new ArrayList<>();

if ( !"pom".equals( getProject().getPackaging().toLowerCase( Locale.US ) ) )
{
Expand All @@ -85,7 +85,7 @@ protected List<String> getSourceRoots()
@Override
protected List<String> getSourceRoots( MavenProject project )
{
List<String> l = new ArrayList<String>();
List<String> l = new ArrayList<>();

if ( project.getExecutionProject() != null )
{
Expand Down
38 changes: 16 additions & 22 deletions maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ private void appendFooter( PrintWriter out, String bottom )
* @param sourceReader Reader
* @param destWriter Writer
* @param locale String
* @param inputEncoding String
* @param outputEncoding String
* @param javadocLinkDir String
* @param revision String
Expand All @@ -403,7 +402,7 @@ private void transform( Reader sourceReader, Writer destWriter, Locale locale,

PrintWriter out = new PrintWriter( destWriter );

String line = "";
String line;

appendHeader( out );

Expand Down Expand Up @@ -518,7 +517,7 @@ private String getPackageRoot()
{
StringBuilder buff = new StringBuilder();

JavaFile jf = null;
JavaFile jf;

try
{
Expand Down Expand Up @@ -548,12 +547,10 @@ private String getPackageRoot()
* @param line String
* @return String
*/
private final String uriFilter( String line )
private String uriFilter( String line )
{
for ( int i = 0; i < VALID_URI_SCHEMES.length; ++i )
for ( String scheme : VALID_URI_SCHEMES )
{
String scheme = VALID_URI_SCHEMES[i];

int index = line.indexOf( scheme );

if ( index != -1 )
Expand Down Expand Up @@ -619,9 +616,9 @@ private String xrLine( String line, String packageName, ClassType classType )
{
StringBuilder buff = new StringBuilder( line );

String link = null;
String find = null;
String href = null;
String link;
String find;
String href;

if ( classType != null )
{
Expand Down Expand Up @@ -847,7 +844,7 @@ private String stringFilter( String line )
{
startStringIndex = -1;
endStringIndex = tempIndex;
buf.append( line.substring( 0, endStringIndex + 1 ) );
buf.append( line, 0, endStringIndex + 1 );
buf.append( STRING_END );
line = line.substring( endStringIndex + 1 );
}
Expand Down Expand Up @@ -1047,7 +1044,7 @@ else if ( linenumber < 100 )
*/
private String jxrFilter( String line )
{
JavaFile jf = null;
JavaFile jf;

try
{
Expand All @@ -1065,7 +1062,7 @@ private String jxrFilter( String line )
return line;
}

Set<String> packages = new HashSet<String>();
Set<String> packages = new HashSet<>();

// get the imported packages
for ( ImportType importType : jf.getImportTypes() )
Expand Down Expand Up @@ -1109,11 +1106,8 @@ private String jxrFilter( String line )
// if there is a "." in the string then we have to assume
// it is a package.

String fqpnPackage = null;
String fqpnClass = null;

fqpnPackage = wordName.substring( 0, wordName.lastIndexOf( '.' ) );
fqpnClass = wordName.substring( wordName.lastIndexOf( '.' ) + 1, wordName.length() );
String fqpnPackage = wordName.substring( 0, wordName.lastIndexOf( '.' ) );
String fqpnClass = wordName.substring( wordName.lastIndexOf( '.' ) + 1 );

// note. since this is a reference to a full package then
// it doesn't have to be explicitly imported so this information
Expand Down Expand Up @@ -1261,7 +1255,7 @@ private String importFilter( String line )
if ( start != -1 )
{
// filter out this packagename...
String pkg = line.substring( start, line.length() ).trim();
String pkg = line.substring( start ).trim();

// specify the classname of this import if any.
String classname = null;
Expand All @@ -1274,7 +1268,7 @@ else if ( !isPackage )
{
// this is an explicit Class import

String packageLine = pkg.toString();
String packageLine = pkg;

// This catches a boundary problem where you have something like:
//
Expand Down Expand Up @@ -1334,9 +1328,9 @@ else if ( !isPackage )
*/
private boolean isInvalidURICharacter( char c )
{
for ( int i = 0; i < VALID_URI_CHARS.length; ++i )
for ( char validUriChar : VALID_URI_CHARS )
{
if ( VALID_URI_CHARS[i] == c )
if ( validUriChar == c )
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static List<StringEntry> tokenize( String line, int start )
{
Matcher matcher = NONBREAKERS.matcher( line.substring( start ) );

List<StringEntry> words = new ArrayList<StringEntry>();
List<StringEntry> words = new ArrayList<>();

while ( matcher.find() )
{
Expand Down Expand Up @@ -129,10 +129,10 @@ private static int getStart( String string )
private static boolean isBreaker( char c )
{

for ( int i = 0; i < BREAKERS.length; ++i )
for ( char breaker : BREAKERS )
{

if ( BREAKERS[i] == c )
if ( breaker == c )
{
return true;
}
Expand Down

0 comments on commit 38a4bfd

Please sign in to comment.