You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2011/08/18 10:44:53 UTC
svn commit: r1159087 - in
/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl:
BootstrapInstaller.java Sling.java
Author: cziegeler
Date: Thu Aug 18 08:44:52 2011
New Revision: 1159087
URL: http://svn.apache.org/viewvc?rev=1159087&view=rev
Log:
SLING-2184 : Copy sling_bootstrap.txt if contained in launchpad
Modified:
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.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=1159087&r1=1159086&r2=1159087&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 Thu Aug 18 08:44:52 2011
@@ -129,7 +129,7 @@ class BootstrapInstaller {
/**
* The name of the bootstrap commands file
*/
- private static final String BOOTSTRAP_CMD_FILENAME = "sling_bootstrap.txt";
+ public static final String BOOTSTRAP_CMD_FILENAME = "sling_bootstrap.txt";
/**
* The {@link Logger} use for logging messages during installation and
@@ -266,18 +266,8 @@ class BootstrapInstaller {
* @throws IllegalStateException if the sling home or startup directories cannot be created/accessed
*/
private File getSlingStartupDir(String slingHome) {
- if (isBlank(slingHome)) {
- throw new IllegalStateException("Fatal error in bootstrap: Cannot get the "+SharedConstants.SLING_HOME+" value: " + slingHome);
- }
- File slingHomeDir = new File(slingHome).getAbsoluteFile();
- if (! slingHomeDir.exists()
- || ! slingHomeDir.canRead()
- || ! slingHomeDir.canWrite()
- || ! slingHomeDir.isDirectory()) {
- throw new IllegalStateException("Fatal error in bootstrap: Cannot find accessible existing "
- +SharedConstants.SLING_HOME+" directory: " + slingHomeDir);
- }
- File slingHomeStartupDir = getOrCreateDirectory(slingHomeDir, PATH_STARTUP);
+ final File slingHomeDir = new File(slingHome);
+ final File slingHomeStartupDir = getOrCreateDirectory(slingHomeDir, PATH_STARTUP);
return slingHomeStartupDir;
}
Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java?rev=1159087&r1=1159086&r2=1159087&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java (original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java Thu Aug 18 08:44:52 2011
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -204,7 +205,10 @@ public class Sling {
this.logger.log(Logger.LOG_INFO, "Starting Apache Sling");
// read the default parameters
- Map<String, String> props = this.loadConfigProperties(propOverwrite);
+ final Map<String, String> props = this.loadConfigProperties(propOverwrite);
+
+ // check for bootstrap command file
+ copyBootstrapCommandFile(props);
// check for auto-start bundles
this.setInstallBundles(props);
@@ -384,7 +388,7 @@ public class Sling {
* an error.
*/
private Map<String, String> loadConfigProperties(
- Map<String, String> propOverwrite) throws BundleException {
+ final Map<String, String> propOverwrite) throws BundleException {
// The config properties file is either specified by a system
// property or it is in the same directory as the Felix JAR file.
// Try to load it from one of these places.
@@ -1035,4 +1039,46 @@ public class Sling {
// Return the value.
return val;
}
+
+ private void copyBootstrapCommandFile(final Map<String, String> props) {
+ // check last modification date
+ final URL url = this.resourceProvider.getResource(BootstrapInstaller.BOOTSTRAP_CMD_FILENAME);
+ if ( url != null ) {
+ this.logger.log(Logger.LOG_DEBUG, "Checking last modification date of bootstrap command file.");
+ InputStream is = null;
+ OutputStream os = null;
+ try {
+ final long lastModified = url.openConnection().getLastModified();
+ final File slingHome = new File(props.get(SharedConstants.SLING_HOME));
+ final File cmdFile = new File(slingHome, BootstrapInstaller.BOOTSTRAP_CMD_FILENAME);
+ boolean copyFile = true;
+ if ( cmdFile.exists() && cmdFile.lastModified() >= lastModified ) {
+ copyFile = false;
+ }
+ if ( copyFile ) {
+ this.logger.log(Logger.LOG_INFO, "Copying bootstrap command file.");
+ is = this.resourceProvider.getResourceAsStream(BootstrapInstaller.BOOTSTRAP_CMD_FILENAME);
+ os = new FileOutputStream(cmdFile);
+ final byte[] buffer = new byte[2048];
+ int l;
+ while ( (l = is.read(buffer, 0, buffer.length)) != -1 ) {
+ os.write(buffer, 0, l);
+ }
+ }
+
+ } catch (final IOException ioe) {
+ this.logger.log(Logger.LOG_INFO, "Ignoring exception during processing of bootstrap command file.", ioe);
+ } finally {
+ if ( is != null ) {
+ try { is.close(); } catch (final IOException ignore) {}
+ }
+ if ( os != null ) {
+ try { os.close(); } catch (final IOException ignore) {}
+ }
+ }
+ } else {
+ this.logger.log(Logger.LOG_DEBUG, "Bootstrap command file not found.");
+ }
+
+ }
}