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()
36 .append("\t\t<version>"
37 + project
.getParentArtifact().getBaseVersion()
39 bundlesPom
.append("\t</parent>\n");
41 .append("\t<groupId>" + project
.getGroupId() + "</groupId>\n");
42 bundlesPom
.append("\t<artifactId>" + bundlesPomArtifactId
44 bundlesPom
.append("\t<packaging>pom</packaging>\n");
45 bundlesPom
.append("\t<dependencies>\n");
47 List bundlePackages
= analyze(true);
49 for (int i
= 0; i
< bundlePackages
.size(); i
++) {
50 AbstractBundlesPackagerMojo
.BundlePackage bundlePackage
= (BundlePackage
) bundlePackages
53 File manifestFile
= new File(bundlePackage
.getPackageFile()
58 JarArchiver jarArchiver
= new JarArchiver();
59 jarArchiver
.setDestFile(bundlePackage
.getPackageFile());
60 DefaultFileSet fileSet
= new DefaultFileSet();
61 fileSet
.setDirectory(bundlePackage
.getBundleDir());
62 String
[] includes
= { "**/*" };
63 String
[] excludes
= { "**/.svn", "**/.svn/**" };
64 fileSet
.setIncludes(includes
);
65 fileSet
.setExcludes(excludes
);
67 jarArchiver
.addFileSet(fileSet
);
70 FileOutputStream out
= new FileOutputStream(manifestFile
);
72 System
.out
.println("\n# BUNDLE "
73 + bundlePackage
.getArtifact().getArtifactId());
74 Attributes mainAttrs
= bundlePackage
.getManifest()
76 for (Iterator it
= mainAttrs
.keySet().iterator(); it
.hasNext();) {
77 Object key
= it
.next();
78 Object value
= mainAttrs
.get(key
);
79 System
.out
.println(key
+ ": " + value
);
82 bundlePackage
.getManifest().write(out
);
84 jarArchiver
.setManifest(manifestFile
);
86 jarArchiver
.createArchive();
87 } catch (Exception e
) {
88 throw new MojoExecutionException("Could not package bundle "
89 + bundlePackage
.getBundleDir(), e
);
92 // update dependencies POM
93 bundlesPom
.append("\t\t<dependency>\n");
95 .append("\t\t\t<groupId>"
96 + bundlePackage
.getArtifact().getGroupId()
98 bundlesPom
.append("\t\t\t<artifactId>"
99 + bundlePackage
.getArtifact().getArtifactId()
100 + "</artifactId>\n");
102 .append("\t\t\t<version>"
103 + bundlePackage
.getArtifact().getVersion()
105 bundlesPom
.append("\t\t</dependency>\n");
109 bundlesPom
.append("\t</dependencies>\n");
110 bundlesPom
.append("</project>\n");
113 FileWriter writer
= new FileWriter(bundlesPomFile());
114 writer
.write(bundlesPom
.toString());
116 } catch (IOException e
) {
117 throw new MojoExecutionException("Could not write dependency pom",