Author: lcorneliussen Date: Thu Dec 29 12:50:18 2011 New Revision: 1225516 URL: http://svn.apache.org/viewvc?rev=1225516&view=rev Log: [NPANDAY-480] Support Windows Azure Cloud Service Project and Packaging (CCPack)
o support for worker roles Modified: incubator/npanday/trunk/plugins/azure-maven-plugin/pom.xml incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/CreateCloudServicePackageMojo.java incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/ResolveWorkerRoleFilesMojo.java Modified: incubator/npanday/trunk/plugins/azure-maven-plugin/pom.xml URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/azure-maven-plugin/pom.xml?rev=1225516&r1=1225515&r2=1225516&view=diff ============================================================================== --- incubator/npanday/trunk/plugins/azure-maven-plugin/pom.xml (original) +++ incubator/npanday/trunk/plugins/azure-maven-plugin/pom.xml Thu Dec 29 12:50:18 2011 @@ -76,6 +76,17 @@ </dependency> <dependency> <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-archiver</artifactId> + <version>2.0</version> + <exclusions> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>${plexus.utils.version}</version> </dependency> Modified: incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/CreateCloudServicePackageMojo.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/CreateCloudServicePackageMojo.java?rev=1225516&r1=1225515&r2=1225516&view=diff ============================================================================== --- incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/CreateCloudServicePackageMojo.java (original) +++ incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/CreateCloudServicePackageMojo.java Thu Dec 29 12:50:18 2011 @@ -128,20 +128,74 @@ public class CreateCloudServicePackageMo for ( Object artifactAsObject : projectDependencyArtifacts ) { Artifact artifact = (Artifact) artifactAsObject; - if ( artifact.getType().equals( ArtifactType.MSDEPLOY_PACKAGE.getPackagingType() ) - || artifact.getType().equals( ArtifactType.MSDEPLOY_PACKAGE.getExtension() ) ) + final boolean isWebRole = artifact.getType().equals( + ArtifactType.MSDEPLOY_PACKAGE.getPackagingType() + ) || artifact.getType().equals( + ArtifactType.MSDEPLOY_PACKAGE.getExtension() + ); + + final boolean isWorkerRole = artifact.getType().equals( + ArtifactType.DOTNET_APPLICATION.getPackagingType() + ) || artifact.getType().equals( + ArtifactType.DOTNET_APPLICATION.getExtension() + ); + + if ( !isWebRole && !isWorkerRole ) + { + throw new MojoExecutionException( + "NPANDAY-123-005: Artifact type " + artifact.getType() + " of artifact " + artifact.getArtifactId() + + " is not supported for azure cloud services.\n\nPlease use " + + ArtifactType.DOTNET_APPLICATION.getPackagingType() + " for worker roles, and " + + ArtifactType.MSDEPLOY_PACKAGE.getPackagingType() + " for web roles" + ); + } + + final File roleRoot = new File( + PathUtil.getPreparedPackageFolder( project ), artifact.getArtifactId() + ); + + if ( isWebRole ) + { + getLog().debug( "NPANDAY-123-003: Found web role " + artifact.getArtifactId() ); + } + else if ( isWorkerRole ) + { + getLog().debug( "NPANDAY-123-004: Found worker role " + artifact.getArtifactId() ); + } + + if ( !roleRoot.exists() ) { - final File webRoot = new File( - PathUtil.getPreparedPackageFolder( project ), artifact.getArtifactId() + throw new MojoExecutionException( + "NPANDAY-123-006: Could not find worker/web role root for " + artifact.getArtifactId() + ": " + + roleRoot ); + } + if ( isWebRole ) + { + commands.add( + "/role:" + artifact.getArtifactId() + ";" + roleRoot.getAbsolutePath() + ); + // TODO: 'Web/' is hardcoded here; where to get it from? commands.add( - "/role:" + artifact.getArtifactId() + ";" + webRoot.getAbsolutePath() + "/sitePhysicalDirectories:" + artifact.getArtifactId() + ";Web/;" + roleRoot.getAbsolutePath() ); + } + else if ( isWorkerRole ) + { + File entryPoint = new File( roleRoot, artifact.getArtifactId() + ".dll" ); + + if ( !entryPoint.exists() ) + { + throw new MojoExecutionException( + "NPANDAY-123-007: Could not find entry point dll for " + artifact.getArtifactId() + ": " + + entryPoint + ); + } - // TODO: 'Web/' is hardcoded here; where to get it from?1 (310) 728-2143 x2813 commands.add( - "/sitePhysicalDirectories:" + artifact.getArtifactId() + ";Web/;" + webRoot.getAbsolutePath() + "/role:" + artifact.getArtifactId() + ";" + roleRoot.getAbsolutePath() + ";" + + entryPoint.getAbsolutePath() ); } } @@ -149,5 +203,4 @@ public class CreateCloudServicePackageMo return commands; } - } Modified: incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/ResolveWorkerRoleFilesMojo.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/ResolveWorkerRoleFilesMojo.java?rev=1225516&r1=1225515&r2=1225516&view=diff ============================================================================== --- incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/ResolveWorkerRoleFilesMojo.java (original) +++ incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday.plugin.azure/ResolveWorkerRoleFilesMojo.java Thu Dec 29 12:50:18 2011 @@ -19,24 +19,89 @@ package npanday.plugin.azure; +import npanday.ArtifactType; +import npanday.PathUtil; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.zip.ZipUnArchiver; + +import java.io.File; +import java.util.Set; /** - * - * * @author <a href="mailto:lcornelius...@apache.org">Lars Corneliussen</a> * @goal resolve-worker-roles - * * @requiresDependencyResolution runtime */ public class ResolveWorkerRoleFilesMojo extends AbstractNPandayMojo { + /** + * The Zip archiver. + * + * @parameter expression="${component.org.codehaus.plexus.archiver.UnArchiver#zip}" + * @required + */ + private ZipUnArchiver unarchiver; + public void execute() throws MojoExecutionException, MojoFailureException { + // TODO: this mojo could be moved to application-maven-plugin / unpack-dependencies (as with msdeploy) super.execute(); + final Set projectDependencyArtifacts = project.getDependencyArtifacts(); + for ( Object artifactAsObject : projectDependencyArtifacts ) + { + Artifact artifact = (Artifact) artifactAsObject; + if ( artifact.getType().equals( ArtifactType.DOTNET_APPLICATION.getPackagingType() ) + || artifact.getType().equals( ArtifactType.DOTNET_APPLICATION.getExtension() ) ) + { + unpack( artifact ); + } + } + } + + private void unpack( Artifact artifact ) throws MojoFailureException + { + // TODO: partially duplicate code with MSDeploy unpack-dependencies + File targetDirectory = new File( PathUtil.getPreparedPackageFolder( project ), artifact.getArtifactId() ); + try + { + if ( !artifact.isResolved() ) + { + throw new MojoFailureException( + "NPANDAY-131-000: The artifact should already have been resolved: " + artifact + ); + } + + final File packageSource = artifact.getFile(); + assert packageSource != null : "package source should not be null here"; + getLog().info( + "NPANDAY-131-002: Unpacking worker role " + artifact.getArtifactId() + " from " + packageSource + " " + + "to " + targetDirectory + ); + + // unarchiver expects the dir to be there + targetDirectory.mkdirs(); + + unarchiver.setSourceFile( packageSource ); + unarchiver.setDestDirectory( targetDirectory ); + unarchiver.extract(); + if ( targetDirectory.listFiles().length == 0 ) + { + throw new MojoFailureException( + "NPANDAY-131-003: Wasn't able to unpack worker role " + artifact.getArtifactId() + ); + } + } + catch ( ArchiverException e ) + { + throw new MojoFailureException( + "NPANDAY-131-001: Unable to unpack worker role from artifact: " + artifact + ); + } } }