Return-Path: X-Original-To: apmail-archiva-commits-archive@www.apache.org Delivered-To: apmail-archiva-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6581A9C33 for ; Mon, 2 Apr 2012 07:18:15 +0000 (UTC) Received: (qmail 66701 invoked by uid 500); 2 Apr 2012 07:18:15 -0000 Delivered-To: apmail-archiva-commits-archive@archiva.apache.org Received: (qmail 66609 invoked by uid 500); 2 Apr 2012 07:18:13 -0000 Mailing-List: contact commits-help@archiva.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@archiva.apache.org Delivered-To: mailing list commits@archiva.apache.org Received: (qmail 66587 invoked by uid 99); 2 Apr 2012 07:18:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2012 07:18:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2012 07:18:11 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6125923889BB for ; Mon, 2 Apr 2012 07:17:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1308255 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main: java/org/apache/archiva/webapp/ui/services/api/ java/org/apache/archiva/webapp/ui/services/model/ webapp/js/archiva/ Date: Mon, 02 Apr 2012 07:17:51 -0000 To: commits@archiva.apache.org From: olamy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120402071751.6125923889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olamy Date: Mon Apr 2 07:17:50 2012 New Revision: 1308255 URL: http://svn.apache.org/viewvc?rev=1308255&view=rev Log: cleanup logic to upload artifacts groupId,artifactId,version,packaging can be changed at save time Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java?rev=1308255&r1=1308254&r2=1308255&view=diff ============================================================================== --- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java (original) +++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java Mon Apr 2 07:17:50 2012 @@ -207,7 +207,8 @@ public class DefaultFileUploadService return fileMetadatas == null ? Collections.emptyList() : fileMetadatas; } - public Boolean save( String repositoryId, final String groupId, final String artifactId, final boolean generatePom ) + public Boolean save( String repositoryId, final String groupId, final String artifactId, String version, + String packaging, final boolean generatePom ) throws ArchivaRestServiceException { List fileMetadatas = @@ -231,7 +232,8 @@ public class DefaultFileUploadService { FileMetadata fileMetadata = iterator.next(); log.debug( "fileToAdd: {}", fileMetadata ); - saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated ); + saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version, + packaging ); pomGenerated = true; } @@ -248,13 +250,14 @@ public class DefaultFileUploadService { FileMetadata fileMetadata = iterator.next(); log.debug( "fileToAdd: {}", fileMetadata ); - savePomFile( repositoryId, fileMetadata ); + savePomFile( repositoryId, fileMetadata, groupId, artifactId, version, packaging ); } return Boolean.TRUE; } - protected void savePomFile( String repositoryId, FileMetadata fileMetadata ) + protected void savePomFile( String repositoryId, FileMetadata fileMetadata, String groupId, String artifactId, + String version, String packaging ) throws ArchivaRestServiceException { @@ -266,11 +269,11 @@ public class DefaultFileUploadService ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId ); ArtifactReference artifactReference = new ArtifactReference(); - artifactReference.setArtifactId( fileMetadata.getArtifactId() ); - artifactReference.setGroupId( fileMetadata.getGroupId() ); - artifactReference.setVersion( fileMetadata.getVersion() ); + artifactReference.setArtifactId( artifactId ); + artifactReference.setGroupId( groupId ); + artifactReference.setVersion( version ); artifactReference.setClassifier( fileMetadata.getClassifier() ); - artifactReference.setType( fileMetadata.getPackaging() ); + artifactReference.setType( packaging ); ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId ); @@ -309,7 +312,8 @@ public class DefaultFileUploadService } } - protected void saveFile( String repositoryId, FileMetadata fileMetadata, boolean generatePom ) + protected void saveFile( String repositoryId, FileMetadata fileMetadata, boolean generatePom, String groupId, + String artifactId, String version, String packaging ) throws ArchivaRestServiceException { try @@ -318,11 +322,11 @@ public class DefaultFileUploadService ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId ); ArtifactReference artifactReference = new ArtifactReference(); - artifactReference.setArtifactId( fileMetadata.getArtifactId() ); - artifactReference.setGroupId( fileMetadata.getGroupId() ); - artifactReference.setVersion( fileMetadata.getVersion() ); + artifactReference.setArtifactId( artifactId ); + artifactReference.setGroupId( groupId ); + artifactReference.setVersion( version ); artifactReference.setClassifier( fileMetadata.getClassifier() ); - artifactReference.setType( fileMetadata.getPackaging() ); + artifactReference.setType( packaging ); ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId ); @@ -342,7 +346,7 @@ public class DefaultFileUploadService File versionMetadataFile = new File( targetPath, MetadataTools.MAVEN_METADATA ); ArchivaRepositoryMetadata versionMetadata = getMetadata( versionMetadataFile ); - if ( VersionUtil.isSnapshot( fileMetadata.getVersion() ) ) + if ( VersionUtil.isSnapshot( version ) ) { TimeZone timezone = TimeZone.getTimeZone( "UTC" ); DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" ); @@ -364,7 +368,7 @@ public class DefaultFileUploadService } String filename = artifactPath.substring( lastIndex + 1 ); - if ( VersionUtil.isSnapshot( fileMetadata.getVersion() ) ) + if ( VersionUtil.isSnapshot( version ) ) { filename = filename.replaceAll( "SNAPSHOT", timestamp + "-" + newBuildNumber ); } @@ -375,8 +379,7 @@ public class DefaultFileUploadService try { File targetFile = new File( targetPath, filename ); - if ( targetFile.exists() && !VersionUtil.isSnapshot( fileMetadata.getVersion() ) - && repoConfig.isBlockRedeployments() ) + if ( targetFile.exists() && !VersionUtil.isSnapshot( version ) && repoConfig.isBlockRedeployments() ) { throw new ArchivaRestServiceException( "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.", @@ -407,7 +410,8 @@ public class DefaultFileUploadService try { - File generatedPomFile = createPom( targetPath, pomFilename, fileMetadata ); + File generatedPomFile = + createPom( targetPath, pomFilename, fileMetadata, groupId, artifactId, version, packaging ); triggerAuditEvent( repoConfig.getId(), path + "/" + pomFilename, AuditEvent.UPLOAD_FILE ); if ( fixChecksums ) { @@ -427,12 +431,13 @@ public class DefaultFileUploadService if ( !archivaAdministration.getKnownContentConsumers().contains( "metadata-updater" ) ) { updateProjectMetadata( targetPath.getAbsolutePath(), lastUpdatedTimestamp, timestamp, newBuildNumber, - fixChecksums, fileMetadata ); + fixChecksums, fileMetadata, groupId, artifactId, version, packaging ); - if ( VersionUtil.isSnapshot( fileMetadata.getVersion() ) ) + if ( VersionUtil.isSnapshot( version ) ) { updateVersionMetadata( versionMetadata, versionMetadataFile, lastUpdatedTimestamp, timestamp, - newBuildNumber, fixChecksums, fileMetadata ); + newBuildNumber, fixChecksums, fileMetadata, groupId, artifactId, version, + packaging ); } } } @@ -471,15 +476,16 @@ public class DefaultFileUploadService return metadata; } - private File createPom( File targetPath, String filename, FileMetadata fileMetadata ) + private File createPom( File targetPath, String filename, FileMetadata fileMetadata, String groupId, + String artifactId, String version, String packaging ) throws IOException { Model projectModel = new Model(); projectModel.setModelVersion( "4.0.0" ); - projectModel.setGroupId( fileMetadata.getGroupId() ); - projectModel.setArtifactId( fileMetadata.getArtifactId() ); - projectModel.setVersion( fileMetadata.getVersion() ); - projectModel.setPackaging( fileMetadata.getPackaging() ); + projectModel.setGroupId( groupId ); + projectModel.setArtifactId( artifactId ); + projectModel.setVersion( version ); + projectModel.setPackaging( packaging ); File pomFile = new File( targetPath, filename ); MavenXpp3Writer writer = new MavenXpp3Writer(); @@ -547,11 +553,12 @@ public class DefaultFileUploadService * Update artifact level metadata. If it does not exist, create the metadata and fix checksums if necessary. */ private void updateProjectMetadata( String targetPath, Date lastUpdatedTimestamp, String timestamp, int buildNumber, - boolean fixChecksums, FileMetadata fileMetadata ) + boolean fixChecksums, FileMetadata fileMetadata, String groupId, + String artifactId, String version, String packaging ) throws RepositoryMetadataException { List availableVersions = new ArrayList(); - String latestVersion = fileMetadata.getVersion(); + String latestVersion = version; File projectDir = new File( targetPath ).getParentFile(); File projectMetadataFile = new File( projectDir, MetadataTools.MAVEN_METADATA ); @@ -564,36 +571,36 @@ public class DefaultFileUploadService Collections.sort( availableVersions, VersionComparator.getInstance() ); - if ( !availableVersions.contains( fileMetadata.getVersion() ) ) + if ( !availableVersions.contains( version ) ) { - availableVersions.add( fileMetadata.getVersion() ); + availableVersions.add( version ); } latestVersion = availableVersions.get( availableVersions.size() - 1 ); } else { - availableVersions.add( fileMetadata.getVersion() ); + availableVersions.add( version ); - projectMetadata.setGroupId( fileMetadata.getGroupId() ); - projectMetadata.setArtifactId( fileMetadata.getArtifactId() ); + projectMetadata.setGroupId( groupId ); + projectMetadata.setArtifactId( artifactId ); } if ( projectMetadata.getGroupId() == null ) { - projectMetadata.setGroupId( fileMetadata.getGroupId() ); + projectMetadata.setGroupId( groupId ); } if ( projectMetadata.getArtifactId() == null ) { - projectMetadata.setArtifactId( fileMetadata.getArtifactId() ); + projectMetadata.setArtifactId( artifactId ); } projectMetadata.setLatestVersion( latestVersion ); projectMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp ); projectMetadata.setAvailableVersions( availableVersions ); - if ( !VersionUtil.isSnapshot( fileMetadata.getVersion() ) ) + if ( !VersionUtil.isSnapshot( version ) ) { projectMetadata.setReleasedVersion( latestVersion ); } @@ -612,14 +619,15 @@ public class DefaultFileUploadService */ private void updateVersionMetadata( ArchivaRepositoryMetadata metadata, File metadataFile, Date lastUpdatedTimestamp, String timestamp, int buildNumber, - boolean fixChecksums, FileMetadata fileMetadata ) + boolean fixChecksums, FileMetadata fileMetadata, String groupId, + String artifactId, String version, String packaging ) throws RepositoryMetadataException { if ( !metadataFile.exists() ) { - metadata.setGroupId( fileMetadata.getGroupId() ); - metadata.setArtifactId( fileMetadata.getArtifactId() ); - metadata.setVersion( fileMetadata.getVersion() ); + metadata.setGroupId( groupId ); + metadata.setArtifactId( artifactId ); + metadata.setVersion( version ); } if ( metadata.getSnapshotVersion() == null ) Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java?rev=1308255&r1=1308254&r2=1308255&view=diff ============================================================================== --- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java (original) +++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java Mon Apr 2 07:17:50 2012 @@ -67,12 +67,13 @@ public interface FileUploadService List getSessionFileMetadatas() throws ArchivaRestServiceException; - @Path( "save/{repositoryId}/{groupId}/{artifactId}" ) + @Path( "save/{repositoryId}/{groupId}/{artifactId}/{version}/{packaging}" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ) Boolean save( @PathParam( "repositoryId" ) String repositoryId, @PathParam( "groupId" ) String groupId, - @PathParam( "artifactId" ) String artifactId, @QueryParam( "generatePom" ) boolean generatePom ) + @PathParam( "artifactId" ) String artifactId, @PathParam( "version" ) String version, + @PathParam( "packaging" ) String packaging, @QueryParam( "generatePom" ) boolean generatePom ) throws ArchivaRestServiceException; Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java?rev=1308255&r1=1308254&r2=1308255&view=diff ============================================================================== --- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java (original) +++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java Mon Apr 2 07:17:50 2012 @@ -43,14 +43,6 @@ public class FileMetadata private String errorKey; - private String groupId; - - private String artifactId; - - private String version; - - private String packaging; - private String classifier; private boolean pomFile; @@ -134,46 +126,6 @@ public class FileMetadata this.errorKey = errorKey; } - public String getGroupId() - { - return groupId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public String getVersion() - { - return version; - } - - public void setVersion( String version ) - { - this.version = version; - } - - public String getPackaging() - { - return packaging; - } - - public void setPackaging( String packaging ) - { - this.packaging = packaging; - } - public String getClassifier() { return classifier; @@ -245,10 +197,6 @@ public class FileMetadata sb.append( ", deleteUrl='" ).append( deleteUrl ).append( '\'' ); sb.append( ", deleteType='" ).append( deleteType ).append( '\'' ); sb.append( ", errorKey='" ).append( errorKey ).append( '\'' ); - sb.append( ", groupId='" ).append( groupId ).append( '\'' ); - sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); - sb.append( ", version='" ).append( version ).append( '\'' ); - sb.append( ", packaging='" ).append( packaging ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( ", pomFile=" ).append( pomFile ); sb.append( '}' ); Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js?rev=1308255&r1=1308254&r2=1308255&view=diff ============================================================================== --- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js (original) +++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js Mon Apr 2 07:17:50 2012 @@ -47,6 +47,7 @@ define("archiva.artifacts-management",[" return; } var url="restServices/archivaUiServices/fileUploadService/save/"+this.repositoryId()+"/"+this.groupId()+"/"+this.artifactId(); + url+="/"+this.version()+"/"+this.packaging(); if (this.generatePom()){ url+="?generatePom=true"; } @@ -89,21 +90,8 @@ define("archiva.artifacts-management",[" } }); $('#fileupload').fileupload({ - add: function (e, data) { - if(!mainContent.find("#fileupload" ).valid()){ - return; - } - data.formData = { - groupId: artifactUploadViewModel.groupId(), - artifactId: artifactUploadViewModel.artifactId(), - version: artifactUploadViewModel.version(), - packaging: artifactUploadViewModel.packaging() - }; - $.blueimpUI.fileupload.prototype.options.add.call(this, e, data); - }, submit: function (e, data) { var $this = $(this); - $this.fileupload('send', data); artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile)); return false;