You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/05/17 16:47:49 UTC
svn commit: r538950 -
/felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
Author: rickhall
Date: Thu May 17 07:47:48 2007
New Revision: 538950
URL: http://svn.apache.org/viewvc?view=rev&rev=538950
Log:
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.
Modified:
felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java?view=diff&rev=538950&r1=538949&r2=538950
==============================================================================
--- felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java Thu May 17 07:47:48 2007
@@ -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);
@@ -465,5 +470,46 @@
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();
}
}