]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Generate pom for created artifacts
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 4 Jun 2009 08:00:40 +0000 (08:00 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 4 Jun 2009 08:00:40 +0000 (08:00 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk/maven@2455 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

maven-argeo-osgi-plugin/pom.xml
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/DeployBundlesMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/InstallBundlesMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/PackageBundlesMojo.java

index 5998beedd4c1f1da8129944a5662f9f11bb55157..a4a8db4d63476ee24866cc6144cee611d5fa3977 100644 (file)
@@ -7,7 +7,7 @@
                <relativePath>..</relativePath>\r
        </parent>\r
        <artifactId>maven-argeo-osgi-plugin</artifactId>\r
-       <version>0.1.9</version>\r
+       <version>0.1.10</version>\r
        <packaging>maven-plugin</packaging>\r
        <name>Argeo OSGi Plugin</name>\r
 \r
index acc894107424a2716f26c101ff28286df1022bd8..53f686099bce229a4b6b3087b90dc48964fd7062 100644 (file)
@@ -3,6 +3,7 @@ package org.argeo.slc.maven.plugins.osgi;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -14,8 +15,12 @@ import java.util.jar.Manifest;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 
 /**
  * @author mbaudier
@@ -162,7 +167,7 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
                        newVersionArt = versionMfMain;
                }
 
-               //boolean debug = true;
+               // boolean debug = true;
                boolean debug = getLog().isDebugEnabled();
                if (debug && willGenerate) {
                        getLog().info("\n## " + artifactId);
@@ -199,6 +204,45 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
                                bundlesPomArtifactId, project.getVersion(), "pom");
        }
 
+       protected StringBuffer createPomFileHeader(String parentGroupId,
+                       String parentArtifactId, String parentBaseVersion, String groupId,
+                       String artifactId, String packaging) {
+               StringBuffer pom = new StringBuffer();
+               // not using append() systematically for the sake of clarity
+               pom.append("<project>\n");
+               pom.append("\t<modelVersion>4.0.0</modelVersion>\n");
+               pom.append("\t<parent>\n");
+               pom.append("\t\t<groupId>" + parentGroupId + "</groupId>\n");
+               pom.append("\t\t<artifactId>" + parentArtifactId + "</artifactId>\n");
+               pom.append("\t\t<version>" + parentBaseVersion + "</version>\n");
+               pom.append("\t</parent>\n");
+               pom.append("\t<groupId>" + groupId + "</groupId>\n");
+               pom.append("\t<artifactId>" + artifactId + "</artifactId>\n");
+               pom.append("\t<packaging>" + packaging + "</packaging>\n");
+               return pom;
+               
+               // TODO: use the Model object e.g.: (from install plugin)
+//        Model model = new Model();
+//        model.setModelVersion( "4.0.0" );
+//        model.setGroupId( groupId );
+//        model.setArtifactId( artifactId );
+//        model.setVersion( version );
+//        model.setPackaging( packaging );
+//        model.setDescription( "POM was created from install:install-file" );
+//        fw = new FileWriter( tempFile );
+//        tempFile.deleteOnExit();
+//        new MavenXpp3Writer().write( fw, model );
+//        ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, tempFile );
+//        artifact.addMetadata( metadata );
+
+       }
+
+       /** Simple close the project tag */
+       protected String closePomFile(StringBuffer pom) {
+               pom.append("</project>\n");
+               return pom.toString();
+       }
+
        protected static class BundlePackage {
                private final Artifact artifact;
                private final File bundleDir;
@@ -229,6 +273,14 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
                public Manifest getManifest() {
                        return manifest;
                }
+
+               public File getManifestFile() {
+                       return new File(getPackageFile().getPath() + ".MF");
+               }
+
+               public File getPomFile() {
+                       return new File(getPackageFile().getPath() + ".pom.xml");
+               }
        }
 
        protected Manifest readManifest(File file) throws IOException {
index 0483b40f419d915c821cd7e286a47a722900757b..170469a7c115af5074829e43be3f7c36f04da8dc 100644 (file)
@@ -3,10 +3,12 @@ package org.argeo.slc.maven.plugins.osgi;
 import java.io.File;
 import java.util.List;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.deployer.ArtifactDeployer;
 import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 
 /**
  * @goal deploy-bundles
@@ -24,8 +26,12 @@ public class DeployBundlesMojo extends AbstractBundlesPackagerMojo {
                        AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages
                                        .get(i);
                        try {
-                               deployer.deploy(bundlePackage.getPackageFile(), bundlePackage
-                                               .getArtifact(), deploymentRepository, local);
+                               Artifact artifact = bundlePackage.getArtifact();
+                               ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(
+                                               artifact, bundlePackage.getPomFile());
+                               artifact.addMetadata(metadata);
+                               deployer.deploy(bundlePackage.getPackageFile(), artifact,
+                                               deploymentRepository, local);
                        } catch (ArtifactDeploymentException e) {
                                throw new MojoExecutionException("Could not deploy bundle "
                                                + bundlePackage.getBundleDir(), e);
index d3b4dfa5678427564671cedc666382b57229160a..e4924da20b842ff3484b6cafbc791d73f5defe4d 100644 (file)
@@ -3,10 +3,12 @@ package org.argeo.slc.maven.plugins.osgi;
 import java.io.File;
 import java.util.List;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.installer.ArtifactInstallationException;
 import org.apache.maven.artifact.installer.ArtifactInstaller;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 
 /**
  * @goal install-bundles
@@ -24,8 +26,12 @@ public class InstallBundlesMojo extends AbstractBundlesPackagerMojo {
                        AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages
                                        .get(i);
                        try {
-                               installer.install(bundlePackage.getPackageFile(), bundlePackage
-                                               .getArtifact(), local);
+                               Artifact artifact = bundlePackage.getArtifact();
+                               ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(
+                                               artifact, bundlePackage.getPomFile());
+                               artifact.addMetadata(metadata);
+                               installer.install(bundlePackage.getPackageFile(), artifact,
+                                               local);
                        } catch (ArtifactInstallationException e) {
                                throw new MojoExecutionException("Could not install bundle "
                                                + bundlePackage.getBundleDir(), e);
index abb5fcf1bb20cd3789c011653916c5406cab6ae7..46598ead67e944e9d35ebb0ba536eb3cfe1dacf6 100644 (file)
@@ -8,6 +8,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.jar.Attributes;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
@@ -22,26 +23,10 @@ import org.codehaus.plexus.archiver.util.DefaultFileSet;
 public class PackageBundlesMojo extends AbstractBundlesPackagerMojo {
 
        public void execute() throws MojoExecutionException, MojoFailureException {
-               StringBuffer bundlesPom = new StringBuffer();
-               // not using append() systematically for the sake of clarity
-               bundlesPom.append("<project>\n");
-               bundlesPom.append("\t<modelVersion>4.0.0</modelVersion>\n");
-               bundlesPom.append("\t<parent>\n");
-               bundlesPom.append("\t\t<groupId>"
-                               + project.getParentArtifact().getGroupId() + "</groupId>\n");
-               bundlesPom.append("\t\t<artifactId>"
-                               + project.getParentArtifact().getArtifactId()
-                               + "</artifactId>\n");
-               bundlesPom
-                               .append("\t\t<version>"
-                                               + project.getParentArtifact().getBaseVersion()
-                                               + "</version>\n");
-               bundlesPom.append("\t</parent>\n");
-               bundlesPom
-                               .append("\t<groupId>" + project.getGroupId() + "</groupId>\n");
-               bundlesPom.append("\t<artifactId>" + bundlesPomArtifactId
-                               + "</artifactId>\n");
-               bundlesPom.append("\t<packaging>pom</packaging>\n");
+               StringBuffer bundlesPom = createPomFileHeader(project
+                               .getParentArtifact().getGroupId(), project.getParentArtifact()
+                               .getArtifactId(), project.getParentArtifact().getBaseVersion(),
+                               project.getGroupId(), bundlesPomArtifactId, "pom");
                bundlesPom.append("\t<dependencies>\n");
 
                List bundlePackages = analyze(true);
@@ -50,10 +35,6 @@ public class PackageBundlesMojo extends AbstractBundlesPackagerMojo {
                        AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages
                                        .get(i);
 
-                       File manifestFile = new File(bundlePackage.getPackageFile()
-                                       .getPath()
-                                       + ".MF");
-
                        // Package as jar
                        JarArchiver jarArchiver = new JarArchiver();
                        jarArchiver.setDestFile(bundlePackage.getPackageFile());
@@ -64,6 +45,7 @@ public class PackageBundlesMojo extends AbstractBundlesPackagerMojo {
                        fileSet.setIncludes(includes);
                        fileSet.setExcludes(excludes);
                        try {
+                               File manifestFile = bundlePackage.getManifestFile();
                                jarArchiver.addFileSet(fileSet);
 
                                // Write manifest
@@ -89,6 +71,24 @@ public class PackageBundlesMojo extends AbstractBundlesPackagerMojo {
                                                + bundlePackage.getBundleDir(), e);
                        }
 
+                       // Write bundle POM
+                       File pomFile = bundlePackage.getPomFile();
+                       StringBuffer pomBuf = createPomFileHeader(project
+                                       .getParentArtifact().getGroupId(), project
+                                       .getParentArtifact().getArtifactId(), project
+                                       .getParentArtifact().getBaseVersion(), bundlePackage
+                                       .getArtifact().getGroupId(), bundlePackage.getArtifact()
+                                       .getArtifactId(), "jar");
+                       String pomStr = closePomFile(pomBuf);
+                       try {
+                               FileUtils.writeStringToFile(pomFile, pomStr);
+                       } catch (IOException e) {
+                               throw new MojoExecutionException(
+                                               "Could not write pom for bundle "
+                                                               + bundlePackage.getArtifact().getArtifactId(),
+                                               e);
+                       }
+
                        // update dependencies POM
                        bundlesPom.append("\t\t<dependency>\n");
                        bundlesPom
@@ -107,16 +107,13 @@ public class PackageBundlesMojo extends AbstractBundlesPackagerMojo {
                }
 
                bundlesPom.append("\t</dependencies>\n");
-               bundlesPom.append("</project>\n");
+               String bundlePomStr = closePomFile(bundlesPom);
 
                try {
-                       FileWriter writer = new FileWriter(bundlesPomFile());
-                       writer.write(bundlesPom.toString());
-                       writer.close();
+                       FileUtils.writeStringToFile(bundlesPomFile(), bundlePomStr);
                } catch (IOException e) {
                        throw new MojoExecutionException("Could not write dependency pom",
                                        e);
                }
        }
-
 }