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
.commons
.io
.FileUtils
;
12 import org
.apache
.commons
.io
.IOUtils
;
13 import org
.apache
.maven
.plugin
.MojoExecutionException
;
14 import org
.apache
.maven
.plugin
.MojoFailureException
;
15 import org
.codehaus
.plexus
.archiver
.jar
.JarArchiver
;
16 import org
.codehaus
.plexus
.archiver
.util
.DefaultFileSet
;
19 * @goal package-bundles
24 public class PackageBundlesMojo
extends AbstractBundlesPackagerMojo
{
26 public void execute() throws MojoExecutionException
, MojoFailureException
{
27 StringBuffer bundlesPom
= createPomFileHeader(project
28 .getParentArtifact().getGroupId(), project
.getParentArtifact()
29 .getArtifactId(), project
.getParentArtifact().getBaseVersion(),
30 project
.getGroupId(), bundlesPomArtifactId
, "pom");
31 bundlesPom
.append("\t<dependencies>\n");
33 List bundlePackages
= analyze(true);
35 for (int i
= 0; i
< bundlePackages
.size(); i
++) {
36 AbstractBundlesPackagerMojo
.BundlePackage bundlePackage
= (BundlePackage
) bundlePackages
40 JarArchiver jarArchiver
= new JarArchiver();
41 jarArchiver
.setDestFile(bundlePackage
.getPackageFile());
42 DefaultFileSet fileSet
= new DefaultFileSet();
43 fileSet
.setDirectory(bundlePackage
.getBundleDir());
44 String
[] includes
= { "**/*" };
45 String
[] excludes
= { "**/.svn", "**/.svn/**" };
46 fileSet
.setIncludes(includes
);
47 fileSet
.setExcludes(excludes
);
49 FileOutputStream manifestOut
= null;
51 File manifestFile
= bundlePackage
.getManifestFile();
52 jarArchiver
.addFileSet(fileSet
);
55 manifestOut
= new FileOutputStream(manifestFile
);
57 System
.out
.println("\n# BUNDLE "
58 + bundlePackage
.getArtifact().getArtifactId());
59 Attributes mainAttrs
= bundlePackage
.getManifest()
61 for (Iterator it
= mainAttrs
.keySet().iterator(); it
.hasNext();) {
62 Object key
= it
.next();
63 Object value
= mainAttrs
.get(key
);
64 System
.out
.println(key
+ ": " + value
);
67 bundlePackage
.getManifest().write(manifestOut
);
70 jarArchiver
.setManifest(manifestFile
);
71 jarArchiver
.createArchive();
72 } catch (Exception e
) {
73 throw new MojoExecutionException("Could not package bundle "
74 + bundlePackage
.getBundleDir(), e
);
76 IOUtils
.closeQuietly(manifestOut
);
80 File pomFile
= bundlePackage
.getPomFile();
81 StringBuffer pomBuf
= createPomFileHeader(project
82 .getParentArtifact().getGroupId(), project
83 .getParentArtifact().getArtifactId(), project
84 .getParentArtifact().getBaseVersion(), bundlePackage
85 .getArtifact().getGroupId(), bundlePackage
.getArtifact()
86 .getArtifactId(), "jar");
87 String pomStr
= closePomFile(pomBuf
);
89 FileUtils
.writeStringToFile(pomFile
, pomStr
);
90 } catch (IOException e
) {
91 throw new MojoExecutionException(
92 "Could not write pom for bundle "
93 + bundlePackage
.getArtifact().getArtifactId(),
97 // update dependencies POM
98 bundlesPom
.append("\t\t<dependency>\n");
100 .append("\t\t\t<groupId>"
101 + bundlePackage
.getArtifact().getGroupId()
103 bundlesPom
.append("\t\t\t<artifactId>"
104 + bundlePackage
.getArtifact().getArtifactId()
105 + "</artifactId>\n");
107 .append("\t\t\t<version>"
108 + bundlePackage
.getArtifact().getVersion()
110 bundlesPom
.append("\t\t</dependency>\n");
114 bundlesPom
.append("\t</dependencies>\n");
115 String bundlePomStr
= closePomFile(bundlesPom
);
118 FileUtils
.writeStringToFile(bundlesPomFile(), bundlePomStr
);
119 } catch (IOException e
) {
120 throw new MojoExecutionException("Could not write dependency pom",