summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-12-17 23:28:45 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-12-17 23:28:45 +0000
commitab2dab63f7c14481bc8014daaf5451e2efc5cc8f (patch)
tree4783b0af597e505e989d87b2c2fe0042b7ae3e06 /sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache
parent0326969fc32e2c5424ae30552cc6438ed67d916c (diff)
TUSCANY-3395 - Tyding up the ContributionScanner API to scan the contribution and produce a list of Artifacts with proper URI and Location URL instead of doing this in two steps
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@891986 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache')
-rw-r--r--sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java30
-rw-r--r--sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java19
-rw-r--r--sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java25
-rw-r--r--sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java59
-rw-r--r--sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java57
5 files changed, 116 insertions, 74 deletions
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
index 2331edf3f8..232bf9c72f 100644
--- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
+++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.contribution.processor.impl;
import java.io.File;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -123,32 +124,32 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
if (scanner == null) {
File file = toFile(contributionURL);
if (file != null && file.isDirectory()) {
- scanner = new DirectoryContributionScanner();
+ scanner = new DirectoryContributionScanner(contributionFactory);
} else {
- scanner = new JarContributionScanner();
+ scanner = new JarContributionScanner(contributionFactory);
}
}
// Scan the contribution and list the artifacts contained in it
- List<Artifact> artifacts = contribution.getArtifacts();
boolean contributionMetadata = false;
- List<String> artifactURIs = scanner.scan(contribution);
- for (String artifactURI: artifactURIs) {
- URL artifactURL = scanner.getArtifactURL(contribution, artifactURI);
-
+ List<Artifact> artifacts = scanner.scan(contribution);
+ for (Artifact artifact : artifacts) {
// Add the deployed artifact model to the contribution
- Artifact artifact = this.contributionFactory.createArtifact();
- artifact.setURI(artifactURI);
- artifact.setLocation(artifactURL.toString());
- artifacts.add(artifact);
modelResolver.addModel(artifact, context);
- monitor.pushContext("Artifact: " + artifactURI);
+ monitor.pushContext("Artifact: " + artifact.getURI());
old = context.setContribution(contribution);
try {
// Read each artifact
- Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL, context);
+ URL artifactLocationURL = null;
+ try {
+ artifactLocationURL = new URL(artifact.getLocation());
+ } catch(MalformedURLException e) {
+ //ignore
+ }
+
+ Object model = artifactProcessor.read(contributionURL, URI.create(artifact.getURI()), artifactLocationURL, context);
if (model != null) {
artifact.setModel(model);
@@ -171,6 +172,9 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
context.setContribution(old);
}
}
+
+ List<Artifact> contributionArtifacts = contribution.getArtifacts();
+ contributionArtifacts.addAll(artifacts);
// If no sca-contribution.xml file was provided then just consider
// all composites in the contribution as deployables
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java
index d2f29a001b..bba42a6b09 100644
--- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java
+++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java
@@ -19,9 +19,9 @@
package org.apache.tuscany.sca.contribution.scanner;
import java.io.IOException;
-import java.net.URL;
import java.util.List;
+import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
@@ -46,22 +46,9 @@ public interface ContributionScanner {
* Returns a list of artifacts in the contribution.
*
* @param contribution Contribution URL
- * @return List of artifact URIs
+ * @return List of artifact populated with URIs and location URL
* @throws ContributionReadException
* @throws IOException
*/
- 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 contribution Contribution URL
- * @param artifact The relative URI for the artifact
- * @throws ContributionReadException
- * @return The artifact URL
- */
- URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException;
+ List<Artifact> scan(Contribution contribution) throws ContributionReadException;
}
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java
index 610a1eb7ba..c5aed5ccd3 100644
--- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java
+++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java
@@ -21,15 +21,17 @@ package org.apache.tuscany.sca.contribution.scanner;
import java.io.IOException;
import java.lang.reflect.Constructor;
-import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
/**
@@ -79,7 +81,7 @@ public class DefaultContributionScannerExtensionPoint implements ContributionSca
String contributionType = attributes.get("type");
// Create a scanner wrapper and register it
- ContributionScanner scanner = new LazyContributionScanner(contributionType, scannerDeclaration);
+ ContributionScanner scanner = new LazyContributionScanner(registry, contributionType, scannerDeclaration);
addContributionScanner(scanner);
}
@@ -90,21 +92,22 @@ public class DefaultContributionScannerExtensionPoint implements ContributionSca
* A facade for contribution scanners.
*/
private static class LazyContributionScanner implements ContributionScanner {
-
+ private ExtensionPointRegistry registry;
private ServiceDeclaration scannerDeclaration;
private String contributionType;
private ContributionScanner scanner;
+ private ContributionFactory contributionFactory;
- private LazyContributionScanner(String contributionType, ServiceDeclaration scannerDeclaration) {
+ private LazyContributionScanner(ExtensionPointRegistry registry, String contributionType, ServiceDeclaration scannerDeclaration) {
+ this.registry = registry;
this.scannerDeclaration = scannerDeclaration;
this.contributionType = contributionType;
+
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.contributionFactory = factories.getFactory(ContributionFactory.class);
}
- public URL getArtifactURL(Contribution contributionSourceURL, String artifact) throws ContributionReadException {
- return getScanner().getArtifactURL(contributionSourceURL, artifact);
- }
-
- public List<String> scan(Contribution contributionSourceURL) throws ContributionReadException {
+ public List<Artifact> scan(Contribution contributionSourceURL) throws ContributionReadException {
return getScanner().scan(contributionSourceURL);
}
@@ -116,8 +119,8 @@ public class DefaultContributionScannerExtensionPoint implements ContributionSca
if (scanner == null) {
try {
Class<ContributionScanner> scannerClass = (Class<ContributionScanner>)scannerDeclaration.loadClass();
- Constructor<ContributionScanner> constructor = scannerClass.getConstructor();
- scanner = constructor.newInstance();
+ Constructor<ContributionScanner> constructor = scannerClass.getConstructor(ContributionFactory.class);
+ scanner = constructor.newInstance(contributionFactory);
} catch (Exception e) {
throw new IllegalStateException(e);
}
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
index 144302c3e4..4a1a222da8 100644
--- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
+++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
@@ -24,11 +24,12 @@ 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.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.PackageType;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.scanner.ContributionScanner;
@@ -39,25 +40,47 @@ import org.apache.tuscany.sca.contribution.scanner.ContributionScanner;
* @version $Rev$ $Date$
*/
public class DirectoryContributionScanner implements ContributionScanner {
-
- public DirectoryContributionScanner() {
+ private ContributionFactory contributionFactory;
+
+ public DirectoryContributionScanner(ContributionFactory contributionFactory) {
+ this.contributionFactory = contributionFactory;
}
public String getContributionType() {
return PackageType.FOLDER;
}
- public URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException {
+ public List<Artifact> scan(Contribution contribution) throws ContributionReadException {
File directory = directory(contribution);
- File file = new File(directory, artifact);
- try {
- return file.toURI().toURL();
- } catch (MalformedURLException e) {
- throw new ContributionReadException(e);
+ List<Artifact> artifacts = new ArrayList<Artifact>();
+ List<String> artifactURIs = scanContributionArtifacts(contribution);
+ for(String uri : artifactURIs) {
+ try {
+ File file = new File(directory, uri);
+
+ Artifact artifact = contributionFactory.createArtifact();
+ artifact.setURI(uri);
+ artifact.setLocation(file.toURI().toURL().toString());
+
+ artifacts.add(artifact);
+ } catch (MalformedURLException e) {
+ throw new ContributionReadException(e);
+ }
}
+
+ contribution.getTypes().add(getContributionType());
+ return artifacts;
}
- public List<String> scan(Contribution contribution) throws ContributionReadException {
+
+ /**
+ * Scan the contribution to retrieve all artifact uris
+ *
+ * @param contribution
+ * @return
+ * @throws ContributionReadException
+ */
+ private List<String> scanContributionArtifacts(Contribution contribution) throws ContributionReadException {
File directory = directory(contribution);
List<String> artifacts = new ArrayList<String>();
try {
@@ -65,10 +88,10 @@ public class DirectoryContributionScanner implements ContributionScanner {
} catch (IOException e) {
throw new ContributionReadException(e);
}
- contribution.getTypes().add(getContributionType());
+
return artifacts;
}
-
+
/**
* Recursively traverse a root directory
*
@@ -95,8 +118,15 @@ public class DirectoryContributionScanner implements ContributionScanner {
}
}
}
-
- private static File directory(Contribution contribution) throws ContributionReadException {
+
+ /**
+ * Get the contribution location as a file
+ *
+ * @param contribution
+ * @return
+ * @throws ContributionReadException
+ */
+ private File directory(Contribution contribution) throws ContributionReadException {
File file;
URI uri = null;
try {
@@ -113,5 +143,6 @@ public class DirectoryContributionScanner implements ContributionScanner {
}
return file;
}
+
}
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java
index 2c5b849a20..25be92c310 100644
--- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java
+++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/JarContributionScanner.java
@@ -30,7 +30,9 @@ import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import org.apache.tuscany.sca.common.java.io.IOHelper;
+import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.PackageType;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.scanner.ContributionScanner;
@@ -41,29 +43,17 @@ import org.apache.tuscany.sca.contribution.scanner.ContributionScanner;
* @version $Rev$ $Date$
*/
public class JarContributionScanner implements ContributionScanner {
+ private ContributionFactory contributionFactory;
- public JarContributionScanner() {
+ public JarContributionScanner(ContributionFactory contributionFactory) {
+ this.contributionFactory = contributionFactory;
}
public String getContributionType() {
return PackageType.JAR;
}
- public URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException {
- try {
- URL url;
- if (contribution.toString().startsWith("jar:")) {
- url = new URL(new URL(contribution.getLocation()), artifact.toString());
- } else {
- url = new URL("jar:" + contribution.getLocation() + "!/" + artifact);
- }
- return url;
- } catch (MalformedURLException e) {
- throw new ContributionReadException(e);
- }
- }
-
- public List<String> scan(Contribution contribution) throws ContributionReadException {
+ public List<Artifact> scan(Contribution contribution) throws ContributionReadException {
// Assume the URL references a JAR file
try {
@@ -108,8 +98,16 @@ public class JarContributionScanner implements ContributionScanner {
}
}
- // Return list of URIs
- List<String> artifacts = new ArrayList<String>(names);
+ // Return list of artifacts
+ List<Artifact> artifacts = new ArrayList<Artifact>();
+ for(String uri : names) {
+ Artifact artifact = contributionFactory.createArtifact();
+ artifact.setURI(uri);
+ artifact.setLocation(getArtifactURL(contribution, uri).toString());
+
+ artifacts.add(artifact);
+ }
+
contribution.getTypes().add(getContributionType());
return artifacts;
@@ -120,7 +118,26 @@ public class JarContributionScanner implements ContributionScanner {
throw new ContributionReadException(e);
}
}
-
- public void postProcess(Contribution contribution) {
+
+ /**
+ * Produces a location URL for a given artifact in the contribution
+ *
+ * @param contribution
+ * @param artifact
+ * @return
+ * @throws ContributionReadException
+ */
+ private static URL getArtifactURL(Contribution contribution, String artifact) throws ContributionReadException {
+ try {
+ URL url;
+ if (contribution.toString().startsWith("jar:")) {
+ url = new URL(new URL(contribution.getLocation()), artifact.toString());
+ } else {
+ url = new URL("jar:" + contribution.getLocation() + "!/" + artifact);
+ }
+ return url;
+ } catch (MalformedURLException e) {
+ throw new ContributionReadException(e);
+ }
}
}