Return-Path: Delivered-To: apmail-incubator-aries-commits-archive@minotaur.apache.org Received: (qmail 67434 invoked from network); 5 Mar 2010 21:08:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Mar 2010 21:08:47 -0000 Received: (qmail 22476 invoked by uid 500); 5 Mar 2010 21:08:33 -0000 Delivered-To: apmail-incubator-aries-commits-archive@incubator.apache.org Received: (qmail 22419 invoked by uid 500); 5 Mar 2010 21:08:33 -0000 Mailing-List: contact aries-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: aries-dev@incubator.apache.org Delivered-To: mailing list aries-commits@incubator.apache.org Received: (qmail 22411 invoked by uid 99); 5 Mar 2010 21:08:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Mar 2010 21:08:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Fri, 05 Mar 2010 21:08:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8F78F238896F; Fri, 5 Mar 2010 21:08:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r919617 - in /incubator/aries/trunk/eba-maven-plugin: pom.xml src/main/java/org/apache/aries/plugin/eba/EbaMojo.java Date: Fri, 05 Mar 2010 21:08:11 -0000 To: aries-commits@incubator.apache.org From: gcc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100305210811.8F78F238896F@eris.apache.org> Author: gcc Date: Fri Mar 5 21:08:11 2010 New Revision: 919617 URL: http://svn.apache.org/viewvc?rev=919617&view=rev Log: ARIES-212 Switched on using true Pom . -> Application-SymbolicName Pom -> Application-Name Pom -> Application-Version (cleaned up for OSGi) Pom -> Application-Description Pom -> Application-Content Service imports/exports configured using ... ... Modified: incubator/aries/trunk/eba-maven-plugin/pom.xml incubator/aries/trunk/eba-maven-plugin/src/main/java/org/apache/aries/plugin/eba/EbaMojo.java Modified: incubator/aries/trunk/eba-maven-plugin/pom.xml URL: http://svn.apache.org/viewvc/incubator/aries/trunk/eba-maven-plugin/pom.xml?rev=919617&r1=919616&r2=919617&view=diff ============================================================================== --- incubator/aries/trunk/eba-maven-plugin/pom.xml (original) +++ incubator/aries/trunk/eba-maven-plugin/pom.xml Fri Mar 5 21:08:11 2010 @@ -46,6 +46,16 @@ + biz.aQute + bndlib + 0.0.357 + + + org.apache.felix + maven-bundle-plugin + 2.0.0 + + org.apache.maven maven-plugin-api 2.0 Modified: incubator/aries/trunk/eba-maven-plugin/src/main/java/org/apache/aries/plugin/eba/EbaMojo.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/eba-maven-plugin/src/main/java/org/apache/aries/plugin/eba/EbaMojo.java?rev=919617&r1=919616&r2=919617&view=diff ============================================================================== --- incubator/aries/trunk/eba-maven-plugin/src/main/java/org/apache/aries/plugin/eba/EbaMojo.java (original) +++ incubator/aries/trunk/eba-maven-plugin/src/main/java/org/apache/aries/plugin/eba/EbaMojo.java Fri Mar 5 21:08:11 2010 @@ -29,7 +29,9 @@ import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; - +import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter; +import org.apache.maven.shared.osgi.Maven2OsgiConverter; +import aQute.lib.osgi.Analyzer; import java.io.File; import java.io.IOException; import java.util.Iterator; @@ -46,11 +48,31 @@ public class EbaMojo extends AbstractMojo { - public static final String APPLICATION_MF_URI = "META-INF/application.mf"; + + + public static final String APPLICATION_MF_URI = "META-INF/APPLICATION.MF"; private static final String[] DEFAULT_INCLUDES = {"**/**"}; /** + * Application manifest headers + */ + private static final String MANIFEST_VERSION = "Manifest-Version: "; + private static final String APPLICATION_MANIFESTVERSION = "Application-ManifestVersion: "; + private static final String APPLICATION_SYMBOLICNAME = "Application-SymbolicName: "; + private static final String APPLICATION_VERSION = "Application-Version: "; + private static final String APPLICATION_NAME = "Application-Name: "; + private static final String APPLICATION_DESCRIPTION = "Application-Description: "; + private static final String APPLICATION_CONTENT = "Application-Content: "; + private static final String APPLICATION_EXPORTSERVICE = "Application-ExportService: "; + private static final String APPLICATION_IMPORTSERVICE = "Application-ImportService: "; + + /** + * Coverter for maven pom values to OSGi manifest values (pulled in from the maven-bundle-plugin) + */ + private Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter(); + + /** * Single directory for extra files to include in the eba. * * @parameter expression="${basedir}/src/main/eba" @@ -59,9 +81,9 @@ private File ebaSourceDirectory; /** - * The location of the application.mf file to be used within the eba file. + * The location of the APPLICATION.MF file to be used within the eba file. * - * @parameter expression="${basedir}/src/main/eba/META-INF/application.mf" + * @parameter expression="${basedir}/src/main/eba/META-INF/APPLICATION.MF" */ private File applicationManifestFile; @@ -130,6 +152,27 @@ private ZipArchiver zipArchiver; /** + * Whether to generate a manifest based on maven configuration. + * + * @parameter expression="${generateManifest}" default-value="false" + */ + private boolean generateManifest; + + /** + * Any service exports to add to a generated manifest. + * + * @parameter expression="${serviceExports}" + */ + private String serviceExports; + + /** + * Any service imports to add to a generated manifest. + * + * @parameter expression="${serviceImports}" + */ + private String serviceImports; + + /** * Adding pom.xml and pom.properties to the archive. * * @parameter expression="${addMavenDescriptor}" default-value="true" @@ -171,6 +214,7 @@ getLog().debug( "workDirectory[" + workDirectory + "]" ); getLog().debug( "outputDirectory[" + outputDirectory + "]" ); getLog().debug( "finalName[" + finalName + "]" ); + getLog().debug( "generateManifest[" + generateManifest + "]" ); zipArchiver.setIncludeEmptyDirs( includeEmptyDirs ); zipArchiver.setCompress( true ); @@ -258,19 +302,43 @@ // Include custom manifest if necessary try { - includeCustomApplicationManifestFile(); + if (!generateManifest) { + includeCustomApplicationManifestFile(); + } } catch ( IOException e ) { - throw new MojoExecutionException( "Error copying application.mf file", e ); + throw new MojoExecutionException( "Error copying APPLICATION.MF file", e ); } + // Generate application manifest if requested + if (generateManifest) { + String fileName = new String(getBuildDir() + "/" + + APPLICATION_MF_URI); + File appMfFile = new File(fileName); + + try { + // Delete any old manifest + if (appMfFile.exists()) { + FileUtils.fileDelete(fileName); + } + + appMfFile.getParentFile().mkdirs(); + if (appMfFile.createNewFile()) { + writeApplicationManifest(fileName); + } + } catch (java.io.IOException e) { + throw new MojoExecutionException( + "Error generating APPLICATION.MF file: " + fileName, e); + } + } + // Check if connector deployment descriptor is there File ddFile = new File( getBuildDir(), APPLICATION_MF_URI); if ( !ddFile.exists() ) { getLog().warn( - "eba deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." ); + "Application manifest: " + ddFile.getAbsolutePath() + " does not exist." ); } try @@ -312,6 +380,78 @@ } } + private void writeApplicationManifest(String fileName) + throws MojoExecutionException { + try { + // TODO: add support for dependency version ranges. Need to pick + // them up from the pom and convert them to OSGi version ranges. + FileUtils.fileAppend(fileName, MANIFEST_VERSION + "1" + "\n"); + FileUtils.fileAppend(fileName, APPLICATION_MANIFESTVERSION + "1" + "\n"); + FileUtils.fileAppend(fileName, APPLICATION_SYMBOLICNAME + + getApplicationSymbolicName(project.getArtifact()) + "\n"); + FileUtils.fileAppend(fileName, APPLICATION_VERSION + + aQute.lib.osgi.Analyzer.cleanupVersion(project.getVersion()) + "\n"); +// + maven2OsgiConverter.getVersion(project.getVersion()) + "\n"); + FileUtils.fileAppend(fileName, APPLICATION_NAME + project.getName() + "\n"); + FileUtils.fileAppend(fileName, APPLICATION_DESCRIPTION + + project.getDescription() + "\n"); + + // Write the APPLICATION-CONTENT + // TODO: check that the dependencies are bundles (currently, the converter + // will throw an exception) + Set artifacts; + if (useTransitiveDependencies) { + artifacts = project.getArtifacts(); + } else { + artifacts = project.getDependencyArtifacts(); + } + Iterator iter = artifacts.iterator(); + + FileUtils.fileAppend(fileName, APPLICATION_CONTENT); + if (iter.hasNext()) { + Artifact artifact = iter.next(); + FileUtils.fileAppend(fileName, maven2OsgiConverter + .getBundleSymbolicName(artifact) + + ";version=\"" + + aQute.lib.osgi.Analyzer.cleanupVersion(artifact.getVersion()) +// + maven2OsgiConverter.getVersion(artifact.getVersion()) + + "\""); + } + while (iter.hasNext()) { + Artifact artifact = iter.next(); + FileUtils.fileAppend(fileName, ",\n " + + maven2OsgiConverter.getBundleSymbolicName(artifact) + + ";version=\"" + + aQute.lib.osgi.Analyzer.cleanupVersion(artifact.getVersion()) +// + maven2OsgiConverter.getVersion(artifact.getVersion()) + + "\""); + } + + FileUtils.fileAppend(fileName, "\n"); + + // Add any service imports or exports + if (serviceExports != null) { + FileUtils.fileAppend(fileName, APPLICATION_EXPORTSERVICE + + serviceExports + "\n"); + } + if (serviceImports != null) { + FileUtils.fileAppend(fileName, APPLICATION_IMPORTSERVICE + + serviceImports + "\n"); + } + + } catch (Exception e) { + throw new MojoExecutionException( + "Error writing dependencies into APPLICATION.MF", e); + } + + } + + // The maven2OsgiConverter assumes the artifact is a jar so we need our own + // This uses the same fallback scheme as the converter + private String getApplicationSymbolicName(Artifact artifact) { + return artifact.getGroupId() + "." + artifact.getArtifactId(); + } + protected File getBuildDir() { if ( buildDir == null ) @@ -329,7 +469,7 @@ } File appMfFile = applicationManifestFile; if (appMfFile.exists()) { - getLog().info( "Using application.mf "+ applicationManifestFile); + getLog().info( "Using APPLICATION.MF "+ applicationManifestFile); File metaInfDir = new File(getBuildDir(), "META-INF"); FileUtils.copyFileToDirectory( appMfFile, metaInfDir); }