From e5de45d6b3ec7de0879dbaf7e9d3052ed9a7c698 Mon Sep 17 00:00:00 2001 From: Wendy Smoak Date: Sun, 4 May 2008 09:09:22 +0000 Subject: [PATCH] [MRM-774] Allow a POM file to be uploaded along with the artifact. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@653190 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/web/action/UploadAction.java | 80 +++++++++++++++---- .../WEB-INF/jsp/include/uploadForm.jspf | 9 ++- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index e4e9b0b00..0efc1f37a 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -96,19 +96,34 @@ public class UploadAction private String classifier; /** - * The artifact to be deployed. + * The temporary file representing the artifact to be deployed. */ - private File file; + private File artifactFile; /** * The content type of the artifact to be deployed. */ - private String contentType; + private String artifactContentType; /** - * The temporary filename of the artifact to be deployed. + * The original filename of the uploaded artifact file. */ - private String filename; + private String artifactFilename; + + /** + * The temporary file representing the pom to be deployed alongside the artifact. + */ + private File pomFile; + + /** + * The content type of the pom file. + */ + private String pomContentType; + + /** + * The original filename of the uploaded pom file. + */ + private String pomFilename; /** * The repository where the artifact is to be deployed. @@ -144,19 +159,34 @@ public class UploadAction private ProjectModelWriter pomWriter = new ProjectModel400Writer(); - public void setUpload( File file ) + public void setArtifact( File file ) + { + this.artifactFile = file; + } + + public void setArtifactContentType( String contentType ) + { + this.artifactContentType = contentType; + } + + public void setArtifactFileName( String filename ) + { + this.artifactFilename = filename; + } + + public void setPom( File file ) { - this.file = file; + this.pomFile = file; } - public void setUploadContentType( String contentType ) + public void setPomContentType( String contentType ) { - this.contentType = contentType; + this.pomContentType = contentType; } - public void setUploadFileName( String filename ) + public void setPomFileName( String filename ) { - this.filename = filename; + this.pomFilename = filename; } public String getGroupId() @@ -279,7 +309,7 @@ public class UploadAction try { - copyFile( targetPath, artifactPath.substring( lastIndex + 1 ) ); + copyFile( artifactFile, targetPath, artifactPath.substring( lastIndex + 1 ) ); } catch ( IOException ie ) { @@ -304,6 +334,22 @@ public class UploadAction return ERROR; } } + + if ( pomFile != null && pomFile.length() > 0 ) + { + + try + { + String targetFilename = artifactPath.substring( lastIndex + 1 ).replaceAll( packaging, "pom" ); + copyFile( pomFile, targetPath, targetFilename ); + } + catch ( IOException ie ) + { + addActionError( "Error encountered while uploading pom file: " + ie.getMessage() ); + return ERROR; + } + + } updateMetadata( getMetadata( targetPath.getAbsolutePath() ) ); @@ -329,14 +375,14 @@ public class UploadAction return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() ); } - private void copyFile( File targetPath, String artifactFilename ) + private void copyFile( File sourceFile, File targetPath, String targetFilename ) throws IOException { - FileOutputStream out = new FileOutputStream( new File( targetPath, artifactFilename ) ); + FileOutputStream out = new FileOutputStream( new File( targetPath, targetFilename ) ); try { - FileInputStream input = new FileInputStream( file ); + FileInputStream input = new FileInputStream( sourceFile ); int i = 0; while ( ( i = input.read() ) != -1 ) { @@ -374,7 +420,7 @@ public class UploadAction /** * Update artifact level metadata. If it does not exist, create the metadata. * - * @param targetPath + * @param metadataFile */ private void updateMetadata( File metadataFile ) throws RepositoryMetadataException @@ -435,7 +481,7 @@ public class UploadAction addActionError( "User is not authorized to upload in repository " + repositoryId ); } - if ( file == null || file.length() == 0 ) + if ( artifactFile == null || artifactFile.length() == 0 ) { addActionError( "Please add a file to upload." ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf index 91635a367..e44d0b162 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf @@ -27,9 +27,10 @@ - - + label="Generate Maven 2 POM"/> + + + - + \ No newline at end of file -- 2.39.5