1 package org
.argeo
.slc
.maven
.plugins
.osgi
;
4 import java
.io
.FileOutputStream
;
5 import java
.io
.FileWriter
;
6 import java
.io
.IOException
;
7 import java
.util
.Iterator
;
9 import java
.util
.jar
.Attributes
;
11 import org
.apache
.maven
.plugin
.MojoExecutionException
;
12 import org
.apache
.maven
.plugin
.MojoFailureException
;
13 import org
.codehaus
.plexus
.archiver
.jar
.JarArchiver
;
14 import org
.codehaus
.plexus
.archiver
.util
.DefaultFileSet
;
17 * @goal package-bundles
22 public class PackageBundlesMojo
extends AbstractBundlesPackagerMojo
{
24 public void execute() throws MojoExecutionException
, MojoFailureException
{
25 StringBuffer bundlesPom
= new StringBuffer();
26 // not using append() systematically for the sake of clarity
27 bundlesPom
.append("<project>\n");
28 bundlesPom
.append("\t<modelVersion>4.0.0</modelVersion>\n");
29 bundlesPom
.append("\t<parent>\n");
30 bundlesPom
.append("\t\t<groupId>"
31 + project
.getParentArtifact().getGroupId() + "</groupId>\n");
32 bundlesPom
.append("\t\t<artifactId>"
33 + project
.getParentArtifact().getArtifactId()
35 bundlesPom
.append("\t\t<version>"
36 + project
.getParentArtifact().getVersion() + "</version>\n");
37 bundlesPom
.append("\t</parent>\n");
39 .append("\t<groupId>" + project
.getGroupId() + "</groupId>\n");
40 bundlesPom
.append("\t<artifactId>" + bundlesPomArtifactId
42 bundlesPom
.append("\t<packaging>pom</packaging>\n");
43 bundlesPom
.append("\t<dependencies>\n");
45 List bundlePackages
= analyze();
47 for (int i
= 0; i
< bundlePackages
.size(); i
++) {
48 AbstractBundlesPackagerMojo
.BundlePackage bundlePackage
= (BundlePackage
) bundlePackages
51 File manifestFile
= new File(bundlePackage
.getPackageFile()
56 JarArchiver jarArchiver
= new JarArchiver();
57 jarArchiver
.setDestFile(bundlePackage
.getPackageFile());
58 DefaultFileSet fileSet
= new DefaultFileSet();
59 fileSet
.setDirectory(bundlePackage
.getBundleDir());
60 String
[] includes
= { "**/*" };
61 String
[] excludes
= { "**/.svn", "**/.svn/**" };
62 fileSet
.setIncludes(includes
);
63 fileSet
.setExcludes(excludes
);
65 jarArchiver
.addFileSet(fileSet
);
68 FileOutputStream out
= new FileOutputStream(manifestFile
);
70 System
.out
.println("\n# BUNDLE "
71 + bundlePackage
.getArtifact().getArtifactId());
72 Attributes mainAttrs
= bundlePackage
.getManifest()
74 for (Iterator it
= mainAttrs
.keySet().iterator(); it
.hasNext();) {
75 Object key
= it
.next();
76 Object value
= mainAttrs
.get(key
);
77 System
.out
.println(key
+ ": " + value
);
80 bundlePackage
.getManifest().write(out
);
82 jarArchiver
.setManifest(manifestFile
);
84 jarArchiver
.createArchive();
85 } catch (Exception e
) {
86 throw new MojoExecutionException("Could not package bundle "
87 + bundlePackage
.getBundleDir(), e
);
90 // update dependencies POM
91 bundlesPom
.append("\t\t<dependency>\n");
93 .append("\t\t\t<groupId>"
94 + bundlePackage
.getArtifact().getGroupId()
96 bundlesPom
.append("\t\t\t<artifactId>"
97 + bundlePackage
.getArtifact().getArtifactId()
100 .append("\t\t\t<version>"
101 + bundlePackage
.getArtifact().getVersion()
103 bundlesPom
.append("\t\t</dependency>\n");
107 bundlesPom
.append("\t</dependencies>\n");
108 bundlesPom
.append("</project>\n");
111 FileWriter writer
= new FileWriter(bundlesPomFile());
112 writer
.write(bundlesPom
.toString());
114 } catch (IOException e
) {
115 throw new MojoExecutionException("Could not write dependency pom",