diff options
Diffstat (limited to 'sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany')
6 files changed, 746 insertions, 0 deletions
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java new file mode 100644 index 0000000000..8fb945a28a --- /dev/null +++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java @@ -0,0 +1,249 @@ +/* + * 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.tuscany.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import org.osoa.sca.ComponentContext; + +/** + * SCARuntime is used to start a Tuscany SCA runtime. + */ +public abstract class SCARuntime { + + private static SCARuntime instance; + + /** + * Read the service name from a configuration file + * + * @param classLoader + * @param name The name of the service class + * @return A class name which extends/implements the service class + * @throws IOException + */ + private static String getServiceName(ClassLoader classLoader, String name) throws IOException { + InputStream is = classLoader.getResourceAsStream("META-INF/services/" + name); + if (is == null) { + return null; + } + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(is)); + while (true) { + String line = reader.readLine(); + if (line == null) { + break; + } else if (!line.startsWith("#")) { + return line.trim(); + } + } + } finally { + if (reader != null) { + reader.close(); + } + } + return null; + } + + /** + * Returns a SCARuntime instance. If the system property + * "org.apache.tuscany.api.SCARuntime" is set, its value is used as the name + * of the implementation class. Otherwise, if the resource + * "META-INF/services/org.apache.tuscany.api.SCARuntime" can be loaded from + * the supplied classloader. Otherwise, it will use + * "org.apache.tuscany.runtime.embedded.DefaultSCARuntime" as the default. + * The named class is loaded from the supplied classloader and instantiated + * using its default (no-arg) constructor. + * + * @return + */ + private static SCARuntime newInstance(final ClassLoader classLoader) { + + try { + final String name = SCARuntime.class.getName(); + String className = AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(name); + } + }); + + if (className == null) { + className = getServiceName(classLoader, name); + } + if (className == null) { + className = "org.apache.tuscany.runtime.embedded.DefaultSCARuntime"; + } + Class cls = Class.forName(className, true, classLoader); + return (SCARuntime)cls.newInstance(); // NOPMD lresende + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Get an instance of SCA Runtime + * + * @return The instance + */ + public static synchronized SCARuntime getInstance() { // NOPMD + if (instance != null) { + return instance; + } + ClassLoader classLoader = SCARuntime.class.getClassLoader(); + instance = newInstance(classLoader); + return instance; + } + + /** + * Start the Tuscany runtime using default SCDLs + */ + public static void start() { + try { + getInstance().startup(null, null, null, null); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDLs + * + * @param system The URL for the system SCDL + * @param extensions An array of URLs for extensions + * @param application The URL for the application SCDL + */ + public static void start(URL system, URL[] extensions, URL application, String compositePath) { + try { + getInstance().startup(system, extensions, application, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDL + * + * @param application The URL for the application SCDL + */ + public static void start(URL application, String compositePath) { + try { + getInstance().startup(null, null, application, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDL + * + * @param compositePath The path of the application SCDL + */ + public static void start(String compositePath) { + try { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL applicationURL = cl.getResource(compositePath); + getInstance().startup(null, null, applicationURL, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDL + * + * @param compositePath The path of the system SCDL + * @param compositePath The path of the application SCDL + */ + public static void start(String system, String compositePath) { + try { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL systemURL = cl.getResource(system); + URL applicationURL = cl.getResource(compositePath); + getInstance().startup(systemURL, null, applicationURL, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Get the ComponentContext by name + * + * @param componentName + * @return + */ + public static ComponentContext getComponentContext(String componentName) { + return getInstance().getContext(componentName); + } + + /** + * Get access to a system service + * + * @param serviceName + * @return + */ + protected abstract Object getSystemService(String serviceName); + + /** + * Stop the SCA Runtime + */ + public static void stop() { + try { + getInstance().shutdown(); + } catch (Exception e) { + throw new IllegalStateException(e); + } finally { + instance = null; + } + } + + /** + * Look up the ComponentContext by name + * + * @param componentName + * @return + */ + protected abstract ComponentContext getContext(String componentName); + + /** + * Start up the runtime + * + * @param system The URL of the SCDL for tuscany system composite + * @param extensions The URLs of the SCDLs for tuscany extension composites + * @param application The URL of the SCDL for the application composite + * @param compositePath The path of the application composite relative to + * the application URL + * @throws Exception + */ + protected abstract void startup(URL system, URL[] extensions, URL application, String compositePath) + throws Exception; + + /** + * Shutdown the runtime + * + * @throws Exception + */ + protected abstract void shutdown() throws Exception; +} diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java new file mode 100644 index 0000000000..1a6ab28cf4 --- /dev/null +++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java @@ -0,0 +1,75 @@ +/* + * 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.tuscany.runtime.embedded; + +import java.net.URI; +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import org.apache.tuscany.api.SCARuntime; +import org.apache.tuscany.api.TuscanyException; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceUnavailableException; + +/** + * Default implementation of SCARuntime. + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("deprecation") +public class DefaultSCARuntime extends SCARuntime { + + protected SimpleRuntime runtime; + + protected void startup(URL system, URL[] exts, URL applicationSCDL, String compositePath) throws Exception { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + List<URL> extensions = exts == null ? null : Arrays.asList(exts); + URI contributionURI = URI.create("/default"); + SimpleRuntimeInfo runtimeInfo = new SimpleRuntimeInfoImpl(cl, system, extensions, contributionURI, + applicationSCDL, compositePath); + runtime = new SimpleRuntimeImpl(runtimeInfo); + + try { + runtime.start(); + } catch (TuscanyException e) { + throw e; + } + + } + + protected void shutdown() throws Exception { + runtime.destroy(); + } + + @Override + protected ComponentContext getContext(String componentName) { + return runtime.getComponentContext(URI.create(SimpleRuntimeInfo.DEFAULT_COMPOSITE + "/" + componentName)); + } + + @Override + public Object getSystemService(String serviceName) { + try { + return runtime.getSystemService(Object.class, serviceName); + } catch (TargetResolutionException e) { + throw new ServiceUnavailableException(e); + } + } +} diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java new file mode 100644 index 0000000000..676d42a3af --- /dev/null +++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java @@ -0,0 +1,48 @@ +/* + * 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.tuscany.runtime.embedded; + +import org.apache.tuscany.host.runtime.TuscanyRuntime; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.TargetResolutionException; + +/** + * A simple runtime to host both Tuscany and application code on the same classpath + * + * @version $Rev$ $Date$ + */ +public interface SimpleRuntime extends TuscanyRuntime<SimpleRuntimeInfo> { + /** + * Start the embedded Tuscany + * @return + * @throws Exception + */ + Component start() throws Exception; + + /** + * Look up system services by name + * @param <T> + * @param type + * @param name + * @return + * @throws TargetResolutionException + */ + <T> T getSystemService(Class<T> type, String name) throws TargetResolutionException; +} diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java new file mode 100644 index 0000000000..990fa0107f --- /dev/null +++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java @@ -0,0 +1,136 @@ +/* + * 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.tuscany.runtime.embedded; + +import static org.apache.tuscany.runtime.embedded.SimpleRuntimeInfo.DEFAULT_COMPOSITE; + +import java.net.URI; +import java.net.URL; +import java.util.Collection; + +import org.apache.tuscany.api.annotation.LogLevel; +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.apache.tuscany.core.implementation.PojoWorkContextTunnel; +import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation; +import org.apache.tuscany.core.runtime.AbstractRuntime; +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ComponentException; +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.ScopeRegistry; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.CompositeImplementation; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.resolver.ResolutionException; + +/** + * @version $Rev$ $Date$ + */ +public class SimpleRuntimeImpl extends AbstractRuntime<SimpleRuntimeInfo> implements SimpleRuntime { + private ScopeContainer<URI> container; + + public SimpleRuntimeImpl(SimpleRuntimeInfo runtimeInfo) { + super(SimpleRuntimeInfo.class); + ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader(); + setHostClassLoader(hostClassLoader); + setApplicationScdl(runtimeInfo.getApplicationSCDL()); + setSystemScdl(runtimeInfo.getSystemSCDL()); + setRuntimeInfo(runtimeInfo); + } + + public interface SimpleMonitor { + @LogLevel("SEVERE") + void runError(Exception e); + } + + protected Collection<Component> deployExtension(Component parent, + URI name, + URL extensionSCDL, + ClassLoader systemClassLoader) throws LoaderException, + BuilderException, ComponentException, ResolutionException { + + SystemCompositeImplementation impl = new SystemCompositeImplementation(); + impl.setScdlLocation(extensionSCDL); + impl.setClassLoader(systemClassLoader); + ComponentDefinition<SystemCompositeImplementation> definition + = new ComponentDefinition<SystemCompositeImplementation>(name, impl); + + Collection<Component> components = getDeployer().deploy(parent, definition); + for (Component component : components) { + component.start(); + } + return components; + } + + @SuppressWarnings("unchecked") + public Component start() throws Exception { + initialize(); + + ScopeRegistry scopeRegistry = getScopeRegistry(); + container = scopeRegistry.getScopeContainer(Scope.COMPOSITE); + + /* + int i = 0; + for (URL ext : runtimeInfo.getExtensionSCDLs()) { + URI uri = URI.create("/extensions/extension" + (i++)); + deployExtension(null, uri, ext, runtimeInfo.getClassLoader()); + } + */ + + CompositeImplementation impl = new CompositeImplementation(); + impl.setScdlLocation(applicationScdl); + impl.setClassLoader(runtimeInfo.getClassLoader()); + + ComponentDefinition<CompositeImplementation> definition + = new ComponentDefinition<CompositeImplementation>(DEFAULT_COMPOSITE, impl); + Collection<Component> components = getDeployer().deploy(null, definition); + for (Component component : components) { + component.start(); + } + container.startContext(DEFAULT_COMPOSITE, DEFAULT_COMPOSITE); + getWorkContext().setIdentifier(Scope.COMPOSITE, DEFAULT_COMPOSITE); + WorkContext workContext = new SimpleWorkContext(); + workContext.setIdentifier(Scope.COMPOSITE, DEFAULT_COMPOSITE); + PojoWorkContextTunnel.setThreadWorkContext(workContext); + return componentManager.getComponent(definition.getUri()); + } + + @SuppressWarnings("deprecation") + public <T> T getSystemService(Class<T> type, String name) throws TargetResolutionException { + SCAObject child = componentManager.getComponent(URI.create(name)); + if (child == null) { + return null; + } + AtomicComponent service = (AtomicComponent)child; + return type.cast(service.getTargetInstance()); + } + + @Override + public void destroy() { + container.stopContext(DEFAULT_COMPOSITE); + getWorkContext().setIdentifier(Scope.COMPOSITE, null); + super.destroy(); + } + +} diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java new file mode 100644 index 0000000000..740c51a3a3 --- /dev/null +++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.runtime.embedded; + +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.host.RuntimeInfo; +import org.apache.tuscany.spi.bootstrap.ComponentNames; + +/** + * @version $Rev$ $Date$ + */ +public interface SimpleRuntimeInfo extends RuntimeInfo { + URI DEFAULT_COMPOSITE = ComponentNames.TUSCANY_APPLICATION_ROOT.resolve("default"); + + String DEFAULT_SYSTEM_SCDL = "META-INF/tuscany/default-system.composite"; + String SYSTEM_SCDL = "system.composite"; + String EXTENSION_SCDL = "META-INF/sca/extension.composite"; + String SERVICE_SCDL = "META-INF/sca/service.composite"; + String META_APPLICATION_SCDL = "META-INF/sca/application.composite"; + String APPLICATION_SCDL = "application.composite"; + + ClassLoader getClassLoader(); + + String getCompositePath(); + + URL getSystemSCDL(); + + URL getApplicationSCDL(); + + List<URL> getExtensionSCDLs(); + + URL getContributionRoot(); + + URI getContributionURI(); + +} diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java new file mode 100644 index 0000000000..6839eefc93 --- /dev/null +++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java @@ -0,0 +1,182 @@ +/* + * 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.tuscany.runtime.embedded; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +import org.apache.tuscany.core.util.FileHelper; +import org.apache.tuscany.host.AbstractRuntimeInfo; + +/** + * @version $Rev$ $Date$ + */ +public class SimpleRuntimeInfoImpl extends AbstractRuntimeInfo implements SimpleRuntimeInfo { + private ClassLoader classLoader; + private String compositePath; + + private List<URL> extensions; + private URL applicationSCDL; + private URL systemSCDL; + + private URL contributionURL; + private URI contributionURI; + + /** + * @param classLoader + * @param compositePath + * @param extensions + * @param applicationSCDL + * @param systemSCDL + */ + public SimpleRuntimeInfoImpl(ClassLoader classLoader, + URL systemSCDL, + List<URL> extensions, + URI contributionURI, + URL applicationSCDL, + String compositePath) { + this(classLoader, compositePath); + this.extensions = extensions; + this.applicationSCDL = applicationSCDL; + this.systemSCDL = systemSCDL; + this.contributionURI = contributionURI; + } + + public SimpleRuntimeInfoImpl(ClassLoader classLoader, String compositePath) { + // super(domain, applicationRootDirectory, baseUrl, online, runtimeId); + super(URI.create("sca://domain/local"), null, null, false, "simple"); + if (classLoader != null) { + this.classLoader = classLoader; + } else { + classLoader = Thread.currentThread().getContextClassLoader(); + } + this.compositePath = compositePath != null ? compositePath : APPLICATION_SCDL; + getApplicationSCDL(); + this.contributionURI = URI.create("/default"); + } + + public ClassLoader getClassLoader() { + return classLoader; + } + + public String getCompositePath() { + return compositePath; + } + + public final URL getApplicationSCDL() { + if (applicationSCDL == null) { + applicationSCDL = classLoader.getResource(compositePath); + if (applicationSCDL == null) { + applicationSCDL = classLoader.getResource(APPLICATION_SCDL); + if (applicationSCDL == null) { + applicationSCDL = classLoader.getResource(META_APPLICATION_SCDL); + if (applicationSCDL != null) { + compositePath = META_APPLICATION_SCDL; + } + } else { + if (compositePath == null) { + compositePath = APPLICATION_SCDL; + } + } + if (applicationSCDL == null) { + throw new IllegalArgumentException("application SCDL not found: " + APPLICATION_SCDL); + } + } + } + return applicationSCDL; + } + + public URL getContributionRoot() { + if (contributionURL == null) { + contributionURL = getContributionLocation(getApplicationSCDL(), compositePath); + } + return contributionURL; + } + + public List<URL> getExtensionSCDLs() { + if (extensions == null) { + try { + List<URL> extensionURLs = new ArrayList<URL>(); + Enumeration<URL> urls = classLoader.getResources(SERVICE_SCDL); + extensionURLs.addAll(Collections.list(urls)); + urls = classLoader.getResources(EXTENSION_SCDL); + extensionURLs.addAll(Collections.list(urls)); + if (extensions != null) { + for (URL ext : extensions) { + if (!extensionURLs.contains(ext)) { + extensionURLs.add(ext); + } + } + } + extensions = extensionURLs; + } catch (IOException e) { + throw new IllegalArgumentException(e); + } + } + return extensions; + } + + public URL getSystemSCDL() { + if (systemSCDL == null) { + systemSCDL = classLoader.getResource(SYSTEM_SCDL); + if (systemSCDL == null) { + systemSCDL = classLoader.getResource(DEFAULT_SYSTEM_SCDL); + } + } + return systemSCDL; + } + + private static URL getContributionLocation(URL applicationSCDL, String compositePath) { + URL root = null; + // "jar:file://....../something.jar!/a/b/c/app.composite" + try { + String scdlUrl = applicationSCDL.toExternalForm(); + String protocol = applicationSCDL.getProtocol(); + if ("file".equals(protocol)) { + // directory contribution + if (scdlUrl.endsWith(compositePath)) { + String location = scdlUrl.substring(0, scdlUrl.lastIndexOf(compositePath)); + // workaround from evil url/uri form maven + root = FileHelper.toFile(new URL(location)).toURI().toURL(); + } + + } else if ("jar".equals(protocol)) { + // jar contribution + String location = scdlUrl.substring(4, scdlUrl.lastIndexOf("!/")); + // workaround from evil url/uri form maven + root = FileHelper.toFile(new URL(location)).toURI().toURL(); + } + } catch (MalformedURLException mfe) { + throw new IllegalArgumentException(mfe); + } + + return root; + } + + public URI getContributionURI() { + return contributionURI; + } +} |