Author: jgbutler
Date: Mon Mar  8 23:58:51 2010
New Revision: 920579

URL: http://svn.apache.org/viewvc?rev=920579&view=rev
Log:
[Ibator] Improve eclipse classloading

Modified:
    
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.doc/html-src/eclipseui/releasenotes.html
    
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorAction.java
    
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorThread.java
    
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/content/IbatorConfigurationFileAdapter.java

Modified: 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.doc/html-src/eclipseui/releasenotes.html
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.doc/html-src/eclipseui/releasenotes.html?rev=920579&r1=920578&r2=920579&view=diff
==============================================================================
--- 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.doc/html-src/eclipseui/releasenotes.html
 (original)
+++ 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.doc/html-src/eclipseui/releasenotes.html
 Mon Mar  8 23:58:51 2010
@@ -13,6 +13,14 @@
   <li>Upgraded to Ibator Version 1.2.2</li>
   <li>Fixed divide by zero error when there are no tables that match
       the configuration</li>
+  <li>Changed build process to use PDE Headless build.  The Ibator feature now 
includes source bundles
+      for all plugins!  Also, the feature is now well behaved according to 
Eclipse
+      standards (no bundle is unpack upon install).</li>
+  <li>Enhanced the classloading strategy for generating iBATIS artifacts from 
the popup menu.
+      Ibator will now find resources and JAR files in project where the 
configuration file
+      lives if that project is a Java project.</li>
+  <li>Changed classpath variable IBATOR_JAR to IBATOR_HOME</li>
+  <li>Changed classpath variable IBATOR_JAR_SRC to IBATOR_SRC_HOME</li>
 </ul>
 
 <h2>Version 1.2.1</h2>

Modified: 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorAction.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorAction.java?rev=920579&r1=920578&r2=920579&view=diff
==============================================================================
--- 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorAction.java
 (original)
+++ 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorAction.java
 Mon Mar  8 23:58:51 2010
