summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/modules/workspace-impl/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-12 00:43:48 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-12 00:43:48 +0000
commit9425990f532b1152c2d73db96c0f07ef5216a3d1 (patch)
treea8986fc31f96eb02484a0ae9d1c14cfa788e30ac /sca-java-2.x/contrib/modules/workspace-impl/src
parent40523f9c6cb1f7a785c2dbd2466dc410ae6ddf66 (diff)
Moving 2.x contribs
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835178 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/contrib/modules/workspace-impl/src')
-rw-r--r--sca-java-2.x/contrib/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderImpl.java144
-rw-r--r--sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.workspace.builder.ContributionBuilder18
-rw-r--r--sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages.properties22
-rw-r--r--sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages_it.properties21
-rw-r--r--sca-java-2.x/contrib/modules/workspace-impl/src/test/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderTestCase.java100
5 files changed, 305 insertions, 0 deletions
diff --git a/sca-java-2.x/contrib/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderImpl.java b/sca-java-2.x/contrib/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderImpl.java
new file mode 100644
index 0000000000..bdfd244293
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderImpl.java
@@ -0,0 +1,144 @@
+/*
+ * 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.sca.workspace.builder.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.DefaultImport;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.resolver.DefaultImportModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.workspace.Workspace;
+import org.apache.tuscany.sca.workspace.builder.ContributionBuilder;
+import org.apache.tuscany.sca.workspace.builder.ContributionBuilderException;
+
+/**
+ * A contribution dependency builder.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionDependencyBuilderImpl implements ContributionBuilder {
+ private static final Logger logger = Logger.getLogger(ContributionDependencyBuilderImpl.class.getName());
+
+ /**
+ * Constructs a new ContributionDependencyBuilder.
+ */
+ public ContributionDependencyBuilderImpl(FactoryExtensionPoint factories) {
+ }
+
+ public String getID() {
+ return "org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder";
+ }
+
+ public void build(Contribution contribution, Workspace workspace, Monitor monitor) throws ContributionBuilderException{
+ contribution.getDependencies().clear();
+
+ List<Contribution> dependencies = new ArrayList<Contribution>();
+ Set<Contribution> set = new HashSet<Contribution>();
+
+ dependencies.add(contribution);
+ set.add(contribution);
+ addContributionDependencies(contribution, workspace, dependencies, set, monitor);
+
+ Collections.reverse(dependencies);
+
+ contribution.getDependencies().addAll(dependencies);
+ }
+
+ /**
+ * Analyze a contribution and add its dependencies to the given dependency set.
+ * @param contribution
+ * @param workspace
+ * @param dependencies
+ * @param set
+ * @param monitor
+ */
+ private void addContributionDependencies(Contribution contribution, Workspace workspace, List<Contribution> dependencies, Set<Contribution> set, Monitor monitor) {
+
+ // Go through the contribution imports
+ for (Import import_: contribution.getImports()) {
+ boolean resolved = false;
+
+ // Go through all contribution candidates and their exports
+ List<Export> matchingExports = new ArrayList<Export>();
+ for (Contribution dependency: workspace.getContributions()) {
+ if (dependency == contribution) {
+ // Do not self import
+ continue;
+ }
+ for (Export export: dependency.getExports()) {
+
+ // If an export from a contribution matches the import in hand
+ // add that contribution to the dependency set
+ if (import_.match(export)) {
+ resolved = true;
+ matchingExports.add(export);
+
+ if (!set.contains(dependency)) {
+ set.add(dependency);
+ dependencies.add(dependency);
+
+ // Now add the dependencies of that contribution
+ addContributionDependencies(dependency, workspace, dependencies, set, monitor);
+ }
+ }
+ }
+ }
+
+ if (resolved) {
+
+ // Initialize the import's model resolver with a delegating model
+ // resolver which will delegate to the matching exports
+ import_.setModelResolver(new DefaultImportModelResolver(matchingExports));
+
+ } else {
+ // Record import resolution issue
+ if (!(import_ instanceof DefaultImport)) {
+ warning(monitor, "UnresolvedImport", import_, import_);
+ }
+ }
+ }
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private static void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = monitor.createProblem(ContributionDependencyBuilderImpl.class.getName(), "workspace-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.workspace.builder.ContributionBuilder b/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.workspace.builder.ContributionBuilder
new file mode 100644
index 0000000000..379d0a017e
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.workspace.builder.ContributionBuilder
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl;id=org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder
diff --git a/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages.properties b/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages.properties
new file mode 100644
index 0000000000..0c07a3a30f
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages.properties
@@ -0,0 +1,22 @@
+#
+#
+# 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.
+#
+#
+
+UnresolvedImport = Unresolved import: Import = {0}
diff --git a/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages_it.properties b/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages_it.properties
new file mode 100644
index 0000000000..2e8326c062
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/workspace-impl/src/main/resources/workspace-validation-messages_it.properties
@@ -0,0 +1,21 @@
+#
+#
+# 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.
+#
+#
+
diff --git a/sca-java-2.x/contrib/modules/workspace-impl/src/test/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderTestCase.java b/sca-java-2.x/contrib/modules/workspace-impl/src/test/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderTestCase.java
new file mode 100644
index 0000000000..be64c65c45
--- /dev/null
+++ b/sca-java-2.x/contrib/modules/workspace-impl/src/test/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * 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.sca.workspace.builder.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.apache.tuscany.sca.contribution.namespace.DefaultNamespaceImportExportFactory;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceExport;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory;
+import org.apache.tuscany.sca.workspace.DefaultWorkspaceFactory;
+import org.apache.tuscany.sca.workspace.Workspace;
+import org.apache.tuscany.sca.workspace.WorkspaceFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the contribution dependency analyzer.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionDependencyBuilderTestCase {
+
+ private ContributionFactory contributionFactory;
+ private WorkspaceFactory workspaceFactory;
+ private NamespaceImportExportFactory importExportFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ contributionFactory = new DefaultContributionFactory();
+ workspaceFactory = new DefaultWorkspaceFactory();
+ importExportFactory = new DefaultNamespaceImportExportFactory();
+ }
+
+ @Test
+ public void testAnalyze() throws Exception {
+ Workspace workspace = workspaceFactory.createWorkspace();
+ Contribution importer = contributionFactory.createContribution();
+ importer.setURI("importer");
+ workspace.getContributions().add(importer);
+ NamespaceImport import_ = importExportFactory.createNamespaceImport();
+ import_.setNamespace("http://foo");
+ importer.getImports().add(import_);
+
+ Contribution imported = contributionFactory.createContribution();
+ imported.setURI("imported");
+ workspace.getContributions().add(imported);
+ NamespaceExport export = importExportFactory.createNamespaceExport();
+ export.setNamespace("http://foo");
+ imported.getExports().add(export);
+ import_ = importExportFactory.createNamespaceImport();
+ import_.setNamespace("http://bar");
+ imported.getImports().add(import_);
+
+ Contribution imported2 = contributionFactory.createContribution();
+ imported2.setURI("imported2");
+ workspace.getContributions().add(imported2);
+ export = importExportFactory.createNamespaceExport();
+ export.setNamespace("http://bar");
+ imported2.getExports().add(export);
+
+ Contribution another = contributionFactory.createContribution();
+ another.setURI("another");
+ workspace.getContributions().add(another);
+ export = importExportFactory.createNamespaceExport();
+ export.setNamespace("http://another");
+ another.getExports().add(export);
+
+ ContributionDependencyBuilderImpl builder = new ContributionDependencyBuilderImpl(null);
+ builder.build(importer, workspace, null);
+ List<Contribution> dependencies = importer.getDependencies();
+ assertTrue(dependencies.size() == 3);
+ assertTrue(dependencies.contains(importer));
+ assertTrue(dependencies.contains(imported));
+ assertTrue(dependencies.contains(imported2));
+ }
+
+}