You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/07/14 20:37:08 UTC
svn commit: r421980 - in /incubator/tuscany/sandbox/chianti/sca:
commands/launcher/src/main/resources/META-INF/tuscany/
core/src/main/java/org/apache/tuscany/core/launcher/
core/src/main/java/org/apache/tuscany/core/services/extension/
spi/src/main/jav...
Author: jboynes
Date: Fri Jul 14 11:37:07 2006
New Revision: 421980
URL: http://svn.apache.org/viewvc?rev=421980&view=rev
Log:
add a service that will load extensions by scanning a directory
add RuntimeInfo so that the scanner knows where to find the directory
Added:
incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java (with props)
incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/
incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java (with props)
incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java (with props)
incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/
incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java (with props)
Modified:
incubator/tuscany/sandbox/chianti/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java
incubator/tuscany/sandbox/chianti/sca/test/src/main/resources/META-INF/tuscany/system.scdl
Modified: incubator/tuscany/sandbox/chianti/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl?rev=421980&r1=421979&r2=421980&view=diff
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl (original)
+++ incubator/tuscany/sandbox/chianti/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl Fri Jul 14 11:37:07 2006
@@ -85,4 +85,10 @@
<!-- Java implementation type -->
<include name="org.apache.tuscany.launcher.JavaImplementation" scdlLocation="javaImplementation.scdl"/>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender">
+ <system:implementation.system class="org.apache.tuscany.core.services.extension.DirectoryScanExtender"/>
+ <property name="path">extension</property>
+ </component>
</composite>
Modified: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java?rev=421980&r1=421979&r2=421980&view=diff
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java (original)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/Launcher.java Fri Jul 14 11:37:07 2006
@@ -20,6 +20,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.net.URI;
import javax.xml.stream.XMLInputFactory;
@@ -29,10 +30,12 @@
import org.apache.tuscany.spi.model.ComponentDefinition;
import org.apache.tuscany.spi.bootstrap.ComponentNames;
import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
+import org.apache.tuscany.spi.services.info.RuntimeInfo;
import org.apache.tuscany.core.bootstrap.Bootstrapper;
import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
import org.apache.tuscany.core.monitor.NullMonitorFactory;
import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.implementation.system.component.SystemCompositeComponent;
/**
* Support class for launcher implementations.
@@ -146,6 +149,11 @@
runtime = bootstrapper.createRuntime();
runtime.start();
+ // initialize the runtime info
+ SystemCompositeComponent parent = (SystemCompositeComponent) runtime.getSystemComponent();
+ RuntimeInfo runtimeInfo = new LauncherRuntimeInfo(getInstallDirectory());
+ parent.registerJavaObject("RuntimeInfo", RuntimeInfo.class, runtimeInfo);
+
// create a ComponentDefinition to represent the component we are going to deploy
SystemCompositeImplementation moduleImplementation = new SystemCompositeImplementation();
URL scdl = getClass().getResource("/META-INF/tuscany/system.scdl");
@@ -159,7 +167,6 @@
moduleImplementation);
// deploy the component into the runtime under the system parent
- CompositeComponent parent = runtime.getSystemComponent();
CompositeComponent<?> composite = (CompositeComponent<?>) bootDeployer.deploy(parent, moduleDefinition);
// start the system
@@ -186,5 +193,25 @@
// deploy the component into the runtime under the system parent
CompositeComponent parent = runtime.getRootComponent();
return (CompositeComponent<?>) deployer.deploy(parent, moduleDefinition);
+ }
+
+ public File getInstallDirectory() {
+ String property = System.getProperty("tuscany.installDir");
+ if (property != null) {
+ return new File(property);
+ }
+
+ URL url = getClass().getResource("Launcher.class");
+ if (!"jar".equals(url.getProtocol())) {
+ throw new IllegalStateException("Must be run from a jar: " + url);
+ }
+ String jarLocation = url.toString();
+ jarLocation = jarLocation.substring(4, jarLocation.lastIndexOf("!/"));
+ if (!jarLocation.startsWith("file:")) {
+ throw new IllegalStateException("Must be run from a local filesystem: " + jarLocation);
+ }
+
+ File jarFile = new File(URI.create(jarLocation));
+ return jarFile.getParentFile().getParentFile();
}
}
Added: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java?rev=421980&view=auto
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java (added)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java Fri Jul 14 11:37:07 2006
@@ -0,0 +1,36 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ * Licensed 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.tuscany.core.launcher;
+
+import java.io.File;
+
+import org.apache.tuscany.spi.services.info.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LauncherRuntimeInfo implements RuntimeInfo {
+ private final File installDirectory;
+
+ public LauncherRuntimeInfo(File installDirectory) {
+ this.installDirectory = installDirectory;
+ }
+
+ public File getInstallDirectory() {
+ return installDirectory;
+ }
+}
Propchange: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/launcher/LauncherRuntimeInfo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java?rev=421980&view=auto
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java (added)
+++ incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java Fri Jul 14 11:37:07 2006
@@ -0,0 +1,124 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ * Licensed 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.tuscany.core.services.extension;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.core.implementation.system.component.SystemCompositeComponent;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.spi.TuscanyException;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.services.VoidService;
+import org.apache.tuscany.spi.services.info.RuntimeInfo;
+
+/**
+ * Service that extends the runtime by loading composites located in a directory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DirectoryScanExtender implements VoidService {
+ private String path;
+ private RuntimeInfo runtimeInfo;
+ private Deployer deployer;
+ private SystemCompositeComponent parent;
+
+ @Property
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @Autowire
+ public void setRuntimeInfo(RuntimeInfo runtimeInfo) {
+ this.runtimeInfo = runtimeInfo;
+ }
+
+ @Autowire
+ public void setDeployer(Deployer deployer) {
+ this.deployer = deployer;
+ }
+
+ @Autowire
+ public void setParent(SystemCompositeComponent parent) {
+ this.parent = parent;
+ }
+
+ @Init(eager = true)
+ public void init() {
+ assert runtimeInfo != null;
+ File extensionDir = new File(runtimeInfo.getInstallDirectory(), path);
+ if (!extensionDir.isDirectory()) {
+ // we don't have an extension directory, there's nothing to do
+ return;
+ }
+
+ File[] files = extensionDir.listFiles();
+ for (File file : files) {
+ deployExtension(file);
+ }
+ }
+
+ private void deployExtension(File file) {
+ // extension name is file name less any extension
+ String name = file.getName();
+ int dot = name.lastIndexOf('.');
+ if (dot > 0) {
+ name = name.substring(0, dot);
+ }
+
+ // todo do we want to support unpacked directories as extensions?
+ // get the URL of the JAR file and the SCDL inside
+ URL extensionURL;
+ URL scdl;
+ try {
+ extensionURL = new URL("jar:" + file.toURI().toURL() + "!/");
+ scdl = new URL(extensionURL, "META-INF/sca/default.scdl");
+ } catch (MalformedURLException e) {
+ // file may not be a JAR file
+ return;
+ }
+
+ // assume this class's ClassLoader is the Tuscany system classloader
+ // and use it as the extension's parent ClassLoader
+ ClassLoader extensionCL = new URLClassLoader(new URL[]{extensionURL}, getClass().getClassLoader());
+
+ // create a ComponentDefinition to represent the component we are going to deploy
+ SystemCompositeImplementation implementation = new SystemCompositeImplementation();
+ implementation.setScdlLocation(scdl);
+ implementation.setClassLoader(extensionCL);
+ ComponentDefinition<SystemCompositeImplementation> definition =
+ new ComponentDefinition<SystemCompositeImplementation>(name, implementation);
+
+ try {
+ Component<?> component = deployer.deploy(parent, definition);
+ component.start();
+ } catch (LoaderException e) {
+ // FIXME handle the exception
+ } catch (TuscanyException e) {
+ // FIXME handle the exception
+ }
+ }
+}
Propchange: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/chianti/sca/core/src/main/java/org/apache/tuscany/core/services/extension/DirectoryScanExtender.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java?rev=421980&view=auto
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java (added)
+++ incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java Fri Jul 14 11:37:07 2006
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ * Licensed 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.tuscany.spi.services;
+
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Empty interface for a service component that has no operations.
+ * This can be used as a default service interface by components that
+ * do not wish the base class to be used as the interface as specified
+ * by the defaulting rules.
+ *
+ * @version $Rev$ $Date$
+ */
+@Service
+public interface VoidService {
+}
Propchange: incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java?rev=421980&view=auto
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java (added)
+++ incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java Fri Jul 14 11:37:07 2006
@@ -0,0 +1,33 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ * Licensed 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.tuscany.spi.services.info;
+
+import java.io.File;
+
+/**
+ * Interface that provides information on the runtime environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeInfo {
+ /**
+ * Return the directory where the running runtime was installed.
+ *
+ * @return the directory where the runtime was installed
+ */
+ File getInstallDirectory();
+}
Propchange: incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/chianti/sca/spi/src/main/java/org/apache/tuscany/spi/services/info/RuntimeInfo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/sandbox/chianti/sca/test/src/main/resources/META-INF/tuscany/system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/chianti/sca/test/src/main/resources/META-INF/tuscany/system.scdl?rev=421980&r1=421979&r2=421980&view=diff
==============================================================================
--- incubator/tuscany/sandbox/chianti/sca/test/src/main/resources/META-INF/tuscany/system.scdl (original)
+++ incubator/tuscany/sandbox/chianti/sca/test/src/main/resources/META-INF/tuscany/system.scdl Fri Jul 14 11:37:07 2006
@@ -85,4 +85,10 @@
<!-- Java implementation type -->
<include name="org.apache.tuscany.test.JavaImplementation" scdlLocation="javaImplementation.scdl"/>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender">
+ <system:implementation.system class="org.apache.tuscany.core.services.extension.DirectoryScanExtender"/>
+ <property name="path">extension</property>
+ </component>
</composite>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org