Applied patch (FELIX-261) to improve plugins default handling of maven
resources; I had to modify the patch slightly to dumb it down for JDK 1.4.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@538950 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java b/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
index 3ec2bec..7a8fb0f 100644
--- a/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
+++ b/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
@@ -97,10 +97,6 @@
  public void execute() throws MojoExecutionException {
   Properties properties = new Properties();
 
-  if (new File(baseDir, "src/main/resources").exists()) {
-    header(properties, Analyzer.INCLUDE_RESOURCE, "src/main/resources/");
-  }
-  
   /* ignore project types not supported, useful when the plugin is configured in the parent pom */
   if (!SUPPORTED_PROJECT_TYPES.contains(getProject().getArtifact().getType())) {
     getLog().debug("Ignoring project " + getProject().getArtifact() + " : type not supported by bundle plugin");
@@ -122,7 +118,6 @@
  /* transform directives from their XML form to the expected BND syntax (eg. _include becomes -include) */
  protected Map transformDirectives(Map instructions) {
   Set removedKeys = new HashSet();
-//System.out.println("BEFORE "+instructions);
   for (Iterator i = instructions.entrySet().iterator(); i.hasNext();) {
     final Map.Entry e = (Map.Entry)i.next();
     final String key = (String)e.getKey();
@@ -136,7 +131,6 @@
     }
   }
   instructions.keySet().removeAll(removedKeys);
-//System.out.println("AFTER "+instructions);
   return instructions;
  }
 
@@ -153,6 +147,17 @@
 
    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) {
+       properties.put(Analyzer.INCLUDE_RESOURCE, includeResource + ',' + mavenResourcePaths);
+     } else {
+       properties.put(Analyzer.INCLUDE_RESOURCE, mavenResourcePaths);
+     }
+   }
+  
    Builder builder = new Builder();
    builder.setBase(baseDir);
    builder.setProperties(properties);
@@ -466,4 +471,45 @@
  void setOutputDirectory(File outputDirectory){
      this.outputDirectory = outputDirectory;
  }
+
+ String getMavenResourcePaths()
+ {
+     final String basePath = baseDir.getAbsolutePath();
+
+     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();
+
+         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();
+ }
 }