Author: fmeschbe
Date: Wed Nov 25 12:39:29 2009
New Revision: 884073
URL: http://svn.apache.org/viewvc?rev=884073&view=rev
Log:
SLING-1157 apply BootstrapInstaller extension supporting WAR bundles (another
thanks to Justin Edelson for providing)
(this is slightly modified compared to the patch: the extensions have leading
dots, the list is an array and the FileFilter also calls the isBundle(String)
method to share code)
Also this commit converts some of the constants into private constants of the
class.
Modified:
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java
Modified:
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java?rev=884073&r1=884072&r2=884073&view=diff
==============================================================================
---
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java
(original)
+++
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java
Wed Nov 25 12:39:29 2009
@@ -66,18 +66,18 @@
* location of Bundles installed by this class is the name (without the
* path) of the resource from which the Bundle was installed.
*/
- static final String SCHEME = "slinginstall:";
+ private static final String SCHEME = "slinginstall:";
/**
* The root location in which the bundles are looked up for installation
* (value is "resources/").
*/
- static final String PATH_RESOURCES = "resources/";
+ private static final String PATH_RESOURCES = "resources/";
/**
* The path of startup bundles in the sling home
*/
- static final String PATH_STARTUP = "startup/";
+ private static final String PATH_STARTUP = "startup/";
/**
* The location of the core Bundles (value is "resources/corebundles").
@@ -96,22 +96,27 @@
static final String PATH_BUNDLES = PATH_RESOURCES + "bundles";
/**
+ * The possible file extensions for a bundle archive file.
+ */
+ private static final String[] BUNDLE_EXTENSIONS = { ".jar", ".war" };
+
+ /**
* The start level to be assigned to bundles found in the (old style)
* {...@link #PATH_CORE_BUNDLES resources/corebundles} location (value is
1).
*/
- static final int STARTLEVEL_CORE_BUNDLES = 1;
+ private static final int STARTLEVEL_CORE_BUNDLES = 1;
/**
* The start level to be assigned to bundles found in the (old style)
* {...@link #PATH_BUNDLES resources/bundles} location (value is 0).
*/
- static final int STARTLEVEL_BUNDLES = 0;
+ private static final int STARTLEVEL_BUNDLES = 0;
/**
* The marker start level indicating the location of the bundle cannot be
* resolved to a valid start level (value is -1).
*/
- static final int STARTLEVEL_NONE = -1;
+ private static final int STARTLEVEL_NONE = -1;
/** The data file which works as a marker to detect the first startup. */
private static final String DATA_FILE = "bootstrapinstaller.ser";
@@ -123,7 +128,7 @@
private final Logger logger;
/**
- * The {...@link ResourceProvider} used to access the Bundle jar files to
+ * The {...@link ResourceProvider} used to access the Bundle files to
* install.
*/
private final ResourceProvider resourceProvider;
@@ -394,9 +399,9 @@
while (res.hasNext()) {
// path to the next resource
String path = res.next();
- // we only deal with jars
- if (path.endsWith(".jar")) {
- // try to access the JAR file, ignore if not possible
+
+ if (isBundle(path)) {
+ // try to access the bundle file, ignore if not possible
InputStream ins = resourceProvider.getResourceAsStream(path);
if (ins == null) {
continue;
@@ -411,9 +416,9 @@
// copy over the bundle based on the startlevel
String bundleFileName = extractFileName(path);
- File bundleJar = new File(startUpLevelDir, bundleFileName);
+ File bundleFile = new File(startUpLevelDir, bundleFileName);
try {
- copyStreamToFile(ins, bundleJar);
+ copyStreamToFile(ins, bundleFile);
} catch (IOException e) {
// should this fail here or just log a warning?
throw new RuntimeException("Failure copying file from "
@@ -425,6 +430,21 @@
}
/**
+ * Determine if a path could be a bundle based on its extension.
+ *
+ * @param path the path to the file
+ * @return true if the path could be a bundle
+ */
+ static boolean isBundle(String path) {
+ for (String extension : BUNDLE_EXTENSIONS) {
+ if (path.endsWith(extension)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Copies a stream from the resource (jar/war) to a file
* @param fromStream
* @param toFile
@@ -450,15 +470,15 @@
}
/**
- * Install the Bundles from JAR files found in startup directory under the
+ * Install the Bundles from files found in startup directory under the
* level directories, this will only install bundles which are new or
updated
* and will skip over them otherwise
*
* @param context The <code>BundleContext</code> used to install the new
Bundles.
* @param currentBundles The currently installed Bundles indexed by their
* Bundle location.
- * @param parent The path to the location in which to look for JAR files to
- * install. Only resources whose name ends with <em>.jar</em>
are
+ * @param parent The path to the location in which to look for bundle
files to
+ * install. Only resources whose name ends with one of the
known bundle extensions are
* considered for installation.
* @param installed The list of Bundles installed by this method. Each
* Bundle successfully installed is added to this list.
@@ -490,9 +510,9 @@
}
// iterate through all files in the startlevel dir
- File[] jarFiles = levelDir.listFiles(JAR_FILE_FILTER);
- for (File bundleJar : jarFiles) {
- requireRestart |= installBundle(bundleJar, startLevel,
+ File[] bundleFiles = levelDir.listFiles(BUNDLE_FILE_FILTER);
+ for (File bundleFile : bundleFiles) {
+ requireRestart |= installBundle(bundleFile, startLevel,
context, currentBundles, installed, startLevelService);
}
}
@@ -846,7 +866,7 @@
for (File levelDir : directories) {
// iterate through all files in the startlevel dir
- File[] jarFiles = levelDir.listFiles(JAR_FILE_FILTER);
+ File[] jarFiles = levelDir.listFiles(BUNDLE_FILE_FILTER);
for (File bundleJar : jarFiles) {
if (bundleJar.lastModified() > selfStamp) {
selfStamp = bundleJar.lastModified();
@@ -871,11 +891,11 @@
};
/**
- * Simple jar file filter
+ * Simple bundle file filter
*/
- private static final FileFilter JAR_FILE_FILTER = new FileFilter() {
+ private static final FileFilter BUNDLE_FILE_FILTER = new FileFilter() {
public boolean accept(File f) {
- return f.isFile() && f.getName().endsWith(".jar");
+ return f.isFile() && isBundle(f.getName());
}
};