diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-27 01:21:22 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-27 01:21:22 +0000 |
commit | 3426488b8797730981da3aa0deb6b0b9f02bd9d1 (patch) | |
tree | 75fcd5b3ce847c7ef8879236b769a95a918440a8 /java/sca/modules/contribution | |
parent | 3842c8e1357e155ba9c780ec7a040c49b3e1d7d8 (diff) |
Refactor the contribution scanner to take Contribution as an argument
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@778953 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/contribution')
11 files changed, 138 insertions, 123 deletions
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java index de09725cdb..bdc523c33e 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.contribution; import java.util.List; +import java.util.Set; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Extensible; @@ -88,11 +89,11 @@ public interface Contribution extends Artifact, Extensible { /** * Returns the list of contributions that this contribution depends on. - * + * * @return */ List<Contribution> getDependencies(); - + /** * Returns the ClassLoader used to load classes and resources from * this contribution @@ -115,4 +116,10 @@ public interface Contribution extends Artifact, Extensible { */ void setClassLoader(ClassLoader classLoader); + /** + * Get a list of mime types that apply to this contribution archive + * @return + */ + Set<String> getTypes(); + }
\ No newline at end of file diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java index 26833bb4c0..c6c0aff737 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java @@ -6,49 +6,49 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution; /** * Constants for the main supported contribution package types. - * + * * @version $Rev$ $Date$ */ public interface PackageType { - + /** * Java compressed contribution package */ - String JAR = "application/x-compressed"; + String JAR = "application/java-archive"; /** * Zip archive contribution package */ - String ZIP = "application/x-compressed"; + String ZIP = "application/zip"; /** * Filesystem folder contribution package */ String FOLDER = "application/vnd.tuscany.folder"; - - + + String BUNDLE = "application/osgi.bundle"; - + /** * Java EE Web Application Archive */ String WAR = "application/war"; - + /** * Java EE Enterprise Application Archive */ diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java index 04a39b061d..7be9472fc9 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java @@ -20,7 +20,9 @@ package org.apache.tuscany.sca.contribution.impl; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; @@ -47,6 +49,7 @@ class ContributionImpl extends ExtensibleImpl implements Contribution { private List<Artifact> artifacts = new ArrayList<Artifact>(); private List<Contribution> dependencies = new ArrayList<Contribution>(); private ModelResolver modelResolver; + private Set<String> types = new HashSet<String>(); // FIXME remove this dependency on Java ClassLoaders private ClassLoader classLoader; @@ -157,4 +160,8 @@ class ContributionImpl extends ExtensibleImpl implements Contribution { "from: " + location; } + public Set<String> getTypes() { + return types; + } + } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java index 516b0d6342..d54eac2228 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.java.impl; @@ -46,8 +46,11 @@ import org.apache.tuscany.sca.extensibility.ServiceDiscovery; public class ClassLoaderModelResolver extends URLClassLoader implements ModelResolver { private Contribution contribution; private Map<String, ModelResolver> importResolvers = new HashMap<String, ModelResolver>(); - - private static ClassLoader parentClassLoader() { + + private static ClassLoader parentClassLoader(Contribution contribution) { + if (contribution.getClassLoader() != null) { + return contribution.getClassLoader(); + } ClassLoader parentClassLoader = null; // FIXME: Need a better way to not use the ThreadContextClassLoader when running in Equinox @@ -64,6 +67,10 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes } private static URL[] getContributionURLs(final Contribution contribution) throws IOException { + if (contribution.getClassLoader() != null) { + // Do not include the contribution url + return new URL[0]; + } List<URL> urls = new ArrayList<URL>(); urls.add(new URL(contribution.getLocation())); urls.addAll(ContributionHelper.getNestedJarUrls(contribution)); @@ -71,9 +78,9 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes } public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) throws IOException { - super(getContributionURLs(contribution), parentClassLoader()); + super(getContributionURLs(contribution), parentClassLoader(contribution)); this.contribution = contribution; - + // Index Java import resolvers by package name Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>(); for (Import import_: this.contribution.getImports()) { @@ -87,7 +94,7 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes resolvers.add(javaImport.getModelResolver()); } } - + // Create a delegating model resolver for each imported package for (Map.Entry<String, List<ModelResolver>> entry: resolverMap.entrySet()) { importResolvers.put(entry.getKey(), new DefaultDelegatingModelResolver(entry.getValue())); @@ -106,38 +113,38 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes if (!(unresolved instanceof ClassReference)) { return unresolved; } - + try { - + // Load the class and return a class reference for it String className = ((ClassReference)unresolved).getClassName(); Class<?> clazz = Class.forName(className, true, this); return modelClass.cast(new ClassReference(clazz)); - + } catch (ClassNotFoundException e) { return unresolved; } catch (NoClassDefFoundError e) { return unresolved; } } - + @Override public URL findResource(String name) { - + //TODO delegate to the Java import resolvers - + URL url = super.findResource(name); return url; } @Override public Enumeration<URL> findResources(String name) throws IOException { - + //TODO delegate to the Java import resolvers //Enumeration<URL> importedResources; - + Enumeration<URL> resources = super.findResources(name); - List<URL> allResources = new ArrayList<URL>(); + List<URL> allResources = new ArrayList<URL>(); //for (; importedResources.hasMoreElements(); ) { // allResources.add(importedResources.nextElement()); //} @@ -146,10 +153,10 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes } return Collections.enumeration(allResources); } - + @Override protected Class<?> findClass(String name) throws ClassNotFoundException { - + // Extract the package name int d = name.lastIndexOf('.'); String packageName; @@ -158,7 +165,7 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes } else { packageName = null; } - + // First try to load the class using the Java import resolvers ModelResolver importResolver = importResolvers.get(packageName); if (importResolver != null) { @@ -172,5 +179,5 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes Class<?> clazz = super.findClass(name); return clazz; } - + } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java index cf62a047f4..5d8b950c45 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java @@ -129,9 +129,9 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso // Scan the contribution and list the artifacts contained in it List<Artifact> artifacts = contribution.getArtifacts(); boolean contributionMetadata = false; - List<String> artifactURIs = scanner.getArtifacts(contributionURL); + List<String> artifactURIs = scanner.scan(contribution); for (String artifactURI: artifactURIs) { - URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI); + URL artifactURL = scanner.getArtifactURL(contribution, artifactURI); // Add the deployed artifact model to the contribution Artifact artifact = this.contributionFactory.createArtifact(); @@ -177,7 +177,6 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso DefaultExport defaultExport = contributionFactory.createDefaultExport(); contribution.getExports().add(defaultExport); } - return contribution; } @@ -199,10 +198,10 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso resolveExports(contribution, contributionResolver); // Resolve Imports resolveImports(contribution, contributionResolver); - + preResolved = true; } // end method preResolve - + public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { if( !preResolved ) preResolve( contribution, resolver); @@ -230,7 +229,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso } } // end for } // end method resolve - + /** * Resolves the Exports of the contribution * @param contribution @@ -247,7 +246,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso } // end for } // end method resolveExports - + /** * Resolves the Imports of the contribution * @param contribution @@ -256,7 +255,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso private void resolveImports(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { for (Import import_: contribution.getImports()) { extensionProcessor.resolve(import_, resolver); - } // end for + } // end for } // end method resolveImports } // end class ContributionContentProcessor diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java index 5f50b46022..ef435d6aed 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java @@ -123,7 +123,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut for (String path: new String[]{ Contribution.SCA_CONTRIBUTION_GENERATED_META, Contribution.SCA_CONTRIBUTION_META}) { - URL url = scanner.getArtifactURL(contributionURL, path); + URL url = scanner.getArtifactURL(contribution, path); try { // Check if the file actually exists before trying to read it URLConnection connection = url.openConnection(); @@ -151,7 +151,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut if (!contributionMetadata) { List<String> artifactURIs; try { - artifactURIs = scanner.getArtifacts(contributionURL); + artifactURIs = scanner.scan(contribution); } catch (ContributionReadException e) { artifactURIs = null; } @@ -168,7 +168,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor<Contribut } } if (read) { - URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI); + URL artifactURL = scanner.getArtifactURL(contribution, artifactURI); // Read each artifact Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL); diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java index f84e336e6d..d2f29a001b 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.scanner; @@ -22,46 +22,46 @@ import java.io.IOException; import java.net.URL; import java.util.List; +import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; /** * Interface for contribution package scanners - * + * * Contribution scanners understand the format of the contribution and how to get the * artifacts in the contribution. - * + * * @version $Rev$ $Date$ */ public interface ContributionScanner { - + /** * Returns the type of package supported by this package scanner. - * + * * @return the package type */ String getContributionType(); /** * Returns a list of artifacts in the contribution. - * - * @param contributionURL Contribution URL + * + * @param contribution Contribution URL * @return List of artifact URIs * @throws ContributionReadException * @throws IOException */ - List<String> getArtifacts(URL contributionURL) throws ContributionReadException; + List<String> scan(Contribution contribution) throws ContributionReadException; /** * Return the URL for an artifact in the contribution. - * + * * This is needed for archives such as jar files that have specific URL schemes * for the artifacts they contain. - * - * @param contributionURL Contribution URL + * + * @param contribution Contribution URL * @param artifact The relative URI for the artifact * @throws ContributionReadException * @return The artifact URL */ - URL getArtifactURL(URL contributionURL, String artifact) throws ContributionReadException; - + URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException; } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java index 2a288e1708..a1af72da72 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.scanner; @@ -27,13 +27,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; /** * Default implementation of a contribution scanner extension point. - * + * * @version $Rev$ $Date$ */ public class DefaultContributionScannerExtensionPoint implements ContributionScannerExtensionPoint { @@ -62,24 +63,24 @@ public class DefaultContributionScannerExtensionPoint implements ContributionSca return; // Get the scanner service declarations - Collection<ServiceDeclaration> scannerDeclarations; + Collection<ServiceDeclaration> scannerDeclarations; try { scannerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionScanner.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } - + for (ServiceDeclaration scannerDeclaration: scannerDeclarations) { Map<String, String> attributes = scannerDeclaration.getAttributes(); - + // Load a URL artifact scanner String contributionType = attributes.get("type"); - + // Create a scanner wrapper and register it ContributionScanner scanner = new LazyContributionScanner(contributionType, scannerDeclaration); addContributionScanner(scanner); } - + loaded = true; } @@ -87,28 +88,28 @@ public class DefaultContributionScannerExtensionPoint implements ContributionSca * A facade for contribution scanners. */ private static class LazyContributionScanner implements ContributionScanner { - + private ServiceDeclaration scannerDeclaration; private String contributionType; private ContributionScanner scanner; - + private LazyContributionScanner(String contributionType, ServiceDeclaration scannerDeclaration) { this.scannerDeclaration = scannerDeclaration; this.contributionType = contributionType; } - public URL getArtifactURL(URL contributionSourceURL, String artifact) throws ContributionReadException { + public URL getArtifactURL(Contribution contributionSourceURL, String artifact) throws ContributionReadException { return getScanner().getArtifactURL(contributionSourceURL, artifact); } - public List<String> getArtifacts(URL contributionSourceURL) throws ContributionReadException { - return getScanner().getArtifacts(contributionSourceURL); + public List<String> scan(Contribution contributionSourceURL) throws ContributionReadException { + return getScanner().scan(contributionSourceURL); } public String getContributionType() { return contributionType; } - + private ContributionScanner getScanner() { if (scanner == null) { try { diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java index 16838a95a5..95a4ed69e8 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.scanner.impl; @@ -22,17 +22,20 @@ package org.apache.tuscany.sca.contribution.scanner.impl; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.PackageType; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.scanner.ContributionScanner; /** * Folder contribution processor. - * + * * @version $Rev$ $Date$ */ public class DirectoryContributionScanner implements ContributionScanner { @@ -41,11 +44,11 @@ public class DirectoryContributionScanner implements ContributionScanner { } public String getContributionType() { - return "application/vnd.tuscany.folder"; + return PackageType.FOLDER; } - public URL getArtifactURL(URL contributionURL, String artifact) throws ContributionReadException { - File directory = directory(contributionURL); + public URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException { + File directory = directory(contribution); File file = new File(directory, artifact); try { return file.toURI().toURL(); @@ -54,20 +57,21 @@ public class DirectoryContributionScanner implements ContributionScanner { } } - public List<String> getArtifacts(URL contributionURL) throws ContributionReadException { - File directory = directory(contributionURL); + public List<String> scan(Contribution contribution) throws ContributionReadException { + File directory = directory(contribution); List<String> artifacts = new ArrayList<String>(); try { traverse(artifacts, directory, directory); } catch (IOException e) { throw new ContributionReadException(e); } + contribution.getTypes().add(getContributionType()); return artifacts; } /** * Recursively traverse a root directory - * + * * @param fileList * @param file * @param root @@ -82,7 +86,7 @@ public class DirectoryContributionScanner implements ContributionScanner { uri = uri.substring(0, uri.length() - 1); } fileList.add(uri); - + File[] files = file.listFiles(); for (File f: files) { if (!f.getName().startsWith(".")) { @@ -92,16 +96,17 @@ public class DirectoryContributionScanner implements ContributionScanner { } } - private static File directory(URL url) throws ContributionReadException { + private static File directory(Contribution contribution) throws ContributionReadException { File file; try { - file = new File(url.toURI()); + file = new File(new URI(contribution.getLocation())); } catch (URISyntaxException e) { throw new ContributionReadException(e); } if (!file.exists() || !file.isDirectory()) { - throw new ContributionReadException(url.toString()); + throw new ContributionReadException(contribution.getLocation()); } return file; } + } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java index efb3e02b5a..f1fb6f2a70 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.scanner.impl; @@ -30,12 +30,14 @@ import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.PackageType; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.scanner.ContributionScanner; /** * JAR Contribution processor. - * + * * @version $Rev$ $Date$ */ public class JarContributionScanner implements ContributionScanner { @@ -44,16 +46,16 @@ public class JarContributionScanner implements ContributionScanner { } public String getContributionType() { - return "application/x-compressed"; + return PackageType.JAR; } - public URL getArtifactURL(URL contributionURL, String artifact) throws ContributionReadException { + public URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException { try { URL url; - if (contributionURL.toString().startsWith("jar:")) { - url = new URL(contributionURL, artifact.toString()); + if (contribution.toString().startsWith("jar:")) { + url = new URL(new URL(contribution.getLocation()), artifact.toString()); } else { - url = new URL("jar:" + contributionURL.toExternalForm() + "!/" + artifact); + url = new URL("jar:" + contribution.getLocation() + "!/" + artifact); } return url; } catch (MalformedURLException e) { @@ -61,11 +63,12 @@ public class JarContributionScanner implements ContributionScanner { } } - public List<String> getArtifacts(URL contributionURL) throws ContributionReadException { + public List<String> scan(Contribution contribution) throws ContributionReadException { // Assume the URL references a JAR file try { - URLConnection connection = contributionURL.openConnection(); + URL url = new URL(contribution.getLocation()); + URLConnection connection = url.openConnection(); connection.setUseCaches(false); JarInputStream jar = new JarInputStream(connection.getInputStream()); try { @@ -77,9 +80,9 @@ public class JarContributionScanner implements ContributionScanner { break; } - String name = entry.getName(); + String name = entry.getName(); if (name.length() != 0 && !name.startsWith(".")) { - + // Trim trailing / if (name.endsWith("/")) { name = name.substring(0, name.length() - 1); @@ -88,7 +91,7 @@ public class JarContributionScanner implements ContributionScanner { // Add the entry name if (!names.contains(name)) { names.add(name); - + // Add parent folder names to the list too for (;;) { int s = name.lastIndexOf('/'); @@ -106,11 +109,12 @@ public class JarContributionScanner implements ContributionScanner { } } } - + // Return list of URIs List<String> artifacts = new ArrayList<String>(names); + contribution.getTypes().add(getContributionType()); return artifacts; - + } finally { jar.close(); } @@ -118,4 +122,7 @@ public class JarContributionScanner implements ContributionScanner { throw new ContributionReadException(e); } } + + public void postProcess(Contribution contribution) { + } } diff --git a/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint b/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint deleted file mode 100644 index 9e6433ba6c..0000000000 --- a/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint +++ /dev/null @@ -1,18 +0,0 @@ -# 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.
-
-org.apache.tuscany.sca.contribution.processor.DefaultContributionPostProcessorExtensionPoint
|