]> source.dussan.org Git - archiva.git/commitdiff
more code simplification with 1.7 features
authorOlivier Lamy <olamy@apache.org>
Thu, 17 Apr 2014 00:46:06 +0000 (10:46 +1000)
committerOlivier Lamy <olamy@apache.org>
Thu, 17 Apr 2014 00:46:06 +0000 (10:46 +1000)
archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java
archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java

index 25e99477381daf8cacb77d3ec588cb23b5ca014a..ae433878d9edd41beb2b416118f430cc4a514f0c 100644 (file)
@@ -38,8 +38,6 @@ import org.apache.maven.artifact.manager.WagonManager;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -255,7 +253,7 @@ public class ArchivaCli
     }
 
     private void doConversion( String properties )
-        throws FileNotFoundException, IOException, RepositoryConversionException, PlexusSisuBridgeException
+        throws IOException, RepositoryConversionException, PlexusSisuBridgeException
     {
         LegacyRepositoryConverter legacyRepositoryConverter = lookup( LegacyRepositoryConverter.class );
 
index 3635408df57dedc852cde6708aafaaff688a3b0c..ba8bf2703c6371c7e39ff1aec48ff94bda68fc74 100644 (file)
@@ -51,12 +51,12 @@ import org.springframework.stereotype.Service;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -393,24 +393,13 @@ public class LegacyToDefaultConverter
     private Metadata readMetadata( File file )
         throws ArtifactConversionException
     {
-        Metadata metadata;
         MetadataXpp3Reader reader = new MetadataXpp3Reader();
 
-        try (FileReader fileReader = new FileReader( file ))
+        try (Reader fileReader = Files.newBufferedReader( file.toPath(), Charset.defaultCharset() ))
         {
             return reader.read( fileReader );
         }
-        catch ( FileNotFoundException e )
-        {
-            throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
-                                                   e ); //$NON-NLS-1$
-        }
-        catch ( IOException e )
-        {
-            throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
-                                                   e ); //$NON-NLS-1$
-        }
-        catch ( XmlPullParserException e )
+        catch ( IOException | XmlPullParserException e )
         {
             throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
                                                    e ); //$NON-NLS-1$
index 0a8f22ffce5aa92e37aca1e0194a1a943ac0291e..07f108c3007efbdd589c49a62cdc14ac1bb33d9d 100644 (file)
@@ -60,24 +60,12 @@ public class ValidateChecksumConsumer
 
     private static final String CHECKSUM_IO_ERROR = "checksum-io-error";
 
-    /**
-     * default-value="validate-checksums"
-     */
     private String id = "validate-checksums";
 
-    /**
-     * default-value="Validate checksums against file."
-     */
     private String description = "Validate checksums against file.";
 
-    /**
-     *
-     */
     private ChecksumFile checksum;
 
-    /**
-     *
-     */
     private List<Digester> allDigesters;
 
     @Inject
index 4ae8d222cc156cd16d5e56fd55626a1504b5c963..6a9a396244731f9d1c7940ec861c07cb71be336c 100644 (file)
@@ -50,7 +50,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -352,11 +351,7 @@ public class DownloadRemoteIndexTask
                 wagon.get( addParameters( name, this.remoteRepository ), file );
                 return Files.newInputStream( file.toPath() );
             }
-            catch ( AuthorizationException e )
-            {
-                throw new IOException( e.getMessage(), e );
-            }
-            catch ( TransferFailedException e )
+            catch ( AuthorizationException | TransferFailedException e )
             {
                 throw new IOException( e.getMessage(), e );
             }
index c7303cef5dce230360df89956ca8e9f03a4b5d8a..0543c334d459d0e5d42c1f9ee1c260288f0b7ed2 100644 (file)
@@ -87,6 +87,8 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -688,19 +690,12 @@ public class Maven2RepositoryStorage
         try
         {
             // MavenXpp3Reader leaves the file open, so we need to close it ourselves.
-            FileReader reader = new FileReader( pom );
+
             Model model = null;
-            try
+            try (Reader reader = Files.newBufferedReader( pom.toPath(), Charset.defaultCharset() ))
             {
                 model = MAVEN_XPP_3_READER.read( reader );
             }
-            finally
-            {
-                if ( reader != null )
-                {
-                    reader.close();
-                }
-            }
 
             DistributionManagement dist = model.getDistributionManagement();
             if ( dist != null )
@@ -724,10 +719,6 @@ public class Maven2RepositoryStorage
                 }
             }
         }
-        catch ( FileNotFoundException e )
-        {
-            // Artifact has no POM in repo : ignore
-        }
         catch ( IOException e )
         {
             // Unable to read POM : ignore.
index 15129c9a4b49fb0e0358f87e33962495a7daf99d..e04c7d3bf9dfbe5f13c6f8908410bd9d14247aca 100644 (file)
@@ -46,6 +46,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -857,7 +858,7 @@ public class FileMetadataRepository
         {
             return readProperties( directory, propertiesKey );
         }
-        catch ( FileNotFoundException e )
+        catch ( FileNotFoundException | NoSuchFileException e )
         {
             // ignore and return new properties
         }
index 750b112f6fca241a19de727b18ce5fac31abbcb7..b86bee0effd6d63ea9e9ae5105776065273fb8aa 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.archiva.reports.consumers;
 
 import junit.framework.TestCase;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.consumers.ConsumerException;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.repository.MetadataRepository;
@@ -28,26 +29,24 @@ import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
 import org.apache.archiva.reports.RepositoryProblemFacet;
-import org.apache.archiva.consumers.ConsumerException;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Matchers;
 import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.nio.file.NoSuchFileException;
 import java.util.Arrays;
 import java.util.Date;
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 
 import static org.mockito.Mockito.*;
-import org.springframework.test.annotation.DirtiesContext;
 
 @SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
 @RunWith( ArchivaSpringJUnit4ClassRunner.class )