db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r581971 - in /db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui: ./ src/org/apache/derby/ui/common/ src/org/apache/derby/ui/container/ src/org/apache/derby/ui/popup/actions/ src/org/apache/derby/ui/util/
Date Thu, 04 Oct 2007 17:22:09 GMT
Author: dyre
Date: Thu Oct  4 10:22:05 2007
New Revision: 581971

URL: http://svn.apache.org/viewvc?rev=581971&view=rev
Log:
DERBY-1931: Derby JAR files should be grouped as a single library in Package Explorer
Contributed by Aaron Tarter


Added:
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainer.java
  (with props)
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainerInitializer.java
  (with props)
Modified:
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/plugin.xml
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/common/Messages.java
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/AddDerbyNature.java
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/RemoveDerbyNature.java
    db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/util/DerbyUtils.java

Modified: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/plugin.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/plugin.xml?rev=581971&r1=581970&r2=581971&view=diff
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/plugin.xml (original)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/plugin.xml Thu Oct  4 10:22:05
2007
@@ -421,4 +421,9 @@
             configTypeID="org.apache.derby.ui.sysinfoDerbyLaunchConfigurationType"
             id="org.apache.derby.ui.sysinfoDerbyLaunchConfigurationTypeImage"/>
    </extension>
+   <extension point="org.eclipse.jdt.core.classpathContainerInitializer">
+      <classpathContainerInitializer
+            id="DERBY_CONTAINER"
+            class="org.apache.derby.ui.container.DerbyClasspathContainerInitializer"/>
+   </extension>
 </plugin>

Modified: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/common/Messages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/common/Messages.java?rev=581971&r1=581970&r2=581971&view=diff
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/common/Messages.java
(original)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/common/Messages.java
Thu Oct  4 10:22:05 2007
@@ -45,4 +45,6 @@
 	
 	public static String NO_ACTION="Unable to execute the action";
 	public static String SERVER_RUNNING="The Network Server is already running.\nStop the server
prior to changing the settings.";
+	
+	public static String DERBY_CONTAINER_DESC = "Derby Libraries";
 }

