[jboss-svn-commits] JBL Code SVN: r13728 - labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jul 23 11:27:34 EDT 2007
Author: KrisVerlaenen
Date: 2007-07-23 11:27:34 -0400 (Mon, 23 Jul 2007)
New Revision: 13728
Modified:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java
Log:
Drools builder now also supports the definition of the dsl in the .package file
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java 2007-07-23 14:49:39 UTC (rev 13727)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java 2007-07-23 15:27:34 UTC (rev 13728)
@@ -10,12 +10,15 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.builder.Util;
import org.drools.eclipse.editors.completion.DSLTree;
import org.drools.lang.dsl.DSLMapping;
import org.drools.lang.dsl.DSLMappingEntry;
import org.drools.lang.dsl.DSLMappingFile;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
/**
@@ -58,7 +61,28 @@
/** Get a reader to the DSL contents */
public static Reader getDSLContent(String ruleSource, IResource input) throws CoreException {
String dslFileName = findDSLConfigName( ruleSource );
- if (dslFileName == null) return null;
+ if (dslFileName == null) {
+ // try searching the .package file
+ if (input != null && input.getParent() != null) {
+ MyResourceVisitor visitor = new MyResourceVisitor();
+ input.getParent().accept(visitor, IResource.DEPTH_ONE, IResource.NONE);
+ IResource packageDef = visitor.getPackageDef();
+ if (packageDef != null) {
+ if (packageDef instanceof IFile) {
+ IFile file = (IFile) packageDef;
+ try {
+ String content = new String(Util.getResourceContentsAsCharArray(file));
+ dslFileName = findDSLConfigName( content );
+ } catch (CoreException e) {
+ DroolsEclipsePlugin.log(e);
+ }
+ }
+ }
+ }
+ }
+ if (dslFileName == null) {
+ return null;
+ }
IResource res = findDSLResource( input, dslFileName );
if (res instanceof IFile) {
IFile dslConf = (IFile) res;
@@ -176,4 +200,16 @@
return dslTree;
}
+ private static class MyResourceVisitor implements IResourceVisitor {
+ private IResource packageDef;
+ public boolean visit(IResource resource) throws CoreException {
+ if ("package".equals(resource.getFileExtension())) {
+ packageDef = resource;
+ }
+ return true;
+ }
+ public IResource getPackageDef() {
+ return packageDef;
+ }
+ }
}
More information about the jboss-svn-commits
mailing list