Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2014-09-10 06:28:29 +0000
committerJan Bartel2014-09-10 06:28:29 +0000
commit09e22c042ce1ce72cc75a61a1f983f49d77a585d (patch)
treeaa7d2ff489f6cad77a759684c9007948d4bda9ed /jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse
parentc80f5561392d951c36ad922146228378ecb27e43 (diff)
downloadorg.eclipse.jetty.project-09e22c042ce1ce72cc75a61a1f983f49d77a585d.tar.gz
org.eclipse.jetty.project-09e22c042ce1ce72cc75a61a1f983f49d77a585d.tar.xz
org.eclipse.jetty.project-09e22c042ce1ce72cc75a61a1f983f49d77a585d.zip
443661 Rename manifest and service constants for jetty osgi resource fragment code
Diffstat (limited to 'jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse')
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java6
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java84
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebappConstants.java7
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java2
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java22
5 files changed, 86 insertions, 35 deletions
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java
index e1251df52e..9fbade35d8 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleWebAppProvider.java
@@ -25,6 +25,7 @@ import java.util.Map;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
+import org.eclipse.jetty.osgi.boot.utils.Util;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.osgi.framework.Bundle;
@@ -122,9 +123,10 @@ public class BundleWebAppProvider extends AbstractWebAppProvider implements Bund
Dictionary headers = bundle.getHeaders();
//does the bundle have a OSGiWebappConstants.JETTY_WAR_FOLDER_PATH
- if (headers.get(OSGiWebappConstants.JETTY_WAR_FOLDER_PATH) != null)
+ String resourcePath = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_FOLDER_PATH, OSGiWebappConstants.JETTY_WAR_RESOURCE_PATH, headers);
+ if (resourcePath != null)
{
- String base = (String)headers.get(OSGiWebappConstants.JETTY_WAR_FOLDER_PATH);
+ String base = resourcePath;
contextPath = getContextPath(bundle);
String originId = getOriginId(bundle, base);
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java
index 4482640bcf..8f878c7064 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebInfConfiguration.java
@@ -22,13 +22,16 @@ import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.regex.Pattern;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory;
+import org.eclipse.jetty.osgi.boot.utils.Util;
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -197,7 +200,7 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
@Override
public void configure(WebAppContext context) throws Exception
{
- TreeMap<String, Resource> patchResourcesPath = new TreeMap<String, Resource>();
+ TreeMap<String, Resource> prependedResourcesPath = new TreeMap<String, Resource>();
TreeMap<String, Resource> appendedResourcesPath = new TreeMap<String, Resource>();
Bundle bundle = (Bundle)context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
@@ -221,46 +224,33 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
// looked up.
for (Bundle frag : fragments)
{
- String fragFolder = (String) frag.getHeaders().get(OSGiWebappConstants.JETTY_WAR_FRAGMENT_FOLDER_PATH);
- String patchFragFolder = (String) frag.getHeaders().get(OSGiWebappConstants.JETTY_WAR_PATCH_FRAGMENT_FOLDER_PATH);
- if (fragFolder != null)
- {
- URL fragUrl = frag.getEntry(fragFolder);
- if (fragUrl == null) { throw new IllegalArgumentException("Unable to locate " + fragFolder
- + " inside "
- + " the fragment '"
- + frag.getSymbolicName()
- + "'"); }
- fragUrl = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(fragUrl);
- String key = fragFolder.startsWith("/") ? fragFolder.substring(1) : fragFolder;
- appendedResourcesPath.put(key + ";" + frag.getSymbolicName(), Resource.newResource(fragUrl));
- }
- if (patchFragFolder != null)
- {
- URL patchFragUrl = frag.getEntry(patchFragFolder);
- if (patchFragUrl == null)
- {
- throw new IllegalArgumentException("Unable to locate " + patchFragUrl
- + " inside fragment '"+frag.getSymbolicName()+ "'");
- }
- patchFragUrl = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(patchFragUrl);
- String key = patchFragFolder.startsWith("/") ? patchFragFolder.substring(1) : patchFragFolder;
- patchResourcesPath.put(key + ";" + frag.getSymbolicName(), Resource.newResource(patchFragUrl));
- }
+ String path = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_FRAGMENT_FOLDER_PATH,OSGiWebappConstants.JETTY_WAR_FRAGMENT_RESOURCE_PATH,frag.getHeaders());
+ convertFragmentPathToResource(path, frag, appendedResourcesPath);
+ path = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_PATCH_FRAGMENT_FOLDER_PATH, OSGiWebappConstants.JETTY_WAR_PREPEND_FRAGMENT_RESOURCE_PATH, frag.getHeaders());
+ convertFragmentPathToResource(path, frag, prependedResourcesPath);
}
if (!appendedResourcesPath.isEmpty())
- context.setAttribute(WebInfConfiguration.RESOURCE_DIRS, new HashSet<Resource>(appendedResourcesPath.values()));
+ {
+ LinkedHashSet<Resource> resources = new LinkedHashSet<Resource>();
+ //Add in any existing setting of extra resource dirs
+ Set<Resource> resourceDirs = (Set<Resource>)context.getAttribute(WebInfConfiguration.RESOURCE_DIRS);
+ if (resourceDirs != null && !resourceDirs.isEmpty())
+ resources.addAll(resourceDirs);
+ //Then append the values from JETTY_WAR_FRAGMENT_FOLDER_PATH
+ resources.addAll(appendedResourcesPath.values());
+
+ context.setAttribute(WebInfConfiguration.RESOURCE_DIRS, resources);
+ }
}
}
super.configure(context);
- // place the patch resources at the beginning of the contexts's resource base
- if (!patchResourcesPath.isEmpty())
+ // place the prepended resources at the beginning of the contexts's resource base
+ if (!prependedResourcesPath.isEmpty())
{
- Resource[] resources = new Resource[1+patchResourcesPath.size()];
- ResourceCollection mergedResources = new ResourceCollection (patchResourcesPath.values().toArray(new Resource[patchResourcesPath.size()]));
- System.arraycopy(patchResourcesPath.values().toArray(new Resource[patchResourcesPath.size()]), 0, resources, 0, patchResourcesPath.size());
+ Resource[] resources = new Resource[1+prependedResourcesPath.size()];
+ System.arraycopy(prependedResourcesPath.values().toArray(new Resource[prependedResourcesPath.size()]), 0, resources, 0, prependedResourcesPath.size());
resources[resources.length-1] = context.getBaseResource();
context.setBaseResource(new ResourceCollection(resources));
}
@@ -306,4 +296,32 @@ public class OSGiWebInfConfiguration extends WebInfConfiguration
return resources;
}
+
+
+ /**
+ * Convert a path inside a fragment into a Resource
+ * @param resourcePath
+ * @param fragment
+ * @param resourceMap
+ * @throws Exception
+ */
+ private void convertFragmentPathToResource (String resourcePath, Bundle fragment, Map<String, Resource> resourceMap )
+ throws Exception
+ {
+ if (resourcePath == null)
+ return;
+
+ URL url = fragment.getEntry(resourcePath);
+ if (url == null)
+ {
+ throw new IllegalArgumentException("Unable to locate " + resourcePath
+ + " inside "
+ + " the fragment '"
+ + fragment.getSymbolicName()
+ + "'");
+ }
+ url = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(url);
+ String key = resourcePath.startsWith("/") ? resourcePath.substring(1) : resourcePath;
+ resourceMap.put(key + ";" + fragment.getSymbolicName(), Resource.newResource(url));
+ }
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebappConstants.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebappConstants.java
index e82f2e813c..0080d0fa27 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebappConstants.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiWebappConstants.java
@@ -67,16 +67,23 @@ public class OSGiWebappConstants
public static final String JETTY_CONTEXT_FILE_PATH = "Jetty-ContextFilePath";
/** path within the bundle to the folder that contains the basic resources. */
+ @Deprecated
public static final String JETTY_WAR_FOLDER_PATH = "Jetty-WarFolderPath";
+ public static final String JETTY_WAR_RESOURCE_PATH = "Jetty-WarResourcePath";
/** path within a fragment hosted by a web-bundle to a folder that contains basic resources.
* the path is appended to the lookup path where jetty locates static resources */
+ @Deprecated
public static final String JETTY_WAR_FRAGMENT_FOLDER_PATH = "Jetty-WarFragmentFolderPath";
+ public static final String JETTY_WAR_FRAGMENT_RESOURCE_PATH = "Jetty-WarFragmentResourcePath";
+
/** path within a fragment hosted by a web-bundle to a folder that contains basic resources.
* The path is prefixed to the lookup path where jetty locates static resources:
* this will override static resources with the same name in the web-bundle. */
+ @Deprecated
public static final String JETTY_WAR_PATCH_FRAGMENT_FOLDER_PATH = "Jetty-WarPatchFragmentFolderPath";
+ public static final String JETTY_WAR_PREPEND_FRAGMENT_RESOURCE_PATH = "Jetty-WarPrependFragmentResourcePath";
/** installation path of webapp bundle
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java
index e3fbf3b256..81b6280693 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/ServiceWebAppProvider.java
@@ -128,6 +128,8 @@ public class ServiceWebAppProvider extends AbstractWebAppProvider implements Ser
String base = (String)serviceRef.getProperty(OSGiWebappConstants.JETTY_WAR_FOLDER_PATH);
if (base == null)
+ base = (String)serviceRef.getProperty(OSGiWebappConstants.JETTY_WAR_RESOURCE_PATH);
+ if (base == null)
base = (String)serviceRef.getProperty(OSGiWebappConstants.SERVICE_PROP_WAR);
if (base == null)
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java
index d688f68d5a..6eaa801230 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/Util.java
@@ -35,6 +35,28 @@ public class Util
{
public static final String DEFAULT_DELIMS = ",;";
+
+ /**
+ * Get the value of a manifest header.
+ *
+ * @param name the name of the header
+ * @param altName an alternative name for the header (useful for deprecated names)
+ * @param manifest
+ * @return
+ */
+ public static String getManifestHeaderValue (String name, String altName, Dictionary manifest)
+ {
+ if (manifest == null)
+ return null;
+ if (name == null && altName == null)
+ return null;
+ if (name != null)
+ return (String)manifest.get(name);
+ return (String)manifest.get(altName);
+ }
+
+
+
/* ------------------------------------------------------------ */
/**
* Treating the string as a separated list of filenames,

Back to the top