You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2016/03/12 13:29:06 UTC
[1/2] maven-indexer git commit: fix junit
Repository: maven-indexer
Updated Branches:
refs/heads/master ecefb53f2 -> a7aeb9f2f
fix junit
Signed-off-by: olivier lamy <ol...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/maven-indexer/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-indexer/commit/fc39081a
Tree: http://git-wip-us.apache.org/repos/asf/maven-indexer/tree/fc39081a
Diff: http://git-wip-us.apache.org/repos/asf/maven-indexer/diff/fc39081a
Branch: refs/heads/master
Commit: fc39081a3c770e1a2cb34878257831eee371b986
Parents: ecefb53
Author: olivier lamy <ol...@apache.org>
Authored: Sat Mar 12 23:05:44 2016 +1100
Committer: olivier lamy <ol...@apache.org>
Committed: Sat Mar 12 23:05:44 2016 +1100
----------------------------------------------------------------------
.../apache/maven/index/context/IndexUtils.java | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/fc39081a/indexer-core/src/main/java/org/apache/maven/index/context/IndexUtils.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/context/IndexUtils.java b/indexer-core/src/main/java/org/apache/maven/index/context/IndexUtils.java
index 78ff5d1..d10461c 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/context/IndexUtils.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/context/IndexUtils.java
@@ -123,8 +123,22 @@ public class IndexUtils
ArtifactInfo artifactInfo = new ArtifactInfo();
// Add minimal information to the artifact info linking it to the context it belongs to.
- artifactInfo.setRepository(context.getRepositoryId());
- artifactInfo.setContext(context.getId());
+ try
+ {
+ artifactInfo.setRepository(context.getRepositoryId());
+ }
+ catch ( UnsupportedOperationException e )
+ {
+ // we ignore that as PartialImplementation can generate this UnsupportedOperationException
+ }
+ try
+ {
+ artifactInfo.setContext(context.getId());
+ }
+ catch ( Exception e )
+ {
+ // we ignore that as PartialImplementation can generate this UnsupportedOperationException
+ }
for ( IndexCreator ic : context.getIndexCreators() )
{
[2/2] maven-indexer git commit: use try with resources syntax
Posted by ol...@apache.org.
use try with resources syntax
Signed-off-by: olivier lamy <ol...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/maven-indexer/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-indexer/commit/a7aeb9f2
Tree: http://git-wip-us.apache.org/repos/asf/maven-indexer/tree/a7aeb9f2
Diff: http://git-wip-us.apache.org/repos/asf/maven-indexer/diff/a7aeb9f2
Branch: refs/heads/master
Commit: a7aeb9f2fe34e6c9f5222bcc2e31f43442cdf99c
Parents: fc39081
Author: olivier lamy <ol...@apache.org>
Authored: Sat Mar 12 23:22:03 2016 +1100
Committer: olivier lamy <ol...@apache.org>
Committed: Sat Mar 12 23:22:03 2016 +1100
----------------------------------------------------------------------
.../apache/maven/index/cli/NexusIndexerCli.java | 15 +----
.../org/apache/maven/index/DefaultIndexer.java | 8 +--
.../DefaultArtifactPackagingMapper.java | 10 +---
.../maven/index/packer/DefaultIndexPacker.java | 28 +--------
.../maven/index/packer/DigesterUtils.java | 31 +++-------
.../index/updater/DefaultIndexUpdater.java | 61 +++-----------------
.../index/updater/DefaultIndexUpdaterTest.java | 18 +-----
7 files changed, 28 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
----------------------------------------------------------------------
diff --git a/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java b/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
index c140ace..9f33f67 100644
--- a/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
+++ b/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
@@ -415,14 +415,11 @@ public class NexusIndexerCli
long tstart = System.currentTimeMillis();
- final FSDirectory directory = FSDirectory.open( outputFolder );
-
final List<IndexCreator> indexers = getIndexers( cli, plexus );
- BufferedInputStream is = null;
- try
+ try (BufferedInputStream is = new BufferedInputStream( new FileInputStream( indexArchive ) ); //
+ FSDirectory directory = FSDirectory.open( outputFolder ))
{
- is = new BufferedInputStream( new FileInputStream( indexArchive ) );
DefaultIndexUpdater.unpackIndexData( is, directory, (IndexingContext) Proxy.newProxyInstance(
getClass().getClassLoader(), new Class[] { IndexingContext.class }, new PartialImplementation()
{
@@ -434,14 +431,6 @@ public class NexusIndexerCli
);
}
- finally
- {
- IOUtil.close( is );
- if ( directory != null )
- {
- directory.close();
- }
- }
if ( !quiet )
{
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexer.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexer.java b/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexer.java
index 03999bc..fa07aff 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexer.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexer.java
@@ -187,11 +187,9 @@ public class DefaultIndexer
public Collection<ArtifactInfo> identify( final File artifact, final Collection<IndexingContext> contexts )
throws IOException
{
- FileInputStream is = null;
- try
+ try (FileInputStream is = new FileInputStream( artifact ))
{
final MessageDigest sha1 = MessageDigest.getInstance( "SHA-1" );
- is = new FileInputStream( artifact );
final byte[] buff = new byte[4096];
int n;
while ( ( n = is.read( buff ) ) > -1 )
@@ -207,10 +205,6 @@ public class DefaultIndexer
ioe.initCause( ex );
throw ioe;
}
- finally
- {
- IOUtil.close( is );
- }
}
public Collection<ArtifactInfo> identify( Query query, Collection<IndexingContext> contexts )
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
index 04b1b16..dd02e25 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
@@ -104,12 +104,8 @@ public class DefaultArtifactPackagingMapper
Properties userMappings = new Properties();
- FileInputStream fis = null;
-
- try
+ try (FileInputStream fis= new FileInputStream( propertiesFile ))
{
- fis = new FileInputStream( propertiesFile );
-
userMappings.load( fis );
if ( userMappings.keySet().size() > 0 )
@@ -131,10 +127,6 @@ public class DefaultArtifactPackagingMapper
getLogger().warn(
"Got IO exception during read of file: " + propertiesFile.getAbsolutePath() );
}
- finally
- {
- IOUtil.close( fis );
- }
}
else
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java b/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
index b66cbde..933dd1b 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
@@ -221,21 +221,13 @@ public class DefaultIndexPacker
targetArchive.delete();
}
- OutputStream os = null;
-
- try
+ try( OutputStream os = new FileOutputStream( targetArchive ) )
{
- os = new FileOutputStream( targetArchive );
-
IndexDataWriter dw = new IndexDataWriter( os );
dw.write( request.getContext(), request.getIndexReader(), docIndexes );
os.flush();
}
- finally
- {
- IOUtil.close( os );
- }
}
void writeIndexProperties( IndexPackingRequest request, Properties info )
@@ -247,29 +239,15 @@ public class DefaultIndexPacker
info.setProperty( IndexingContext.INDEX_ID, request.getContext().getId() );
- OutputStream os = null;
-
- try
+ try (OutputStream os = new FileOutputStream( propertyFile ))
{
- os = new FileOutputStream( propertyFile );
-
info.store( os, null );
}
- finally
- {
- IOUtil.close( os );
- }
- try
+ try (OutputStream os = new FileOutputStream( targetPropertyFile ))
{
- os = new FileOutputStream( targetPropertyFile );
-
info.store( os, null );
}
- finally
- {
- IOUtil.close( os );
- }
if ( request.isCreateChecksumFiles() )
{
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-core/src/main/java/org/apache/maven/index/packer/DigesterUtils.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/packer/DigesterUtils.java b/indexer-core/src/main/java/org/apache/maven/index/packer/DigesterUtils.java
index 9c9c874..be98346 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/packer/DigesterUtils.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/packer/DigesterUtils.java
@@ -42,7 +42,7 @@ public class DigesterUtils
* Calculates a digest for a String user the requested algorithm.
*
* @param alg
- * @param content
+ * @param is
* @return
* @throws NoSuchAlgorithmException
*/
@@ -119,7 +119,7 @@ public class DigesterUtils
/**
* Calculates a SHA1 digest for a stream.
*
- * @param content
+ * @param is
* @return
*/
public static String getSha1Digest( InputStream is )
@@ -138,17 +138,14 @@ public class DigesterUtils
/**
* Calculates a SHA1 digest for a file.
*
- * @param content
+ * @param file
* @return
*/
public static String getSha1Digest( File file )
+ throws IOException
{
- FileInputStream fis = null;
-
- try
+ try (FileInputStream fis = new FileInputStream( file ))
{
- fis = new FileInputStream( file );
-
return getDigest( "SHA1", fis );
}
catch ( NoSuchAlgorithmException e )
@@ -161,10 +158,6 @@ public class DigesterUtils
// will not happen
return null;
}
- finally
- {
- IOUtil.close( fis );
- }
}
// MD5
@@ -198,7 +191,7 @@ public class DigesterUtils
/**
* Calculates a SHA1 digest for a stream.
*
- * @param content
+ * @param is
* @return
*/
public static String getMd5Digest( InputStream is )
@@ -217,17 +210,15 @@ public class DigesterUtils
/**
* Calculates a SHA1 digest for a file.
*
- * @param content
+ * @param file
* @return
*/
public static String getMd5Digest( File file )
+ throws IOException
{
- FileInputStream fis = null;
- try
+ try (InputStream fis = new FileInputStream( file ))
{
- fis = new FileInputStream( file );
-
return getDigest( "MD5", fis );
}
catch ( NoSuchAlgorithmException e )
@@ -240,10 +231,6 @@ public class DigesterUtils
// will not happen
return null;
}
- finally
- {
- IOUtil.close( fis );
- }
}
// --
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java b/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
index 2c1067c..7f90ee1 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
@@ -200,14 +200,9 @@ public class DefaultIndexUpdater
indexDir.delete();
indexDir.mkdirs();
- final Directory directory = updateRequest.getFSDirectoryFactory().open( indexDir );
-
- BufferedInputStream is = null;
-
- try
+ try(BufferedInputStream is = new BufferedInputStream( fetcher.retrieve( remoteIndexFile ) ); //
+ Directory directory = updateRequest.getFSDirectoryFactory().open( indexDir ))
{
- is = new BufferedInputStream( fetcher.retrieve( remoteIndexFile ) );
-
Date timestamp = null;
if ( remoteIndexFile.endsWith( ".gz" ) )
@@ -247,13 +242,6 @@ public class DefaultIndexUpdater
}
finally
{
- IOUtil.close( is );
-
- if ( directory != null )
- {
- directory.close();
- }
-
try
{
FileUtils.deleteDirectory( indexDir );
@@ -321,14 +309,10 @@ public class DefaultIndexUpdater
{
File indexProperties = new File( indexDirectoryFile, remoteIndexPropertiesName );
- FileInputStream fis = null;
-
- try
+ try ( FileInputStream fis = new FileInputStream( indexProperties ))
{
Properties properties = new Properties();
- fis = new FileInputStream( indexProperties );
-
properties.load( fis );
return properties;
@@ -337,11 +321,6 @@ public class DefaultIndexUpdater
{
getLogger().debug( "Unable to read remote properties stored locally", e );
}
- finally
- {
- IOUtil.close( fis );
- }
-
return null;
}
@@ -352,15 +331,10 @@ public class DefaultIndexUpdater
if ( properties != null )
{
- OutputStream os = new BufferedOutputStream( new FileOutputStream( file ) );
- try
+ try (OutputStream os = new BufferedOutputStream( new FileOutputStream( file ) ))
{
properties.store( os, null );
}
- finally
- {
- IOUtil.close( os );
- }
}
else
{
@@ -371,9 +345,7 @@ public class DefaultIndexUpdater
private Properties downloadIndexProperties( final ResourceFetcher fetcher )
throws IOException
{
- InputStream fis = fetcher.retrieve( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE );
-
- try
+ try (InputStream fis = fetcher.retrieve( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ))
{
Properties properties = new Properties();
@@ -381,10 +353,6 @@ public class DefaultIndexUpdater
return properties;
}
- finally
- {
- IOUtil.close( fis );
- }
}
public Date getTimestamp( final Properties properties, final String key )
@@ -643,9 +611,8 @@ public class DefaultIndexUpdater
throws IOException
{
File chunksFile = new File( dir, CHUNKS_FILENAME );
- BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream( chunksFile, true ) );
- Writer w = new OutputStreamWriter( os, CHUNKS_FILE_ENCODING );
- try
+ try (BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream( chunksFile, true ) ); //
+ Writer w = new OutputStreamWriter( os, CHUNKS_FILE_ENCODING ))
{
for ( String filename : newChunks )
{
@@ -653,11 +620,6 @@ public class DefaultIndexUpdater
}
w.flush();
}
- finally
- {
- IOUtil.close( w );
- IOUtil.close( os );
- }
super.commit();
}
@@ -667,9 +629,8 @@ public class DefaultIndexUpdater
ArrayList<String> chunks = new ArrayList<String>();
File chunksFile = new File( dir, CHUNKS_FILENAME );
- BufferedReader r =
- new BufferedReader( new InputStreamReader( new FileInputStream( chunksFile ), CHUNKS_FILE_ENCODING ) );
- try
+ try (BufferedReader r =
+ new BufferedReader( new InputStreamReader( new FileInputStream( chunksFile ), CHUNKS_FILE_ENCODING ) ))
{
String str;
while ( ( str = r.readLine() ) != null )
@@ -677,10 +638,6 @@ public class DefaultIndexUpdater
chunks.add( str );
}
}
- finally
- {
- IOUtil.close( r );
- }
return chunks;
}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a7aeb9f2/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
index d3f739a..cdf6d71 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
@@ -923,18 +923,13 @@ public class DefaultIndexUpdaterTest
{
Properties properties = getProperties();
- ByteArrayOutputStream buf = new ByteArrayOutputStream();
- try
+ try (ByteArrayOutputStream buf = new ByteArrayOutputStream())
{
properties.store( buf, null );
buf.flush();
- }
- finally
- {
- IOUtil.close( buf );
+ return new ByteArrayInputStream( buf.toByteArray() );
}
- return new ByteArrayInputStream( buf.toByteArray() );
}
abstract Properties getProperties();
@@ -952,17 +947,10 @@ public class DefaultIndexUpdaterTest
this.file = new File( basedir, IndexingContext.INDEX_UPDATER_PROPERTIES_FILE );
- FileOutputStream fos = null;
- try
+ try ( FileOutputStream fos = new FileOutputStream( this.file ))
{
- fos = new FileOutputStream( this.file );
-
properties.store( fos, "" );
}
- finally
- {
- IOUtil.close( fos );
- }
}
@Override