No code changes - just formatting.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@561706 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
index d98b5da..d1ee6ad 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -17,23 +17,40 @@
* under the License.
*/
package org.apache.felix.bundleplugin;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.util.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
import java.util.zip.ZipException;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.*;
-import org.apache.maven.plugin.*;
+import org.apache.maven.model.License;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.osgi.Maven2OsgiConverter;
-import aQute.lib.osgi.*;
-
+import aQute.lib.osgi.Analyzer;
+import aQute.lib.osgi.Builder;
+import aQute.lib.osgi.EmbeddedResource;
+import aQute.lib.osgi.FileResource;
+import aQute.lib.osgi.Jar;
+
/**
* Create an OSGi bundle from Maven project
- *
+ *
* @goal bundle
* @phase package
* @requiresDependencyResolution runtime
@@ -41,416 +58,478 @@
*/
public class BundlePlugin extends AbstractMojo {
- /**
- * Project types which this plugin supports.
- *
- * @parameter
- */
- private List supportedProjectTypes = Arrays.asList(new String[]{"jar","bundle"});
+ /**
+ * Project types which this plugin supports.
+ *
+ * @parameter
+ */
+ private List supportedProjectTypes = Arrays.asList(new String[]{"jar","bundle"});
- /**
- * The directory for the generated bundles.
- *
- * @parameter expression="${project.build.outputDirectory}"
- * @required
- */
- private File outputDirectory;
-
- /**
- * The directory for the pom
- *
- * @parameter expression="${basedir}"
- * @required
- */
- private File baseDir;
-
- /**
- * The directory for the generated JAR.
- *
- * @parameter expression="${project.build.directory}"
- * @required
- */
- private String buildDirectory;
-
- /**
- * The Maven project.
- *
- * @parameter expression="${project}"
- * @required
- * @readonly
- */
- private MavenProject project;
-
- /**
- * The name of the generated JAR file.
- *
- * @parameter
- */
- private Map instructions = new HashMap();
+ /**
+ * The directory for the generated bundles.
+ *
+ * @parameter expression="${project.build.outputDirectory}"
+ * @required
+ */
+ private File outputDirectory;
- /**
- * @component
- */
- private Maven2OsgiConverter maven2OsgiConverter;
+ /**
+ * The directory for the pom
+ *
+ * @parameter expression="${basedir}"
+ * @required
+ */
+ private File baseDir;
- protected Maven2OsgiConverter getMaven2OsgiConverter() {
- return maven2OsgiConverter;
- }
+ /**
+ * The directory for the generated JAR.
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ private String buildDirectory;
- void setMaven2OsgiConverter(Maven2OsgiConverter maven2OsgiConverter) {
- this.maven2OsgiConverter = maven2OsgiConverter;
- }
+ /**
+ * The Maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
- protected MavenProject getProject() {
- return project;
- }
+ /**
+ * The name of the generated JAR file.
+ *
+ * @parameter
+ */
+ private Map instructions = new HashMap();
- public void execute() throws MojoExecutionException {
- Properties properties = new Properties();
+ /**
+ * @component
+ */
+ private Maven2OsgiConverter maven2OsgiConverter;
- /* ignore project types not supported, useful when the plugin is configured in the parent pom */
- if (!supportedProjectTypes.contains(getProject().getArtifact().getType())) {
- getLog().debug("Ignoring project " + getProject().getArtifact() + " : type " + getProject().getArtifact().getType() +
- " is not supported by bundle plugin, supported types are " + supportedProjectTypes );
- return;
- }
-
- execute(project, instructions, properties);
- }
-
- protected void execute(MavenProject project, Map instructions, Properties properties) throws MojoExecutionException {
- try {
- execute(project, instructions, properties, getClasspath(project));
- }
- catch ( IOException e ) {
- throw new MojoExecutionException("Error calculating classpath for project " + project, e);
- }
- }
-
- /* transform directives from their XML form to the expected BND syntax (eg. _include becomes -include) */
- protected Map transformDirectives(Map instructions) {
- Map transformedInstructions = new HashMap();
- for (Iterator i = instructions.entrySet().iterator(); i.hasNext();) {
- Map.Entry e = (Map.Entry)i.next();
-
- String key = (String)e.getKey();
- if (key.startsWith("_")) {
- key = "-"+key.substring(1);
+ protected Maven2OsgiConverter getMaven2OsgiConverter()
+ {
+ return this.maven2OsgiConverter;
}
- String value = (String)e.getValue();
- if (null == value) {
- value = "";
+ void setMaven2OsgiConverter(Maven2OsgiConverter maven2OsgiConverter)
+ {
+ this.maven2OsgiConverter = maven2OsgiConverter;
}
- transformedInstructions.put(key, value);
- }
- return transformedInstructions;
- }
-
- protected void execute(MavenProject project, Map instructions, Properties properties, Jar[] classpath) throws MojoExecutionException {
- try {
- File jarFile = new File(getBuildDirectory(), getBundleName(project));
-
- properties.putAll(getDefaultProperties(project));
-
- String bsn = project.getGroupId() + "." + project.getArtifactId();
- if (!instructions.containsKey(Analyzer.PRIVATE_PACKAGE)) {
- properties.put(Analyzer.EXPORT_PACKAGE, bsn + ".*");
- }
-
- properties.putAll(transformDirectives(instructions));
-
- // pass maven resource paths onto BND analyzer
- String mavenResourcePaths = getMavenResourcePaths();
- if (mavenResourcePaths.length() > 0) {
- final String includeResource = (String)properties.get(Analyzer.INCLUDE_RESOURCE);
- if (includeResource != null) {
- getLog().warn(Analyzer.INCLUDE_RESOURCE + ": overriding " + mavenResourcePaths + " with " + includeResource );
- } else {
- properties.put(Analyzer.INCLUDE_RESOURCE, mavenResourcePaths);
- }
- }
-
- Builder builder = new Builder();
- builder.setBase(baseDir);
- builder.setProperties(properties);
- builder.setClasspath(classpath);
-
- builder.build();
- Jar jar = builder.getJar();
- doMavenMetadata(project, jar);
- builder.setJar(jar);
-
- List errors = builder.getErrors();
- List warnings = builder.getWarnings();
-
- if (errors.size() > 0) {
- jarFile.delete();
- for (Iterator e = errors.iterator(); e.hasNext();) {
- String msg = (String) e.next();
- getLog().error("Error building bundle " + project.getArtifact() + " : " + msg);
+ protected MavenProject getProject()
+ {
+ return this.project;
}
- throw new MojoFailureException("Found errors, see log");
- }
- else {
- jarFile.getParentFile().mkdirs();
- builder.getJar().write(jarFile);
- project.getArtifact().setFile(jarFile);
- }
- for (Iterator w = warnings.iterator(); w.hasNext();) {
- String msg = (String) w.next();
- getLog().warn("Warning building bundle " + project.getArtifact() + " : " + msg);
- }
-
- }
- catch (Exception e) {
- e.printStackTrace();
- throw new MojoExecutionException("Unknown error occurred", e);
- }
- }
-
- private Map getProperies(Model projectModel, String prefix, Object model) {
- Map properties = new HashMap();
- Method methods[] = Model.class.getDeclaredMethods();
- for (int i = 0; i < methods.length; i++) {
- String name = methods[i].getName();
- if ( name.startsWith("get") ) {
- try {
- Object v = methods[i].invoke(projectModel, null );
- if ( v != null ) {
- name = prefix + Character.toLowerCase(name.charAt(3)) + name.substring(4);
- if ( v.getClass().isArray() )
- properties.put( name, Arrays.asList((Object[])v).toString() );
- else
- properties.put( name, v );
-
- }
+
+ /**
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ public void execute() throws MojoExecutionException
+ {
+ Properties properties = new Properties();
+
+ // ignore project types not supported, useful when the plugin is configured in the parent pom
+ if (!this.supportedProjectTypes.contains(this.getProject().getArtifact().getType()))
+ {
+ this.getLog().debug("Ignoring project " + this.getProject().getArtifact() + " : type " + this.getProject().getArtifact().getType() +
+ " is not supported by bundle plugin, supported types are " + this.supportedProjectTypes );
+ return;
+ }
+
+ this.execute(this.project, this.instructions, properties);
}
- catch (Exception e) {
- // too bad
+
+ protected void execute(MavenProject project, Map instructions, Properties properties)
+ throws MojoExecutionException
+ {
+ try
+ {
+ this.execute(project, instructions, properties, this.getClasspath(project));
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException("Error calculating classpath for project " + project, e);
+ }
}
- }
- }
- return properties;
- }
-
- private StringBuffer printLicenses(List licenses) {
- if (licenses == null || licenses.size() == 0)
- return null;
- StringBuffer sb = new StringBuffer();
- String del = "";
- for (Iterator i = licenses.iterator(); i.hasNext();) {
- License l = (License) i.next();
- String url = l.getUrl();
- sb.append(del);
- sb.append(url);
- del = ", ";
- }
- return sb;
- }
-
- /**
- * @param jar
- * @throws IOException
- */
- private void doMavenMetadata(MavenProject project, Jar jar) throws IOException {
- String path = "META-INF/maven/" + project.getGroupId() + "/"
- + project.getArtifactId();
- File pomFile = new File(baseDir, "pom.xml");
- jar.putResource(path + "/pom.xml", new FileResource(pomFile));
-
- Properties p = new Properties();
- p.put("version", project.getVersion());
- p.put("groupId", project.getGroupId());
- p.put("artifactId", project.getArtifactId());
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- p.store(out, "Generated by org.apache.felix.plugin.bundle");
- jar.putResource(path + "/pom.properties", new EmbeddedResource(out
- .toByteArray(), System.currentTimeMillis()));
- }
-
- /**
- * @return
- * @throws ZipException
- * @throws IOException
- */
- protected Jar[] getClasspath(MavenProject project) throws ZipException, IOException {
- List list = new ArrayList();
-
- if (getOutputDirectory() != null && getOutputDirectory().exists()) {
- list.add(new Jar(".", getOutputDirectory()));
- }
-
- Set artifacts = project.getDependencyArtifacts();
- for (Iterator it = artifacts.iterator(); it.hasNext();) {
- Artifact artifact = (Artifact) it.next();
- if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
- || Artifact.SCOPE_SYSTEM.equals(artifact.getScope())
- || Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
- File file = getFile(artifact);
- if (file == null) {
- throw new RuntimeException("File is not available for artifact " + artifact + " in project " + project.getArtifact());
+
+ /* transform directives from their XML form to the expected BND syntax (eg. _include becomes -include) */
+ protected Map transformDirectives(Map instructions)
+ {
+ Map transformedInstructions = new HashMap();
+ for (Iterator i = instructions.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry e = (Map.Entry)i.next();
+
+ String key = (String)e.getKey();
+ if (key.startsWith("_"))
+ {
+ key = "-"+key.substring(1);
+ }
+
+ String value = (String)e.getValue();
+ if (null == value)
+ {
+ value = "";
+ }
+
+ transformedInstructions.put(key, value);
+ }
+ return transformedInstructions;
}
- Jar jar = new Jar(artifact.getArtifactId(), file);
- list.add(jar);
- }
- }
- Jar[] cp = new Jar[list.size()];
- list.toArray(cp);
- return cp;
- }
-
- /**
- * Get the file for an Artifact
- *
- * @param artifact
- */
- protected File getFile(Artifact artifact) {
- return artifact.getFile();
- }
- private void header(Properties properties, String key, Object value) {
- if (value == null)
- return;
-
- if (value instanceof Collection && ((Collection) value).isEmpty())
- return;
-
- properties.put(key, value.toString());
- }
+ protected void execute(MavenProject project, Map instructions, Properties properties, Jar[] classpath)
+ throws MojoExecutionException
+ {
+ try
+ {
+ File jarFile = new File(this.getBuildDirectory(), this.getBundleName(project));
- /**
- * Convert a Maven version into an OSGi compliant version
- *
- * @param version Maven version
- * @return the OSGi version
- */
- protected String convertVersionToOsgi(String version)
- {
- return getMaven2OsgiConverter().getVersion( version );
- }
+ properties.putAll(this.getDefaultProperties(project));
- /**
- * TODO this should return getMaven2Osgi().getBundleFileName( project.getArtifact() )
- */
- protected String getBundleName(MavenProject project) {
- return project.getBuild().getFinalName() + ".jar";
- }
+ String bsn = project.getGroupId() + "." + project.getArtifactId();
+ if (!instructions.containsKey(Analyzer.PRIVATE_PACKAGE))
+ {
+ properties.put(Analyzer.EXPORT_PACKAGE, bsn + ".*");
+ }
- public String getBuildDirectory() {
- return buildDirectory;
- }
+ properties.putAll(this.transformDirectives(instructions));
- void setBuildDirectory(String buildirectory) {
- this.buildDirectory = buildirectory;
- }
+ // pass maven resource paths onto BND analyzer
+ String mavenResourcePaths = this.getMavenResourcePaths();
+ if (mavenResourcePaths.length() > 0)
+ {
+ final String includeResource = (String)properties.get(Analyzer.INCLUDE_RESOURCE);
+ if (includeResource != null)
+ {
+ this.getLog().warn(Analyzer.INCLUDE_RESOURCE + ": overriding " + mavenResourcePaths + " with " + includeResource );
+ } else
+ {
+ properties.put(Analyzer.INCLUDE_RESOURCE, mavenResourcePaths);
+ }
+ }
- /**
- * Get a list of packages inside a Jar
- *
- * @param jar
- * @return list of package names
- */
- public List getPackages(Jar jar) {
- List packages = new ArrayList();
- for (Iterator p = jar.getDirectories().entrySet().iterator(); p.hasNext();) {
- Map.Entry directory = (Map.Entry) p.next();
- String path = (String) directory.getKey();
+ Builder builder = new Builder();
+ builder.setBase(this.baseDir);
+ builder.setProperties(properties);
+ builder.setClasspath(classpath);
- String pack = path.replace('/', '.');
- packages.add(pack);
- }
- return packages;
- }
+ builder.build();
+ Jar jar = builder.getJar();
+ this.doMavenMetadata(project, jar);
+ builder.setJar(jar);
- protected Properties getDefaultProperties(MavenProject project) {
- Properties properties = new Properties();
- // Setup defaults
- String bsn = project.getGroupId() + "." + project.getArtifactId();
- properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
- properties.put(Analyzer.IMPORT_PACKAGE, "*");
+ List errors = builder.getErrors();
+ List warnings = builder.getWarnings();
- String version = getMaven2OsgiConverter().getVersion( project.getVersion() );
-
- properties.put(Analyzer.BUNDLE_VERSION, version);
- header(properties, Analyzer.BUNDLE_DESCRIPTION, project
- .getDescription());
- header(properties, Analyzer.BUNDLE_LICENSE, printLicenses(project
- .getLicenses()));
- header(properties, Analyzer.BUNDLE_NAME, project.getName());
-
- if (project.getOrganization() != null) {
- header(properties, Analyzer.BUNDLE_VENDOR, project
- .getOrganization().getName());
- if (project.getOrganization().getUrl() != null) {
- header(properties, Analyzer.BUNDLE_DOCURL, project
- .getOrganization().getUrl());
- }
- }
+ if (errors.size() > 0)
+ {
+ jarFile.delete();
+ for (Iterator e = errors.iterator(); e.hasNext();)
+ {
+ String msg = (String) e.next();
+ this.getLog().error("Error building bundle " + project.getArtifact() + " : " + msg);
+ }
+ throw new MojoFailureException("Found errors, see log");
+ }
+ else
+ {
+ jarFile.getParentFile().mkdirs();
+ builder.getJar().write(jarFile);
+ project.getArtifact().setFile(jarFile);
+ }
+ for (Iterator w = warnings.iterator(); w.hasNext();)
+ {
+ String msg = (String) w.next();
+ this.getLog().warn("Warning building bundle " + project.getArtifact() + " : " + msg);
+ }
- properties.putAll(project.getProperties());
- properties.putAll(project.getModel().getProperties());
- properties.putAll( getProperies(project.getModel(), "project.build.", project.getBuild()));
- properties.putAll( getProperies(project.getModel(), "pom.", project.getModel()));
- properties.putAll( getProperies(project.getModel(), "project.", project));
- properties.put("project.baseDir", baseDir );
- properties.put("project.build.directory", getBuildDirectory() );
- properties.put("project.build.outputdirectory", getOutputDirectory() );
-
- return properties;
- }
-
- void setBasedir(File basedir){
- this.baseDir = basedir;
- }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException("Unknown error occurred", e);
+ }
+ }
- File getOutputDirectory(){
- return this.outputDirectory;
- }
+ private Map getProperies(Model projectModel, String prefix, Object model)
+ {
+ Map properties = new HashMap();
+ Method methods[] = Model.class.getDeclaredMethods();
+ for (int i = 0; i < methods.length; i++)
+ {
+ String name = methods[i].getName();
+ if ( name.startsWith("get") )
+ {
+ try
+ {
+ Object v = methods[i].invoke(projectModel, null );
+ if ( v != null )
+ {
+ name = prefix + Character.toLowerCase(name.charAt(3)) + name.substring(4);
+ if ( v.getClass().isArray() )
+ properties.put( name, Arrays.asList((Object[])v).toString() );
+ else
+ properties.put( name, v );
- void setOutputDirectory(File outputDirectory){
- this.outputDirectory = outputDirectory;
- }
+ }
+ }
+ catch (Exception e)
+ {
+ // too bad
+ }
+ }
+ }
+ return properties;
+ }
- String getMavenResourcePaths()
- {
- final String basePath = baseDir.getAbsolutePath();
+ private StringBuffer printLicenses(List licenses)
+ {
+ if (licenses == null || licenses.size() == 0)
+ return null;
+ StringBuffer sb = new StringBuffer();
+ String del = "";
+ for (Iterator i = licenses.iterator(); i.hasNext();)
+ {
+ License l = (License) i.next();
+ String url = l.getUrl();
+ sb.append(del);
+ sb.append(url);
+ del = ", ";
+ }
+ return sb;
+ }
- StringBuffer resourcePaths = new StringBuffer();
- for (Iterator i = project.getResources().iterator(); i.hasNext();) {
- org.apache.maven.model.Resource resource = (org.apache.maven.model.Resource)i.next();
+ /**
+ * @param jar
+ * @throws IOException
+ */
+ private void doMavenMetadata(MavenProject project, Jar jar) throws IOException {
+ String path = "META-INF/maven/" + project.getGroupId() + "/"
+ + project.getArtifactId();
+ File pomFile = new File(this.baseDir, "pom.xml");
+ jar.putResource(path + "/pom.xml", new FileResource(pomFile));
- final String sourcePath = resource.getDirectory();
- final String targetPath = resource.getTargetPath();
+ Properties p = new Properties();
+ p.put("version", project.getVersion());
+ p.put("groupId", project.getGroupId());
+ p.put("artifactId", project.getArtifactId());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ p.store(out, "Generated by org.apache.felix.plugin.bundle");
+ jar.putResource(path + "/pom.properties", new EmbeddedResource(out
+ .toByteArray(), System.currentTimeMillis()));
+ }
- // ignore empty or non-local resources
- if (new File(sourcePath).exists() && ((targetPath == null) || (targetPath.indexOf("..") < 0))) {
- String path = sourcePath;
+ /**
+ * @return
+ * @throws ZipException
+ * @throws IOException
+ */
+ protected Jar[] getClasspath(MavenProject project) throws ZipException, IOException
+ {
+ List list = new ArrayList();
- // make relative to basedir
- if (path.startsWith(basePath)) {
- path = path.substring(basePath.length() + 1);
- }
+ if (this.getOutputDirectory() != null && this.getOutputDirectory().exists())
+ {
+ list.add(new Jar(".", this.getOutputDirectory()));
+ }
- if (targetPath != null) {
- path = targetPath + '=' + path;
- }
+ Set artifacts = project.getDependencyArtifacts();
+ for (Iterator it = artifacts.iterator(); it.hasNext();)
+ {
+ Artifact artifact = (Artifact) it.next();
+ if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
+ || Artifact.SCOPE_SYSTEM.equals(artifact.getScope())
+ || Artifact.SCOPE_PROVIDED.equals(artifact.getScope()))
+ {
+ File file = this.getFile(artifact);
+ if (file == null)
+ {
+ throw new RuntimeException("File is not available for artifact " + artifact + " in project " + project.getArtifact());
+ }
+ Jar jar = new Jar(artifact.getArtifactId(), file);
+ list.add(jar);
+ }
+ }
+ Jar[] cp = new Jar[list.size()];
+ list.toArray(cp);
+ return cp;
+ }
- if (resourcePaths.length() > 0) {
- resourcePaths.append(',');
- }
+ /**
+ * Get the file for an Artifact
+ *
+ * @param artifact
+ */
+ protected File getFile(Artifact artifact)
+ {
+ return artifact.getFile();
+ }
- if (resource.isFiltering()) {
- resourcePaths.append('{');
- resourcePaths.append(path);
- resourcePaths.append('}');
- } else {
- resourcePaths.append(path);
- }
- }
- }
+ private void header(Properties properties, String key, Object value)
+ {
+ if (value == null)
+ return;
- return resourcePaths.toString();
- }
+ if (value instanceof Collection && ((Collection) value).isEmpty())
+ return;
+
+ properties.put(key, value.toString());
+ }
+
+ /**
+ * Convert a Maven version into an OSGi compliant version
+ *
+ * @param version Maven version
+ * @return the OSGi version
+ */
+ protected String convertVersionToOsgi(String version)
+ {
+ return this.getMaven2OsgiConverter().getVersion( version );
+ }
+
+ /**
+ * TODO this should return getMaven2Osgi().getBundleFileName( project.getArtifact() )
+ */
+ protected String getBundleName(MavenProject project)
+ {
+ return project.getBuild().getFinalName() + ".jar";
+ }
+
+ public String getBuildDirectory()
+ {
+ return this.buildDirectory;
+ }
+
+ void setBuildDirectory(String buildirectory)
+ {
+ this.buildDirectory = buildirectory;
+ }
+
+ /**
+ * Get a list of packages inside a Jar
+ *
+ * @param jar
+ * @return list of package names
+ */
+ public List getPackages(Jar jar)
+ {
+ List packages = new ArrayList();
+ for (Iterator p = jar.getDirectories().entrySet().iterator(); p.hasNext();)
+ {
+ Map.Entry directory = (Map.Entry) p.next();
+ String path = (String) directory.getKey();
+
+ String pack = path.replace('/', '.');
+ packages.add(pack);
+ }
+ return packages;
+ }
+
+ protected Properties getDefaultProperties(MavenProject project)
+ {
+ Properties properties = new Properties();
+ // Setup defaults
+ String bsn = project.getGroupId() + "." + project.getArtifactId();
+ properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
+ properties.put(Analyzer.IMPORT_PACKAGE, "*");
+
+ String version = this.getMaven2OsgiConverter().getVersion( project.getVersion() );
+
+ properties.put(Analyzer.BUNDLE_VERSION, version);
+ this.header(properties, Analyzer.BUNDLE_DESCRIPTION, project
+ .getDescription());
+ this.header(properties, Analyzer.BUNDLE_LICENSE, this.printLicenses(project
+ .getLicenses()));
+ this.header(properties, Analyzer.BUNDLE_NAME, project.getName());
+
+ if (project.getOrganization() != null)
+ {
+ this.header(properties, Analyzer.BUNDLE_VENDOR, project
+ .getOrganization().getName());
+ if (project.getOrganization().getUrl() != null)
+ {
+ this.header(properties, Analyzer.BUNDLE_DOCURL, project
+ .getOrganization().getUrl());
+ }
+ }
+
+ properties.putAll(project.getProperties());
+ properties.putAll(project.getModel().getProperties());
+ properties.putAll( this.getProperies(project.getModel(), "project.build.", project.getBuild()));
+ properties.putAll( this.getProperies(project.getModel(), "pom.", project.getModel()));
+ properties.putAll( this.getProperies(project.getModel(), "project.", project));
+ properties.put("project.baseDir", this.baseDir );
+ properties.put("project.build.directory", this.getBuildDirectory() );
+ properties.put("project.build.outputdirectory", this.getOutputDirectory() );
+
+ return properties;
+ }
+
+ void setBasedir(File basedir)
+ {
+ this.baseDir = basedir;
+ }
+
+ File getOutputDirectory()
+ {
+ return this.outputDirectory;
+ }
+
+ void setOutputDirectory(File outputDirectory)
+ {
+ this.outputDirectory = outputDirectory;
+ }
+
+ String getMavenResourcePaths()
+ {
+ final String basePath = this.baseDir.getAbsolutePath();
+
+ StringBuffer resourcePaths = new StringBuffer();
+ for (Iterator i = this.project.getResources().iterator(); i.hasNext();)
+ {
+ org.apache.maven.model.Resource resource = (org.apache.maven.model.Resource)i.next();
+
+ final String sourcePath = resource.getDirectory();
+ final String targetPath = resource.getTargetPath();
+
+ // ignore empty or non-local resources
+ if (new File(sourcePath).exists() && ((targetPath == null) || (targetPath.indexOf("..") < 0)))
+ {
+ String path = sourcePath;
+
+ // make relative to basedir
+ if (path.startsWith(basePath))
+ {
+ path = path.substring(basePath.length() + 1);
+ }
+
+ if (targetPath != null)
+ {
+ path = targetPath + '=' + path;
+ }
+
+ if (resourcePaths.length() > 0)
+ {
+ resourcePaths.append(',');
+ }
+
+ if (resource.isFiltering())
+ {
+ resourcePaths.append('{');
+ resourcePaths.append(path);
+ resourcePaths.append('}');
+ }
+ else
+ {
+ resourcePaths.append(path);
+ }
+ }
+ }
+
+ return resourcePaths.toString();
+ }
}
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
index aafdba0..52abd17 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
@@ -19,7 +19,6 @@
package org.apache.felix.bundleplugin;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
@@ -35,7 +34,7 @@
/**
* Generate an OSGi manifest for this project
- *
+ *
* @goal manifest
* @phase process-classes
* @requiresDependencyResolution runtime
@@ -56,18 +55,18 @@
Manifest manifest;
try
{
- manifest = getManifest( project, instructions, properties, classpath );
+ manifest = this.getManifest( project, instructions, properties, classpath );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error trying to generate Manifest", e );
}
- File outputFile = new File( manifestLocation + "/MANIFEST.MF" );
+ File outputFile = new File( this.manifestLocation + "/MANIFEST.MF" );
try
{
- writeManifest( manifest, outputFile );
+ this.writeManifest( manifest, outputFile );
}
catch ( IOException e )
{
@@ -78,19 +77,19 @@
public Manifest getManifest( MavenProject project, Jar[] classpath )
throws IOException
{
- return getManifest( project, null, null, classpath );
+ return this.getManifest( project, null, null, classpath );
}
public Manifest getManifest( MavenProject project, Map instructions, Properties properties, Jar[] classpath )
throws IOException
{
- return getAnalyzer( project, instructions, properties, classpath ).getJar().getManifest();
+ return this.getAnalyzer( project, instructions, properties, classpath ).getJar().getManifest();
}
protected Analyzer getAnalyzer( MavenProject project, Jar[] classpath )
throws IOException
{
- return getAnalyzer( project, new HashMap(), new Properties(), classpath );
+ return this.getAnalyzer( project, new HashMap(), new Properties(), classpath );
}
protected Analyzer getAnalyzer( MavenProject project, Map instructions, Properties properties, Jar[] classpath )
@@ -98,7 +97,7 @@
{
PackageVersionAnalyzer analyzer = new PackageVersionAnalyzer();
- Properties props = getDefaultProperties( project );
+ Properties props = this.getDefaultProperties( project );
props.putAll( properties );
if ( !instructions.containsKey( Analyzer.IMPORT_PACKAGE ) )
@@ -106,14 +105,14 @@
props.put( Analyzer.IMPORT_PACKAGE, "*" );
}
- props.putAll( transformDirectives( instructions ) );
+ props.putAll( this.transformDirectives( instructions ) );
analyzer.setProperties( props );
File file = project.getArtifact().getFile();
if ( file == null )
{
- analyzer.setJar( getOutputDirectory() );
+ analyzer.setJar( this.getOutputDirectory() );
}
else
{