[jboss-svn-commits] JBL Code SVN: r9492 - in labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin: utils and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Feb 14 08:57:18 EST 2007


Author: mshaw
Date: 2007-02-14 08:57:17 -0500 (Wed, 14 Feb 2007)
New Revision: 9492

Added:
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/utils/
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/utils/ClassPathUtils.java
Modified:
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/RtlNewPage.java
Log:


Added: labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/utils/ClassPathUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/utils/ClassPathUtils.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/utils/ClassPathUtils.java	2007-02-14 13:57:17 UTC (rev 9492)
@@ -0,0 +1,99 @@
+package org.drools.testing.plugin.utils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+
+public class ClassPathUtils {
+
+	public ClassPathUtils () {
+		
+	}
+	
+	 public static URL[] getClasspathAsURLArray(IJavaProject javaProject) {
+		if (javaProject == null)
+			return null;
+		Set visited = new HashSet();
+		List urls = new ArrayList(20);
+		collectClasspathURLs(javaProject, urls, visited, true);
+		URL[] result = new URL[urls.size()];
+		urls.toArray(result);
+		return result;
+	}
+
+	private static void collectClasspathURLs(IJavaProject javaProject,
+			List urls, Set visited, boolean isFirstProject) {
+		if (visited.contains(javaProject))
+			return;
+		visited.add(javaProject);
+		//IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject
+		//		.getProject());
+		IPath outPath = javaProject.getProject().getFullPath();
+		outPath = outPath.addTrailingSeparator();
+		URL out = createFileURL(outPath);
+		urls.add(out);
+		IClasspathEntry[] entries = null;
+		try {
+			entries = javaProject.getResolvedClasspath(true);
+		} catch (JavaModelException e) {
+			return;
+		}
+		IClasspathEntry entry, resEntry;
+		IJavaProject proj = null;
+		List projects = null;
+		for (int i = 0; i < entries.length; i++) {
+			entry = entries[i];
+			switch (entry.getEntryKind()) {
+			case IClasspathEntry.CPE_LIBRARY:
+			case IClasspathEntry.CPE_CONTAINER:
+			case IClasspathEntry.CPE_VARIABLE:
+				collectClasspathEntryURL(entry, urls);
+				break;
+			case IClasspathEntry.CPE_PROJECT: {
+				if (isFirstProject || entry.isExported())
+
+					collectClasspathURLs(getJavaProject(entry), urls, visited,
+							false);
+
+				break;
+			}
+			}
+		}
+	}
+
+	private static URL createFileURL(IPath path) {
+		URL url = null;
+		try {
+			url = new URL("file://" + path.toOSString());
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		}
+		return url;
+	}
+
+	private static void collectClasspathEntryURL(IClasspathEntry entry,
+			List urls) {
+		URL url = createFileURL(entry.getPath());
+		if (url != null)
+			urls.add(url);
+	}
+
+	private static IJavaProject getJavaProject(IClasspathEntry entry) {
+		IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(
+				entry.getPath().segment(0));
+		if (proj != null)
+			return getJavaProject((IClasspathEntry)proj);
+		return null;
+	}
+
+}

Modified: labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java	2007-02-14 12:58:20 UTC (rev 9491)
+++ labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java	2007-02-14 13:57:17 UTC (rev 9492)
@@ -7,6 +7,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
+import java.net.URLClassLoader;
 
 import org.drools.lang.descr.RuleDescr;
 import org.drools.testing.core.beans.Scenario;
@@ -14,8 +15,10 @@
 import org.drools.testing.core.exception.RuleTestLanguageException;
 import org.drools.testing.core.main.Testing;
 import org.drools.testing.plugin.model.RtlModel;
+import org.drools.testing.plugin.utils.ClassPathUtils;
 import org.eclipse.core.resources.IContainer;
 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.ResourcesPlugin;
@@ -24,6 +27,7 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.ISelection;
@@ -138,7 +142,15 @@
 		final IFile file = container.getFile(new Path(fileName));
 		
 		try {
-			Testing testing = new Testing("The Test Test Suite", rtlModel.getPackageDescr());
+			//URLClassLoader urClassLoader = new URLClassLoader(
+			//		ClassPathUtils.getClasspathAsURLArray(
+			//				ResourcesPlugin.getWorkspace().getRoot().getProject("test")));
+			
+			if (resource instanceof IProject)
+				System.out.println("fuck me");
+			IJavaProject proj = (IJavaProject) resource.getAdapter(IJavaProject.class);
+
+			Testing testing = new Testing("The Test Test Suite", rtlModel.getPackageDescr(),GenerateRtlWizard.class.getClassLoader());
 			Scenario scenario = testing.generateScenario("Scenario One",rtlModel.getPackageDescr().getRules());
 			testing.addScenarioToSuite(scenario);
 			TestSuite testSuite = testing.getTestSuite();
@@ -160,11 +172,11 @@
 			throwCoreException(e.getMessage());
 			
 		} catch (IOException e) {
-			throwCoreException(e.getMessage());
+			throwCoreException(e.toString());
 		}catch (MarshalException e) {
-			throwCoreException(e.getMessage());
+			throwCoreException(e.toString());
 		}catch (ValidationException e) {
-			throwCoreException(e.getMessage());
+			throwCoreException(e.toString());
 		}
 		
 		

Modified: labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/RtlNewPage.java
===================================================================
--- labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/RtlNewPage.java	2007-02-14 12:58:20 UTC (rev 9491)
+++ labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/RtlNewPage.java	2007-02-14 13:57:17 UTC (rev 9492)
@@ -21,6 +21,9 @@
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+import org.eclipse.ui.dialogs.ResourceSelectionDialog;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.eclipse.ui.dialogs.WizardResourceImportPage;
 
 /**
  * The "New" wizard page allows setting the container for the new file as well
@@ -60,7 +63,7 @@
 		layout.verticalSpacing = 9;
 		
 		Label label = new Label(container, SWT.NULL);
-		label.setText("&File name:");
+		label.setText("&Drl:");
 
 		fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
 		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
@@ -132,6 +135,10 @@
 		dialog.setFilterExtensions(extensions);
 		dialog.setFilterPath(".");
 		fileText.setText(dialog.open());
+		
+		
+
+
 	}
 	
 	private void handleBrowse() {




More information about the jboss-svn-commits mailing list