summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath')
-rw-r--r--tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/ClasspathUtil.java170
-rw-r--r--tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainer.java154
-rw-r--r--tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainerInitializer.java50
-rw-r--r--tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyLibraryEntryPage.java69
-rw-r--r--tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyRuntimeClasspathContainer.java89
5 files changed, 532 insertions, 0 deletions
diff --git a/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/ClasspathUtil.java b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/ClasspathUtil.java
new file mode 100644
index 0000000000..6c83ea057d
--- /dev/null
+++ b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/ClasspathUtil.java
@@ -0,0 +1,170 @@
+/*
+ * 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.core.classpath;
+
+import static org.apache.tuscany.sca.core.log.LogUtil.error;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+
+/**
+ * Utility functions to help determine the runtime classpath.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class ClasspathUtil {
+
+ private static final String TUSCANY_RUNTIME_LIBRARIES = "org.apache.tuscany.sca.core.runtimeLibraries";
+
+ private static final String TUSCANY_FEATURE = "org.apache.tuscany.sca.feature.core";
+ private static final String TUSCANY_VERSION = "1.5.1";
+
+ /**
+ * Return the installed runtime classpath entries.
+ *
+ * @return
+ * @throws CoreException
+ */
+ public static String installedRuntimeClasspath() throws CoreException {
+
+ List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
+ for (IExtension extension: Platform.getExtensionRegistry().getExtensionPoint(TUSCANY_RUNTIME_LIBRARIES).getExtensions()) {
+ for (IConfigurationElement configuration: extension.getConfigurationElements()) {
+ IClasspathContainer container = (IClasspathContainer)configuration.createExecutableExtension("class");
+ classpathEntries.addAll(Arrays.asList(container.getClasspathEntries()));
+ }
+ }
+
+ String separator = System.getProperty("path.separator");
+ StringBuffer classpath = new StringBuffer();
+ for (int i = 0, n = classpathEntries.size(); i < n; i++) {
+ IClasspathEntry entry = classpathEntries.get(i);
+ if (i >0) {
+ classpath.append(separator);
+ }
+ classpath.append(entry.getPath().toFile().toURI().getPath());
+ }
+
+ return classpath.toString();
+ }
+
+ /**
+ * Returns the Tuscany feature location.
+ *
+ * @return
+ */
+ static IPath feature() {
+ try {
+ URL location = Platform.getInstallLocation().getURL();
+ File feature = new File(location.getPath() + "/features/" + TUSCANY_FEATURE + "_" + TUSCANY_VERSION);
+ return new Path(feature.getPath());
+ } catch (Exception e) {
+ error("Tuscany runtime feature not found", e);
+ return null;
+ }
+ }
+
+ /**
+ * Returns the location of the runtime distribution under the Tuscany feature.
+ *
+ * @param feature
+ * @return
+ */
+ static IPath runtime(IPath feature) {
+ IPath runtimePath = null;
+ try {
+
+ // Find the Tuscany distribution under the feature's runtime directory
+ // Typically runtime/distro-archive-name/un-archived-distro-dir
+ File file = new File(feature.toFile(), "runtime");
+ if (file.exists()) {
+ File distro = null;
+ for (File f: file.listFiles()) {
+ if (f.getName().contains("tuscany-sca")) {
+ distro = f;
+ break;
+ }
+ }
+ if (distro != null) {
+ for (File f: distro.listFiles()) {
+ if (f.getName().contains("tuscany-sca")) {
+ runtimePath = new Path(f.getPath());
+ break;
+ }
+ }
+ if (runtimePath == null) {
+ error("Tuscany runtime distribution directory not found", new FileNotFoundException(distro.getAbsolutePath()));
+ }
+ } else {
+ error("Tuscany runtime distribution archive not found", new FileNotFoundException(file.getAbsolutePath()));
+ }
+ } else {
+ error("Tuscany runtime feature not found", new FileNotFoundException(file.getAbsolutePath()));
+ }
+ } catch (Exception e) {
+ error("Tuscany runtime feature not found", e);
+ }
+ return runtimePath;
+ }
+
+ /**
+ * Returns the location of the src distribution under the Tuscany feature.
+ *
+ * @param feature
+ * @return
+ */
+ static IPath src(IPath feature) {
+ IPath sourcePath = null;
+ try {
+
+ // Find the Tuscany source distribution under the feature's src directory
+ // Typically src/distro-archive-src.zip
+ File file = new File(feature.toFile(), "src");
+ if (file.exists()) {
+ File distro = null;
+ for (File f: file.listFiles()) {
+ if (f.getName().contains("tuscany-sca") && f.getName().endsWith("-src.zip")) {
+ distro = f;
+ break;
+ }
+ }
+ if (distro != null) {
+ sourcePath = new Path(distro.getPath());
+ }
+ }
+ } catch (Exception e) {
+ }
+ return sourcePath;
+ }
+
+}
diff --git a/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainer.java b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainer.java
new file mode 100644
index 0000000000..c1a674a46a
--- /dev/null
+++ b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainer.java
@@ -0,0 +1,154 @@
+/*
+ * 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.core.classpath;
+
+import static org.apache.tuscany.sca.core.classpath.ClasspathUtil.feature;
+import static org.apache.tuscany.sca.core.classpath.ClasspathUtil.runtime;
+import static org.apache.tuscany.sca.core.classpath.ClasspathUtil.src;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * A classpath container for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyClasspathContainer implements IClasspathContainer {
+
+ public static final IPath TUSCANY_LIBRARY_CONTAINER = new Path("org.apache.tuscany.sca.runtime.library");
+
+ private static final String TUSCANY_HOME = "TUSCANY_HOME";
+ private static final String TUSCANY_SRC = "TUSCANY_SRC";
+
+ public TuscanyClasspathContainer() {
+ }
+
+ public IClasspathEntry[] getClasspathEntries() {
+ List<IClasspathEntry> list = new ArrayList<IClasspathEntry>();
+
+ // Find the Tuscany feature
+ IPath feature = feature();
+
+ // Get the runtime location from the installed Tuscany feature
+ IPath runtimePath = runtime(feature);
+
+ if (runtimePath == null) {
+
+ // Try to get the location of the Tuscany binary distribution from
+ // the TUSCANY_HOME property or environment variable
+ String home = System.getProperty(TUSCANY_HOME);
+ if (home == null || home.length() == 0) {
+ home = System.getenv(TUSCANY_HOME);
+ }
+ if (home != null && home.length() != 0) {
+ if (new File(home).exists()) {
+ runtimePath = new Path(home);
+ }
+ }
+ }
+
+ // Get the source location from the installed Tuscany feature
+ IPath sourcePath = src(feature);
+
+ if (sourcePath == null) {
+
+ // Try to get the location of the Tuscany source distribution from
+ // the TUSCANY_SRC property or environment variable
+ String source = System.getProperty(TUSCANY_SRC);
+ if (source == null || source.length() == 0) {
+ source = System.getenv(TUSCANY_SRC);
+ }
+ if (source != null && source.length() != 0) {
+ if (new File(source).exists()) {
+ sourcePath = new Path(source);
+ }
+ }
+ }
+
+ // Add the JARs from runtime/lib and runtime/modules as classpath entries
+ if (runtimePath != null) {
+
+ // Add a selection of the jars from runtime/modules
+ File modulesDirectory = runtimePath.append("modules").toFile();
+ if (modulesDirectory != null && modulesDirectory.exists()) {
+ for (File file : modulesDirectory.listFiles()) {
+ IPath path = new Path(file.getPath());
+ String name = path.lastSegment();
+ String extension = path.getFileExtension();
+
+ // Only include API and launcher JARs
+ if (!"jar".equals(extension)) {
+ continue;
+ }
+ if (name.indexOf("-api-") == -1 && name.indexOf("-launcher-") == -1) {
+ continue;
+ }
+ if (name.startsWith("tuscany-node-api-") || name.startsWith("tuscany-domain-api-")) {
+ continue;
+ }
+
+ list.add(JavaCore.newLibraryEntry(path, sourcePath, null));
+ }
+ }
+
+ File libDirectory = runtimePath.append("lib").toFile();
+ if (libDirectory != null && libDirectory.exists()) {
+ for (File file : libDirectory.listFiles()) {
+ IPath path = new Path(file.getPath());
+ String name = path.lastSegment();
+ String extension = path.getFileExtension();
+
+ // Only include jaxb, jaxws and jsr API JARs
+ if (!"jar".equals(extension)) {
+ continue;
+ }
+ if (name.indexOf("-api-") != -1) {
+ if (name.startsWith("jaxb") || name.startsWith("jaxws") || name.startsWith("jsr")) {
+ list.add(JavaCore.newLibraryEntry(path, sourcePath, null));
+ }
+ }
+ }
+ }
+ }
+
+ return (IClasspathEntry[])list.toArray(new IClasspathEntry[list.size()]);
+ }
+
+ public String getDescription() {
+ return "Tuscany Library";
+ }
+
+ public int getKind() {
+ return IClasspathContainer.K_APPLICATION;
+ }
+
+ public IPath getPath() {
+ return TUSCANY_LIBRARY_CONTAINER;
+ }
+
+}
diff --git a/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainerInitializer.java b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainerInitializer.java
new file mode 100644
index 0000000000..c82281b243
--- /dev/null
+++ b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyClasspathContainerInitializer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.core.classpath;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ClasspathContainerInitializer;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * A classpath container initializer for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyClasspathContainerInitializer extends ClasspathContainerInitializer {
+
+ @Override
+ public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
+
+ TuscanyClasspathContainer classpathContainer = new TuscanyClasspathContainer();
+ JavaCore.setClasspathContainer(containerPath,
+ new IJavaProject[] {project},
+ new IClasspathContainer[] {classpathContainer},
+ null);
+ }
+
+ @Override
+ public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) {
+ return true;
+ }
+}
diff --git a/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyLibraryEntryPage.java b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyLibraryEntryPage.java
new file mode 100644
index 0000000000..21f6f27a6f
--- /dev/null
+++ b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyLibraryEntryPage.java
@@ -0,0 +1,69 @@
+/*
+ * 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.core.classpath;
+
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * A classpath container page for the Tuscany runtime library.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyLibraryEntryPage extends WizardPage implements IClasspathContainerPage {
+
+ private IClasspathEntry classpathEntry;
+
+ public TuscanyLibraryEntryPage() {
+ super("Tuscany");
+ }
+
+ public void createControl(Composite parent) {
+ setTitle("Tuscany Library");
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText("Press Finish to add the Tuscany Library");
+ label.setFont(parent.getFont());
+
+ setControl(label);
+ }
+
+ public boolean finish() {
+ classpathEntry = JavaCore.newContainerEntry(TuscanyClasspathContainer.TUSCANY_LIBRARY_CONTAINER);
+ return true;
+ }
+
+ public boolean isPageComplete() {
+ return true;
+ }
+
+ public IClasspathEntry getSelection() {
+ return classpathEntry;
+ }
+
+ public void setSelection(IClasspathEntry containerEntry) {
+ this.classpathEntry = containerEntry;
+ }
+}
diff --git a/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyRuntimeClasspathContainer.java b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyRuntimeClasspathContainer.java
new file mode 100644
index 0000000000..df73402b67
--- /dev/null
+++ b/tags/java/sca/1.5.1/tools/eclipse/plugins/core/org/apache/tuscany/sca/core/classpath/TuscanyRuntimeClasspathContainer.java
@@ -0,0 +1,89 @@
+/*
+ * 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.core.classpath;
+
+import static org.apache.tuscany.sca.core.classpath.ClasspathUtil.feature;
+import static org.apache.tuscany.sca.core.classpath.ClasspathUtil.runtime;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * A classpath container for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyRuntimeClasspathContainer implements IClasspathContainer {
+
+ public static final IPath TUSCANY_LIBRARY_CONTAINER = new Path("org.apache.tuscany.sca.runtime.library");
+
+ private static final String TUSCANY_HOME = "TUSCANY_HOME";
+
+ public TuscanyRuntimeClasspathContainer() {
+ }
+
+ public IClasspathEntry[] getClasspathEntries() {
+
+ // Find the Tuscany feature
+ IPath feature = feature();
+
+ // Get the runtime location from the installed Tuscany feature
+ IPath runtimePath = runtime(feature);
+
+ if (runtimePath == null) {
+
+ // Try to get the location of the Tuscany binary distribution from
+ // the TUSCANY_HOME property or environment variable
+ String home = System.getProperty(TUSCANY_HOME);
+ if (home == null || home.length() == 0) {
+ home = System.getenv(TUSCANY_HOME);
+ }
+ if (home != null && home.length() != 0) {
+ if (new File(home).exists()) {
+ runtimePath = new Path(home);
+ }
+ }
+ }
+
+ if (runtimePath != null) {
+ return new IClasspathEntry[] {JavaCore.newLibraryEntry(runtimePath, null, null)};
+ } else {
+ return new IClasspathEntry[0];
+ }
+ }
+
+ public String getDescription() {
+ return "Tuscany Library";
+ }
+
+ public int getKind() {
+ return IClasspathContainer.K_APPLICATION;
+ }
+
+ public IPath getPath() {
+ return TUSCANY_LIBRARY_CONTAINER;
+ }
+
+}