Author: guixl Date: Fri Jul 23 10:46:29 2010 New Revision: 967029 URL: http://svn.apache.org/viewvc?rev=967029&view=rev Log: improve Apache Commons SCXML based SCXML runtime creation process
Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF?rev=967029&r1=967028&r2=967029&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF (original) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF Fri Jul 23 10:46:29 2010 @@ -34,5 +34,7 @@ Require-Bundle: org.eclipse.core.runtime org.apache.commons.scxml.modeling;visibility:=reexport, org.apache.commons.scxml.modeling.edit;visibility:=reexport, org.eclipse.gmf.runtime.draw2d.ui;visibility:=reexport, - org.eclipse.gef;visibility:=reexport + org.eclipse.gef;visibility:=reexport, + org.eclipse.jdt;bundle-version="3.4.0", + org.eclipse.jdt.core;bundle-version="3.4.0" Eclipse-LazyStart: true Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java?rev=967029&r1=967028&r2=967029&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java (original) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDebugFileWizard.java Fri Jul 23 10:46:29 2010 @@ -28,7 +28,9 @@ import java.util.List; import org.apache.commons.scxml.modeling.diagram.edit.parts.ServiceTemplateEditPart; import org.apache.commons.scxml.modeling.export.ScxmlExportStreamHandlerAction; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -41,6 +43,9 @@ import org.eclipse.emf.transaction.Trans import org.eclipse.gmf.runtime.diagram.core.services.ViewService; import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation; import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.StructuredSelection; @@ -224,7 +229,7 @@ public class ModelingNewDebugFileWizard int diagramVID = ModelingVisualIDRegistry .getDiagramVisualID(diagramRootElementSelectionPage .getModelElement()); - monitor.beginTask("SCXML document export progress",12); + monitor.beginTask("SCXML document export progress",19); try { String scxmlDoc=testCaseClassName+".xml"; @@ -234,6 +239,13 @@ public class ModelingNewDebugFileWizard IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject theProject = root.getProject(projectName); + IJavaProject javaProject = JavaCore.create(theProject); + IProjectDescription description = theProject.getDescription(); + String[] idList=description.getNatureIds(); + boolean JavaProjectFlag=false; + for(int i=0;i<idList.length;i++) + if(idList[i].equals(JavaCore.NATURE_ID)) JavaProjectFlag=true; + try { if (!theProject.isOpen()) theProject.open(null); @@ -262,26 +274,65 @@ public class ModelingNewDebugFileWizard target.create(shc.string2InputStream(content), false, null); monitor.worked(1); }else monitor.worked(8); + + IFolder libFolder = theProject.getFolder("lib"); + if(!libFolder.exists()) libFolder.create(0, false, null); + monitor.worked(1); + String[] jarList=new String[]{"commons-beanutils-1.8.3.jar","commons-digester-2.0.jar","commons-jexl-1.1.jar","commons-logging-1.1.1.jar","scxml.jar"}; + + for(int i=0;i<jarList.length;i++){ + String jar=jarList[i]; + IFile eachJar=theProject.getFile("/lib/"+jar); + if(!eachJar.exists()){ + eachJar.create(this.getClass().getClassLoader().getResourceAsStream("debug/"+jar), false, null); + IClasspathEntry[] newClassPath=null; + if(JavaProjectFlag){ + if(javaProject.readRawClasspath()!=null){ + IClasspathEntry[] oldClassPath=javaProject.readRawClasspath(); + newClassPath=new IClasspathEntry[oldClassPath.length+1]; + for(int j=0;j<oldClassPath.length;j++) + newClassPath[j]=oldClassPath[j]; + newClassPath[newClassPath.length-1]=JavaCore.newLibraryEntry( + new Path("/"+projectName+"/lib/"+jar), + null, // no source + null, // no source + false); + }else{ + newClassPath=new IClasspathEntry[1]; + newClassPath[0]=JavaCore.newLibraryEntry( + new Path("/"+projectName+"/lib/"+jar), + null, // no source + null, // no source + false); + } + javaProject.setRawClasspath(newClassPath, null); + } + } + monitor.worked(1); + } + monitor.worked(1); } catch (Exception ex) { ex.printStackTrace(); } //create Apache Commons SCXML runtime class - InputStream fileTemplate=this.getClass().getClassLoader().getResourceAsStream("debug/CommonsSCXMLEngine.java"); - monitor.worked(1); - String content=inputStream2String(fileTemplate); - content=content.replace("$CLASS_NAME$", testCaseClassName+"TestCase"); - monitor.worked(1); - - content=content.replace("$SCXML_DOCUMENT_RESOURCE$", scxmlDoc); - monitor.worked(1); - debugClassFile.setContents(string2InputStream(content), 1, null); - monitor.worked(1); - - if (monitor.isCanceled()) throw new InterruptedException( - "The SCXML document debug class creation operation was cancelled"); - - monitor.done(); + InputStream fileTemplate=this.getClass().getClassLoader().getResourceAsStream("debug/CommonsSCXMLEngine.java"); + monitor.worked(1); + String content=inputStream2String(fileTemplate); + String className=debugClassFile.getName().substring(0, debugClassFile.getName().lastIndexOf(".")); + content=content.replace("$CLASS_NAME$", className); + monitor.worked(1); + + content=content.replace("$SCXML_DOCUMENT_RESOURCE$", scxmlDoc); + monitor.worked(1); + debugClassFile.setContents(string2InputStream(content), 1, null); + monitor.worked(1); + + if (monitor.isCanceled()) throw new InterruptedException( + "The SCXML document debug class creation operation was cancelled"); + + monitor.done(); + } catch (CoreException e) { e.printStackTrace(); } catch (IOException e) {