1 17 package org.apache.forrest.eclipse.wizards; 18 19 import org.apache.log4j.Logger; 20 21 import java.io.BufferedReader ; 22 import java.io.IOException ; 23 import java.io.InputStreamReader ; 24 import java.lang.reflect.InvocationTargetException ; 25 26 import org.apache.forrest.eclipse.ForrestPlugin; 27 import org.eclipse.core.resources.IProject; 28 import org.eclipse.core.resources.IProjectDescription; 29 import org.eclipse.core.runtime.CoreException; 30 import org.eclipse.core.runtime.IPath; 31 import org.eclipse.core.runtime.IProgressMonitor; 32 import org.eclipse.core.runtime.IStatus; 33 import org.eclipse.core.runtime.NullProgressMonitor; 34 import org.eclipse.core.runtime.Status; 35 import org.eclipse.core.runtime.SubProgressMonitor; 36 import org.eclipse.jface.viewers.IStructuredSelection; 37 import org.eclipse.jface.wizard.Wizard; 38 import org.eclipse.ui.INewWizard; 39 import org.eclipse.ui.IWorkbench; 40 import org.eclipse.ui.IWorkbenchWizard; 41 import org.eclipse.ui.actions.WorkspaceModifyOperation; 42 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; 43 44 47 48 public class NewProjectWizard extends Wizard implements INewWizard { 49 52 private static final Logger logger = Logger 53 .getLogger(NewProjectWizard.class); 54 55 private WizardNewProjectCreationPage page; 56 57 60 public NewProjectWizard() { 61 super(); 62 setWindowTitle("New Content Package"); 63 setNeedsProgressMonitor(true); 64 } 65 66 69 70 public void addPages() { 71 page = new WizardNewProjectCreationPage("NewProjectCreationWizard"); 72 page.setTitle("New"); 73 page.setDescription("Create a new Content Package."); 74 addPage(page); 75 } 76 77 82 public boolean performFinish() { 83 WorkspaceModifyOperation op= new WorkspaceModifyOperation() { 84 protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException , InterruptedException { 85 finishPage(monitor); 86 } 87 }; 88 try { 89 getContainer().run(false, true, op); 90 } catch (InvocationTargetException e) { 91 return false; } catch (InterruptedException e) { 93 return false; } 95 return true; 96 } 97 98 private void finishPage(IProgressMonitor monitor) throws InterruptedException , CoreException { 99 if (monitor == null) { 100 monitor= new NullProgressMonitor(); 101 } 102 103 int exitValue = -1; 104 try { 105 String strName = page.getProjectName(); 106 monitor.beginTask("Creating "+ strName + " Forrest Project", 3); 107 108 IProject project= page.getProjectHandle(); 109 IPath locationPath= page.getLocationPath(); 110 111 IProjectDescription desc= project.getWorkspace().newProjectDescription(project.getName()); 113 if (!page.useDefaults()) { 114 desc.setLocation(locationPath); 115 } 116 project.create(desc, new SubProgressMonitor(monitor, 1)); 117 project.open(new SubProgressMonitor(monitor, 1)); 118 119 ForrestPlugin plugin = ForrestPlugin.getDefault(); 121 122 String strPath = locationPath.toOSString(); 123 String cmdString = null; 124 125 if (System.getProperty("os.name").toLowerCase().startsWith("linux")) { 126 cmdString = "forrest -Dbasedir=" + strPath + "/" + strName 127 + " seed"; 128 } else if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { 129 cmdString = "cmd /c forrest -Dbasedir=" + strPath + "\\" + strName 130 + " seed"; 131 } 132 133 try { 134 String lineRead = null; 135 Process seedProc = Runtime.getRuntime().exec(cmdString); 136 BufferedReader reader = new BufferedReader (new InputStreamReader (seedProc.getInputStream())); 137 while((lineRead = reader.readLine()) != null) { 138 if (logger.isDebugEnabled()) { 139 logger.debug("finishPage(IProgressMonitor)" + lineRead); 140 } 141 } 142 exitValue = seedProc.exitValue(); 143 } catch (IOException e) { 144 logger.error("finishPage(IProgressMonitor)", e); 146 } 147 148 project.refreshLocal(IProject.DEPTH_INFINITE, monitor); 149 150 152 } finally { 154 monitor.done(); 155 } 156 } 157 158 private void throwCoreException(String message) throws CoreException { 159 IStatus status = 160 new Status(IStatus.ERROR, "org.burrokeet.application", IStatus.OK, message, null); 161 throw new CoreException(status); 162 } 163 164 169 public void init(IWorkbench workbench, IStructuredSelection selection) { 170 } 171 } | Popular Tags |