@@ -74,7 +74,7 @@
                 }
 
                 ErrorDialog.openError(shell, "Ibator for iBATIS",
-                        "Run Complete With Warninigs", ms, Status.WARNING);
+                        "Run Complete With Warnings", ms, Status.WARNING);
             }
         } catch (Exception e) {
             handleException(e, shell);
@@ -131,8 +131,7 @@
         public void run(IProgressMonitor monitor)
                 throws InvocationTargetException, InterruptedException {
             try {
-                RunIbatorThread thread = new RunIbatorThread(selectedFile
-                        .getLocation().toFile(), warnings);
+                RunIbatorThread thread = new RunIbatorThread(selectedFile, 
warnings);
 
                 ResourcesPlugin.getWorkspace().run(thread, monitor);
             } catch (CoreException e) {

Modified: 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorThread.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorThread.java?rev=920579&r1=920578&r2=920579&view=diff
==============================================================================
--- 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorThread.java
 (original)
+++ 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/actions/RunIbatorThread.java
 Mon Mar  8 23:58:51 2010
@@ -15,9 +15,11 @@
  */
 package org.apache.ibatis.ibator.eclipse.ui.actions;
 
-import java.io.File;
 import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -29,28 +31,37 @@
 import org.apache.ibatis.ibator.eclipse.ui.IbatorUIPlugin;
 import org.apache.ibatis.ibator.exception.InvalidConfigurationException;
 import org.apache.ibatis.ibator.exception.XMLParserException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
 
 /**
  * @author Jeff Butler
  *
  */
 public class RunIbatorThread implements IWorkspaceRunnable {
-    private File inputFile;
-
+    private IFile inputFile;
     private List<String> warnings;
+    private ClassLoader oldClassLoader;
 
     /**
      *  
      */
-    public RunIbatorThread(File inputFile, List<String> warnings) {
+    public RunIbatorThread(IFile inputFile, List<String> warnings) {
         super();
         this.inputFile = inputFile;
         this.warnings = warnings;
@@ -64,13 +75,15 @@
     public void run(IProgressMonitor monitor) throws CoreException {
         SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
         subMonitor.beginTask("Generating iBATIS Artifacts:", 1000);
-
+        
+        setClassLoader();
+        
         try {
             subMonitor.subTask("Parsing Configuration");
 
             IbatorConfigurationParser cp = new IbatorConfigurationParser(
                     warnings);
-            IbatorConfiguration config = 
cp.parseIbatorConfiguration(inputFile);
+            IbatorConfiguration config = 
cp.parseIbatorConfiguration(inputFile.getLocation().toFile());
 
             subMonitor.worked(50);
 
@@ -123,6 +136,81 @@
             throw new CoreException(multiStatus);
         } finally {
             monitor.done();
+            restoreClassLoader();
+        }
+    }
+    
+    private void setClassLoader() {
+        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+        IJavaProject javaProject = getJavaProject();
+        
+        try {
+            if (javaProject != null) {
+                List<URL> entries = new ArrayList<URL>();
+                IPath path = javaProject.getOutputLocation();
+                IResource iResource = root.findMember(path);
+                path = iResource.getLocation();
+                path = path.addTrailingSeparator();
+                entries.add(path.toFile().toURL());
+                
+                IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
+                for (IClasspathEntry cpEntry : cpEntries) {
+                    switch (cpEntry.getEntryKind()) {
+                    case IClasspathEntry.CPE_SOURCE:
+                        path = cpEntry.getOutputLocation();
+                        if (path != null) {
+                            iResource = root.findMember(path);
+                            path = iResource.getLocation();
+                            path = path.addTrailingSeparator();
+                            entries.add(path.toFile().toURL());
+                        }
+                        break;
+                    
+                    case IClasspathEntry.CPE_LIBRARY:
+                        iResource = root.findMember(cpEntry.getPath());
+                        if (iResource == null) {
+                            // resource is not in workspace, must be an 
external JAR
+                            path = cpEntry.getPath();
+                        } else {
+                            path = iResource.getLocation();
+                        }
+                        entries.add(path.toFile().toURL());
+                        break;
+                    }
+                }
+            
+                ClassLoader oldCl = 
Thread.currentThread().getContextClassLoader();
+                URL[] entryArray = new URL[entries.size()];
+                entries.toArray(entryArray);
+                ClassLoader newCl = new URLClassLoader(entryArray, oldCl);
+                Thread.currentThread().setContextClassLoader(newCl);
+                oldClassLoader = oldCl;
+            }
+        } catch (Exception e) {
+            // ignore - something too complex is wrong
+            ;
+        }
+        
+    }
+    
+    private void restoreClassLoader() {
+        if (oldClassLoader != null) {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
+    }
+    
+    private IJavaProject getJavaProject() {
+        IJavaProject answer = null;
+        IProject project = inputFile.getProject();
+        try {
+            if (project.hasNature(JavaCore.NATURE_ID)) {
+                answer = JavaCore.create(project);
+            }
+        } catch (CoreException e) {
+            // ignore - something is wrong
+            ;
         }
+            
+        return answer;
     }
 }

Modified: 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/content/IbatorConfigurationFileAdapter.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/content/IbatorConfigurationFileAdapter.java?rev=920579&r1=920578&r2=920579&view=diff
==============================================================================
--- 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/content/IbatorConfigurationFileAdapter.java
 (original)
+++ 
ibatis/java/ibator/trunk/eclipse/org.apache.ibatis.ibator.eclipse.ui/src/org/apache/ibatis/ibator/eclipse/ui/content/IbatorConfigurationFileAdapter.java
 Mon Mar  8 23:58:51 2010
@@ -18,7 +18,7 @@
 import org.eclipse.core.resources.IFile;
 
 /**
- * This is the adapter class for files that are abator configuration files.
+ * This is the adapter class for files that are Ibator configuration files.
  * 
  * @author Jeff Butler
  */
@@ -34,5 +34,4 @@
     public IFile getBaseFile() {
         return baseFile;
     }
-
 }


Reply via email to