Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 900d84f

Browse files
committed
Switch from List to Collection to make it easier to use Sets when preferred
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1816235 13f79535-47bb-0310-9956-ffa450edef68
1 parent 642208e commit 900d84f

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

maven-javadoc-plugin/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ protected void executeReport( Locale unusedLocale )
19771977
throw new MavenReportException( "Failed to generate javadoc options file: " + e.getMessage(), e );
19781978
}
19791979

1980-
List<String> sourcePaths = getSourcePaths();
1980+
Collection<String> sourcePaths = getSourcePaths();
19811981
List<String> files = getFiles( sourcePaths );
19821982
if ( !canGenerateReport( files ) )
19831983
{
@@ -2180,11 +2180,11 @@ protected void executeReport( Locale unusedLocale )
21802180
/**
21812181
* Method to get the files on the specified source paths
21822182
*
2183-
* @param sourcePaths a List that contains the paths to the source files
2183+
* @param sourcePaths a Collection that contains the paths to the source files
21842184
* @return a List that contains the specific path for every source file
21852185
* @throws MavenReportException {@link MavenReportException}
21862186
*/
2187-
protected List<String> getFiles( List<String> sourcePaths )
2187+
protected List<String> getFiles( Collection<String> sourcePaths )
21882188
throws MavenReportException
21892189
{
21902190
List<String> files = new ArrayList<>();
@@ -2207,14 +2207,14 @@ protected List<String> getFiles( List<String> sourcePaths )
22072207
* Method to get the source paths. If no source path is specified in the parameter, the compile source roots
22082208
* of the project will be used.
22092209
*
2210-
* @return a List of the project absolute source paths as <code>String</code>
2210+
* @return a Collection of the project absolute source paths as <code>String</code>
22112211
* @throws MavenReportException {@link MavenReportException}
22122212
* @see JavadocUtil#pruneDirs(MavenProject, List)
22132213
*/
2214-
protected List<String> getSourcePaths()
2214+
protected Collection<String> getSourcePaths()
22152215
throws MavenReportException
22162216
{
2217-
List<String> sourcePaths;
2217+
Collection<String> sourcePaths;
22182218

22192219
if ( StringUtils.isEmpty( sourcepath ) )
22202220
{
@@ -2235,7 +2235,7 @@ protected List<String> getSourcePaths()
22352235
File javadocDir = getJavadocDirectory();
22362236
if ( javadocDir.exists() && javadocDir.isDirectory() )
22372237
{
2238-
List<String> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
2238+
Collection<String> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
22392239
getJavadocDirectory().getAbsolutePath() ) );
22402240
sourcePaths.addAll( l );
22412241
}
@@ -2273,7 +2273,7 @@ protected List<String> getSourcePaths()
22732273
File javadocDir = new File( subProject.getBasedir(), javadocDirRelative );
22742274
if ( javadocDir.exists() && javadocDir.isDirectory() )
22752275
{
2276-
List<String> l = JavadocUtil.pruneDirs( subProject, Collections.singletonList(
2276+
Collection<String> l = JavadocUtil.pruneDirs( subProject, Collections.singletonList(
22772277
javadocDir.getAbsolutePath() ) );
22782278
sourcePaths.addAll( l );
22792279
}
@@ -2288,7 +2288,7 @@ protected List<String> getSourcePaths()
22882288
sourcePaths = JavadocUtil.pruneDirs( project, sourcePaths );
22892289
if ( getJavadocDirectory() != null )
22902290
{
2291-
List<String> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
2291+
Collection<String> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
22922292
getJavadocDirectory().getAbsolutePath() ) );
22932293
sourcePaths.addAll( l );
22942294
}
@@ -2436,11 +2436,11 @@ protected boolean canGenerateReport( List<String> files )
24362436
* Method to get the excluded source files from the javadoc and create the argument string
24372437
* that will be included in the javadoc commandline execution.
24382438
*
2439-
* @param sourcePaths the list of paths to the source files
2439+
* @param sourcePaths the collection of paths to the source files
24402440
* @return a String that contains the exclude argument that will be used by javadoc
24412441
* @throws MavenReportException
24422442
*/
2443-
private String getExcludedPackages( List<String> sourcePaths )
2443+
private String getExcludedPackages( Collection<String> sourcePaths )
24442444
throws MavenReportException
24452445
{
24462446
List<String> excludedNames = null;
@@ -2471,7 +2471,7 @@ private String getExcludedPackages( List<String> sourcePaths )
24712471
* string (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
24722472
* @see File#pathSeparator
24732473
*/
2474-
private String getSourcePath( List<String> sourcePaths )
2474+
private String getSourcePath( Collection<String> sourcePaths )
24752475
{
24762476
String sourcePath = null;
24772477

@@ -3049,7 +3049,7 @@ private String getTagletPath()
30493049
throws MavenReportException
30503050
{
30513051
Set<TagletArtifact> tArtifacts = collectTagletArtifacts();
3052-
List<String> pathParts = new ArrayList<>();
3052+
Collection<String> pathParts = new ArrayList<>();
30533053

30543054
for ( TagletArtifact tagletArtifact : tArtifacts )
30553055
{
@@ -4284,7 +4284,7 @@ private void copyAdditionalJavadocResources( File anOutputDirectory )
42844284
* @param files not null
42854285
* @return the list of package names for files in the sourcePaths
42864286
*/
4287-
private List<String> getPackageNames( List<String> sourcePaths, List<String> files )
4287+
private List<String> getPackageNames( Collection<String> sourcePaths, List<String> files )
42884288
{
42894289
return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, files, true );
42904290
}
@@ -4294,7 +4294,7 @@ private List<String> getPackageNames( List<String> sourcePaths, List<String> fil
42944294
* @param files not null
42954295
* @return a list files with unnamed package names for files in the sourecPaths
42964296
*/
4297-
private List<String> getFilesWithUnnamedPackages( List<String> sourcePaths, List<String> files )
4297+
private List<String> getFilesWithUnnamedPackages( Collection<String> sourcePaths, List<String> files )
42984298
{
42994299
return getPackageNamesOrFilesWithUnnamedPackages( sourcePaths, files, false );
43004300
}
@@ -4307,7 +4307,7 @@ private List<String> getFilesWithUnnamedPackages( List<String> sourcePaths, List
43074307
* @see #getFiles(List)
43084308
* @see #getSourcePaths()
43094309
*/
4310-
private List<String> getPackageNamesOrFilesWithUnnamedPackages( List<String> sourcePaths, List<String> files,
4310+
private List<String> getPackageNamesOrFilesWithUnnamedPackages( Collection<String> sourcePaths, List<String> files,
43114311
boolean onlyPackageName )
43124312
{
43134313
List<String> returnList = new ArrayList<>();
@@ -4624,7 +4624,7 @@ private void validateStandardDocletOptions()
46244624
* @throws MavenReportException if any
46254625
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadocoptions">http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadocoptions</a>
46264626
*/
4627-
private void addJavadocOptions( List<String> arguments, List<String> sourcePaths )
4627+
private void addJavadocOptions( List<String> arguments, Collection<String> sourcePaths )
46284628
throws MavenReportException
46294629
{
46304630
validateJavadocOptions();

maven-javadoc-plugin/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
import java.io.File;
23+
import java.util.Collection;
2324
import java.util.List;
2425
import java.util.Locale;
2526
import java.util.ResourceBundle;
@@ -235,7 +236,7 @@ public boolean canGenerateReport()
235236

236237
if ( !this.isAggregator() || ( this.isAggregator() && this.project.isExecutionRoot() ) )
237238
{
238-
List<String> sourcePaths;
239+
Collection<String> sourcePaths;
239240
List<String> files;
240241
try
241242
{

maven-javadoc-plugin/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@
7878
import java.util.Arrays;
7979
import java.util.Collection;
8080
import java.util.Collections;
81+
import java.util.LinkedHashSet;
8182
import java.util.List;
8283
import java.util.Locale;
8384
import java.util.NoSuchElementException;
8485
import java.util.Properties;
86+
import java.util.Set;
8587
import java.util.StringTokenizer;
8688
import java.util.jar.JarEntry;
8789
import java.util.jar.JarInputStream;
@@ -112,12 +114,12 @@ public class JavadocUtil
112114
* directory <code>String</code> path.
113115
*
114116
* @param project the current Maven project not null
115-
* @param dirs the list of <code>String</code> directories path that will be validated.
117+
* @param dirs the collection of <code>String</code> directories path that will be validated.
116118
* @return a List of valid <code>String</code> directories absolute paths.
117119
*/
118-
public static List<String> pruneDirs( MavenProject project, List<String> dirs )
120+
public static Collection<String> pruneDirs( MavenProject project, Collection<String> dirs )
119121
{
120-
List<String> pruned = new ArrayList<>( dirs.size() );
122+
Set<String> pruned = new LinkedHashSet<>( dirs.size() );
121123
for ( String dir : dirs )
122124
{
123125
if ( dir == null )
@@ -131,7 +133,7 @@ public static List<String> pruneDirs( MavenProject project, List<String> dirs )
131133
directory = new File( project.getBasedir(), directory.getPath() );
132134
}
133135

134-
if ( directory.isDirectory() && !pruned.contains( directory.getAbsolutePath() ) )
136+
if ( directory.isDirectory() )
135137
{
136138
pruned.add( directory.getAbsolutePath() );
137139
}
@@ -147,7 +149,7 @@ public static List<String> pruneDirs( MavenProject project, List<String> dirs )
147149
* @param files the list of <code>String</code> files paths that will be validated.
148150
* @return a List of valid <code>File</code> objects.
149151
*/
150-
protected static List<String> pruneFiles( List<String> files )
152+
protected static List<String> pruneFiles( Collection<String> files )
151153
{
152154
List<String> pruned = new ArrayList<>( files.size() );
153155
for ( String f : files )
@@ -191,7 +193,7 @@ public static boolean shouldPruneFile( String f, List<String> pruned )
191193
* @param excludedPackages the package names to be excluded in the javadoc
192194
* @return a List of the source files to be excluded in the generated javadoc
193195
*/
194-
protected static List<String> getExcludedNames( List<String> sourcePaths, String[] subpackagesList,
196+
protected static List<String> getExcludedNames( Collection<String> sourcePaths, String[] subpackagesList,
195197
String[] excludedPackages )
196198
{
197199
List<String> excludedNames = new ArrayList<>();

maven-javadoc-plugin/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.IOException;
2727
import java.util.ArrayList;
2828
import java.util.Arrays;
29+
import java.util.Collection;
2930
import java.util.HashMap;
3031
import java.util.LinkedHashSet;
3132
import java.util.List;
@@ -39,11 +40,11 @@
3940
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
4041
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
4142
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
42-
import org.apache.maven.plugins.javadoc.options.JavadocOptions;
43-
import org.apache.maven.plugins.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader;
4443
import org.apache.maven.plugins.javadoc.AbstractJavadocMojo;
4544
import org.apache.maven.plugins.javadoc.JavadocUtil;
4645
import org.apache.maven.plugins.javadoc.ResourcesBundleMojo;
46+
import org.apache.maven.plugins.javadoc.options.JavadocOptions;
47+
import org.apache.maven.plugins.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader;
4748
import org.apache.maven.project.MavenProject;
4849
import org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer;
4950
import org.apache.maven.shared.artifact.resolve.ArtifactResolver;
@@ -439,7 +440,7 @@ private List<String> resolveAndUnpack( final List<Artifact> artifacts, final Sou
439440
return result;
440441
}
441442

442-
private static List<String> resolveFromProject( final SourceResolverConfig config,
443+
private static Collection<String> resolveFromProject( final SourceResolverConfig config,
443444
final MavenProject reactorProject, final Artifact artifact )
444445
{
445446
final List<String> dirs = new ArrayList<>();

maven-javadoc-plugin/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ public void testDefaultConfig()
7575
new File( getBasedir(), "target/test/unit/javadocjar-default/target/javadocjar-default-javadoc.jar" );
7676
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
7777

78-
//validate contents of jar file
79-
ZipFile jar = new ZipFile( generatedFile );
8078
Set<String> set = new HashSet<>();
81-
for( Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements(); )
79+
80+
//validate contents of jar file
81+
try ( ZipFile jar = new ZipFile( generatedFile ) )
8282
{
83-
ZipEntry entry = entries.nextElement();
84-
set.add( entry.getName() );
83+
for( Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements(); )
84+
{
85+
ZipEntry entry = entries.nextElement();
86+
set.add( entry.getName() );
87+
}
8588
}
8689

8790
assertTrue( set.contains( "stylesheet.css" ) );

maven-javadoc-plugin/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import java.net.SocketTimeoutException;
2626
import java.net.URL;
2727
import java.util.ArrayList;
28+
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.List;
3031
import java.util.Map;
32+
import java.util.Set;
3133
import java.util.regex.PatternSyntaxException;
3234

3335
import org.apache.commons.lang3.builder.EqualsBuilder;
@@ -585,10 +587,10 @@ public void testPruneDirs()
585587
list.add( getBasedir() + "/target/classes" );
586588
list.add( getBasedir() + "/target/classes" );
587589

588-
List<String> expected = new ArrayList<>();
589-
expected.add( getBasedir() + "/target/classes" );
590+
String FS = System.getProperty( "file.separator" );
591+
Set<String> expected = Collections.singleton( getBasedir() + FS +"target" + FS + "classes" );
590592

591-
assertTrue( EqualsBuilder.reflectionEquals( expected, JavadocUtil.pruneDirs( null, list ) ) );
593+
assertEquals( expected, JavadocUtil.pruneDirs( null, list ) );
592594
}
593595

594596
/**

0 commit comments

Comments
 (0)