You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/11/15 21:56:18 UTC
svn commit: r595454 - in /incubator/sling/trunk/launcher/app: ./
src/main/java/org/apache/sling/launcher/
src/main/java/org/apache/sling/launcher/app/
src/main/java/org/apache/sling/launcher/app/main/
src/main/java/org/apache/sling/launcher/main/ src/m...
Author: fmeschbe
Date: Thu Nov 15 12:56:16 2007
New Revision: 595454
URL: http://svn.apache.org/viewvc?rev=595454&view=rev
Log:
SLING-98 Repackage to match new packaging convention after the Sling API definition
Added:
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
- copied, changed from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextConnection.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
- copied, changed from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextProtocolHandler.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Logger.java
- copied, changed from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Logger.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
- copied, changed from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ResourceProvider.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java
- copied, changed from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Sling.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/
- copied from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/main/
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/SimpleLogger.java
Removed:
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ClassLoaderResourceProvider.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextConnection.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextProtocolHandler.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Logger.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ResourceProvider.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/SimpleLogger.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Sling.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/main/
Modified:
incubator/sling/trunk/launcher/app/pom.xml
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java
incubator/sling/trunk/launcher/app/src/main/resources/sling.properties
Modified: incubator/sling/trunk/launcher/app/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/pom.xml?rev=595454&r1=595453&r2=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/pom.xml (original)
+++ incubator/sling/trunk/launcher/app/pom.xml Thu Nov 15 12:56:16 2007
@@ -28,7 +28,7 @@
<relativePath>../../parent/pom.xml</relativePath>
</parent>
- <artifactId>sling-app</artifactId>
+ <artifactId>org.apache.sling.launcher.app</artifactId>
<packaging>jar</packaging>
<version>2.0.0-incubator-SNAPSHOT</version>
@@ -40,13 +40,13 @@
<scm>
<connection>
- scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/sling-app
+ scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/launcher/app
</connection>
<developerConnection>
- scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/sling-app
+ scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/launcher/app
</developerConnection>
<url>
- http://svn.apache.org/viewvc/incubator/sling/trunk/sling-app
+ http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app
</url>
</scm>
@@ -65,7 +65,7 @@
</goals>
<configuration>
<includeArtifactIds>
- sling-log
+ org.apache.sling.osgi.log
</includeArtifactIds>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>
@@ -80,7 +80,7 @@
</goals>
<configuration>
<excludeArtifactIds>
- org.apache.felix.framework,org.osgi.core,org.osgi.compendium,sling-log
+ org.apache.felix.framework,org.osgi.core,org.osgi.compendium,org.apache.sling.osgi.log
</excludeArtifactIds>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>
@@ -113,7 +113,7 @@
<archive>
<manifest>
<mainClass>
- org.apache.sling.launcher.main.Main
+ org.apache.sling.launcher.app.main.Main
</mainClass>
<addDefaultImplementationEntries>
true
@@ -163,7 +163,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-log</artifactId>
+ <artifactId>org.apache.sling.osgi.log</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
@@ -172,7 +172,7 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-assembly</artifactId>
+ <artifactId>org.apache.sling.osgi.assembly</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
@@ -210,7 +210,7 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-console-web</artifactId>
+ <artifactId>org.apache.sling.osgi.console.web</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
</dependencies>
@@ -339,59 +339,49 @@
-->
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-jasper-sling</artifactId>
+ <artifactId>org.apache.sling.api</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-mime</artifactId>
+ <artifactId>org.apache.sling.core</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-jackrabbit-api</artifactId>
+ <artifactId>org.apache.sling.commons.mime</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-jackrabbit-server</artifactId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>
- sling-jackrabbit-classloader
- </artifactId>
- <version>2.0.0-incubator-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling-component-api</artifactId>
+ <artifactId>org.apache.sling.jcr.resource</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-content-jcr</artifactId>
+ <artifactId>org.apache.sling.jcr.jackrabbit.server</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-core</artifactId>
- <version>2.0.0-incubator-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling-scripting-core</artifactId>
+ <artifactId>
+ org.apache.sling.jcr.classloader
+ </artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-scripting-jsp</artifactId>
+ <artifactId>org.apache.sling.scripting.jsp</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>sling-scripting-jsp-taglib</artifactId>
+ <artifactId>org.apache.sling.scripting.jsp.taglib</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
</dependencies>
Copied: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextConnection.java (from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextConnection.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextConnection.java?p2=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextConnection.java&p1=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextConnection.java&r1=593045&r2=595454&rev=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextConnection.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextConnection.java Thu Nov 15 12:56:16 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.launcher;
+package org.apache.sling.launcher.app;
import java.io.IOException;
import java.io.InputStream;
@@ -24,20 +24,20 @@
/**
* The <code>ContextConnection</code> extends the
* <code>java.net.URLConnection</code> to provide access to a resource which
- * is available from the servlet context.
+ * is available from {@link ResourceProvider} provided to {@link Sling}.
* <p>
* This class is implemented by actually connecting to a resource URL which is
- * provided by the servlet context and delegating the relevant method calls.
+ * provided by the resource provider and delegating the relevant method calls.
* Currently only {@link #getContentLength()}, {@link #getContentType()},
* {@link #getInputStream()} and {@link #getLastModified()} are supported.
*/
public class ContextConnection extends URLConnection {
/**
- * The <code>ServletContext</code> to which requests for content access
- * are delegated.
+ * The {@link ResourceProvider} to which requests for content access are
+ * delegated.
*/
- private final ResourceProvider classLoader;
+ private final ResourceProvider resourceProvider;
/**
* The delegatee <code>URLConnection</code> to which some of the method
@@ -49,34 +49,29 @@
* Creates an instance of this context connection.
*
* @param url The original URL whose path part is used to address the
- * resource from the servlet context.
- * @param context The <code>ServletContext</code> to which requests for
- * content access are delegated.
+ * resource from the resource provider.
+ * @param resourceProvider The {@link ResourceProvider} to which requests
+ * for content access are delegated.
*/
- ContextConnection(URL url, ResourceProvider classLoader) {
+ ContextConnection(URL url, ResourceProvider resourceProvider) {
super(url);
- this.classLoader = classLoader;
+ this.resourceProvider = resourceProvider;
}
/**
- * Accesses the servlet context resource by opening the connection to the
- * respective resource URL.
- * <p>
- * If this instance has already been connected, this method has no effect.
- *
- * @throws IOException If the URL path does not address an existing resource
- * in the servlet context or if opening the connection to that resource
- * fails.
+ * Accesses the the resource from the underlaying resource provider at the
+ * URL's path.
*/
public void connect() throws IOException {
if (!this.connected) {
- URL contextURL = this.classLoader.getResource(this.url.getPath());
+ URL contextURL = resourceProvider.getResource(url.getPath());
if (contextURL == null) {
- throw new IOException("Resource " + this.url.getPath() + " does not exist");
+ throw new IOException("Resource " + url.getPath()
+ + " does not exist");
}
- this.delegatee = contextURL.openConnection();
- this.connected = true;
+ delegatee = contextURL.openConnection();
+ connected = true;
}
}
@@ -85,7 +80,7 @@
* not been connected yet.
*/
public int getContentLength() {
- return (this.delegatee == null) ? -1 : this.delegatee.getContentLength();
+ return (delegatee == null) ? -1 : delegatee.getContentLength();
}
/**
@@ -93,7 +88,7 @@
* if this connection has not been connected yet.
*/
public String getContentType() {
- return (this.delegatee == null) ? null : this.delegatee.getContentType();
+ return (delegatee == null) ? null : delegatee.getContentType();
}
/**
@@ -101,11 +96,12 @@
* is not connected yet, the conneciton is opened.
*
* @throws IOException may be thrown if an error occurrs opening the
- * connection or accessing the content as an <code>InputStream</code>.
+ * connection or accessing the content as an
+ * <code>InputStream</code>.
*/
public InputStream getInputStream() throws IOException {
- this.connect();
- return this.delegatee.getInputStream();
+ connect();
+ return delegatee.getInputStream();
}
/**
@@ -113,6 +109,6 @@
* connection has not been connected yet.
*/
public long getLastModified() {
- return (this.delegatee == null) ? 0 : this.delegatee.getLastModified();
+ return (delegatee == null) ? 0 : delegatee.getLastModified();
}
}
Copied: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java (from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextProtocolHandler.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java?p2=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java&p1=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextProtocolHandler.java&r1=593045&r2=595454&rev=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ContextProtocolHandler.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java Thu Nov 15 12:56:16 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.launcher;
+package org.apache.sling.launcher.app;
import java.net.URL;
import java.net.URLConnection;
@@ -30,29 +30,29 @@
public class ContextProtocolHandler extends AbstractURLStreamHandlerService {
/**
- * The <code>ServletContext</code> to which requests for content access
- * are delegated.
+ * The {@link ResourceProvider} to which requests for content access are
+ * delegated.
*/
- private final ResourceProvider classLoader;
+ private final ResourceProvider resourceProvider;
/**
* Creates an instance of this protocol handler setting the servlet context
* which is queried to access content.
*
- * @param context The <code>ServletContext</code> to which requests for
- * content access are delegated.
+ * @param resourceProvider The {@link ResourceProvider} to which requests
+ * for content access are delegated.
*/
- public ContextProtocolHandler(ResourceProvider classLoader) {
- this.classLoader = classLoader;
+ public ContextProtocolHandler(ResourceProvider resourceProvider) {
+ this.resourceProvider = resourceProvider;
}
/**
- * Returns an instance of the {@link ContextConnection} class to access
- * the content of the <code>url</code>.
+ * Returns an instance of the {@link ContextConnection} class to access the
+ * content of the <code>url</code>.
*
* @param url The URL whose content is requested.
*/
public URLConnection openConnection(URL url) {
- return new ContextConnection(url, this.classLoader);
+ return new ContextConnection(url, resourceProvider);
}
}
Copied: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Logger.java (from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Logger.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Logger.java?p2=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Logger.java&p1=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Logger.java&r1=593045&r2=595454&rev=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Logger.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Logger.java Thu Nov 15 12:56:16 2007
@@ -14,17 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.launcher;
+package org.apache.sling.launcher.app;
/**
- * The <code>Logger</code> TODO
+ * The <code>Logger</code> class defines a simple API to abstract the real
+ * logging to use depending on whether Sling is running as a standalone
+ * application or as a web application.
*/
public abstract class Logger {
+ /** Logs an informational message */
public void log(String message) {
this.log(message, null);
}
+ /** Logs an error message with an accompanying Throwable */
public abstract void log(String message, Throwable throwable);
}
Copied: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java (from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ResourceProvider.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java?p2=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java&p1=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ResourceProvider.java&r1=593045&r2=595454&rev=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/ResourceProvider.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java Thu Nov 15 12:56:16 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.launcher;
+package org.apache.sling.launcher.app;
import java.io.IOException;
import java.io.InputStream;
@@ -22,14 +22,27 @@
import java.util.Iterator;
/**
- * The <code>ResourceProvider</code> TODO
+ * The <code>ResourceProvider</code> defines a simple API to access resources
+ * from the environment depending on how Sling is launched.
*/
public abstract class ResourceProvider {
+ /**
+ * Returns an iterator of paths strings of the children of the given folder
+ * defined by its path.
+ */
public abstract Iterator<String> getChildren(String path);
+ /**
+ * Returns an URL to the resource with the given path or <code>null</code>
+ * if no such resource exists.
+ */
public abstract URL getResource(String path);
+ /**
+ * Returns an <code>InputStream</code> to the resource given by the path
+ * or <code>null</code> if no such resource exists.
+ */
public InputStream getResourceAsStream(String path) {
URL res = this.getResource(path);
if (res != null) {
Copied: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java (from r593045, incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Sling.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java?p2=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java&p1=incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Sling.java&r1=593045&r2=595454&rev=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/Sling.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java Thu Nov 15 12:56:16 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.launcher;
+package org.apache.sling.launcher.app;
import java.io.File;
import java.io.FileInputStream;
@@ -38,8 +38,6 @@
import java.util.UUID;
import java.util.Map.Entry;
-import javax.servlet.ServletException;
-
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.FelixConstants;
import org.osgi.framework.BundleActivator;
@@ -115,24 +113,6 @@
public static final String PROP_SYSTEM_PACKAGES = "org.apache.sling.launcher.system.packages";
/**
- * The name of the servlet context attribute containing the
- * <code>Felix</code> instance.
- * <p>
- * This context attribute must be used with utmost care ! It is not intended
- * for this value to be used in generall applications of the framework.
- */
- public static final String CONTEXT_ATTR_SLING_FRAMEWORK = "org.apache.sling.framework";
-
- /**
- * The name of the servlet context attribute containing the
- * <code>BundleContext</code> instance of the system bundle.
- * <p>
- * This context attribute must be used with utmost care ! It is not intended
- * for this value to be used in generall applications of the framework.
- */
- public static final String CONTEXT_ATTR_SLING_SYSTEM_BUNDLE_CONTEXT = "org.apache.sling.system.bundlecontext";
-
- /**
* The name of the configuration property defining the Sling home directory
* (value is "sling.home"). This is a Platform file system directory below
* which all runtime data, such as the Felix bundle archives, logfiles, CRX
@@ -156,7 +136,7 @@
* @see #SLING_HOME
*/
public static final String SLING_HOME_URL = "sling.home.url";
-
+
/**
* The name of the framework property containing the identifier of the
* running Sling instance (value is "sling.id"). This value of this property
@@ -170,7 +150,7 @@
* {@link #SLING_ID Sling instance identifier} (value is "sling.id").
*/
public static final String SLING_ID_FILE = SLING_ID;
-
+
/**
* The name of the configuration property defining a properties file
* defining a list of bundles, which are installed into the framework when
@@ -204,7 +184,7 @@
/**
* The simple logger to log messages during startup and shutdown to
*/
- private final Logger logger;
+ protected final Logger logger;
private ResourceProvider resourceProvider;
@@ -232,10 +212,8 @@
public Sling(Logger logger, ResourceProvider resourceProvider,
Map<String, String> propOverwrite) throws BundleException {
- this.logger = (logger != null) ? logger : new SimpleLogger();
- this.resourceProvider = (resourceProvider != null)
- ? resourceProvider
- : new ClassLoaderResourceProvider(this.getClass().getClassLoader());
+ this.logger = logger;
+ this.resourceProvider = resourceProvider;
this.logger.log("Starting Sling");
@@ -248,7 +226,7 @@
// ensure execution environment
this.setExecutionEnvironment(props);
-
+
// ensure the instance ID
props.put(SLING_ID, getInstanceId(props));
@@ -277,7 +255,8 @@
public final void destroy() {
// shutdown the Felix container
if (felix != null) {
- String label = "Sling Instance " + felix.getBundleContext().getProperty(SLING_ID);
+ String label = "Sling Instance "
+ + felix.getBundleContext().getProperty(SLING_ID);
logger.log("Shutting down " + label);
felix.stopAndWait();
logger.log(label + " stopped");
@@ -379,8 +358,8 @@
slingHome = props.get(SLING_HOME);
if (slingHome == null || slingHome.length() == 0) {
slingHome = "sling";
- this.logger.log("sling.home is not defined. Using '" + slingHome
- + "'");
+ this.logger.log("sling.home is not defined. Using '"
+ + slingHome + "'");
}
}
@@ -494,7 +473,8 @@
tmp.putAll(origProps);
tmp.store(os, "Overlay properties for configuration");
} catch (Exception ex) {
- this.logger.log("Error loading overlay properties from " + propFile, ex);
+ this.logger.log(
+ "Error loading overlay properties from " + propFile, ex);
} finally {
if (os != null) {
try {
@@ -658,7 +638,7 @@
* <code>${sling.home}/sling.id</code> file if existing and valid.
* Otherwise a new id is created as a random UUID and then stored in the
* file.
- *
+ *
* @return the Sling Instance Identifier
*/
private String getInstanceId(Map<String, String> props) {
@@ -673,12 +653,13 @@
byte[] rawBytes = new byte[36];
if (fin.read(rawBytes) == 36) {
String rawString = new String(rawBytes, "ISO-8859-1");
-
+
// roundtrip to ensure correct format of UUID value
- slingId = UUID.fromString(rawString).toString();
+ slingId = UUID.fromString(rawString).toString();
}
} catch (Throwable t) {
- logger.log("Failed reading UUID from id file " + idFile + ", creating new id", t);
+ logger.log("Failed reading UUID from id file " + idFile
+ + ", creating new id", t);
} finally {
if (fin != null) {
try {
@@ -688,11 +669,11 @@
}
}
}
-
+
// no sling id yet or failure to read file: create an id and store
if (slingId == null) {
slingId = UUID.randomUUID().toString();
-
+
idFile.delete();
idFile.getParentFile().mkdirs();
FileOutputStream fout = null;
@@ -711,7 +692,7 @@
}
}
}
-
+
return slingId;
}
@@ -887,8 +868,8 @@
this.load(props, is);
}
} catch (IOException ioe) {
- this.logger.log("Error loading config properties from " + file,
- ioe);
+ this.logger.log("Error loading config properties from "
+ + file, ioe);
}
}
}
@@ -909,8 +890,8 @@
try {
this.load(props, is);
} catch (IOException ioe) {
- this.logger.log("Error loading config properties from " + resource,
- ioe);
+ this.logger.log("Error loading config properties from "
+ + resource, ioe);
}
}
}
Added: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java?rev=595454&view=auto
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java (added)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java Thu Nov 15 12:56:16 2007
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launcher.app.main;
+
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Pattern;
+
+import org.apache.sling.launcher.app.ResourceProvider;
+import org.apache.sling.launcher.app.Sling;
+
+/**
+ * The <code>ClassLoaderResourceProvider</code> TODO
+ */
+class ClassLoaderResourceProvider extends ResourceProvider {
+
+ private final ClassLoader classLoader;
+
+ public ClassLoaderResourceProvider(ClassLoader classLoader) {
+ this.classLoader = (classLoader != null)
+ ? classLoader
+ : this.getClass().getClassLoader();
+ }
+
+ @Override
+ public Iterator<String> getChildren(String path) {
+ List<String> children;
+
+ URL url = this.classLoader.getResource(Sling.CONFIG_PROPERTIES);
+ if (url != null) {
+ Pattern pathPattern = Pattern.compile("^" + path + "/[^/]+$");
+
+ children = new ArrayList<String>();
+ try {
+ URLConnection conn = url.openConnection();
+ if (conn instanceof JarURLConnection) {
+ JarFile jar = ((JarURLConnection) conn).getJarFile();
+ Enumeration<JarEntry> entries = jar.entries();
+ while (entries.hasMoreElements()) {
+ String entry = entries.nextElement().getName();
+ if (pathPattern.matcher(entry).matches()) {
+ children.add(entry);
+ }
+ }
+ }
+ } catch (IOException ioe) {
+ // ignore for now
+ }
+ } else {
+ children = Collections.emptyList();
+ }
+
+ return children.iterator();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.sling.core.launcher.ResourceProvider#getResource(java.lang.String)
+ */
+ public URL getResource(String path) {
+ // ensure path
+ if (path == null || path.length() == 0) {
+ return null;
+ }
+
+ // remove leading slash
+ if (path.charAt(0) == '/') {
+ path = path.substring(1);
+ }
+
+ return (this.classLoader != null) ? this.classLoader.getResource(path) : null;
+ }
+
+}
Modified: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java?rev=595454&r1=593045&r2=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java Thu Nov 15 12:56:16 2007
@@ -14,71 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.launcher.main;
+package org.apache.sling.launcher.app.main;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
-import org.apache.sling.launcher.Sling;
+import org.apache.sling.launcher.app.Logger;
+import org.apache.sling.launcher.app.ResourceProvider;
+import org.apache.sling.launcher.app.Sling;
+import org.apache.sling.osgi.log.LogbackManager;
import org.osgi.framework.BundleException;
/**
- * The <code>Sling</code> serves as a basic servlet for Project Sling. The
- * tasks of this servlet are as follows:
- * <ul>
- * <li>The {@link #init()} method launches Apache <code>Felix</code> as the
- * OSGi framework implementation we use.
- * <li>Registers as a service listener interested for services of type
- * <code>javax.servlet.Servlet</code>.
- * <li>Handles requests by delegating to a servlet which is expected to be
- * registered with the framework as a service of type
- * <code>javax.servlet.Servlet</code>. If no delegatee servlet has been
- * registered request handlings results in a temporary unavailability of the
- * servlet.
- * </ul>
- * <p>
- * <b>Request Handling</b>
- * <p>
- * This servlet handles request by forwarding to a delegatee servlet. The
- * delegatee servlet is automatically retrieved from the service registry by the
- * {@link #getDelegatee()}. This method also makes sure, the such a servlet
- * actually exits by throwing an <code>UnvailableException</code> if not and
- * also makes sure the servlet is initialized.
- * <p>
- * <b>Launch Configuration</b>
- * <p>
- * The Apache <code>Felix</code> framework requires configuration parameters
- * to be specified for startup. This servlet builds the list of parameters from
- * three locations:
- * <ol>
- * <li>The <code>com/day/osgi/servlet/Sling.properties</code> is read from
- * the servlet class path. This properties file contains default settings.</li>
- * <li>Extensions of this servlet may provide additional properties to be
- * loaded overwriting the {@link #loadPropertiesOverride(Properties)} method.
- * <li>Finally, web application init parameters are added to the properties and
- * may overwrite existing properties of the same name(s).
- * </ol>
- * <p>
- * After loading all properties, variable substitution takes place on the
- * property values. A variable is indicated as <code>${<prop-name>}</code>
- * where <code><prop-name></code> is the name of a system or
- * configuration property (configuration properties override system properties).
- * Variables may be nested and are resolved from inner-most to outer-most. For
- * example, the property value <code>${outer-${inner}}</code> is resolved by
- * first resolving <code>${inner}</code> and then resolving the property whose
- * name is the catenation of <code>outer-</code> and the result of resolving
- * <code>${inner}</code>.
- * <p>
- * <b>Logging</b>
- * <p>
- * This servlet logs through the servlet container logging mechanism by calling
- * the <code>GenericServlet.log</code> methods. Bundles launched within the
- * framework provided by this servlet may use whatever logging mechanism they
- * choose to use. The Day Commons OSGI Log Bundle provides an OSGi Log Service
- * implementation, which also provides access to Apache Commons Logging, SLF4J
- * and Log4J logging. It is recommended that this bundle is used to setup and
- * configure logging for systems based on this servlet.
+ * The <code>Main</code> class is a simple Java Application which interprests
+ * the command line and creates the {@link Sling} launcher class and thus starts
+ * the OSGi framework. In addition a shutdown thread is registered to ensure
+ * proper shutdown on VM termination.
+ * <p>
+ * The supported command line options are:
+ * <dl>
+ * <dt>-l loglevel</dt>
+ * <dd>Sets the initial loglevel as an integer in the range 0 to 4 or as one of
+ * the well known level strings FATAL, ERROR, WARN, INFO or DEBUG. This option
+ * overwrites the <code>org.apache.sling.osg.log.level</code> setting the
+ * <code>sling.properties</code> file.</dd>
+ * <dt>-f logfile</dt>
+ * <dd>The log file, \"-\" for stdout (default logs/error.log). This option
+ * overwrites the <code>org.apache.sling.osg.log.file</code> setting the
+ * <code>sling.properties</code> file.</dd>
+ * <dt>-c slinghome</dt>
+ * <dd>The directory in which Sling locates its initial configuration file
+ * <code>sling.properties</code> and where files of Sling itself such as the
+ * Apache Felix bundle archive or the JCR repository files are stored (default
+ * sling).</dd>
+ * <dt>-a address</dt>
+ * <dd>The interfact to bind to (use 0.0.0.0 for any). This option is not
+ * implemented yet.</dd>
+ * <dt>-p port</dt>
+ * <dd>The port to listen (default 8080) to handle HTTP requests. This option
+ * overwrites the <code>org.osgi.service.http.port</code> setting the
+ * <code>sling.properties</code> file.</dd>
+ * <dt>-h</dt>
+ * <dd>Prints a simple usage message listing all available command line
+ * options.</dd>
+ * </dl>
*/
public class Main {
@@ -86,14 +65,22 @@
private static final String[] logLevels = { "FATAL", "ERROR", "WARN",
"INFO", "DEBUG" };
- private static final String PROP_LOG_LEVEL = "org.apache.sling.log.level";
+ /** The Sling configuration property name setting the initial log level */
+ private static final String PROP_LOG_LEVEL = LogbackManager.LOG_LEVEL;
- private static final String PROP_LOG_FILE = "org.apache.sling.log.file";
+ /** The Sling configuration property name setting the initial log file */
+ private static final String PROP_LOG_FILE = LogbackManager.LOG_FILE;
+ /**
+ * The configuration property setting the port on which the HTTP service
+ * listens
+ */
private static final String PROP_PORT = "org.osgi.service.http.port";
+ /** The default port on which the HTTP service listens. */
private static final String DEFAULT_PORT = "8080";
+ /** The parsed command line mapping (Sling) option name to option value */
private static Map<String, String> commandLine;
public static void main(String[] args) throws Exception {
@@ -115,7 +102,10 @@
// properties file, though
try {
- Sling sling = new Sling(null, null, props) {
+ Logger logger = new SimpleLogger();
+ ResourceProvider resProvider = new ClassLoaderResourceProvider(
+ Main.class.getClassLoader());
+ Sling sling = new Sling(logger, resProvider, props) {
protected void loadPropertiesOverride(
Map<String, String> properties) {
if (commandLine != null) {
@@ -126,7 +116,7 @@
Runtime.getRuntime().addShutdownHook(new TerminateSling(sling));
} catch (BundleException be) {
- System.err.println("Failed to Start OSGi framework");
+ log("Failed to Start OSGi framework");
be.printStackTrace(System.err);
System.exit(2);
}
@@ -147,16 +137,24 @@
}
}
+ /**
+ * Parses the command line in <code>args</code> and sets appropriate Sling
+ * configuration options in the <code>props</code> map.
+ */
private static void parseCommandLine(String[] args,
Map<String, String> props) {
- int argc = 0;
- while (argc < args.length) {
- String arg = args[argc++];
+ for (int argc = 0; argc < args.length; argc++) {
+ String arg = args[argc];
if (arg.startsWith("-")) {
+
+ // require at least another character naming the option
if (arg.length() != 2) {
usage("Missing option name", 1);
}
+
+ // option argument is following the current option
String value = argc < args.length ? args[argc++] : null;
+
switch (arg.charAt(1)) {
case 'l':
if (value == null) {
@@ -174,6 +172,7 @@
props.put(PROP_LOG_LEVEL, value);
}
break;
+
case 'f':
if (value == null) {
usage("Missing log file value", 1);
@@ -183,9 +182,7 @@
}
props.put(PROP_LOG_FILE, value);
break;
- case 'd':
- log("The -d command line parameter is deprecated: use -c instead.");
- // fall through
+
case 'c':
if (value == null) {
usage("Missing directory value", 1);
@@ -193,6 +190,7 @@
}
props.put(Sling.SLING_HOME, value);
break;
+
case 'p':
if (value == null) {
usage("Missing port value", 1);
@@ -206,21 +204,18 @@
usage("Bad port: " + value, 1);
}
break;
+
case 'a':
if (value == null) {
usage("Missing address value", 1);
continue;
}
log("Setting the address to bind to is not supported, binding to 0.0.0.0");
- // try {
- // // just to verify it is a number
- // InetAddress.getByName(value);
- // } catch (UnknownHostException e) {
- // log("Bad address: " + value);
- // }
break;
+
case 'h':
usage(null, 0);
+
default:
usage("Unrecognized option " + arg, 1);
break;
@@ -229,31 +224,34 @@
}
}
+ /** prints a simple usage plus optional error message and exists with code */
private static void usage(String message, int code) {
if (message != null) {
log(message);
- System.err.println();
+ log("");
}
- System.err.println("usage: "
+ log("usage: "
+ Main.class.getName()
+ " [ -l loglevel ] [ -f logfile ] [ -c slinghome ] [ -a address ] [ -p port ] [ -h ]");
- System.err.println(" -l loglevel the initial loglevel (0..4, FATAL, ERROR, WARN, INFO, DEBUG)");
- System.err.println(" -f logfile the log file, \"-\" for stdout (default logs/error.log)");
- System.err.println(" -c slinghome the sling context directory (default sling)");
- System.err.println(" -a address the interfact to bind to (use 0.0.0.0 for any) (not supported yet)");
- System.err.println(" -p port the port to listen to (default 8080)");
- System.err.println(" -h prints this usage message");
+ log(" -l loglevel the initial loglevel (0..4, FATAL, ERROR, WARN, INFO, DEBUG)");
+ log(" -f logfile the log file, \"-\" for stdout (default logs/error.log)");
+ log(" -c slinghome the sling context directory (default sling)");
+ log(" -a address the interfact to bind to (use 0.0.0.0 for any) (not supported yet)");
+ log(" -p port the port to listen to (default 8080)");
+ log(" -h prints this usage message");
// exiting now
System.exit(code);
}
+ /** Writes the message to stderr output */
private static void log(String message) {
System.err.println(message);
}
+ /** Converts the loglevel code to a loglevel string name */
private static String toLogLevel(int level) {
if (level >= 0 && level < logLevels.length) {
return logLevels[level];
@@ -263,6 +261,7 @@
return null;
}
+ /** Verifies the log level is one of the known values, returns null otherwise */
private static String checkLogLevel(String level) {
for (int i = 0; i < logLevels.length; i++) {
if (logLevels[i].equalsIgnoreCase(level)) {
Added: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/SimpleLogger.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/SimpleLogger.java?rev=595454&view=auto
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/SimpleLogger.java (added)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/SimpleLogger.java Thu Nov 15 12:56:16 2007
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launcher.app.main;
+
+import org.apache.sling.launcher.app.Logger;
+
+/**
+ * The <code>SimpleLogger</code> TODO
+ */
+class SimpleLogger extends Logger {
+
+ public void log(String message, Throwable t) {
+ if (t != null) {
+ System.err.println(message);
+ t.printStackTrace(System.err);
+ } else {
+ System.out.println(message);
+ }
+ }
+
+}
Modified: incubator/sling/trunk/launcher/app/src/main/resources/sling.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/resources/sling.properties?rev=595454&r1=595453&r2=595454&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/resources/sling.properties (original)
+++ incubator/sling/trunk/launcher/app/src/main/resources/sling.properties Thu Nov 15 12:56:16 2007
@@ -77,11 +77,11 @@
#
-# Default Logging Configuration (see org.apache.sling.sling-log Bundle documentation)
-# org.apache.sling.log.intialize = true
-org.apache.sling.log.level = INFO
-org.apache.sling.log.file = ${sling.home}/logs/error.log
-# org.apache.sling.log.url = URL to logger configuration file
+# Default Logging Configuration (see org.apache.sling.osgi.log Bundle documentation)
+# org.apache.sling.osgi.log.intialize = true
+org.apache.sling.osgi.log.level = INFO
+org.apache.sling.osgi.log.file = ${sling.home}/logs/error.log
+# org.apache.sling.osgi.log.url = URL to logger configuration file
#