You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by sp...@apache.org on 2006/04/20 01:03:08 UTC

svn commit: r395422 - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.st.core/ org.apache.geronimo.st.core/META-INF/ org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/ org.apache.geronimo.st.v1.core/ org.apache.geronim...

Author: sppatel
Date: Wed Apr 19 16:03:06 2006
New Revision: 395422

URL: http://svn.apache.org/viewcvs?rev=395422&view=rev
Log:
share runtime target handler

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java   (with props)
Removed:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerRuntimeTargetHandler.java
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/build.properties
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/plugin.xml
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/META-INF/MANIFEST.MF
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/plugin.xml

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF?rev=395422&r1=395421&r2=395422&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF Wed Apr 19 16:03:06 2006
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Geronimo Server Tools Core Plug-in
-Bundle-SymbolicName: org.apache.geronimo.st.core
+Bundle-SymbolicName: org.apache.geronimo.st.core;singleton:=true
 Bundle-Version: 1.0.0
 Bundle-Activator: org.apache.geronimo.st.core.Activator
 Bundle-Vendor: Apache

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/build.properties
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/build.properties?rev=395422&r1=395421&r2=395422&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/build.properties (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/build.properties Wed Apr 19 16:03:06 2006
@@ -1,4 +1,5 @@
 source.. = src/
 output.. = bin/
 bin.includes = META-INF/,\
-               .
\ No newline at end of file
+               .,\
+               plugin.xml

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml?rev=395422&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml Wed Apr 19 16:03:06 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+	<extension point="org.eclipse.wst.server.core.runtimeTargetHandlers">
+		<runtimeTargetHandler id="org.eclipse.jst.server.geronimo.runtimeTarget"
+			runtimeTypeIds="org.apache.geronimo.generic.runtime.*"
+            class="org.apache.geronimo.st.core.GeronimoServerRuntimeTargetHandler"/>
+    </extension>
+    
+	<extension point="org.eclipse.jst.server.core.runtimeClasspathProviders">
+		<runtimeClasspathProvider id="org.apache.geronimo.generic.runtime.10"
+			runtimeTypeIds="org.apache.geronimo.generic.runtime.*"
+			class="org.apache.geronimo.st.core.GeronimoServerRuntimeTargetHandler"/>
+    </extension>
+
+</plugin>

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml
------------------------------------------------------------------------------
    svn:keywords = Date Rev

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/plugin.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java?rev=395422&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java Wed Apr 19 16:03:06 2006
@@ -0,0 +1,203 @@
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed 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.geronimo.st.core;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.server.generic.core.internal.GenericServerRuntimeTargetHandler;
+import org.eclipse.jst.server.generic.core.internal.ServerTypeDefinitionUtil;
+import org.eclipse.jst.server.generic.servertype.definition.ArchiveType;
+import org.eclipse.jst.server.generic.servertype.definition.Classpath;
+import org.eclipse.jst.server.generic.servertype.definition.ServerRuntime;
+import org.eclipse.wst.server.core.IRuntime;
+
+public class GeronimoServerRuntimeTargetHandler extends
+		GenericServerRuntimeTargetHandler {
+
+	private static final String EXTENSION_RUNTIME_ACCESS = "discouragedRuntimeAccess";
+
+	String cachedArchiveString = null;
+	IClasspathEntry[] cachedClasspath = null;
+	private static Map map;
+	private IPath runtimeLoc;
+	private String runtimeTypeId;
+
+	static {
+		loadExtensions();
+	}
+
+	private static synchronized void loadExtensions() {
+		map = new HashMap();
+		IExtensionRegistry registry = Platform.getExtensionRegistry();
+		IConfigurationElement[] cf = registry.getConfigurationElementsFor(Activator.PLUGIN_ID, EXTENSION_RUNTIME_ACCESS);
+		for (int i = 0; i < cf.length; i++) {
+			IConfigurationElement element = cf[i];
+			if ("restriction".equals(element.getName())) {
+				String runtimeId = element.getAttribute("id");
+				if (runtimeId != null) {
+					IConfigurationElement[] children = element.getChildren();
+					for (int j = 0; j < children.length; j++) {
+						String path = children[j].getAttribute("value");
+						if (path != null) {
+							Collection c = (Collection) map.get(runtimeId);
+							if (c == null) {
+								c = new ArrayList();
+								map.put(runtimeId, c);
+							}
+							c.add(new Path(path));
+						}
+					}
+				}
+			}
+
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see ClasspathRuntimeTargetHandler#resolveClasspathContainer(IRuntime,
+	 *      java.lang.String)
+	 */
+	public IClasspathEntry[] resolveClasspathContainer(IRuntime runtime,
+			String id) {
+		this.runtimeTypeId = runtime.getRuntimeType().getId();
+		return getServerClassPathEntry(runtime);
+	}
+
+	public IClasspathEntry[] getServerClassPathEntry(IRuntime runtime) {
+		this.runtimeLoc = runtime.getLocation();
+		ServerRuntime serverDefinition = ServerTypeDefinitionUtil.getServerTypeDefinition(runtime);
+		String ref = serverDefinition.getProject().getClasspathReference();
+		Classpath cp = serverDefinition.getClasspath(ref);
+		List archives = cp.getArchive();
+
+		// It's expensive to keep searching directories, so try to cache the
+		// result
+		IClasspathEntry[] savedClasspath = getCachedClasspathFor(serverDefinition, archives);
+		if (savedClasspath != null)
+			return savedClasspath;
+
+		Iterator archiveIter = archives.iterator();
+		ArrayList entryList = new ArrayList();
+		while (archiveIter.hasNext()) {
+			ArchiveType archive = (ArchiveType) archiveIter.next();
+			String item = serverDefinition.getResolver().resolveProperties(archive.getPath());
+			IPath path = new Path(item);
+			File file = path.toFile();
+			if (file.isDirectory()) {
+				boolean discourageAccess = isAccessDiscouraged(path);
+				File[] list = file.listFiles();
+				for (int i = 0; i < list.length; i++) {
+					if (!list[i].isDirectory()) {
+						Path p = new Path(list[i].getAbsolutePath());
+						if (!discourageAccess)
+							discourageAccess = isAccessDiscouraged(p);
+						addLibEntry(entryList, p, discourageAccess);
+					}
+				}
+			} else {
+				addLibEntry(entryList, path, isAccessDiscouraged(path));
+			}
+		}
+
+		IClasspathEntry[] classpath = (IClasspathEntry[]) entryList.toArray(new IClasspathEntry[entryList.size()]);
+		setCachedClasspath(classpath);
+
+		return classpath;
+	}
+
+	private boolean isAccessDiscouraged(IPath path) {
+		Collection c = (Collection) map.get(runtimeTypeId);
+		if (c == null || c.isEmpty())
+			return false;
+
+		Iterator i = c.iterator();
+		while (i.hasNext()) {
+			IPath xPath = (IPath) i.next();
+			if (path.toFile().isDirectory()
+					&& runtimeLoc.append(xPath).isPrefixOf(path)) {
+				return true;
+			} else if (runtimeLoc.append(xPath).equals(path)) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	private void addLibEntry(ArrayList entryList, IPath path,
+			boolean discourageAccess) {
+		IClasspathEntry entry = null;
+		if (discourageAccess) {
+			IAccessRule rule = JavaCore.newAccessRule(new Path("**"), IAccessRule.K_DISCOURAGED);
+			IAccessRule rules[] = new IAccessRule[] { rule };
+			entry = JavaCore.newLibraryEntry(path, null, null, rules, new IClasspathAttribute[] {}, false);
+		} else {
+			entry = JavaCore.newLibraryEntry(path, null, null);
+		}
+		entryList.add(entry);
+	}
+
+	private IClasspathEntry[] getCachedClasspathFor(
+			ServerRuntime serverDefinition, List archives) {
+
+		// Need to iterate through the list, and expand the variables (in case
+		// they have changed)
+		// The simplest approach is to construct/cache a string for this
+		// That will still save the overhead of going to the filesystem
+
+		StringBuffer buffer = new StringBuffer();
+		Iterator archiveIter = archives.iterator();
+		while (archiveIter.hasNext()) {
+			ArchiveType archive = (ArchiveType) archiveIter.next();
+			String item = serverDefinition.getResolver().resolveProperties(archive.getPath());
+			buffer.append(item);
+			buffer.append(File.pathSeparatorChar);
+		}
+
+		String archiveString = buffer.toString();
+
+		if (cachedArchiveString != null
+				&& cachedArchiveString.equals(archiveString))
+			return cachedClasspath;
+
+		// This is a cache miss - ensure the data is null (to be safe), but save
+		// the key (archiveString) now
+		// The data will be set once it's calculated
+		cachedClasspath = null;
+		cachedArchiveString = archiveString;
+		return null;
+	}
+
+	private void setCachedClasspath(IClasspathEntry[] classpath) {
+		cachedClasspath = classpath;
+	}
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GeronimoServerRuntimeTargetHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/plugin.xml
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/plugin.xml?rev=395422&r1=395421&r2=395422&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/plugin.xml (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/plugin.xml Wed Apr 19 16:03:06 2006
@@ -51,7 +51,7 @@
         </serverdefinition>
     </extension>
     
-    <extension point="org.eclipse.wst.server.core.runtimeTargetHandlers">
+    <!--<extension point="org.eclipse.wst.server.core.runtimeTargetHandlers">
         <runtimeTargetHandler id="org.eclipse.jst.server.geronimo.runtimeTarget"
             runtimeTypeIds="org.apache.geronimo.generic.runtime.*"
             class="org.apache.geronimo.st.v1.core.GeronimoServerRuntimeTargetHandler"/>
@@ -61,7 +61,7 @@
         <runtimeClasspathProvider id="org.apache.geronimo.generic.runtime.10"
             runtimeTypeIds="org.apache.geronimo.generic.runtime.10"
             class="org.apache.geronimo.st.v1.core.GeronimoServerRuntimeTargetHandler"/>
-    </extension>
+    </extension> -->
     
     <extension point="org.eclipse.wst.common.project.facet.core.runtimes">
         <runtime-component-type id="org.apache.geronimo.runtime"/>

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/META-INF/MANIFEST.MF?rev=395422&r1=395421&r2=395422&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/META-INF/MANIFEST.MF (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/META-INF/MANIFEST.MF Wed Apr 19 16:03:06 2006
@@ -11,5 +11,9 @@
  org.apache.geronimo.runtime.v11,
  org.apache.geronimo.st.core,
  org.eclipse.wst.server.core,
- org.eclipse.debug.core
+ org.eclipse.debug.core,
+ com.ibm.etools.emf.event,
+ org.apache.geronimo.v11.deployment.model,
+ org.eclipse.wst.common.modulecore,
+ org.eclipse.core.resources
 Eclipse-AutoStart: true

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/plugin.xml
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/plugin.xml?rev=395422&r1=395421&r2=395422&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/plugin.xml (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/plugin.xml Wed Apr 19 16:03:06 2006
@@ -49,17 +49,5 @@
             definitionfile="/serverdef/geronimo11.serverdef">
         </serverdefinition>
     </extension>
-    
-    <extension point="org.eclipse.wst.server.core.runtimeTargetHandlers">
-        <runtimeTargetHandler id="org.eclipse.jst.server.geronimo.runtimeTarget"
-            runtimeTypeIds="org.apache.geronimo.generic.runtime.*"
-            class="org.apache.geronimo.st.core.GeronimoServerRuntimeTargetHandler"/>
-    </extension>
-    
-    <extension point="org.eclipse.jst.server.core.runtimeClasspathProviders">
-        <runtimeClasspathProvider id="org.apache.geronimo.generic.runtime.10"
-            runtimeTypeIds="org.apache.geronimo.generic.runtime.10"
-            class="org.apache.geronimo.st.core.GeronimoServerRuntimeTargetHandler"/>
-    </extension>
   
 </plugin>