mirror of https://github.com/apache/archiva.git
[MRM-1097] close some open streams
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@779841 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a229a13bf
commit
b8578cfac9
|
@ -19,6 +19,9 @@ package org.apache.maven.archiva.cli;
|
|||
* 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.List;
|
|||
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.apache.maven.artifact.manager.WagonManager;
|
|||
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 @@ public class ArchivaCli
|
|||
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 class ArchivaCli
|
|||
|
||||
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 @@ public class ArchivaCli
|
|||
{
|
||||
// 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,8 +167,7 @@ public class ArchivaCli
|
|||
|
||||
try
|
||||
{
|
||||
RepositoryScanStatistics stats =
|
||||
scanner.scan( repo, knownConsumerList, invalidConsumerList, ignoredContent,
|
||||
RepositoryScanStatistics stats = scanner.scan( repo, knownConsumerList, invalidConsumerList, ignoredContent,
|
||||
RepositoryScanner.FRESH_SCAN );
|
||||
|
||||
System.out.println( "\n" + stats.toDump( repo ) );
|
||||
|
@ -215,8 +215,8 @@ public class ArchivaCli
|
|||
{
|
||||
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() + ")" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,16 @@ public class ArchivaCli
|
|||
|
||||
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,7 +260,8 @@ public class ArchivaCli
|
|||
fileExclusionPatterns = Arrays.asList( StringUtils.split( s, "," ) );
|
||||
}
|
||||
|
||||
legacyRepositoryConverter.convertLegacyRepository( oldRepositoryPath, newRepositoryPath, fileExclusionPatterns );
|
||||
legacyRepositoryConverter.convertLegacyRepository( oldRepositoryPath, newRepositoryPath,
|
||||
fileExclusionPatterns );
|
||||
}
|
||||
|
||||
private static class Commands
|
||||
|
@ -271,7 +281,9 @@ public class ArchivaCli
|
|||
@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")
|
||||
|
|
|
@ -19,6 +19,9 @@ package org.apache.maven.archiva.web.action;
|
|||
* 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.DateFormat;
|
|||
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.ManagedRepositoryContent;
|
|||
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.metadata.RepositoryMetadataWriter;
|
|||
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,11 +68,6 @@ import org.apache.maven.archiva.security.AccessDeniedException;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -434,11 +434,11 @@ public class UploadAction
|
|||
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 @@ public class UploadAction
|
|||
finally
|
||||
{
|
||||
out.close();
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -608,8 +609,9 @@ public class UploadAction
|
|||
}
|
||||
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() +
|
||||
"']." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ package org.apache.maven.archiva.web.startup;
|
|||
* 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;
|
||||
|
||||
/**
|
||||
|
@ -54,10 +54,10 @@ public class BannerTest
|
|||
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()
|
||||
|
@ -86,6 +86,8 @@ public class BannerTest
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue