You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2007/03/16 20:57:14 UTC
svn commit: r519116 [1/2] - in /incubator/tuscany/java/sca/kernel:
core/src/main/java/org/apache/tuscany/core/services/deployment/
core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/
core/src/main/java/org/apache/tuscany/core/u...
Author: lresende
Date: Fri Mar 16 12:57:12 2007
New Revision: 519116
URL: http://svn.apache.org/viewvc?view=rev&rev=519116
Log:
Merging contribution services
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java
- copied, changed from r518700, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/ScdlContributionProcessor.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java
Removed:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/ScdlContributionProcessor.java
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java
Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java?view=auto&rev=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java Fri Mar 16 12:57:12 2007
@@ -0,0 +1,124 @@
+/*
+ * 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.core.services.deployment;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.osoa.sca.Constants.SCA_NS;
+
+import java.net.URI;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.ContributionImport;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Loader that handles <include> elements.
+ *
+ * @version $Rev: 515261 $ $Date: 2007-03-06 11:22:46 -0800 (Tue, 06 Mar 2007) $
+ */
+public class ContributionLoader extends LoaderExtension<Contribution> {
+ private static final QName CONTRIBUTION = new QName(SCA_NS, "contribution");
+ private static final QName DEPLOYABLE = new QName(SCA_NS, "deployable");
+ private static final QName IMPORT = new QName(SCA_NS, "import");
+ private static final QName EXPORT = new QName(SCA_NS, "export");
+
+ @Constructor({"registry"})
+ public ContributionLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return CONTRIBUTION;
+ }
+
+ public Contribution load(ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+
+ Contribution contribution = new Contribution();
+ while (true) {
+ int event = reader.next();
+ switch (event) {
+ case START_ELEMENT:
+ QName element = reader.getName();
+ if (DEPLOYABLE.equals(element)) {
+ String name = reader.getAttributeValue(null, "composite");
+ if (name == null) {
+ throw new InvalidValueException("Attribute 'composite' is missing");
+ }
+ QName compositeName = null;
+ int index = name.indexOf(':');
+ if (index != -1) {
+ String prefix = name.substring(0, index);
+ String localPart = name.substring(index);
+ String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
+ if (ns == null) {
+ throw new InvalidValueException("Invalid prefix: " + prefix);
+ }
+ compositeName = new QName(ns, localPart, prefix);
+ } else {
+ String prefix = "";
+ String ns = reader.getNamespaceURI();
+ String localPart = name;
+ compositeName = new QName(ns, localPart, prefix);
+ }
+ contribution.getDeployables().add(compositeName);
+ } else if (IMPORT.equals(element)) {
+ String ns = reader.getAttributeValue(null, "namespace");
+ if (ns == null) {
+ throw new InvalidValueException("Attribute 'namespace' is missing");
+ }
+ String location = reader.getAttributeValue(null, "location");
+ ContributionImport contributionImport = new ContributionImport();
+ if (location != null) {
+ contributionImport.setLocation(URI.create(location));
+ }
+ contributionImport.setNamespace(ns);
+ contribution.getImports().add(contributionImport);
+ } else if (EXPORT.equals(element)) {
+ String ns = reader.getAttributeValue(null, "namespace");
+ if (ns == null) {
+ throw new InvalidValueException("Attribute 'namespace' is missing");
+ }
+ contribution.getExports().add(ns);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (CONTRIBUTION.equals(reader.getName())) {
+ return contribution;
+ }
+ break;
+
+ }
+ }
+ }
+
+}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java Fri Mar 16 12:57:12 2007
@@ -22,19 +22,32 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
import org.apache.tuscany.core.util.FileHelper;
import org.apache.tuscany.core.util.IOHelper;
import org.apache.tuscany.spi.deployer.ContributionRepository;
+import org.osoa.sca.annotations.Constructor;
import org.osoa.sca.annotations.Destroy;
import org.osoa.sca.annotations.EagerInit;
import org.osoa.sca.annotations.Init;
@@ -47,20 +60,43 @@
*/
@EagerInit
public class ContributionRepositoryImpl implements ContributionRepository {
- protected final File rootFile;
- protected final Map<URI, URL> reposirotyContent = new HashMap<URI, URL>();
+ private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT";
+ private final File rootFile;
+ private Map<URI, String> contributionMap = new HashMap<URI, String>();
+
+ private URI domain;
+ private XMLInputFactory factory;
/**
* Constructor with repository root
*
* @param repository
*/
- public ContributionRepositoryImpl(@Property(name = "repository") String repository) throws IOException {
- this.rootFile = new File(repository);
+ @Constructor
+ public ContributionRepositoryImpl(@Property(name = "repository")
+ final String repository) throws IOException {
+ String root = repository;
+ if (repository == null) {
+ root = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ // Default to <user.home>/.tuscany/domains/local/
+ String userHome = System.getProperty("user.home");
+ String slash = File.separator;
+ return userHome + slash + ".tuscany" + slash + "domains" + slash + "local" + slash;
+ }
+ });
+ }
+ this.rootFile = new File(root);
+ this.domain = rootFile.toURI();
FileHelper.forceMkdir(rootFile);
if (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead()) {
throw new IOException("The root is not a directory: " + repository);
}
+ factory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ }
+
+ public URI getDomain() {
+ return domain;
}
/**
@@ -72,7 +108,7 @@
*/
private File mapToFile(URI contribution) {
// FIXME: Map the contribution URI to a file?
- return new File(rootFile, FileHelper.getName(contribution.toString()));
+ return new File(rootFile, "contributions" + File.separator + contribution.getPath());
}
/**
@@ -99,21 +135,57 @@
public URL store(URI contribution, InputStream contributionStream) throws IOException {
// where the file should be stored in the repository
File location = mapToFile(contribution);
+ FileHelper.forceMkdir(location.getParentFile());
copy(contributionStream, location);
// add contribution to repositoryContent
URL contributionURL = location.toURL();
- reposirotyContent.put(contribution, contributionURL);
+ URI relative = rootFile.toURI().relativize(location.toURI());
+ contributionMap.put(contribution, relative.toString());
+ saveMap();
return contributionURL;
}
+ public URL store(URI contribution, URL sourceURL) throws IOException {
+ // where the file should be stored in the repository
+ File location = mapToFile(contribution);
+ File source = FileHelper.toFile(sourceURL);
+ if (source == null || source.isFile()) {
+ InputStream is = sourceURL.openStream();
+ try {
+ return store(contribution, is);
+ } finally {
+ IOHelper.closeQuietly(is);
+ }
+ }
+
+ FileHelper.forceMkdir(location);
+ FileHelper.copyDirectory(source, location);
+
+ // add contribution to repositoryContent
+ URI relative = rootFile.toURI().relativize(location.toURI());
+ contributionMap.put(contribution, relative.toString());
+ saveMap();
+
+ return location.toURL();
+ }
+
public URL find(URI contribution) {
if (contribution == null) {
return null;
}
- return this.reposirotyContent.get(contribution);
+ String location = contributionMap.get(contribution);
+ if (location == null) {
+ return null;
+ }
+ try {
+ return new File(rootFile, location).toURL();
+ } catch (MalformedURLException e) {
+ // Should not happen
+ throw new AssertionError(e);
+ }
}
public void remove(URI contribution) {
@@ -122,7 +194,8 @@
// remove
try {
FileHelper.forceDelete(FileHelper.toFile(contributionURL));
- this.reposirotyContent.remove(contribution);
+ this.contributionMap.remove(contribution);
+ saveMap();
} catch (IOException ioe) {
// handle file could not be removed
}
@@ -130,13 +203,71 @@
}
public List<URI> list() {
- return new ArrayList<URI>(reposirotyContent.keySet());
+ return new ArrayList<URI>(contributionMap.keySet());
}
-
+
@Init
public void init() {
+ File domainFile = new File(rootFile, "sca-domain.xml");
+ if (!domainFile.isFile()) {
+ return;
+ }
+ FileInputStream is;
+ try {
+ is = new FileInputStream(domainFile);
+ } catch (FileNotFoundException e) {
+ return;
+ }
+ try {
+ XMLStreamReader reader = factory.createXMLStreamReader(new InputStreamReader(is, "UTF-8"));
+ while (reader.hasNext()) {
+ switch (reader.getEventType()) {
+ case XMLStreamConstants.START_ELEMENT:
+ String name = reader.getName().getLocalPart();
+ if ("domain".equals(name)) {
+ String uri = reader.getAttributeValue(null, "uri");
+ if (uri != null) {
+ domain = URI.create(uri);
+ }
+ }
+ if ("contribution".equals(name)) {
+ String uri = reader.getAttributeValue(null, "uri");
+ String location = reader.getAttributeValue(null, "location");
+ contributionMap.put(URI.create(uri), location);
+ }
+ break;
+ default:
+ break;
+ }
+ reader.next();
+ }
+ } catch (Exception e) {
+ // Ignore
+ } finally {
+ IOHelper.closeQuietly(is);
+ }
+ }
+
+ private void saveMap() {
+ File domainFile = new File(rootFile, "sca-domain.xml");
+ FileOutputStream os = null;
+ try {
+ os = new FileOutputStream(domainFile);
+ PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
+ writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ writer.println("<domain uri=\"" + getDomain() + "\" xmlns=\"" + NS + "\">");
+ for (Map.Entry<URI, String> e : contributionMap.entrySet()) {
+ writer.println(" <contribution uri=\"" + e.getKey() + "\" location=\"" + e.getValue() + "\"/>");
+ }
+ writer.println("</domain>");
+ writer.flush();
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ } finally {
+ IOHelper.closeQuietly(os);
+ }
}
-
+
@Destroy
public void destroy() {
}
Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java?view=auto&rev=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java Fri Mar 16 12:57:12 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.core.services.deployment;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Exception that indicates that the supplied XML Document invalid.
+ *
+ * @version $Rev: 511466 $ $Date: 2007-02-25 00:45:22 -0800 (Sun, 25 Feb 2007) $
+ */
+public class InvalidContributionMetadataException extends DeploymentException {
+
+ protected InvalidContributionMetadataException() {
+ }
+
+ protected InvalidContributionMetadataException(String message) {
+ super(message);
+ }
+
+ protected InvalidContributionMetadataException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ protected InvalidContributionMetadataException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected InvalidContributionMetadataException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ protected InvalidContributionMetadataException(Throwable cause) {
+ super(cause);
+ }
+}
Copied: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java (from r518700, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/ScdlContributionProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java?view=diff&rev=519116&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/ScdlContributionProcessor.java&r1=518700&p2=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/ScdlContributionProcessor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java Fri Mar 16 12:57:12 2007
@@ -23,11 +23,13 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
-import javax.xml.stream.XMLInputFactory;
-import org.osoa.sca.annotations.Reference;
+import javax.xml.stream.XMLInputFactory;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.host.deployment.DeploymentException;
import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.ContentType;
import org.apache.tuscany.spi.deployer.ContributionProcessor;
import org.apache.tuscany.spi.deployer.DeploymentContext;
import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
@@ -37,18 +39,19 @@
import org.apache.tuscany.spi.model.CompositeComponentType;
import org.apache.tuscany.spi.model.CompositeImplementation;
import org.apache.tuscany.spi.model.Contribution;
+import org.osoa.sca.annotations.Reference;
-import org.apache.tuscany.core.deployer.RootDeploymentContext;
-import org.apache.tuscany.host.deployment.DeploymentException;
-
-public class ScdlContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
- public static final String CONTENT_TYPE = "application/v.tuscany.scdl";
+public class CompositeContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.COMPOSITE;
+ protected XMLInputFactory xmlFactory;
private final LoaderRegistry registry;
- private final XMLInputFactory xmlFactory;
- public ScdlContributionProcessor(@Reference LoaderRegistry registry) {
+ public CompositeContributionProcessor(@Reference LoaderRegistry registry) {
super();
this.registry = registry;
this.xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
@@ -60,9 +63,9 @@
}
- public void processContent(Contribution contribution, URI source, InputStream inputStream)
+ public void processContent(Contribution contribution, URI artifactURI, InputStream inputStream)
throws DeploymentException, IOException {
- if (source == null) {
+ if (artifactURI == null) {
throw new IllegalArgumentException("Invalid null source uri.");
}
@@ -72,7 +75,7 @@
try {
URI contributionId = contribution.getUri();
- URL scdlLocation = contribution.getArtifact(source).getLocation();
+ URL scdlLocation = contribution.getArtifact(artifactURI).getLocation();
CompositeClassLoader cl = new CompositeClassLoader(null, getClass().getClassLoader());
cl.addURL(contribution.getLocation());
@@ -87,11 +90,14 @@
implementation.setComponentType(componentType);
ComponentDefinition<CompositeImplementation> componentDefinition =
new ComponentDefinition<CompositeImplementation>(implementation);
+
+ //FIXME this changed in trunk....
+ //componentDefinition.setName(componentType.getName());
- contribution.getArtifact(source).addModelObject(null, null, componentDefinition);
+ contribution.getArtifact(artifactURI).addModelObject(CompositeComponentType.class, null, componentDefinition);
} catch (LoaderException le) {
- throw new InvalidComponentDefinitionlException(contribution.getArtifact(source).getLocation()
+ throw new InvalidComponentDefinitionlException(contribution.getArtifact(artifactURI).getLocation()
.toExternalForm(), le);
}
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java Fri Mar 16 12:57:12 2007
@@ -29,46 +29,60 @@
import java.util.List;
import org.apache.tuscany.core.services.deployment.ContentTypeDescriberImpl;
+import org.apache.tuscany.core.util.FileHelper;
+import org.apache.tuscany.core.util.IOHelper;
import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.deployer.ContentType;
import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
import org.apache.tuscany.spi.deployer.ContributionProcessor;
import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
public class FolderContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
- public static final String CONTENT_TYPE = "application/v.tuscany.folder";
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.FOLDER;
@Override
public String getContentType() {
return CONTENT_TYPE;
}
-
+ /**
+ * Recursively traverse a root directory
+ *
+ * @param fileList
+ * @param root
+ * @throws IOException
+ */
private void traverse(List<URL> fileList, File root) throws IOException {
if (root.isFile()) {
fileList.add(root.toURL());
- } else if (root.isDirectory() && !root.getName().equals(".svn")) {
- File[] files = root.listFiles();
+ } else if (root.isDirectory()) {
+ // FIXME: Maybe we should externalize it as a property
+ // Regular expression to exclude .xxx files
+ File[] files = root.listFiles(FileHelper.getFileFilter("[^\u002e].*", true));
for (int i = 0; i < files.length; i++) {
traverse(fileList, files[i]);
}
}
}
-
/**
* Get a list of files from the directory
*
* @return
* @throws IOException
*/
- protected List<URL> getArtifacts(URL rootURL, InputStream sourceInputStream)
- throws DeploymentException, IOException {
+ protected List<URL> getArtifacts(URL rootURL) throws DeploymentException,
+ IOException {
List<URL> artifacts = new ArrayList<URL>();
// Assume the root is a jar file
File rootFolder;
-
+
try {
rootFolder = new File(rootURL.toURI());
if (rootFolder.isDirectory()) {
@@ -80,10 +94,9 @@
}
return artifacts;
- }
-
-
- public void processContent(Contribution contribution, URI source, InputStream inputStream)
+ }
+
+ public void processContent(Contribution contribution, URI source, InputStream inputStream)
throws DeploymentException, IOException {
if (contribution == null) {
throw new IllegalArgumentException("Invalid null contribution.");
@@ -93,33 +106,34 @@
throw new IllegalArgumentException("Invalid null source uri.");
}
- URL sourceURL = contribution.getArtifact(source).getLocation();
+ URL contributionURL = contribution.getArtifact(source).getLocation();
+
+ for (URL artifactURL : getArtifacts(contributionURL)) {
+ String artifactPath = artifactURL.toExternalForm().substring(contributionURL.toExternalForm().length());
+ URI artifactURI = contribution.getUri().resolve(artifactPath);
+ DeployedArtifact artifact = new DeployedArtifact(artifactURI);
+ artifact.setLocation(artifactURL);
+ contribution.addArtifact(artifact);
- for (URL artifactURL : getArtifacts(sourceURL, inputStream)) {
- // FIXME
- // contribution.addArtifact(artifact)
-
ContentTypeDescriber contentTypeDescriber = new ContentTypeDescriberImpl();
String contentType = contentTypeDescriber.getContentType(artifactURL, null);
- System.out.println("File : " + artifactURL);
- System.out.println("Type : " + contentType);
-
-
- //just process scdl for now
- if ("application/v.tuscany.scdl".equals(contentType) || "application/java-vm".equals(contentType)) {
- this.registry.processContent(contribution, source, inputStream);
- }
- // process each artifact
- //this.registry.processContent(contribution, artifactURL, inputStream);
+ // just process scdl and contribution metadata for now
+ if (ContentType.COMPOSITE.equals(contentType)) {
+ InputStream is = artifactURL.openStream();
+ try {
+ this.registry.processContent(contribution, artifactURI, is);
+ } finally {
+ IOHelper.closeQuietly(is);
+ is = null;
+ }
+ }
}
-
}
- public void processModel(Contribution contribution, URI source, Object modelObject)
- throws DeploymentException, IOException {
- // TODO Auto-generated method stub
-
+ public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+ IOException {
+ // NOOP
}
-}
+}
\ No newline at end of file
Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java?view=auto&rev=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java Fri Mar 16 12:57:12 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.core.services.deployment.contribution;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Exception that indicates that the supplied XML Document invalid.
+ *
+ */
+public class InvalidPojoComponentDefinitionlException extends DeploymentException {
+
+ protected InvalidPojoComponentDefinitionlException(String componentDefinitionLocatoin) {
+ super(componentDefinitionLocatoin);
+ }
+
+ protected InvalidPojoComponentDefinitionlException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java Fri Mar 16 12:57:12 2007
@@ -23,7 +23,6 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -31,8 +30,9 @@
import java.util.jar.JarInputStream;
import org.apache.tuscany.core.services.deployment.ContentTypeDescriberImpl;
-import org.apache.tuscany.core.util.FileHelper;
+import org.apache.tuscany.core.util.IOHelper;
import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.deployer.ContentType;
import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
import org.apache.tuscany.spi.deployer.ContributionProcessor;
import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
@@ -40,7 +40,10 @@
import org.apache.tuscany.spi.model.DeployedArtifact;
public class JarContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
- public static final String CONTENT_TYPE = "application/x-compressed";
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.JAR;
@Override
public String getContentType() {
@@ -69,7 +72,10 @@
continue;
}
- artifacts.add(new URL(rootURL, entry.getName()));
+ // FIXME: Maybe we should externalize the filter as a property
+ if (!entry.getName().startsWith(".")) {
+ artifacts.add(new URL(rootURL, entry.getName()));
+ }
}
} finally {
jar.close();
@@ -106,31 +112,27 @@
for (URL artifactURL : getArtifacts(sourceURL, inputStream)) {
URI artifactURI;
-
- try {
- artifactURI = new URI(source.toASCIIString() + "/" + FileHelper.getName(artifactURL.getPath()));
- DeployedArtifact artifact = new DeployedArtifact(artifactURI);
- artifact.setLocation(artifactURL);
- contribution.addArtifact(artifact);
-
-
- ContentTypeDescriber contentTypeDescriber = new ContentTypeDescriberImpl();
- String contentType = contentTypeDescriber.getContentType(artifactURL, null);
- System.out.println("Type : " + contentType);
-
-
- //just process scdl for now
- if ("application/v.tuscany.scdl".equals(contentType)
- /* || "application/java-vm".equals(contentType) */) {
- this.registry.processContent(contribution, artifactURI, artifactURL.openStream());
+
+ String artifactPath = artifactURL.toExternalForm().substring(sourceURL.toExternalForm().length());
+ artifactURI = contribution.getUri().resolve(artifactPath);
+ DeployedArtifact artifact = new DeployedArtifact(artifactURI);
+ artifact.setLocation(artifactURL);
+ contribution.addArtifact(artifact);
+
+
+ ContentTypeDescriber contentTypeDescriber = new ContentTypeDescriberImpl();
+ String contentType = contentTypeDescriber.getContentType(artifactURL, null);
+
+ // just process scdl for now
+ if (ContentType.COMPOSITE.equals(contentType)) {
+ InputStream is = IOHelper.getInputStream(artifactURL);
+ try {
+ this.registry.processContent(contribution, artifactURI, is);
+ } finally {
+ IOHelper.closeQuietly(is);
+ is = null;
}
- } catch (URISyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
-
-
-
}
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java Fri Mar 16 12:57:12 2007
@@ -24,20 +24,28 @@
import java.net.URI;
import java.net.URL;
-import org.osoa.sca.annotations.Constructor;
-import org.osoa.sca.annotations.Reference;
-
+import org.apache.tuscany.host.deployment.DeploymentException;
import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.ContentType;
import org.apache.tuscany.spi.deployer.ContributionProcessor;
import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
import org.apache.tuscany.spi.model.Contribution;
-
-import org.apache.tuscany.host.deployment.DeploymentException;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
public class JavaContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
- public static final String CONTENT_TYPE = "application/java-vm";
- //private Introspector introspector;
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.JAVA;
+ /**
+ * Pojo introspector
+ */
+ private Introspector introspector;
@Constructor
public JavaContributionProcessor(@Reference IntrospectionRegistry introspector) {
@@ -60,10 +68,10 @@
}
- public void processContent(Contribution contribution, URI source, InputStream inputStream)
+ public void processContent(Contribution contribution, URI artifactURI, InputStream inputStream)
throws DeploymentException, IOException {
- if (source == null) {
- throw new IllegalArgumentException("Invalid null source uri.");
+ if (artifactURI == null) {
+ throw new IllegalArgumentException("Invalid null artifact uri.");
}
if (inputStream == null) {
@@ -72,24 +80,24 @@
// TODO Auto-generated method stub
- //try {
- CompositeClassLoader cl = new CompositeClassLoader(null, getClass().getClassLoader());
- cl.addURL(contribution.getLocation());
-
- String clazzName = getClazzName(contribution.getArtifact(source).getLocation());
- System.out.println(clazzName);
-
- //Class clazz = cl.loadClass(clazzName);
-
-// PojoComponentType javaInfo = introspector.introspect(null, clazz, null, null);
-// } catch (ClassNotFoundException cnfe) {
-// String msg = cnfe.getMessage();
-//
-// }
-// catch(ProcessingException pe){
-// String msg = pe.getMessage();
+ try {
+ CompositeClassLoader cl = new CompositeClassLoader(null, getClass().getClassLoader());
+ cl.addURL(contribution.getLocation());
+
+ String clazzName = getClazzName(contribution.getArtifact(artifactURI).getLocation());
+ System.out.println(clazzName);
+ Class clazz = cl.loadClass(clazzName);
+ //PojoComponentType javaInfo = introspector.introspect(null, clazz, null, null);
+
+ //contribution.getArtifact(artifactURI).addModelObject(PojoComponentType.class, null, javaInfo);
+
+ } catch (ClassNotFoundException cnfe) {
+ throw new InvalidPojoComponentDefinitionlException(contribution.getArtifact(artifactURI).getLocation().toExternalForm(), cnfe);
+ //} catch (ProcessingException pe) {
+ // throw new InvalidPojoComponentDefinitionlException(contribution.getArtifact(artifactURI).getLocation().toExternalForm(), pe);
+ }
}
public void processModel(Contribution contribution, URI source, Object modelObject)
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java Fri Mar 16 12:57:12 2007
@@ -20,9 +20,13 @@
package org.apache.tuscany.core.util;
import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
+import java.util.regex.Pattern;
public class FileHelper {
/**
@@ -39,21 +43,23 @@
* The Windows separator character.
*/
private static final char WINDOWS_SEPARATOR = '\\';
-
+
protected FileHelper() {
-
}
+
/**
* Returns the index of the last directory separator character.
* <p>
- * This method will handle a file in either Unix or Windows format.
- * The position of the last forward or backslash is returned.
+ * This method will handle a file in either Unix or Windows format. The
+ * position of the last forward or backslash is returned.
* <p>
- * The output will be the same irrespective of the machine that the code is running on.
- *
- * @param filename the filename to find the last path separator in, null returns -1
- * @return the index of the last separator character, or -1 if there
- * is no such character
+ * The output will be the same irrespective of the machine that the code is
+ * running on.
+ *
+ * @param filename the filename to find the last path separator in, null
+ * returns -1
+ * @return the index of the last separator character, or -1 if there is no
+ * such character
*/
public static int indexOfLastSeparator(String filename) {
if (filename == null) {
@@ -63,19 +69,22 @@
int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
return Math.max(lastUnixPos, lastWindowsPos);
}
-
+
/**
- * Returns the index of the last extension separator character, which is a dot.
+ * Returns the index of the last extension separator character, which is a
+ * dot.
* <p>
- * This method also checks that there is no directory separator after the last dot.
- * To do this it uses {@link #indexOfLastSeparator(String)} which will
- * handle a file in either Unix or Windows format.
- * <p>
- * The output will be the same irrespective of the machine that the code is running on.
- *
- * @param filename the filename to find the last path separator in, null returns -1
- * @return the index of the last separator character, or -1 if there
- * is no such character
+ * This method also checks that there is no directory separator after the
+ * last dot. To do this it uses {@link #indexOfLastSeparator(String)} which
+ * will handle a file in either Unix or Windows format.
+ * <p>
+ * The output will be the same irrespective of the machine that the code is
+ * running on.
+ *
+ * @param filename the filename to find the last path separator in, null
+ * returns -1
+ * @return the index of the last separator character, or -1 if there is no
+ * such character
*/
public static int indexOfExtension(String filename) {
if (filename == null) {
@@ -85,23 +94,27 @@
int lastSeparator = indexOfLastSeparator(filename);
return lastSeparator > extensionPos ? -1 : extensionPos;
}
-
+
/**
* Gets the name minus the path from a full filename.
* <p>
- * This method will handle a file in either Unix or Windows format.
- * The text after the last forward or backslash is returned.
+ * This method will handle a file in either Unix or Windows format. The text
+ * after the last forward or backslash is returned.
+ *
* <pre>
- * a/b/c.txt --> c.txt
- * a.txt --> a.txt
- * a/b/c --> c
- * a/b/c/ --> ""
+ * a/b/c.txt --> c.txt
+ * a.txt --> a.txt
+ * a/b/c --> c
+ * a/b/c/ --> ""
* </pre>
+ *
* <p>
- * The output will be the same irrespective of the machine that the code is running on.
- *
- * @param fileName the filename to query, null returns null
- * @return the name of the file without the path, or an empty string if none exists
+ * The output will be the same irrespective of the machine that the code is
+ * running on.
+ *
+ * @param fileName the filename to query, null returns null
+ * @return the name of the file without the path, or an empty string if none
+ * exists
*/
public static String getName(String fileName) {
if (fileName == null) {
@@ -110,21 +123,24 @@
int index = indexOfLastSeparator(fileName);
return fileName.substring(index + 1);
}
-
+
/**
* Gets the extension of a filename.
* <p>
* This method returns the textual part of the filename after the last dot.
* There must be no directory separator after the dot.
+ *
* <pre>
- * foo.txt --> "txt"
- * a/b/c.jpg --> "jpg"
- * a/b.txt/c --> ""
- * a/b/c --> ""
+ * foo.txt --> "txt"
+ * a/b/c.jpg --> "jpg"
+ * a/b.txt/c --> ""
+ * a/b/c --> ""
* </pre>
+ *
* <p>
- * The output will be the same irrespective of the machine that the code is running on.
- *
+ * The output will be the same irrespective of the machine that the code is
+ * running on.
+ *
* @param filename the filename to retrieve the extension of.
* @return the extension of the file or an empty string if none exists.
*/
@@ -139,13 +155,13 @@
return filename.substring(index + 1);
}
}
-
+
/**
* Make a directory, including any necessary but nonexistent parent
- * directories. If there already exists a file with specified name or
- * the directory cannot be created then an exception is thrown.
- *
- * @param directory directory to create, not null
+ * directories. If there already exists a file with specified name or the
+ * directory cannot be created then an exception is thrown.
+ *
+ * @param directory directory to create, not null
* @throws NullPointerException if the directory is null
* @throws IOException if the directory cannot be created
*/
@@ -153,21 +169,17 @@
if (directory.exists()) {
if (directory.isFile()) {
String message =
- "File "
- + directory
- + " exists and is "
- + "not a directory. Unable to create directory.";
+ "File " + directory + " exists and is " + "not a directory. Unable to create directory.";
throw new IOException(message);
}
} else {
if (!directory.mkdirs()) {
- String message =
- "Unable to create directory " + directory;
+ String message = "Unable to create directory " + directory;
throw new IOException(message);
}
}
}
-
+
/**
* Delete a file. If file is a directory, delete it and all sub-directories.
* <p>
@@ -175,10 +187,10 @@
* <ul>
* <li>A directory to be deleted does not have to be empty.</li>
* <li>You get exceptions when a file or directory cannot be deleted.
- * (java.io.File methods returns a boolean)</li>
+ * (java.io.File methods returns a boolean)</li>
* </ul>
- *
- * @param file file or directory to delete, not null
+ *
+ * @param file file or directory to delete, not null
* @throws NullPointerException if the directory is null
* @throws IOException in case deletion is unsuccessful
*/
@@ -190,36 +202,89 @@
throw new FileNotFoundException("File does not exist: " + file);
}
if (!file.delete()) {
- String message =
- "Unable to delete file: " + file;
+ String message = "Unable to delete file: " + file;
throw new IOException(message);
}
}
}
-
+
/**
- * Recursively delete a directory.
- *
- * @param directory directory to delete
- * @throws IOException in case deletion is unsuccessful
+ * Convert from a <code>URL</code> to a <code>File</code>.
+ * <p>
+ * From version 1.1 this method will decode the URL. Syntax such as
+ * <code>file:///my%20docs/file.txt</code> will be correctly decoded to
+ * <code>/my docs/file.txt</code>.
+ *
+ * @param url the file URL to convert, null returns null
+ * @return the equivalent <code>File</code> object, or <code>null</code>
+ * if the URL's protocol is not <code>file</code>
+ * @throws IllegalArgumentException if the file is incorrectly encoded
*/
- public static void deleteDirectory(File directory)
- throws IOException {
- if (!directory.exists()) {
- return;
+ public static File toFile(URL url) {
+ if (url == null || !url.getProtocol().equals("file")) {
+ return null;
+ } else {
+ String filename = url.getFile().replace('/', File.separatorChar);
+ int pos = 0;
+ while ((pos = filename.indexOf('%', pos)) >= 0) { // NOPMD
+ if (pos + 2 < filename.length()) {
+ String hexStr = filename.substring(pos + 1, pos + 3);
+ char ch = (char)Integer.parseInt(hexStr, 16);
+ filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
+ }
+ }
+ return new File(filename);
}
+ }
- cleanDirectory(directory);
- if (!directory.delete()) {
- String message =
- "Unable to delete directory " + directory + ".";
- throw new IOException(message);
+ public static FileFilter getFileFilter(String regExp, boolean ignoreCase) {
+ return new RegExpFilter(regExp, ignoreCase);
+ }
+
+ /**
+ * A regular-expression based resource filter
+ */
+ public static class RegExpFilter implements FileFilter {
+ private Pattern pattern;
+
+ public RegExpFilter(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ public RegExpFilter(String patternStr, boolean ignoreCase) {
+ this.pattern = Pattern.compile(patternStr, ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
+ }
+
+ public boolean accept(File file) {
+ return pattern.matcher(file.getName()).matches();
+ }
+
+ /**
+ * Convert wildcard into a regex pattern
+ *
+ * @param str
+ * @return
+ */
+ public static RegExpFilter getWildcardFilter(String str, boolean ignoreCase) {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < str.length(); i++) {
+ char ch = str.charAt(i);
+ if (ch == '?') {
+ buffer.append('.');
+ } else if (ch == '*') {
+ buffer.append(".*");
+ } else {
+ buffer.append(ch);
+ }
+ }
+ return new RegExpFilter(buffer.toString(), ignoreCase);
}
+
}
/**
* Clean a directory without deleting it.
- *
+ *
* @param directory directory to clean
* @throws IOException in case cleaning is unsuccessful
*/
@@ -235,7 +300,7 @@
}
File[] files = directory.listFiles();
- if (files == null) { // null if security restricted
+ if (files == null) { // null if security restricted
throw new IOException("Failed to list contents of " + directory);
}
@@ -253,33 +318,387 @@
throw exception;
}
}
-
+
/**
- * Convert from a <code>URL</code> to a <code>File</code>.
+ * Clean a directory without deleting it.
+ *
+ * @param directory directory to clean, must not be <code>null</code>
+ * @throws NullPointerException if the directory is <code>null</code>
+ * @throws IOException in case cleaning is unsuccessful
+ */
+ private static void cleanDirectoryOnExit(File directory) throws IOException {
+ if (!directory.exists()) {
+ String message = directory + " does not exist";
+ throw new IllegalArgumentException(message);
+ }
+
+ if (!directory.isDirectory()) {
+ String message = directory + " is not a directory";
+ throw new IllegalArgumentException(message);
+ }
+
+ File[] files = directory.listFiles();
+ if (files == null) { // null if security restricted
+ throw new IOException("Failed to list contents of " + directory);
+ }
+
+ IOException exception = null;
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ try {
+ forceDeleteOnExit(file);
+ } catch (IOException ioe) {
+ exception = ioe;
+ }
+ }
+
+ if (null != exception) {
+ throw exception;
+ }
+ }
+
+ /**
+ * Copies a whole directory to a new location preserving the file dates.
* <p>
- * From version 1.1 this method will decode the URL.
- * Syntax such as <code>file:///my%20docs/file.txt</code> will be
- * correctly decoded to <code>/my docs/file.txt</code>.
- *
- * @param url the file URL to convert, null returns null
- * @return the equivalent <code>File</code> object, or <code>null</code>
- * if the URL's protocol is not <code>file</code>
- * @throws IllegalArgumentException if the file is incorrectly encoded
+ * This method copies the specified directory and all its child directories
+ * and files to the specified destination. The destination is the new
+ * location and name of the directory.
+ * <p>
+ * The destination directory is created if it does not exist. If the
+ * destination directory did exist, then this method merges the source with
+ * the destination, with the source taking precedence.
+ *
+ * @param srcDir an existing directory to copy, must not be
+ * <code>null</code>
+ * @param destDir the new directory, must not be <code>null</code>
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @since Commons IO 1.1
*/
- public static File toFile(URL url) {
- if (url == null || !url.getProtocol().equals("file")) {
- return null;
+ public static void copyDirectory(File srcDir, File destDir) throws IOException {
+ copyDirectory(srcDir, destDir, true);
+ }
+
+ /**
+ * Copies a whole directory to a new location.
+ * <p>
+ * This method copies the contents of the specified source directory to
+ * within the specified destination directory.
+ * <p>
+ * The destination directory is created if it does not exist. If the
+ * destination directory did exist, then this method merges the source with
+ * the destination, with the source taking precedence.
+ *
+ * @param srcDir an existing directory to copy, must not be
+ * <code>null</code>
+ * @param destDir the new directory, must not be <code>null</code>
+ * @param preserveFileDate true if the file date of the copy should be the
+ * same as the original
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @since Commons IO 1.1
+ */
+ public static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate) throws IOException {
+ if (srcDir == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!srcDir.exists()) {
+ throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
+ }
+ if (!srcDir.isDirectory()) {
+ throw new IOException("Source '" + srcDir + "' exists but is not a directory");
+ }
+ if (srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) {
+ throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same");
+ }
+ doCopyDirectory(srcDir, destDir, preserveFileDate);
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Copies a directory to within another directory preserving the file dates.
+ * <p>
+ * This method copies the source directory and all its contents to a
+ * directory of the same name in the specified destination directory.
+ * <p>
+ * The destination directory is created if it does not exist. If the
+ * destination directory did exist, then this method merges the source with
+ * the destination, with the source taking precedence.
+ *
+ * @param srcDir an existing directory to copy, must not be
+ * <code>null</code>
+ * @param destDir the directory to place the copy in, must not be
+ * <code>null</code>
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @since Commons IO 1.2
+ */
+ public static void copyDirectoryToDirectory(File srcDir, File destDir) throws IOException {
+ if (srcDir == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (!(srcDir.exists() && srcDir.isDirectory())) {
+ throw new IllegalArgumentException("Source '" + destDir + "' is not a directory");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!(destDir.exists() && destDir.isDirectory())) {
+ throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
+ }
+ copyDirectory(srcDir, new File(destDir, srcDir.getName()), true);
+ }
+
+ /**
+ * Copies a file to a new location preserving the file date.
+ * <p>
+ * This method copies the contents of the specified source file to the
+ * specified destination file. The directory holding the destination file is
+ * created if it does not exist. If the destination file exists, then this
+ * method will overwrite it.
+ *
+ * @param srcFile an existing file to copy, must not be <code>null</code>
+ * @param destFile the new file, must not be <code>null</code>
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @see #copyFileToDirectory(File, File)
+ */
+ public static void copyFile(File srcFile, File destFile) throws IOException {
+ copyFile(srcFile, destFile, true);
+ }
+
+ /**
+ * Copies a file to a new location.
+ * <p>
+ * This method copies the contents of the specified source file to the
+ * specified destination file. The directory holding the destination file is
+ * created if it does not exist. If the destination file exists, then this
+ * method will overwrite it.
+ *
+ * @param srcFile an existing file to copy, must not be <code>null</code>
+ * @param destFile the new file, must not be <code>null</code>
+ * @param preserveFileDate true if the file date of the copy should be the
+ * same as the original
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @see #copyFileToDirectory(File, File, boolean)
+ */
+ public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
+ if (srcFile == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destFile == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!srcFile.exists()) {
+ throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
+ }
+ if (srcFile.isDirectory()) {
+ throw new IOException("Source '" + srcFile + "' exists but is a directory");
+ }
+ if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
+ throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same");
+ }
+ if (!(destFile.getParentFile() != null && destFile.getParentFile().exists())) {
+ if (!destFile.getParentFile().mkdirs()) {
+ throw new IOException("Destination '" + destFile + "' directory cannot be created");
+ }
+ }
+ if (!(destFile.exists() && destFile.canWrite())) {
+ throw new IOException("Destination '" + destFile + "' exists but is read-only");
+ }
+ doCopyFile(srcFile, destFile, preserveFileDate);
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Copies a file to a directory preserving the file date.
+ * <p>
+ * This method copies the contents of the specified source file to a file of
+ * the same name in the specified destination directory. The destination
+ * directory is created if it does not exist. If the destination file
+ * exists, then this method will overwrite it.
+ *
+ * @param srcFile an existing file to copy, must not be <code>null</code>
+ * @param destDir the directory to place the copy in, must not be
+ * <code>null</code>
+ * @throws NullPointerException if source or destination is null
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @see #copyFile(File, File, boolean)
+ */
+ public static void copyFileToDirectory(File srcFile, File destDir) throws IOException {
+ copyFileToDirectory(srcFile, destDir, true);
+ }
+
+ /**
+ * Copies a file to a directory optionally preserving the file date.
+ * <p>
+ * This method copies the contents of the specified source file to a file of
+ * the same name in the specified destination directory. The destination
+ * directory is created if it does not exist. If the destination file
+ * exists, then this method will overwrite it.
+ *
+ * @param srcFile an existing file to copy, must not be <code>null</code>
+ * @param destDir the directory to place the copy in, must not be
+ * <code>null</code>
+ * @param preserveFileDate true if the file date of the copy should be the
+ * same as the original
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs during copying
+ * @see #copyFile(File, File, boolean)
+ * @since Commons IO 1.3
+ */
+ public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate) throws IOException {
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!(destDir.exists() && destDir.isDirectory())) {
+ throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
+ }
+ copyFile(srcFile, new File(destDir, srcFile.getName()), preserveFileDate);
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Recursively delete a directory.
+ *
+ * @param directory directory to delete
+ * @throws IOException in case deletion is unsuccessful
+ */
+ public static void deleteDirectory(File directory) throws IOException {
+ if (!directory.exists()) {
+ return;
+ }
+
+ cleanDirectory(directory);
+ if (!directory.delete()) {
+ String message = "Unable to delete directory " + directory + ".";
+ throw new IOException(message);
+ }
+ }
+
+ /**
+ * Recursively schedule directory for deletion on JVM exit.
+ *
+ * @param directory directory to delete, must not be <code>null</code>
+ * @throws NullPointerException if the directory is <code>null</code>
+ * @throws IOException in case deletion is unsuccessful
+ */
+ private static void deleteDirectoryOnExit(File directory) throws IOException {
+ if (!directory.exists()) {
+ return;
+ }
+
+ cleanDirectoryOnExit(directory);
+ directory.deleteOnExit();
+ }
+
+ /**
+ * Internal copy directory method.
+ *
+ * @param srcDir the validated source directory, must not be
+ * <code>null</code>
+ * @param destDir the validated destination directory, must not be
+ * <code>null</code>
+ * @param preserveFileDate whether to preserve the file date
+ * @throws IOException if an error occurs
+ * @since Commons IO 1.1
+ */
+ private static void doCopyDirectory(File srcDir, File destDir, boolean preserveFileDate) throws IOException {
+ if (destDir.exists()) {
+ if (!destDir.isDirectory()) {
+ throw new IOException("Destination '" + destDir + "' exists but is not a directory");
+ }
} else {
- String filename = url.getFile().replace('/', File.separatorChar);
- int pos = 0;
- while ((pos = filename.indexOf('%', pos)) >= 0) { // NOPMD
- if (pos + 2 < filename.length()) {
- String hexStr = filename.substring(pos + 1, pos + 3);
- char ch = (char) Integer.parseInt(hexStr, 16);
- filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
- }
+ if (!destDir.mkdirs()) {
+ throw new IOException("Destination '" + destDir + "' directory cannot be created");
+ }
+ if (preserveFileDate) {
+ destDir.setLastModified(srcDir.lastModified());
+ }
+ }
+ if (!destDir.canWrite()) {
+ throw new IOException("Destination '" + destDir + "' cannot be written to");
+ }
+ // recurse
+ File[] files = srcDir.listFiles();
+ if (files == null) { // null if security restricted
+ throw new IOException("Failed to list contents of " + srcDir);
+ }
+ for (int i = 0; i < files.length; i++) {
+ File copiedFile = new File(destDir, files[i].getName());
+ if (files[i].isDirectory()) {
+ doCopyDirectory(files[i], copiedFile, preserveFileDate);
+ } else {
+ doCopyFile(files[i], copiedFile, preserveFileDate);
}
- return new File(filename);
}
}
+
+ /**
+ * Internal copy file method.
+ *
+ * @param srcFile the validated source file, must not be <code>null</code>
+ * @param destFile the validated destination file, must not be
+ * <code>null</code>
+ * @param preserveFileDate whether to preserve the file date
+ * @throws IOException if an error occurs
+ */
+ private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
+ if (destFile.exists() && destFile.isDirectory()) {
+ throw new IOException("Destination '" + destFile + "' exists but is a directory");
+ }
+
+ FileInputStream input = new FileInputStream(srcFile);
+ try {
+ FileOutputStream output = new FileOutputStream(destFile);
+ try {
+ IOHelper.copy(input, output);
+ } finally {
+ IOHelper.closeQuietly(output);
+ }
+ } finally {
+ IOHelper.closeQuietly(input);
+ }
+
+ if (srcFile.length() != destFile.length()) {
+ throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
+ }
+ if (preserveFileDate) {
+ destFile.setLastModified(srcFile.lastModified());
+ }
+ }
+
+ /**
+ * Schedule a file to be deleted when JVM exits. If file is directory delete
+ * it and all sub-directories.
+ *
+ * @param file file or directory to delete, must not be <code>null</code>
+ * @throws NullPointerException if the file is <code>null</code>
+ * @throws IOException in case deletion is unsuccessful
+ */
+ public static void forceDeleteOnExit(File file) throws IOException {
+ if (file.isDirectory()) {
+ deleteDirectoryOnExit(file);
+ } else {
+ file.deleteOnExit();
+ }
+ }
+
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java Fri Mar 16 12:57:12 2007
@@ -22,24 +22,27 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.util.jar.JarFile;
public class IOHelper {
/**
* The default buffer size to use.
*/
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
+
protected IOHelper() {
-
+
}
/**
* Unconditionally close an <code>InputStream</code>.
- * <p/>
- * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored. This is typically used in
- * finally blocks.
+ * <p>
+ * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
*
- * @param input the InputStream to close, may be null or already closed
+ * @param input the InputStream to close, may be null or already closed
*/
public static void closeQuietly(InputStream input) {
try {
@@ -50,14 +53,14 @@
// ignore
}
}
-
+
/**
* Unconditionally close an <code>OutputStream</code>.
- * <p/>
- * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored. This is typically used in
- * finally blocks.
+ * <p>
+ * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
*
- * @param output the OutputStream to close, may be null or already closed
+ * @param output the OutputStream to close, may be null or already closed
*/
public static void closeQuietly(OutputStream output) {
try {
@@ -68,27 +71,112 @@
// ignore
}
}
-
+
/**
- * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
- * <p/>
- * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>.
+ * Copy bytes from an <code>InputStream</code> to an
+ * <code>OutputStream</code>.
+ * <p>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
- * @param output the <code>OutputStream</code> to write to
+ * @param output the <code>OutputStream</code> to write to
* @return the number of bytes copied
* @throws NullPointerException if the input or output is null
- * @throws IOException if an I/O error occurs
+ * @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static int copy(InputStream input, OutputStream output) throws IOException {
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int count = 0;
int n = 0;
- while (-1 != (n = input.read(buffer))) { //NOPMD
+ while (-1 != (n = input.read(buffer))) { // NOPMD
output.write(buffer, 0, n);
count += n;
}
return count;
}
-}
+
+ public static InputStream getInputStream(URL url) throws IOException {
+ return new SafeURLInputStream(url);
+ }
+
+ /**
+ * This class is a workaround for URL stream issue as illustrated below.
+ * InputStream is=url.getInputStream(); is.close(); // This line doesn't close
+ * the JAR file if the URL is a jar entry like "jar:file:/a.jar!/my.composite" We
+ * also need to turn off the JarFile cache.
+ *
+ * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4950148
+ *
+ * @version $Rev$ $Date$
+ */
+ public static class SafeURLInputStream extends InputStream {
+ private JarFile jarFile;
+ private InputStream is;
+
+ public SafeURLInputStream(URL url) throws IOException {
+ String protocol = url.getProtocol();
+ if (protocol != null && (protocol.equals("jar"))) {
+ JarURLConnection connection = (JarURLConnection)url.openConnection();
+ // We cannot use cache
+ connection.setUseCaches(false);
+ try {
+ is = connection.getInputStream();
+ } catch (IOException e) {
+ throw e;
+ }
+ jarFile = connection.getJarFile();
+ } else {
+ is = url.openStream();
+ }
+ }
+
+ public SafeURLInputStream(JarURLConnection connection) throws IOException {
+ // We cannot use cache
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ jarFile = connection.getJarFile();
+ }
+
+ public int available() throws IOException {
+ return is.available();
+ }
+
+ public void close() throws IOException {
+ is.close();
+ // We need to close the JAR file
+ if (jarFile != null) {
+ jarFile.close();
+ }
+ }
+
+ public synchronized void mark(int readlimit) {
+ is.mark(readlimit);
+ }
+
+ public boolean markSupported() {
+ return is.markSupported();
+ }
+
+ public int read() throws IOException {
+ return is.read();
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ return is.read(b, off, len);
+ }
+
+ public int read(byte[] b) throws IOException {
+ return is.read(b);
+ }
+
+ public synchronized void reset() throws IOException {
+ is.reset();
+ }
+
+ public long skip(long n) throws IOException {
+ return is.skip(n);
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java Fri Mar 16 12:57:12 2007
@@ -19,25 +19,28 @@
package org.apache.tuscany.core.services.deployment;
+import java.io.File;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
+import org.apache.tuscany.core.util.FileHelper;
+
import junit.framework.TestCase;
public class ContributionRepositoryTestCase extends TestCase {
- protected ContributionRepositoryImpl repository;
+ private ContributionRepositoryImpl repository;
protected void setUp() throws Exception {
super.setUp();
// create repository (this should re-create the root directory)
- this.repository = new ContributionRepositoryImpl("target/repository");
-
+ this.repository = new ContributionRepositoryImpl("target/repository/");
+ repository.init();
}
public void testStore() throws Exception {
String resourceLocation = "/repository/sample-calculator.jar";
- URI contribution = getClass().getResource(resourceLocation).toURI();
+ URI contribution = URI.create("sample-calculator.jar");
InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
repository.store(contribution, contributionStream);
@@ -47,7 +50,7 @@
public void testRemove() throws Exception {
String resourceLocation = "/repository/sample-calculator.jar";
- URI contribution = getClass().getResource(resourceLocation).toURI();
+ URI contribution = URI.create("sample-calculator.jar");
InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
repository.store(contribution, contributionStream);
@@ -58,10 +61,16 @@
public void testList() throws Exception {
String resourceLocation = "/repository/sample-calculator.jar";
- URI contribution = getClass().getResource(resourceLocation).toURI();
+ URI contribution = URI.create("sample-calculator.jar");
InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
repository.store(contribution, contributionStream);
assertEquals(1, repository.list().size());
}
-}
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ FileHelper.deleteDirectory(new File("target/repository"));
+ }
+}
\ No newline at end of file
Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java?view=auto&rev=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java Fri Mar 16 12:57:12 2007
@@ -0,0 +1,37 @@
+/*
+ * 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.spi.deployer;
+
+public interface ContentType {
+ /**
+ * Archive specific content types
+ */
+ public static final String JAR = "application/x-compressed";
+ public static final String FOLDER = "application/vnd.tuscany.folder";
+
+ /**
+ * Artifact/File specific content types
+ */
+ public static final String CONTRIBUTION_METADATA = "application/vnd.tuscany.contribution.metadata";
+ public static final String COMPOSITE = "application/vnd.tuscany.composite";
+ public static final String WSDL = "application/vnd.tuscany.wsdl";
+ public static final String JAVA = "application/java-vm";
+
+}
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java?view=diff&rev=519116&r1=519115&r2=519116
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java Fri Mar 16 12:57:12 2007
@@ -26,6 +26,12 @@
import java.util.List;
public interface ContributionRepository {
+ /**
+ * Get the URI of the SCA domain
+ *
+ * @return
+ */
+ URI getDomain();
/**
* Copies a contribution to the repository.
@@ -36,6 +42,14 @@
* distribution
*/
URL store(URI contribution, InputStream contributionStream) throws IOException;
+ /**
+ * Copy a contribution from the source URL to the repository
+ * @param contribution
+ * @param sourceURL
+ * @return
+ * @throws IOException
+ */
+ URL store(URI contribution, URL sourceURL) throws IOException;
/**
* Look up the contribution by URI
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org