From 4f7f1d74f9afa007aea86c99e9652f2309554743 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 28 Nov 2013 23:13:21 +0000 Subject: [PATCH] [MRM-1769]Can't uploads multiple artifacts of different types fix issue deleting temporary files git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1546471 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/api/DefaultFileUploadService.java | 20 +++++++++++-------- .../archiva/web/model/FileMetadata.java | 18 ++++++++++++++--- .../js/templates/archiva/general-admin.html | 3 ++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java index 77b1c0c06..308476686 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java @@ -85,7 +85,7 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * @author Olivier Lamy */ -@Service( "fileUploadService#rest" ) +@Service("fileUploadService#rest") public class DefaultFileUploadService extends AbstractRestService implements FileUploadService @@ -107,7 +107,7 @@ public class DefaultFileUploadService private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; @Inject - @Named( value = "archivaTaskScheduler#repository" ) + @Named(value = "archivaTaskScheduler#repository") private ArchivaTaskScheduler scheduler; private String getStringValue( MultipartBody multipartBody, String attachmentId ) @@ -125,6 +125,7 @@ public class DefaultFileUploadService { String classifier = getStringValue( multipartBody, "classifier" ); + String packaging = getStringValue( multipartBody, "packaging" ); // skygo: http header form pomFile was once sending 1 for true and void for false // leading to permanent false value for pomFile if using toBoolean(); use , "1", "" boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) ); @@ -142,6 +143,7 @@ public class DefaultFileUploadService fileMetadata.setClassifier( classifier ); fileMetadata.setDeleteUrl( tmpFile.getName() ); fileMetadata.setPomFile( pomFile ); + fileMetadata.setPackaging( packaging ); log.info( "uploading file: {}", fileMetadata ); @@ -181,8 +183,7 @@ public class DefaultFileUploadService { File file = new File( SystemUtils.getJavaIoTmpDir(), fileName ); log.debug( "delete file:{},exists:{}", file.getPath(), file.exists() ); - boolean removed = getSessionFileMetadatas().remove( - new FileMetadata( SystemUtils.getJavaIoTmpDir().getPath() + "/" + fileName ) ); + boolean removed = getSessionFileMetadatas().remove( new FileMetadata( fileName ) ); if ( file.exists() ) { return file.delete(); @@ -196,8 +197,9 @@ public class DefaultFileUploadService List fileMetadatas = new ArrayList( getSessionFileMetadatas() ); for ( FileMetadata fileMetadata : fileMetadatas ) { - deleteFile( new File( fileMetadata.getServerFileName() ).getName() ); + deleteFile( new File( fileMetadata.getServerFileName() ).getPath() ); } + getSessionFileMetadatas().clear(); return Boolean.TRUE; } @@ -210,8 +212,8 @@ public class DefaultFileUploadService return fileMetadatas == null ? Collections.emptyList() : fileMetadatas; } - public Boolean save( String repositoryId, String groupId, String artifactId, String version, - String packaging, boolean generatePom ) + public Boolean save( String repositoryId, String groupId, String artifactId, String version, String packaging, + boolean generatePom ) throws ArchivaRestServiceException { repositoryId = StringUtils.trim( repositoryId ); @@ -362,7 +364,8 @@ public class DefaultFileUploadService artifactReference.setGroupId( groupId ); artifactReference.setVersion( version ); artifactReference.setClassifier( fileMetadata.getClassifier() ); - artifactReference.setType( packaging ); + artifactReference.setType( + StringUtils.isEmpty( fileMetadata.getPackaging() ) ? packaging : fileMetadata.getPackaging() ); ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId ); @@ -430,6 +433,7 @@ public class DefaultFileUploadService } catch ( IOException ie ) { + log.error( "IOException copying file: {}", ie.getMessage(), ie ); throw new ArchivaRestServiceException( "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie ); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/model/FileMetadata.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/model/FileMetadata.java index f3a8245e1..0b6dbcc85 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/model/FileMetadata.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/model/FileMetadata.java @@ -45,6 +45,8 @@ public class FileMetadata private String classifier; + private String packaging; + private boolean pomFile; public FileMetadata() @@ -157,6 +159,16 @@ public class FileMetadata this.serverFileName = serverFileName; } + public String getPackaging() + { + return packaging; + } + + public void setPackaging( String packaging ) + { + this.packaging = packaging; + } + @Override public boolean equals( Object o ) { @@ -188,9 +200,8 @@ public class FileMetadata @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append( "FileMetadata" ); - sb.append( "{name='" ).append( name ).append( '\'' ); + final StringBuilder sb = new StringBuilder( "FileMetadata{" ); + sb.append( "name='" ).append( name ).append( '\'' ); sb.append( ", serverFileName='" ).append( serverFileName ).append( '\'' ); sb.append( ", size=" ).append( size ); sb.append( ", url='" ).append( url ).append( '\'' ); @@ -198,6 +209,7 @@ public class FileMetadata sb.append( ", deleteType='" ).append( deleteType ).append( '\'' ); sb.append( ", errorKey='" ).append( errorKey ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' ); + sb.append( ", packaging='" ).append( packaging ).append( '\'' ); sb.append( ", pomFile=" ).append( pomFile ); sb.append( '}' ); return sb.toString(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/general-admin.html b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/general-admin.html index d2cb1e9e4..fe734ee83 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/general-admin.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/general-admin.html @@ -734,7 +734,8 @@ {% for (var i=0, file; file=o.files[i]; i++) { %} {%=file.name%} - + + pomFile: {%=o.formatFileSize(file.size)%} {% if (file.error) { %} -- 2.39.5