Author: wsmoak
Date: Sun May  4 02:09:22 2008
New Revision: 653190

URL: http://svn.apache.org/viewvc?rev=653190&view=rev
Log:
[MRM-774] Allow a POM file to be uploaded along with the artifact.

Modified:
    
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/main/webapp/WEB-INF/jsp/include/uploadForm.jspf

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=653190&r1=653189&r2=653190&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
 Sun May  4 02:09:22 2008
@@ -96,19 +96,34 @@
     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 @@
 
     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 @@
 
             try
             {
-                copyFile( targetPath, artifactPath.substring( lastIndex + 1 ) 
);
+                copyFile( artifactFile, targetPath, artifactPath.substring( 
lastIndex + 1 ) );
             }
             catch ( IOException ie )
             {
@@ -304,6 +334,22 @@
                     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 @@
         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 @@
     /**
      * 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 @@
                 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." );
             }

Modified: 
archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf
URL: 
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf?rev=653190&r1=653189&r2=653190&view=diff
==============================================================================
--- 
archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf
 (original)
+++ 
archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/uploadForm.jspf
 Sun May  4 02:09:22 2008
@@ -27,9 +27,10 @@
 <ww:textfield name="version" label="Version" size="50" required="true"/>
 <ww:textfield name="packaging" label="Packaging" size="50" required="true"/>
 <ww:textfield name="classifier" label="Classifier" size="50" required="false"/>
-<ww:select name="repositoryId" list="managedRepoIdList" label="Repository Id"/>
-<ww:file name="upload" label="File"/>
 <ww:checkbox name="generatePom" value="generatePom" 
-       label="Generate Pom (Currently, only Maven 2 poms can be generated)"/> 
+       label="Generate Maven 2 POM"/> 
+<ww:file name="artifact" label="Artifact File" required="true"/>
+<ww:file name="pom" label="POM File"/>
+<ww:select name="repositoryId" list="managedRepoIdList" label="Repository Id"/>
 
-    
+       
\ No newline at end of file


Reply via email to