Skip to content

Commit b93d9fa

Browse files
committed
Clean up code, apply Java 7 features
1 parent 844da90 commit b93d9fa

40 files changed

+293
-320
lines changed

pom.xml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ limitations under the License.
2222
<parent>
2323
<groupId>org.codehaus.plexus</groupId>
2424
<artifactId>plexus</artifactId>
25-
<version>5.1</version>
25+
<version>6.0</version>
2626
</parent>
2727

2828
<artifactId>plexus-utils</artifactId>
@@ -142,19 +142,4 @@ limitations under the License.
142142
</plugins>
143143
</build>
144144

145-
<profiles>
146-
<profile>
147-
<!-- See https://github.com/codehaus-plexus/plexus-utils/pull/27 -->
148-
<!-- m2e Eclipse plugin doesn't respect the maven-enforcer-plugin 'requireJavaVersion' parameter -->
149-
<id>eclipse-only-jdk-version</id>
150-
<activation>
151-
<property>
152-
<name>m2e.version</name>
153-
</property>
154-
</activation>
155-
<properties>
156-
<javaVersion>7</javaVersion>
157-
</properties>
158-
</profile>
159-
</profiles>
160145
</project>

src/main/java/org/codehaus/plexus/util/AbstractScanner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ protected static boolean match( String pattern, String str, boolean isCaseSensit
229229
* @param includes A list of include patterns. May be <code>null</code>, indicating that all files should be
230230
* included. If a non-<code>null</code> list is given, all elements must be non-<code>null</code>.
231231
*/
232+
@Override
232233
public void setIncludes( String[] includes )
233234
{
234235
if ( includes == null )
@@ -258,6 +259,7 @@ public void setIncludes( String[] includes )
258259
* @param excludes A list of exclude patterns. May be <code>null</code>, indicating that no files should be
259260
* excluded. If a non-<code>null</code> list is given, all elements must be non-<code>null</code>.
260261
*/
262+
@Override
261263
public void setExcludes( String[] excludes )
262264
{
263265
if ( excludes == null )
@@ -361,6 +363,7 @@ protected boolean isExcluded( String name, String[] tokenizedName )
361363
/**
362364
* Adds default exclusions to the current exclusions set.
363365
*/
366+
@Override
364367
public void addDefaultExcludes()
365368
{
366369
int excludesLength = excludes == null ? 0 : excludes.length;

src/main/java/org/codehaus/plexus/util/CachedMap.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public void flush()
191191
* @throws ClassCastException if the key is of an inappropriate type for the backing map (optional).
192192
* @throws NullPointerException if the key is <code>null</code>.
193193
*/
194+
@Override
194195
public Object get( Object key )
195196
{
196197
int index = key.hashCode() & _mask;
@@ -243,6 +244,7 @@ private Object getCacheMissed( Object key, int index )
243244
* @throws IllegalArgumentException if some aspect of this key or value prevents it from being stored in this map.
244245
* @throws NullPointerException if the key is <code>null</code>.
245246
*/
247+
@Override
246248
public Object put( Object key, Object value )
247249
{
248250
// Updates the cache.
@@ -269,6 +271,7 @@ else if ( _keysMap != null )
269271
* @throws NullPointerException if the key is <code>null</code>.
270272
* @throws UnsupportedOperationException if the <code>remove</code> method is not supported by the backing map.
271273
*/
274+
@Override
272275
public Object remove( Object key )
273276
{
274277
// Removes from cache.
@@ -292,6 +295,7 @@ public Object remove( Object key )
292295
* @param key the key whose presence in this map is to be tested.
293296
* @return <code>true</code> if this map contains a mapping for the specified key; <code>false</code> otherwise.
294297
*/
298+
@Override
295299
public boolean containsKey( Object key )
296300
{
297301
// Checks the cache.
@@ -312,6 +316,7 @@ public boolean containsKey( Object key )
312316
*
313317
* @return the number of key-value mappings in this map.
314318
*/
319+
@Override
315320
public int size()
316321
{
317322
return _backingMap.size();
@@ -322,6 +327,7 @@ public int size()
322327
*
323328
* @return <code>true</code> if this map contains no key-value mappings.
324329
*/
330+
@Override
325331
public boolean isEmpty()
326332
{
327333
return _backingMap.isEmpty();
@@ -336,6 +342,7 @@ public boolean isEmpty()
336342
* @throws NullPointerException if the value is <code>null</code> and the backing map does not not permit
337343
* <code>null</code> values.
338344
*/
345+
@Override
339346
public boolean containsValue( Object value )
340347
{
341348
return _backingMap.containsValue( value );
@@ -354,6 +361,7 @@ public boolean containsValue( Object value )
354361
* @throws NullPointerException the specified map is <code>null</code>, or if the backing map does not permit
355362
* <code>null</code> keys or values, and the specified map contains <code>null</code> keys or values.
356363
*/
364+
@Override
357365
public void putAll( Map map )
358366
{
359367
_backingMap.putAll( map );
@@ -365,6 +373,7 @@ public void putAll( Map map )
365373
*
366374
* @throws UnsupportedOperationException if clear is not supported by the backing map.
367375
*/
376+
@Override
368377
public void clear()
369378
{
370379
_backingMap.clear();
@@ -376,6 +385,7 @@ public void clear()
376385
*
377386
* @return an unmodifiable view of the keys contained in this map.
378387
*/
388+
@Override
379389
public Set keySet()
380390
{
381391
return Collections.unmodifiableSet( _backingMap.keySet() );
@@ -386,6 +396,7 @@ public Set keySet()
386396
*
387397
* @return an unmodifiable view of the values contained in this map.
388398
*/
399+
@Override
389400
public Collection values()
390401
{
391402
return Collections.unmodifiableCollection( _backingMap.values() );
@@ -397,6 +408,7 @@ public Collection values()
397408
*
398409
* @return an unmodifiable view of the mappings contained in this map.
399410
*/
411+
@Override
400412
public Set entrySet()
401413
{
402414
return Collections.unmodifiableSet( _backingMap.entrySet() );
@@ -409,6 +421,7 @@ public Set entrySet()
409421
* @param o object to be compared for equality with this map.
410422
* @return <code>true</code> if the specified object is equal to this map.
411423
*/
424+
@Override
412425
public boolean equals( Object o )
413426
{
414427
return _backingMap.equals( o );
@@ -419,6 +432,7 @@ public boolean equals( Object o )
419432
*
420433
* @return the hash code value for this map.
421434
*/
435+
@Override
422436
public int hashCode()
423437
{
424438
return _backingMap.hashCode();

src/main/java/org/codehaus/plexus/util/DirectoryScanner.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void setBasedir( File basedir )
234234
*
235235
* @return the base directory to be scanned
236236
*/
237+
@Override
237238
public File getBasedir()
238239
{
239240
return basedir;
@@ -266,6 +267,7 @@ public boolean isEverythingIncluded()
266267
* @throws IllegalStateException if the base directory was set incorrectly (i.e. if it is <code>null</code>, doesn't
267268
* exist, or isn't a directory).
268269
*/
270+
@Override
269271
public void scan()
270272
throws IllegalStateException
271273
{
@@ -548,6 +550,7 @@ protected boolean isSelected( String name, File file )
548550
* @return the names of the files which matched at least one of the include patterns and none of the exclude
549551
* patterns.
550552
*/
553+
@Override
551554
public String[] getIncludedFiles()
552555
{
553556
String[] files = new String[filesIncluded.size()];
@@ -611,6 +614,7 @@ public String[] getDeselectedFiles()
611614
* @return the names of the directories which matched at least one of the include patterns and none of the exclude
612615
* patterns.
613616
*/
617+
@Override
614618
public String[] getIncludedDirectories()
615619
{
616620
String[] directories = new String[dirsIncluded.size()];
@@ -683,13 +687,7 @@ public String[] getDeselectedDirectories()
683687
public boolean isSymbolicLink( File parent, String name )
684688
throws IOException
685689
{
686-
if ( Java7Detector.isJava7() )
687-
{
688-
return NioFiles.isSymbolicLink( new File( parent, name ) );
689-
}
690-
File resolvedParent = new File( parent.getCanonicalPath() );
691-
File toTest = new File( resolvedParent, name );
692-
return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
690+
return NioFiles.isSymbolicLink( new File( parent, name ) );
693691
}
694692

695693
/**
@@ -707,12 +705,6 @@ public boolean isSymbolicLink( File parent, String name )
707705
public boolean isParentSymbolicLink( File parent, String name )
708706
throws IOException
709707
{
710-
if ( Java7Detector.isJava7() )
711-
{
712-
return NioFiles.isSymbolicLink( parent );
713-
}
714-
File resolvedParent = new File( parent.getCanonicalPath() );
715-
File toTest = new File( resolvedParent, name );
716-
return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
708+
return NioFiles.isSymbolicLink( parent );
717709
}
718710
}

src/main/java/org/codehaus/plexus/util/DirectoryWalker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public int getPercentage()
102102
return (int) Math.floor( percentageOffset + ( percentageWithinDir * percentageSize ) );
103103
}
104104

105+
@Override
105106
public String toString()
106107
{
107108
return "DirStackEntry[" + "dir=" + dir.getAbsolutePath() + ",count=" + count + ",index=" + index
@@ -154,7 +155,7 @@ public void addInclude( String include )
154155
*/
155156
public void addSCMExcludes()
156157
{
157-
String scmexcludes[] = DirectoryScanner.DEFAULTEXCLUDES;
158+
String scmexcludes[] = AbstractScanner.DEFAULTEXCLUDES;
158159
for ( String scmexclude : scmexcludes )
159160
{
160161
addExclude( scmexclude );
@@ -330,7 +331,7 @@ public void scan()
330331
}
331332

332333
fireWalkStarting();
333-
dirStack = new Stack();
334+
dirStack = new Stack<DirStackEntry>();
334335
scanDir( baseDir );
335336
fireWalkFinished();
336337
}
@@ -352,7 +353,7 @@ private void scanDir( File dir )
352353
}
353354
else
354355
{
355-
DirectoryWalker.DirStackEntry previousStackEntry = (DirectoryWalker.DirStackEntry) dirStack.peek();
356+
DirectoryWalker.DirStackEntry previousStackEntry = dirStack.peek();
356357
curStackEntry.percentageOffset = previousStackEntry.getNextPercentageOffset();
357358
curStackEntry.percentageSize = previousStackEntry.getNextPercentageSize();
358359
}

src/main/java/org/codehaus/plexus/util/Expand.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,18 @@ public void execute()
102102
protected void expandFile( final File srcF, final File dir )
103103
throws Exception
104104
{
105-
ZipInputStream zis = null;
106-
try
105+
// code from WarExpand
106+
try ( ZipInputStream zis = new ZipInputStream( new FileInputStream( srcF ) ) )
107107
{
108-
// code from WarExpand
109-
zis = new ZipInputStream( new FileInputStream( srcF ) );
110-
111108
for ( ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry() )
112109
{
113110
extractFile( srcF, dir, zis, ze.getName(), new Date( ze.getTime() ), ze.isDirectory() );
114111
}
115-
116-
// log("expand complete", Project.MSG_VERBOSE);
117-
zis.close();
118-
zis = null;
119112
}
120113
catch ( IOException ioe )
121114
{
122115
throw new Exception( "Error while expanding " + srcF.getPath(), ioe );
123116
}
124-
finally
125-
{
126-
IOUtil.close( zis );
127-
}
128117
}
129118

130119
/**
@@ -159,22 +148,13 @@ protected void extractFile( File srcF, File dir, InputStream compressedInputStre
159148
else
160149
{
161150
byte[] buffer = new byte[65536];
162-
FileOutputStream fos = null;
163-
try
151+
152+
try ( FileOutputStream fos = new FileOutputStream( f ) )
164153
{
165-
fos = new FileOutputStream( f );
166-
167-
for ( int length =
168-
compressedInputStream.read( buffer ); length >= 0; fos.write( buffer, 0, length ), length =
169-
compressedInputStream.read( buffer ) )
154+
for ( int length = compressedInputStream.read( buffer );
155+
length >= 0;
156+
fos.write( buffer, 0, length ), length = compressedInputStream.read( buffer ) )
170157
;
171-
172-
fos.close();
173-
fos = null;
174-
}
175-
finally
176-
{
177-
IOUtil.close( fos );
178158
}
179159
}
180160

0 commit comments

Comments
 (0)