1 2 package com.bull.eclipse.jonas.wizard; 3 4 import java.io.File ; 5 import java.io.IOException ; 6 7 import org.eclipse.ant.core.AntRunner; 8 import org.eclipse.core.resources.IProject; 9 import org.eclipse.core.resources.IResource; 10 import org.eclipse.core.resources.ResourcesPlugin; 11 import org.eclipse.core.runtime.CoreException; 12 import org.eclipse.jdt.internal.ui.JavaPlugin; 13 import org.eclipse.jface.dialogs.MessageDialog; 14 import org.eclipse.jface.viewers.IStructuredSelection; 15 import org.eclipse.jface.wizard.Wizard; 16 import org.eclipse.ui.IWorkbench; 17 import org.eclipse.ui.IWorkbenchWizard; 18 19 import com.bull.eclipse.jonas.JonasLauncherPlugin; 20 import com.bull.eclipse.jonas.JonasProject; 21 import com.bull.eclipse.jonas.utils.FileUtil; 22 23 24 public class CreateEARWizard extends Wizard implements IWorkbenchWizard 25 { 26 private CreateEARWizardPage EarPage; 27 private IStructuredSelection selection; 28 private IProject proj; 29 30 31 public CreateEARWizard() 32 { 33 super(); 34 setDialogSettings( JavaPlugin.getDefault().getDialogSettings() ); 35 setWindowTitle(JonasLauncherPlugin.getResourceString("Create EAR")); 36 } 37 38 public void addPages() 39 { 40 EarPage = new CreateEARWizardPage("EARWizardPage1"); 41 EarPage.setTitle("Create EAR"); 42 EarPage.setDescription("create an EAR file in a Jonas project"); 43 EarPage.setProj(proj); 44 addPage(EarPage); 45 } 46 47 public void init( IWorkbench workbench, IStructuredSelection selection ) 48 { 49 this.selection = selection; 50 Object o = selection.getFirstElement(); 51 if( o instanceof JonasProject ) { 52 proj = ((JonasProject)o).getProject(); 53 } else 54 if( o instanceof IProject ) { 55 proj = (IProject)o; 56 } else 57 if( o instanceof String ) { 58 proj = ResourcesPlugin.getWorkspace().getRoot().getProject((String )selection.getFirstElement()); 59 } 60 } 61 62 public boolean performFinish() 63 { 64 File tempfilea = null; 65 File tempfileb = null; 66 try { 67 String appxml = EarPage.getAppXml(); 68 tempfilea = saveStringToTempfile( "app.xml", appxml ); 69 String bldxml = EarPage.getBldXml(tempfilea.toString()); 70 tempfileb = saveStringToTempfile( "bld.xml", bldxml ); 71 AntRunner antrunner = new AntRunner(); 72 antrunner.setBuildFileLocation(tempfileb.toString()); 73 antrunner.run(); 74 try{ proj.refreshLocal( IResource.DEPTH_INFINITE, null ); } 75 catch( CoreException e ) {} 76 } 77 catch( Exception e ) { 78 MessageDialog.openInformation(null,"Error","exception occurred "+e); 81 JonasLauncherPlugin.log("JOPE: exception in CreateEARWizard.performFinish "+e); 82 } 83 if( tempfilea!=null ) tempfilea.delete(); 84 if( tempfileb!=null ) tempfileb.delete(); 85 86 return true; 87 } 88 89 private File saveStringToTempfile( String filename, String content ) 90 throws IOException 91 { 92 File f = File.createTempFile( filename, "" ); 93 FileUtil.toTextFile( f, content ); 94 return f; 95 } 96 97 } 98 99 100 | Popular Tags |