1 11 package org.eclipse.help.internal.base.ant; 12 13 import java.io.File ; 14 15 import org.apache.tools.ant.BuildException; 16 import org.apache.tools.ant.Task; 17 import org.eclipse.ant.core.AntCorePlugin; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.NullProgressMonitor; 23 import org.eclipse.core.runtime.Path; 24 import org.eclipse.help.search.HelpIndexBuilder; 25 26 32 33 public class BuildHelpIndex extends Task { 34 private String manifest; 35 36 private String destination; 37 38 private HelpIndexBuilder builder; 39 40 43 public BuildHelpIndex() { 44 } 45 46 51 public void execute() throws BuildException { 52 File file = getFile(manifest); 53 if (file == null) 54 throw new BuildException("Manifest not set."); File target = getFile(destination); 56 if (target == null) 57 throw new BuildException("Target directory not set."); builder = new HelpIndexBuilder(); 59 builder.setManifest(file); 60 builder.setDestination(target); 61 IProgressMonitor monitor = (IProgressMonitor) getProject() 62 .getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR); 63 if (monitor == null) 64 monitor = new NullProgressMonitor(); 65 try { 66 builder.execute(monitor); 67 } catch (CoreException e) { 68 if (e.getStatus().getSeverity()==IStatus.ERROR) 69 throw new BuildException(e.getMessage(), e.getCause()); 70 printStatus(e); 71 } 72 } 73 74 private void printStatus(CoreException e) { 75 IStatus status = e.getStatus(); 76 System.out.println(e.getMessage()); 77 if (status.isMultiStatus()) { 78 IStatus [] children = status.getChildren(); 79 for (int i=0; i<children.length; i++) { 80 IStatus child = children[i]; 81 System.out.println(" "+child.getMessage()); } 83 } 84 } 85 86 private File getFile(String fileName) { 87 if (fileName == null) 88 return null; 89 IPath path = new Path(fileName); 90 if (path.isAbsolute()) 91 return new File (fileName); 92 File root = getProject().getBaseDir(); 93 if (fileName.equals(".") || fileName.equals("./")) return root; 95 if (fileName.equals("..") || fileName.equals("../")) return root.getParentFile(); 97 return new File (root, fileName); 98 } 99 100 109 110 public void setManifest(String manifest) { 111 this.manifest = manifest; 112 } 113 114 125 126 public void setDestination(String destination) { 127 this.destination = destination; 128 } 129 } | Popular Tags |