mirror of
https://github.com/apache/archiva.git
synced 2025-02-22 01:44:47 +00:00
more code simplification with 1.7 features
This commit is contained in:
parent
0a21a1167f
commit
2132965397
@ -38,8 +38,6 @@
|
|||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -255,7 +253,7 @@ private Map<String, KnownRepositoryContentConsumer> getConsumers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doConversion( String properties )
|
private void doConversion( String properties )
|
||||||
throws FileNotFoundException, IOException, RepositoryConversionException, PlexusSisuBridgeException
|
throws IOException, RepositoryConversionException, PlexusSisuBridgeException
|
||||||
{
|
{
|
||||||
LegacyRepositoryConverter legacyRepositoryConverter = lookup( LegacyRepositoryConverter.class );
|
LegacyRepositoryConverter legacyRepositoryConverter = lookup( LegacyRepositoryConverter.class );
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -393,24 +393,13 @@ private Metadata createBaseMetadata( Artifact artifact )
|
|||||||
private Metadata readMetadata( File file )
|
private Metadata readMetadata( File file )
|
||||||
throws ArtifactConversionException
|
throws ArtifactConversionException
|
||||||
{
|
{
|
||||||
Metadata metadata;
|
|
||||||
MetadataXpp3Reader reader = new MetadataXpp3Reader();
|
MetadataXpp3Reader reader = new MetadataXpp3Reader();
|
||||||
|
|
||||||
try (FileReader fileReader = new FileReader( file ))
|
try (Reader fileReader = Files.newBufferedReader( file.toPath(), Charset.defaultCharset() ))
|
||||||
{
|
{
|
||||||
return reader.read( fileReader );
|
return reader.read( fileReader );
|
||||||
}
|
}
|
||||||
catch ( FileNotFoundException e )
|
catch ( IOException | XmlPullParserException 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 )
|
|
||||||
{
|
{
|
||||||
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
|
throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
|
||||||
e ); //$NON-NLS-1$
|
e ); //$NON-NLS-1$
|
||||||
|
@ -60,24 +60,12 @@ public class ValidateChecksumConsumer
|
|||||||
|
|
||||||
private static final String CHECKSUM_IO_ERROR = "checksum-io-error";
|
private static final String CHECKSUM_IO_ERROR = "checksum-io-error";
|
||||||
|
|
||||||
/**
|
|
||||||
* default-value="validate-checksums"
|
|
||||||
*/
|
|
||||||
private String id = "validate-checksums";
|
private String id = "validate-checksums";
|
||||||
|
|
||||||
/**
|
|
||||||
* default-value="Validate checksums against file."
|
|
||||||
*/
|
|
||||||
private String description = "Validate checksums against file.";
|
private String description = "Validate checksums against file.";
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private ChecksumFile checksum;
|
private ChecksumFile checksum;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private List<Digester> allDigesters;
|
private List<Digester> allDigesters;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -50,7 +50,6 @@
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -352,11 +351,7 @@ public InputStream retrieve( String name )
|
|||||||
wagon.get( addParameters( name, this.remoteRepository ), file );
|
wagon.get( addParameters( name, this.remoteRepository ), file );
|
||||||
return Files.newInputStream( file.toPath() );
|
return Files.newInputStream( file.toPath() );
|
||||||
}
|
}
|
||||||
catch ( AuthorizationException e )
|
catch ( AuthorizationException | TransferFailedException e )
|
||||||
{
|
|
||||||
throw new IOException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
catch ( TransferFailedException e )
|
|
||||||
{
|
{
|
||||||
throw new IOException( e.getMessage(), e );
|
throw new IOException( e.getMessage(), e );
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,8 @@
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -688,19 +690,12 @@ public void applyServerSideRelocation( ManagedRepositoryContent managedRepositor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
|
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
|
||||||
FileReader reader = new FileReader( pom );
|
|
||||||
Model model = null;
|
Model model = null;
|
||||||
try
|
try (Reader reader = Files.newBufferedReader( pom.toPath(), Charset.defaultCharset() ))
|
||||||
{
|
{
|
||||||
model = MAVEN_XPP_3_READER.read( reader );
|
model = MAVEN_XPP_3_READER.read( reader );
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( reader != null )
|
|
||||||
{
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DistributionManagement dist = model.getDistributionManagement();
|
DistributionManagement dist = model.getDistributionManagement();
|
||||||
if ( dist != null )
|
if ( dist != null )
|
||||||
@ -724,10 +719,6 @@ public void applyServerSideRelocation( ManagedRepositoryContent managedRepositor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( FileNotFoundException e )
|
|
||||||
{
|
|
||||||
// Artifact has no POM in repo : ignore
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
// Unable to read POM : ignore.
|
// Unable to read POM : ignore.
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -857,7 +858,7 @@ private Properties readOrCreateProperties( File directory, String propertiesKey
|
|||||||
{
|
{
|
||||||
return readProperties( directory, propertiesKey );
|
return readProperties( directory, propertiesKey );
|
||||||
}
|
}
|
||||||
catch ( FileNotFoundException e )
|
catch ( FileNotFoundException | NoSuchFileException e )
|
||||||
{
|
{
|
||||||
// ignore and return new properties
|
// ignore and return new properties
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
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.ArtifactMetadata;
|
||||||
import org.apache.archiva.metadata.model.MetadataFacet;
|
import org.apache.archiva.metadata.model.MetadataFacet;
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||||
@ -28,26 +29,24 @@
|
|||||||
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
|
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
|
||||||
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
||||||
import org.apache.archiva.reports.RepositoryProblemFacet;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
|
||||||
|
|
||||||
@SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
|
@SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
|
||||||
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
|
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user