1 11 package org.eclipse.pde.internal.ui.wizards.exports; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 16 import org.eclipse.core.resources.IContainer; 17 import org.eclipse.core.resources.IFile; 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.Path; 22 import org.eclipse.jface.dialogs.MessageDialog; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.pde.internal.core.XMLPrintHandler; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.internal.ui.build.BaseBuildAction; 28 import org.w3c.dom.Document ; 29 30 public abstract class AntGeneratingExportWizard extends BaseExportWizard { 31 32 protected BaseExportWizardPage fPage; 33 34 public void addPages() { 35 fPage = createPage1(); 36 addPage(fPage); 37 } 38 39 protected abstract BaseExportWizardPage createPage1(); 40 41 protected boolean performPreliminaryChecks() { 42 if (fPage.doGenerateAntFile()) 43 generateAntBuildFile(fPage.getAntBuildFileName()); 44 return true; 45 } 46 47 protected boolean confirmDelete() { 48 if (!fPage.doExportToDirectory()) { 49 File zipFile = new File (fPage.getDestination(), fPage.getFileName()); 50 if (zipFile.exists()) { 51 if (!MessageDialog.openQuestion(getContainer().getShell(), 52 PDEUIMessages.BaseExportWizard_confirmReplace_title, 53 NLS.bind(PDEUIMessages.BaseExportWizard_confirmReplace_desc, zipFile.getAbsolutePath()))) 54 return false; 55 zipFile.delete(); 56 } 57 } 58 return true; 59 } 60 61 protected abstract Document generateAntTask(); 62 63 protected void generateAntBuildFile(String filename) { 64 String parent = new Path(filename).removeLastSegments(1).toOSString(); 65 String buildFilename = new Path(filename).lastSegment(); 66 if (!buildFilename.endsWith(".xml")) buildFilename += ".xml"; File dir = new File (new File (parent).getAbsolutePath()); 69 if (!dir.exists()) 70 dir.mkdirs(); 71 72 try { 73 Document task = generateAntTask(); 74 if (task != null) { 75 File buildFile = new File (dir, buildFilename); 76 XMLPrintHandler.writeFile(task, buildFile); 77 generateAntTask(); 78 setDefaultValues(dir, buildFilename); 79 } 80 } catch (IOException e) { 81 } 82 } 83 84 private void setDefaultValues(File dir, String buildFilename) { 85 try { 86 IContainer container = PDEPlugin.getWorkspace().getRoot().getContainerForLocation(new Path(dir.toString())); 87 if (container != null && container.exists()) { 88 IProject project = container.getProject(); 89 if (project != null) { 90 project.refreshLocal(IResource.DEPTH_INFINITE, null); 91 IFile file = container.getFile(new Path(buildFilename)); 92 if (file.exists()) 93 BaseBuildAction.setDefaultValues(file); 94 } 95 } 96 } catch (CoreException e) { 97 } 98 } 99 100 protected String getExportOperation() { 101 return fPage.doExportToDirectory() ? "directory" : "zip"; } 103 104 } 105 | Popular Tags |