Added: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainer.java?rev=581971&view=auto
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainer.java
(added)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainer.java
Thu Oct  4 10:22:05 2007
@@ -0,0 +1,80 @@
+/*
+
+  Derby - Class org.apache.derby.ui.container.DerbyClasspathContainer
+
+  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.derby.ui.container;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.apache.derby.ui.common.CommonNames;
+import org.apache.derby.ui.common.Messages;
+import org.apache.derby.ui.util.Logger;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.osgi.framework.Bundle;
+
+public class DerbyClasspathContainer implements IClasspathContainer {
+    public static final Path CONTAINER_ID = new Path("DERBY_CONTAINER"); //$NON-NLS-1$
+    private IClasspathEntry[] _entries;
+   
+    public DerbyClasspathContainer() {
+        List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
+        Bundle bundle = Platform.getBundle(CommonNames.CORE_PATH);
+        Enumeration en = bundle.findEntries("/", "*.jar", true);
+        String rootPath = null;
+        try { 
+            rootPath = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null)).getPath();
+        } catch(IOException e) {
+            Logger.log(e.getMessage(), IStatus.ERROR);
+        }
+        while(en.hasMoreElements()) {
+            IClasspathEntry cpe = JavaCore.newLibraryEntry(new Path(rootPath+'/'+((URL)en.nextElement()).getFile()),
null, null);
+            entries.add(cpe);
+        }    
+        IClasspathEntry[] cpes = new IClasspathEntry[entries.size()];
+        _entries = (IClasspathEntry[])entries.toArray(cpes);
+    }
+
+    public IClasspathEntry[] getClasspathEntries() {      
+        return _entries;       
+    }
+
+    public String getDescription() {
+        return Messages.DERBY_CONTAINER_DESC;
+    }
+
+    public int getKind() {
+        return K_APPLICATION;
+    }
+
+    public IPath getPath() {
+        return CONTAINER_ID;
+    }
+}

Propchange: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainerInitializer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainerInitializer.java?rev=581971&view=auto
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainerInitializer.java
(added)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainerInitializer.java
Thu Oct  4 10:22:05 2007
@@ -0,0 +1,39 @@
+/*
+
+  Derby - Class org.apache.derby.ui.container.DerbyClasspathContainerInitializer
+
+  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.derby.ui.container;
+
+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;
+
+public class DerbyClasspathContainerInitializer 
+    extends ClasspathContainerInitializer {
+    @Override
+    public void initialize(IPath containerPath, IJavaProject project)
+        throws CoreException {
+        IClasspathContainer container = new DerbyClasspathContainer();
+        JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[]
{container}, null);
+    }
+}

Propchange: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/container/DerbyClasspathContainerInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/AddDerbyNature.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/AddDerbyNature.java?rev=581971&r1=581970&r2=581971&view=diff
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/AddDerbyNature.java
(original)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/AddDerbyNature.java
Thu Oct  4 10:22:05 2007
@@ -21,9 +21,12 @@
 
 package org.apache.derby.ui.popup.actions;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.derby.ui.common.CommonNames;
 import org.apache.derby.ui.common.Messages;
-import org.apache.derby.ui.util.DerbyUtils;
+import org.apache.derby.ui.container.DerbyClasspathContainer;
 import org.apache.derby.ui.util.Logger;
 import org.apache.derby.ui.util.SelectionUtil;
 import org.eclipse.core.resources.IProject;
@@ -113,9 +116,16 @@
             IClasspathEntry[] rawClasspath = currentJavaProject
                     .getRawClasspath();
 
-            currentJavaProject.setRawClasspath(DerbyUtils
-                    .addDerbyJars(rawClasspath), null);
-
+            List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(rawClasspath.length+1);
           
+            for(IClasspathEntry e: rawClasspath) {
+            	newEntries.add(e);
+            }            
+            newEntries.add(JavaCore.newContainerEntry(DerbyClasspathContainer.CONTAINER_ID));
+            
+            IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
+            newEntriesArray = (IClasspathEntry[])newEntries.toArray(newEntriesArray);
+            currentJavaProject.setRawClasspath(newEntriesArray, null);
+                    
             // refresh project so user sees new files, libraries, etc
             currentJavaProject.getProject().refreshLocal(
                     IResource.DEPTH_INFINITE, null);

Modified: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/RemoveDerbyNature.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/RemoveDerbyNature.java?rev=581971&r1=581970&r2=581971&view=diff
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/RemoveDerbyNature.java
(original)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/popup/actions/RemoveDerbyNature.java
Thu Oct  4 10:22:05 2007
@@ -21,11 +21,12 @@
 package org.apache.derby.ui.popup.actions;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.derby.ui.common.CommonNames;
 import org.apache.derby.ui.common.Messages;
+import org.apache.derby.ui.container.DerbyClasspathContainer;
 import org.apache.derby.ui.util.DerbyServerUtils;
-import org.apache.derby.ui.util.DerbyUtils;
 import org.apache.derby.ui.util.Logger;
 import org.apache.derby.ui.util.SelectionUtil;
 import org.eclipse.core.resources.IProject;
@@ -86,7 +87,19 @@
 				DerbyServerUtils.getDefault().stopDerbyServer(currentJavaProject.getProject());
 			}
 			IClasspathEntry[] rawClasspath = currentJavaProject.getRawClasspath();
-			currentJavaProject.setRawClasspath(DerbyUtils.removeDerbyJars(rawClasspath), null);
+			
+			List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
+			for(IClasspathEntry e: rawClasspath) {
+				if(e.getEntryKind()!=IClasspathEntry.CPE_CONTAINER) {
+					newEntries.add(e);
+				} else if(!e.getPath().equals(DerbyClasspathContainer.CONTAINER_ID)) {
+					newEntries.add(e);
+				}
+			}
+			
+			IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
+			newEntriesArray = (IClasspathEntry[])newEntries.toArray(newEntriesArray);			
+			currentJavaProject.setRawClasspath(newEntriesArray, null);
 			
 			IProjectDescription description = currentJavaProject.getProject().getDescription();
 			String[] natures = description.getNatureIds();

Modified: db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/util/DerbyUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/util/DerbyUtils.java?rev=581971&r1=581970&r2=581971&view=diff
==============================================================================
--- db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/util/DerbyUtils.java
(original)
+++ db/derby/code/trunk/plugins/eclipse/org.apache.derby.ui/src/org/apache/derby/ui/util/DerbyUtils.java
Thu Oct  4 10:22:05 2007
@@ -21,7 +21,6 @@
 
 package org.apache.derby.ui.util;
 
-import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -32,7 +31,6 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
@@ -44,8 +42,6 @@
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
 import org.eclipse.jdt.launching.JavaRuntime;
@@ -57,119 +53,10 @@
 
 
 public class DerbyUtils {
-	private final static String PLUGIN_ROOT = "ECLIPSE_HOME/plugins/";
 	
 	private static ManifestElement[] getElements(String bundleName) throws BundleException {
 		String requires = (String)Platform.getBundle(bundleName).getHeaders().get(Constants.BUNDLE_CLASSPATH);
 		return ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, requires);
-	}
-	public static IClasspathEntry[] addDerbyJars(IClasspathEntry[] rawCP) throws Exception{
-		
-		IClasspathEntry[] newRawCP= null;
-		try{
-			//New OSGI way
-			ManifestElement[] elements_core, elements_ui;
-			elements_core = getElements(CommonNames.CORE_PATH);
-			elements_ui=getElements(CommonNames.UI_PATH);
-			
-			Bundle bundle=Platform.getBundle(CommonNames.CORE_PATH);
-			URL pluginURL = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null));
-			String pluginName = new File(pluginURL.getPath()).getName();
-
-			newRawCP=new IClasspathEntry[rawCP.length + (elements_core.length) + (elements_ui.length-1)];
-			System.arraycopy(rawCP, 0, newRawCP, 0, rawCP.length);
-			
-			//Add the CORE jars
-			int oldLength=rawCP.length;
-			for(int i=0;i<elements_core.length;i++){
-				// add JAR as var type entry relative to the eclipse plugins dir, so the entry is portable

-				newRawCP[oldLength+i]=JavaCore.newVariableEntry(new Path(PLUGIN_ROOT+pluginName+"/"+elements_core[i].getValue()),
null, null);				
-				
-			}
-			 // Add the UI jars
-			bundle=Platform.getBundle(CommonNames.UI_PATH);
-			pluginURL = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null));
-			pluginName = new File(pluginURL.getPath()).getName();
-			oldLength=oldLength+elements_core.length -1; 
-			for(int i=0;i<elements_ui.length;i++){
-				if(!(elements_ui[i].getValue().toLowerCase().equals("ui.jar"))){
-					// add JAR as var type entry relative to the eclipse plugins dir, so the entry is portable
-					newRawCP[oldLength+i]=JavaCore.newVariableEntry(new Path(PLUGIN_ROOT+pluginName+"/"+elements_ui[i].getValue()),
null, null);
-				}
-			}					
-			return newRawCP;
-		}catch(Exception e){
-			throw e;
-		}
-		
-	}
-	public static IClasspathEntry[] removeDerbyJars(IClasspathEntry[] rawCP) throws Exception{
-		ArrayList arrL=new ArrayList();
-		for (int i=0;i<rawCP.length;i++){
-			arrL.add(rawCP[i]);
-		}
-		IClasspathEntry[] newRawCP= null;
-		try{
-			ManifestElement[] elements_core, elements_ui;
-			elements_core = getElements(CommonNames.CORE_PATH);
-			elements_ui=getElements(CommonNames.UI_PATH);
-			
-			Bundle bundle;
-			URL pluginURL,jarURL,localURL;
-
-			boolean add;
-			IClasspathEntry icp=null;
-			for (int j=0;j<arrL.size();j++){
-				bundle=Platform.getBundle(CommonNames.CORE_PATH);
-				pluginURL = bundle.getEntry("/");
-				add=true;
-				icp=(IClasspathEntry)arrL.get(j);
-				//remove 'core' jars
-				for (int i=0;i<elements_core.length;i++){
-					jarURL= new URL(pluginURL,elements_core[i].getValue());
-					localURL=Platform.asLocalURL(jarURL);
-					if(((icp).equals(JavaCore.newLibraryEntry(new Path(localURL.getPath()), null, null)))||
-							icp.getPath().toString().toLowerCase().endsWith("derby.jar")||
-							icp.getPath().toString().toLowerCase().endsWith("derbynet.jar")||
-							icp.getPath().toString().toLowerCase().endsWith("derbyclient.jar")||
-							icp.getPath().toString().toLowerCase().endsWith("derbytools.jar")){
-						add=false;
-					}
-				}
-				if(!add){
-					arrL.remove(j);
-					j=j-1;
-				}
-				//REMOVE 'ui' jars
-				bundle=Platform.getBundle(CommonNames.UI_PATH);
-				pluginURL = bundle.getEntry("/");
-				add=true;
-				
-				for (int i=0;i<elements_ui.length;i++){
-					if(!(elements_ui[i].getValue().toLowerCase().equals("ui.jar"))){
-						jarURL= new URL(pluginURL,elements_ui[i].getValue());
-						localURL=Platform.asLocalURL(jarURL);					
-						if((icp).equals(JavaCore.newLibraryEntry(new Path(localURL.getPath()), null, null))){
-							add=false;
-						}
-					}
-				}
-				if(!add){
-					arrL.remove(j);
-					j=j-1;
-				}
-			}
-			newRawCP=new IClasspathEntry[arrL.size()];
-			for (int i=0;i<arrL.size();i++){
-				newRawCP[i]=(IClasspathEntry)arrL.get(i);
-			}
-			return newRawCP;
-		}catch(Exception e){
-			e.printStackTrace();
-			//return rawCP;
-			throw e;
-		}
-		
 	}
 	protected static ILaunch launch(IProject proj, String name, String mainClass, String args,
String vmargs, String app) throws CoreException {	
 		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();



Mime
View raw message