> Can you associate this with a JIRA issue?
>
> I presume this meant that repeated attempts to upload from the web
> interface will lead to problems in 1.2.1?
>
> - Brett
>
>
> On 29/05/2009, at 3:02 PM,
evenisse@... wrote:
>
> Author: evenisse
>> Date: Fri May 29 05:02:22 2009
>> New Revision: 779841
>>
>> URL:
http://svn.apache.org/viewvc?rev=779841&view=rev>> Log:
>> Close some open stream
>>
>> Modified:
>>
>> archiva/trunk/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java
>>
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
>>
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java
>>
>> Modified:
>> archiva/trunk/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java
>> URL:
>>
http://svn.apache.org/viewvc/archiva/trunk/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java?rev=779841&r1=779840&r2=779841&view=diff>>
>> ==============================================================================
>> ---
>> archiva/trunk/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java
>> (original)
>> +++
>> archiva/trunk/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java
>> Fri May 29 05:02:22 2009
>> @@ -19,6 +19,9 @@
>> * under the License.
>> */
>>
>> +import com.sampullara.cli.Args;
>> +import com.sampullara.cli.Argument;
>> +
>> import java.io.File;
>> import java.io.FileInputStream;
>> import java.io.FileNotFoundException;
>> @@ -31,6 +34,7 @@
>> import java.util.Map;
>> import java.util.Properties;
>>
>> +import org.apache.commons.io.IOUtils;
>> import org.apache.commons.lang.StringUtils;
>> import
>> org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
>> import org.apache.maven.archiva.consumers.ConsumerException;
>> @@ -46,14 +50,11 @@
>> import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
>> import org.codehaus.plexus.spring.PlexusToSpringUtils;
>>
>> -import com.sampullara.cli.Args;
>> -import com.sampullara.cli.Argument;
>> -
>> /**
>> * ArchivaCli
>> - *
>> - * @todo add back reading of archiva.xml from a given location
>> + *
>> * @version $Id$
>> + * @todo add back reading of archiva.xml from a given location
>> */
>> public class ArchivaCli
>> {
>> @@ -71,7 +72,8 @@
>> throws IOException
>> {
>> Properties properties = new Properties();
>> - properties.load( ArchivaCli.class.getResourceAsStream(
>> "/META-INF/maven/org.apache.archiva/archiva-cli/pom.properties" ) );
>> + properties.load(
>> + ArchivaCli.class.getResourceAsStream(
>> "/META-INF/maven/org.apache.archiva/archiva-cli/pom.properties" ) );
>> return properties.getProperty( "version" );
>> }
>>
>> @@ -79,9 +81,8 @@
>>
>> public ArchivaCli()
>> {
>> - applicationContext =
>> - new PlexusClassPathXmlApplicationContext( new String[] {
>> "classpath*:/META-INF/spring-context.xml",
>> - "classpath*:/META-INF/plexus/components.xml" } );
>> + applicationContext = new PlexusClassPathXmlApplicationContext(
>> + new String[]{"classpath*:/META-INF/spring-context.xml",
>> "classpath*:/META-INF/plexus/components.xml"} );
>> }
>>
>> public static void main( String[] args )
>> @@ -144,8 +145,8 @@
>> {
>> // hack around poorly configurable project builder by pointing all
>> repositories back at this location to be self
>> // contained
>> - WagonManager wagonManager =
>> - (WagonManager) applicationContext.getBean(
>> PlexusToSpringUtils.buildSpringId( WagonManager.class.getName() ) );
>> + WagonManager wagonManager = (WagonManager)
>> applicationContext.getBean(
>> + PlexusToSpringUtils.buildSpringId(
>> WagonManager.class.getName() ) );
>> wagonManager.addMirror( "internal", "*", new File( path
>> ).toURL().toExternalForm() );
>>
>> ManagedRepositoryConfiguration repo = new
>> ManagedRepositoryConfiguration();
>> @@ -166,9 +167,8 @@
>>
>> try
>> {
>> - RepositoryScanStatistics stats =
>> - scanner.scan( repo, knownConsumerList,
>> invalidConsumerList, ignoredContent,
>> - RepositoryScanner.FRESH_SCAN );
>> + RepositoryScanStatistics stats = scanner.scan( repo,
>> knownConsumerList, invalidConsumerList, ignoredContent,
>> +
>> RepositoryScanner.FRESH_SCAN );
>>
>> System.out.println( "\n" + stats.toDump( repo ) );
>> }
>> @@ -215,12 +215,12 @@
>> {
>> String consumerHint = (String) entry.getKey();
>> RepositoryContentConsumer consumer =
>> (RepositoryContentConsumer) entry.getValue();
>> - System.out.println( " " + consumerHint + ": " +
>> consumer.getDescription() + " ("
>> - + consumer.getClass().getName() + ")" );
>> + System.out.println(
>> + " " + consumerHint + ": " + consumer.getDescription() +
>> " (" + consumer.getClass().getName() + ")" );
>> }
>> }
>>
>> - @SuppressWarnings( "unchecked" )
>> + @SuppressWarnings("unchecked")
>> private Map<String, KnownRepositoryContentConsumer> getConsumers()
>> {
>> return PlexusToSpringUtils.lookupMap(
>> "knownRepositoryContentConsumer", applicationContext );
>> @@ -234,7 +234,16 @@
>>
>> Properties p = new Properties();
>>
>> - p.load( new FileInputStream( properties ) );
>> + FileInputStream fis = new FileInputStream( properties );
>> +
>> + try
>> + {
>> + p.load( fis );
>> + }
>> + finally
>> + {
>> + IOUtils.closeQuietly( fis );
>> + }
>>
>> File oldRepositoryPath = new File( p.getProperty( SOURCE_REPO_PATH
>> ) );
>>
>> @@ -251,33 +260,36 @@
>> fileExclusionPatterns = Arrays.asList( StringUtils.split( s,
>> "," ) );
>> }
>>
>> - legacyRepositoryConverter.convertLegacyRepository(
>> oldRepositoryPath, newRepositoryPath, fileExclusionPatterns );
>> + legacyRepositoryConverter.convertLegacyRepository(
>> oldRepositoryPath, newRepositoryPath,
>> +
>> fileExclusionPatterns );
>> }
>>
>> private static class Commands
>> {
>> - @Argument( description = "Display help information", value =
>> "help", alias = "h" )
>> + @Argument(description = "Display help information", value =
>> "help", alias = "h")
>> private boolean help;
>>
>> - @Argument( description = "Display version information", value =
>> "version", alias = "v" )
>> + @Argument(description = "Display version information", value =
>> "version", alias = "v")
>> private boolean version;
>>
>> - @Argument( description = "List available consumers", value =
>> "listconsumers", alias = "l" )
>> + @Argument(description = "List available consumers", value =
>> "listconsumers", alias = "l")
>> private boolean listConsumers;
>>
>> - @Argument( description = "The consumers to use (comma
>> delimited)", value = "consumers", alias = "u" )
>> + @Argument(description = "The consumers to use (comma delimited)",
>> value = "consumers", alias = "u")
>> private String consumers = "count-artifacts";
>>
>> - @Argument( description = "Scan the specified repository", value =
>> "scan", alias = "s" )
>> + @Argument(description = "Scan the specified repository", value =
>> "scan", alias = "s")
>> private boolean scan;
>>
>> - @Argument( description = "Convert a legacy Maven 1.x repository
>> to a Maven 2.x repository using a properties file to describe the
>> conversion", value = "convert", alias = "c" )
>> + @Argument(
>> + description = "Convert a legacy Maven 1.x repository to a
>> Maven 2.x repository using a properties file to describe the conversion",
>> + value = "convert", alias = "c")
>> private boolean convert;
>>
>> - @Argument( description = "The properties file for the
>> converstion", value = "properties" )
>> + @Argument(description = "The properties file for the
>> converstion", value = "properties")
>> private String properties = "conversion.properties";
>>
>> - @Argument( description = "The repository to scan", value =
>> "repository" )
>> + @Argument(description = "The repository to scan", value =
>> "repository")
>> private String repository;
>> }
>> }
>>
>> Modified:
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
>> URL:
>>
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java?rev=779841&r1=779840&r2=779841&view=diff>>
>> ==============================================================================
>> ---
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
>> (original)
>> +++
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
>> Fri May 29 05:02:22 2009
>> @@ -19,6 +19,9 @@
>> * under the License.
>> */
>>
>> +import com.opensymphony.xwork2.Preparable;
>> +import com.opensymphony.xwork2.Validateable;
>> +
>> import java.io.File;
>> import java.io.FileInputStream;
>> import java.io.FileOutputStream;
>> @@ -27,13 +30,15 @@
>> import java.text.SimpleDateFormat;
>> import java.util.ArrayList;
>> import java.util.Calendar;
>> -import java.util.Date;
>> import java.util.Collections;
>> +import java.util.Date;
>> import java.util.List;
>> import java.util.TimeZone;
>>
>> import org.apache.archiva.checksum.ChecksumAlgorithm;
>> import org.apache.archiva.checksum.ChecksummedFile;
>> +import org.apache.commons.io.FilenameUtils;
>> +import org.apache.commons.lang.StringUtils;
>> import org.apache.maven.archiva.common.utils.VersionComparator;
>> import org.apache.maven.archiva.common.utils.VersionUtil;
>> import org.apache.maven.archiva.configuration.ArchivaConfiguration;
>> @@ -46,7 +51,6 @@
>> import org.apache.maven.archiva.repository.RepositoryContentFactory;
>> import org.apache.maven.archiva.repository.RepositoryException;
>> import org.apache.maven.archiva.repository.RepositoryNotFoundException;
>> -import
>> org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
>> import org.apache.maven.archiva.repository.audit.AuditEvent;
>> import org.apache.maven.archiva.repository.audit.Auditable;
>> import org.apache.maven.archiva.repository.metadata.MetadataTools;
>> @@ -56,6 +60,7 @@
>> import org.apache.maven.archiva.repository.project.ProjectModelException;
>> import org.apache.maven.archiva.repository.project.ProjectModelWriter;
>> import
>> org.apache.maven.archiva.repository.project.writers.ProjectModel400Writer;
>> +import
>> org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
>> import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
>> import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
>> import org.apache.maven.archiva.scheduled.tasks.TaskCreator;
>> @@ -63,17 +68,12 @@
>> import org.apache.maven.archiva.security.ArchivaSecurityException;
>> import org.apache.maven.archiva.security.PrincipalNotFoundException;
>> import org.apache.maven.archiva.security.UserRepositories;
>> -
>> -import com.opensymphony.xwork2.Preparable;
>> -import com.opensymphony.xwork2.Validateable;
>> -import org.apache.commons.io.FilenameUtils;
>> -import org.apache.commons.lang.StringUtils;
>> import org.codehaus.plexus.taskqueue.TaskQueueException;
>>
>> /**
>> * Upload an artifact using Jakarta file upload in webwork. If set by the
>> user a pom will also be generated. Metadata
>> * will also be updated if one exists, otherwise it would be created.
>> - *
>> + *
>> * @plexus.component role="com.opensymphony.xwork2.Action"
>> role-hint="uploadAction" instantiation-strategy="per-lookup"
>> */
>> public class UploadAction
>> @@ -81,11 +81,11 @@
>> implements Validateable, Preparable, Auditable
>> {
>> /**
>> - * @plexus.requirement
>> - */
>> - private RepositoryContentConsumers consumers;
>> -
>> - /**
>> + * @plexus.requirement
>> + */
>> + private RepositoryContentConsumers consumers;
>> +
>> + /**
>> * The groupId of the artifact to be deployed.
>> */
>> private String groupId;
>> @@ -149,16 +149,16 @@
>> * @plexus.requirement
>> */
>> private RepositoryContentFactory repositoryFactory;
>> -
>> +
>> /**
>> * @plexus.requirement
>> */
>> private ArchivaTaskScheduler scheduler;
>> -
>> - private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] {
>> ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
>> +
>> + private ChecksumAlgorithm[] algorithms = new
>> ChecksumAlgorithm[]{ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5};
>>
>> private ProjectModelWriter pomWriter = new ProjectModel400Writer();
>> -
>> +
>> public void setArtifact( File file )
>> {
>> this.artifactFile = file;
>> @@ -293,7 +293,7 @@
>> repositoryId = "";
>> generatePom = false;
>> }
>> -
>> +
>> public String doUpload()
>> {
>> try
>> @@ -319,11 +319,11 @@
>> Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
>> int newBuildNumber = -1;
>> String timestamp = null;
>> -
>> +
>> File metadataFile = getMetadata( targetPath.getAbsolutePath()
>> );
>> ArchivaRepositoryMetadata metadata = getMetadata( metadataFile
>> );
>>
>> - if (VersionUtil.isSnapshot(version))
>> + if ( VersionUtil.isSnapshot( version ) )
>> {
>> TimeZone timezone = TimeZone.getTimeZone( "UTC" );
>> DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
>> @@ -335,8 +335,8 @@
>> }
>> else
>> {
>> - metadata.setSnapshotVersion( new SnapshotVersion()
>> );
>> - newBuildNumber = 1;
>> + metadata.setSnapshotVersion( new SnapshotVersion() );
>> + newBuildNumber = 1;
>> }
>> }
>>
>> @@ -364,12 +364,12 @@
>> }
>>
>> String pomFilename = filename;
>> - if( classifier != null && !"".equals( classifier ) )
>> + if ( classifier != null && !"".equals( classifier ) )
>> {
>> pomFilename = StringUtils.remove( pomFilename, "-" +
>> classifier );
>> }
>> pomFilename = FilenameUtils.removeExtension( pomFilename ) +
>> ".pom";
>> -
>> +
>> if ( generatePom )
>> {
>> try
>> @@ -389,11 +389,11 @@
>> return ERROR;
>> }
>> }
>> -
>> - if ( pomFile != null && pomFile.length() > 0 )
>> +
>> + if ( pomFile != null && pomFile.length() > 0 )
>> {
>> try
>> - {
>> + {
>> copyFile( pomFile, targetPath, pomFilename );
>> queueRepositoryTask( repoConfig.getId(), new File(
>> targetPath, pomFilename ) );
>> //consumers.executeConsumers( repoConfig, new File(
>> targetPath, pomFilename ) );
>> @@ -403,16 +403,16 @@
>> addActionError( "Error encountered while uploading pom
>> file: " + ie.getMessage() );
>> return ERROR;
>> }
>> -
>> +
>> }
>>
>> updateMetadata( metadata, metadataFile, lastUpdatedTimestamp,
>> timestamp, newBuildNumber );
>>
>> String msg = "Artifact \'" + groupId + ":" + artifactId + ":" +
>> version +
>> "\' was successfully deployed to repository \'" +
>> repositoryId + "\'";
>> -
>> +
>> triggerAuditEvent( repositoryId, groupId + ":" + artifactId +
>> ":" + version, AuditEvent.UPLOAD_FILE );
>> -
>> +
>> addActionMessage( msg );
>>
>> reset();
>> @@ -434,11 +434,11 @@
>> throws IOException
>> {
>> FileOutputStream out = new FileOutputStream( new File( targetPath,
>> targetFilename ) );
>> + FileInputStream input = new FileInputStream( sourceFile );
>>
>> try
>> {
>> - FileInputStream input = new FileInputStream( sourceFile );
>> - int i = 0;
>> + int i;
>> while ( ( i = input.read() ) != -1 )
>> {
>> out.write( i );
>> @@ -448,6 +448,7 @@
>> finally
>> {
>> out.close();
>> + input.close();
>> }
>> }
>>
>> @@ -459,8 +460,8 @@
>> projectModel.setArtifactId( artifactId );
>> projectModel.setVersion( version );
>> projectModel.setPackaging( packaging );
>> -
>> - File pomFile = new File( targetPath, filename);
>> +
>> + File pomFile = new File( targetPath, filename );
>> pomWriter.write( projectModel, pomFile );
>>
>> return pomFile;
>> @@ -486,7 +487,7 @@
>>
>> /**
>> * Update artifact level metadata. If it does not exist, create the
>> metadata.
>> - *
>> + *
>> * @param metadata
>> */
>> private void updateMetadata( ArchivaRepositoryMetadata metadata, File
>> metadataFile, Date lastUpdatedTimestamp,
>> @@ -519,11 +520,11 @@
>>
>> if ( metadata.getGroupId() == null )
>> {
>> - metadata.setGroupId( groupId );
>> + metadata.setGroupId( groupId );
>> }
>> if ( metadata.getArtifactId() == null )
>> {
>> - metadata.setArtifactId( artifactId );
>> + metadata.setArtifactId( artifactId );
>> }
>>
>> metadata.setLatestVersion( latestVersion );
>> @@ -560,11 +561,11 @@
>> {
>> addActionError( "Please add a file to upload." );
>> }
>> -
>> +
>> if ( version == null || !VersionUtil.isVersion( version ) )
>> {
>> addActionError( "Invalid version." );
>> - }
>> + }
>> }
>> catch ( PrincipalNotFoundException pe )
>> {
>> @@ -575,7 +576,7 @@
>> addActionError( ae.getMessage() );
>> }
>> }
>> -
>> +
>> private List<String> getManagableRepos()
>> {
>> try
>> @@ -597,19 +598,20 @@
>> }
>> return Collections.emptyList();
>> }
>> -
>> +
>> private void queueRepositoryTask( String repositoryId, File localFile )
>> {
>> RepositoryTask task = TaskCreator.createRepositoryTask(
>> repositoryId, localFile.getName(), localFile );
>> -
>> +
>> try
>> {
>> scheduler.queueRepositoryTask( task );
>> }
>> catch ( TaskQueueException e )
>> {
>> - log.error( "Unable to queue repository task to execute
>> consumers on resource file ['" +
>> - localFile.getName() + "']." );
>> + log.error(
>> + "Unable to queue repository task to execute consumers on
>> resource file ['" + localFile.getName() +
>> + "']." );
>> }
>> }
>> }
>>
>> Modified:
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java
>> URL:
>>
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java?rev=779841&r1=779840&r2=779841&view=diff>>
>> ==============================================================================
>> ---
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java
>> (original)
>> +++
>> archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java
>> Fri May 29 05:02:22 2009
>> @@ -19,24 +19,24 @@
>> * under the License.
>> */
>>
>> -import org.apache.commons.io.IOUtils;
>> -
>> import java.io.File;
>> import java.io.FileInputStream;
>> import java.io.IOException;
>> import java.util.zip.GZIPInputStream;
>>
>> +import org.apache.commons.io.IOUtils;
>> +
>> import junit.framework.TestCase;
>>
>> /**
>> - * BannerTest
>> + * BannerTest
>> *
>> * @version $Id$
>> */
>> public class BannerTest
>> extends TestCase
>> {
>> - private static final String eol =
>> System.getProperty("line.separator");
>> + private static final String eol = System.getProperty(
>> "line.separator" );
>>
>> private void assertEncodeDecode( String encoded, String decoded )
>> {
>> @@ -47,17 +47,17 @@
>> public void testEncodeDecode()
>> {
>> assertEncodeDecode( "[$10 ]", "[ ]" );
>> - assertEncodeDecode( "$$$5_$n$5_", "$_____"+eol+"_____" );
>> + assertEncodeDecode( "$$$5_$n$5_", "$_____" + eol + "_____" );
>> assertEncodeDecode( "$${Refgjuvyr}", "${Erstwhile}" );
>> }
>>
>> public void testInjectVersion()
>> {
>> assertEquals( "[ 1.0 ]", Banner.injectVersion( "[#####]", "1.0" )
>> );
>> - assertEquals( ".\\ 1.0-SNAPSHOT \\._____",
>> Banner.injectVersion( ".\\################\\._____",
>> -
>> "1.0-SNAPSHOT" ) );
>> - assertEquals( "Archiva:\"+eol+\" ( 1.0-alpha-1 )", Banner
>> - .injectVersion( "Archiva:\"+eol+\" (##############)",
>> "1.0-alpha-1" ) );
>> + assertEquals( ".\\ 1.0-SNAPSHOT \\._____",
>> + Banner.injectVersion(
>> ".\\################\\._____", "1.0-SNAPSHOT" ) );
>> + assertEquals( "Archiva:\"+eol+\" ( 1.0-alpha-1 )",
>> + Banner.injectVersion( "Archiva:\"+eol+\"
>> (##############)", "1.0-alpha-1" ) );
>> }
>>
>> public void testGetBanner()
>> @@ -67,16 +67,16 @@
>> String banner = Banner.getBanner( version );
>> assertNotNull( "Banner should not be null.", banner );
>> assertTrue( "Banner contains version.", banner.indexOf( version ) >
>> 0 );
>> -
>> +
>> /* Want to make a new banner?
>> - * Steps to do it.
>> - * 1) Edit the src/test/resources/banner.gz file.
>> - * 2) Save it compressed.
>> - * 3) Add (to this test method) ...
>> - * System.out.println( "\"" + Banner.encode( getRawBanner() )
>> + "\"" );
>> - * 4) Run the test
>> - * 5) Copy / Paste the encoded form into the Banner.getBanner()
>> method.
>> - */
>> + * Steps to do it.
>> + * 1) Edit the src/test/resources/banner.gz file.
>> + * 2) Save it compressed.
>> + * 3) Add (to this test method) ...
>> + * System.out.println( "\"" + Banner.encode( getRawBanner() ) +
>> "\"" );
>> + * 4) Run the test
>> + * 5) Copy / Paste the encoded form into the Banner.getBanner()
>> method.
>> + */
>> }
>>
>> public String getRawBanner()
>> @@ -86,6 +86,8 @@
>> assertTrue( "File [" + gzBanner.getPath() + "] not found.",
>> gzBanner.exists() );
>> FileInputStream fis = new FileInputStream( gzBanner );
>> GZIPInputStream gzis = new GZIPInputStream( fis );
>> - return IOUtils.toString( gzis );
>> + String str = IOUtils.toString( gzis );
>> + IOUtils.closeQuietly( gzis );
>> + return str;
>> }
>> }
>>
>>
>>
>