1 11 package org.eclipse.ant.internal.ui; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import com.ibm.icu.text.MessageFormat; 18 import java.util.ArrayList ; 19 import java.util.HashMap ; 20 import java.util.Hashtable ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Map ; 24 import java.util.StringTokenizer ; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.Target; 28 import org.apache.tools.ant.util.FileUtils; 29 import org.eclipse.ant.core.AntCorePlugin; 30 import org.eclipse.ant.internal.core.AntCoreUtil; 31 import org.eclipse.ant.internal.ui.editor.AntEditor; 32 import org.eclipse.ant.internal.ui.launchConfigurations.AntHomeClasspathEntry; 33 import org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants; 34 import org.eclipse.ant.internal.ui.launchConfigurations.TaskLinkManager; 35 import org.eclipse.ant.internal.ui.model.AntElementNode; 36 import org.eclipse.ant.internal.ui.model.AntModel; 37 import org.eclipse.ant.internal.ui.model.AntProjectNode; 38 import org.eclipse.ant.internal.ui.model.AntTargetNode; 39 import org.eclipse.ant.internal.ui.model.IAntModel; 40 import org.eclipse.ant.internal.ui.model.LocationProvider; 41 import org.eclipse.core.filebuffers.FileBuffers; 42 import org.eclipse.core.filebuffers.ITextFileBuffer; 43 import org.eclipse.core.filebuffers.ITextFileBufferManager; 44 import org.eclipse.core.filebuffers.LocationKind; 45 import org.eclipse.core.resources.IFile; 46 import org.eclipse.core.resources.IWorkspaceRoot; 47 import org.eclipse.core.resources.ResourcesPlugin; 48 import org.eclipse.core.runtime.CoreException; 49 import org.eclipse.core.runtime.IPath; 50 import org.eclipse.core.runtime.IStatus; 51 import org.eclipse.core.runtime.NullProgressMonitor; 52 import org.eclipse.core.runtime.Path; 53 import org.eclipse.core.runtime.Status; 54 import org.eclipse.core.variables.VariablesPlugin; 55 import org.eclipse.debug.core.ILaunchConfiguration; 56 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 57 import org.eclipse.debug.core.model.IProcess; 58 import org.eclipse.debug.ui.console.FileLink; 59 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 60 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 61 import org.eclipse.jdt.launching.IRuntimeClasspathEntry2; 62 import org.eclipse.jdt.launching.JavaRuntime; 63 import org.eclipse.jface.dialogs.MessageDialog; 64 import org.eclipse.jface.text.BadLocationException; 65 import org.eclipse.jface.text.IDocument; 66 import org.eclipse.jface.text.Region; 67 import org.eclipse.swt.SWT; 68 import org.eclipse.swt.program.Program; 69 import org.eclipse.swt.widgets.Shell; 70 import org.eclipse.ui.IEditorDescriptor; 71 import org.eclipse.ui.IEditorInput; 72 import org.eclipse.ui.IEditorPart; 73 import org.eclipse.ui.IEditorRegistry; 74 import org.eclipse.ui.IWorkbenchPage; 75 import org.eclipse.ui.PartInitException; 76 import org.eclipse.ui.PlatformUI; 77 import org.eclipse.ui.browser.IWebBrowser; 78 import org.eclipse.ui.browser.IWorkbenchBrowserSupport; 79 import org.eclipse.ui.console.IHyperlink; 80 import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil; 81 import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder; 82 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 83 import org.eclipse.ui.ide.IDE; 84 import org.eclipse.ui.part.FileEditorInput; 85 import org.eclipse.ui.texteditor.IDocumentProvider; 86 import org.eclipse.ui.texteditor.ITextEditor; 87 88 91 public final class AntUtil { 92 public static final String ATTRIBUTE_SEPARATOR = ","; public static final char ANT_CLASSPATH_DELIMITER= '*'; 94 public static final String ANT_HOME_CLASSPATH_PLACEHOLDER= "G"; public static final String ANT_GLOBAL_USER_CLASSPATH_PLACEHOLDER= "UG"; 97 private static String fgBrowserId; 98 99 102 private AntUtil() { 103 super(); 104 } 105 106 113 public static String combineStrings(String [] strings) { 114 if (strings.length == 0) 115 return null; 116 117 if (strings.length == 1) 118 return strings[0]; 119 120 StringBuffer buf = new StringBuffer (); 121 for (int i = 0; i < strings.length - 1; i++) { 122 buf.append(strings[i]); 123 buf.append(ATTRIBUTE_SEPARATOR); 124 } 125 buf.append(strings[strings.length - 1]); 126 return buf.toString(); 127 } 128 129 137 public static String [] getTargetNames(ILaunchConfiguration configuration) throws CoreException { 138 String attribute= null; 139 if (IAntLaunchConfigurationConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE.equals(configuration.getType().getIdentifier())) { 140 attribute= getTargetNamesForAntBuilder(configuration); 141 } 142 if (attribute == null) { 143 attribute = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String ) null); 144 if (attribute == null) { 145 return null; 146 } 147 } 148 149 return AntUtil.parseRunTargets(attribute); 150 } 151 152 private static String getTargetNamesForAntBuilder(ILaunchConfiguration configuration) throws CoreException { 153 String buildType= ExternalToolBuilder.getBuildType(); 154 String targets= null; 155 if (IExternalToolConstants.BUILD_TYPE_AUTO.equals(buildType)) { 156 targets= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS, (String )null); 157 } else if (IExternalToolConstants.BUILD_TYPE_CLEAN.equals(buildType)) { 158 targets = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS, (String ) null); 159 } else if (IExternalToolConstants.BUILD_TYPE_FULL.equals(buildType)) { 160 targets = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, (String ) null); 161 } else if (IExternalToolConstants.BUILD_TYPE_INCREMENTAL.equals(buildType)) { 162 targets = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS, (String ) null); 163 } 164 165 return targets; 166 } 167 168 177 public static Map getProperties(ILaunchConfiguration configuration) throws CoreException { 178 Map map = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map ) null); 179 return map; 180 } 181 182 189 public static String getAntHome(ILaunchConfiguration configuration) throws CoreException { 190 IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); 191 for (int i = 0; i < entries.length; i++) { 192 IRuntimeClasspathEntry entry = entries[i]; 193 if (entry.getType() == IRuntimeClasspathEntry.OTHER) { 194 IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2)entry; 195 if (entry2.getTypeId().equals(AntHomeClasspathEntry.TYPE_ID)) { 196 return ((AntHomeClasspathEntry)entry2).getAntHome(); 197 } 198 } 199 } 200 return null; 201 } 202 203 212 public static String [] getPropertyFiles(ILaunchConfiguration configuration) throws CoreException { 213 String attribute = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String ) null); 214 if (attribute == null) { 215 return null; 216 } 217 String [] propertyFiles= AntUtil.parseString(attribute, ","); for (int i = 0; i < propertyFiles.length; i++) { 219 String propertyFile = propertyFiles[i]; 220 propertyFile= expandVariableString(propertyFile, AntUIModelMessages.AntUtil_6); 221 propertyFiles[i]= propertyFile; 222 } 223 return propertyFiles; 224 } 225 226 public static AntTargetNode[] getTargets(String path, ILaunchConfiguration config) throws CoreException { 227 File buildfile= getBuildFile(path); 228 if (buildfile == null) { 229 return null; 230 } 231 URL [] urls= getCustomClasspath(config); 232 IAntModel model= getAntModel(buildfile, urls, false, false, false); 234 235 model.setProperties(getAllProperties(config)); 236 model.setPropertyFiles(getPropertyFiles(config)); 237 AntProjectNode project= model.getProjectNode(); model.dispose(); 239 return getTargets(project); 240 } 241 242 private static Map getAllProperties(ILaunchConfiguration config) throws CoreException { 243 String [] arguments = ExternalToolsUtil.getArguments(config); 244 Map properties= new HashMap (); 245 if (arguments != null) { 246 AntCoreUtil.processMinusDProperties(AntCoreUtil.getArrayList(arguments), properties); 247 } 248 Map configProperties= getProperties(config); 249 if (configProperties != null) { 250 Iterator keys= configProperties.keySet().iterator(); 251 while (keys.hasNext()) { 252 String name = (String ) keys.next(); 253 if (properties.get(name) == null) { 254 properties.put(name, configProperties.get(name)); 255 } 256 } 257 } 258 return properties; 259 } 260 261 private static AntTargetNode[] getTargets(AntProjectNode project) { 262 if (project == null || !project.hasChildren()) { 263 return null; 264 } 265 List targets= new ArrayList (); 266 Iterator possibleTargets= project.getChildNodes().iterator(); 267 while (possibleTargets.hasNext()) { 268 AntElementNode node= (AntElementNode)possibleTargets.next(); 269 if (node instanceof AntTargetNode) { 270 targets.add(node); 271 } 272 } 273 if (targets.size() == 0) { 274 return null; 275 } 276 return (AntTargetNode[])targets.toArray(new AntTargetNode[targets.size()]); 277 } 278 279 public static AntTargetNode[] getTargets(String path) { 280 File buildfile= getBuildFile(path); 281 if (buildfile == null) { 282 return null; 283 } 284 IAntModel model= getAntModel(buildfile, null, false, true, true); 286 AntProjectNode project= model.getProjectNode(); 287 if (project == null) { 288 model.dispose(); 289 return null; 290 } 291 AntTargetNode[] targets= getTargets(project); 292 if (targets == null) { 293 Hashtable antTargets= project.getProject().getTargets(); 294 Target implicitTarget= (Target) antTargets.get(""); if (implicitTarget != null) { 296 AntTargetNode implicitTargetNode= new AntTargetNode(implicitTarget); 297 project.addChildNode(implicitTargetNode); 298 return new AntTargetNode[] {implicitTargetNode}; 299 } 300 } 301 return targets; 302 } 303 304 public static IAntModel getAntModel(String buildFilePath, boolean needsLexicalResolution, boolean needsPositionResolution, boolean needsTaskResolution) { 305 IAntModel model= getAntModel(getBuildFile(buildFilePath), null, needsLexicalResolution, needsPositionResolution, needsTaskResolution); 306 return model; 307 } 308 309 313 private static File getBuildFile(String path) { 314 File buildFile = new File (path); 315 if (!buildFile.isFile() || !buildFile.exists()) { 316 return null; 317 } 318 319 return buildFile; 320 } 321 322 private static IAntModel getAntModel(final File buildFile, URL [] urls, boolean needsLexical, boolean needsPosition, boolean needsTask) { 323 if (buildFile == null || !buildFile.exists()) { 324 return null; 325 } 326 IDocument doc= getDocument(buildFile); 327 if (doc == null) { 328 return null; 329 } 330 final IFile file= getFileForLocation(buildFile.getAbsolutePath(), null); 331 LocationProvider provider= new LocationProvider(null) { 332 335 public IFile getFile() { 336 return file; 337 } 338 341 public IPath getLocation() { 342 if (file == null) { 343 return new Path(buildFile.getAbsolutePath()); 344 } 345 return file.getLocation(); 346 } 347 }; 348 IAntModel model= new AntModel(doc, null, provider, needsLexical, needsPosition, needsTask); 349 350 if (urls != null) { 351 model.setClassLoader(AntCorePlugin.getPlugin().getNewClassLoader(urls)); 352 } 353 return model; 354 } 355 356 private static IDocument getDocument(File buildFile) { 357 ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); 358 IPath location= new Path(buildFile.getAbsolutePath()); 359 boolean connected= false; 360 try { 361 ITextFileBuffer buffer= manager.getTextFileBuffer(location, LocationKind.NORMALIZE); 362 if (buffer == null) { 363 manager.connect(location, LocationKind.NORMALIZE, new NullProgressMonitor()); 365 connected= true; 366 buffer= manager.getTextFileBuffer(location, LocationKind.NORMALIZE); 367 if (buffer == null) { 368 return null; 369 } 370 } 371 372 return buffer.getDocument(); 373 } catch (CoreException ce) { 374 AntUIPlugin.log(ce.getStatus()); 375 return null; 376 } finally { 377 if (connected) { 378 try { 379 manager.disconnect(location, LocationKind.NORMALIZE, new NullProgressMonitor()); 380 } catch (CoreException e) { 381 AntUIPlugin.log(e.getStatus()); 382 } 383 } 384 } 385 } 386 387 396 public static URL [] getCustomClasspath(ILaunchConfiguration config) throws CoreException { 397 boolean useDefault = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); 398 if (useDefault) { 399 return null; 400 } 401 IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(config); 402 List userEntries = new ArrayList (unresolved.length); 404 for (int i = 0; i < unresolved.length; i++) { 405 IRuntimeClasspathEntry entry = unresolved[i]; 406 if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { 407 userEntries.add(entry); 408 } 409 } 410 IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspath((IRuntimeClasspathEntry[])userEntries.toArray(new IRuntimeClasspathEntry[userEntries.size()]), config); 411 URL [] urls = new URL [entries.length]; 412 for (int i = 0; i < entries.length; i++) { 413 IRuntimeClasspathEntry entry = entries[i]; 414 try { 415 urls[i] = new URL ("file:"+entry.getLocation()); } catch (MalformedURLException e) { 417 throw new CoreException(new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), AntUIPlugin.INTERNAL_ERROR, AntUIModelMessages.AntUtil_7, e)); 418 } 419 } 420 return urls; 421 } 422 423 private static String expandVariableString(String variableString, String invalidMessage) throws CoreException { 424 String expandedString = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(variableString); 425 if (expandedString == null || expandedString.length() == 0) { 426 String msg = MessageFormat.format(invalidMessage, new String [] {variableString}); 427 throw new CoreException(new Status(IStatus.ERROR, IAntUIConstants.PLUGIN_ID, 0, msg, null)); 428 } 429 430 return expandedString; 431 } 432 433 440 public static String [] parseRunTargets(String extraAttibuteValue) { 441 return parseString(extraAttibuteValue, ATTRIBUTE_SEPARATOR); 442 } 443 444 450 public static String [] parseString(String delimString, String delim) { 451 if (delimString == null) { 452 return new String [0]; 453 } 454 455 StringTokenizer tokenizer = new StringTokenizer (delimString, delim); 458 String [] results = new String [tokenizer.countTokens()]; 459 for (int i = 0; i < results.length; i++) { 460 results[i] = tokenizer.nextToken(); 461 } 462 463 return results; 464 } 465 466 470 public static IFile getFile(String fullPath) { 471 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 472 return root.getFile(new Path(fullPath)); 473 } 474 475 public static IHyperlink getLocationLink(String path, File buildFileParent) { 476 path = path.trim(); 477 if (path.length() == 0) { 478 return null; 479 } 480 if (path.startsWith("file:")) { path= path.substring(5, path.length()); 483 } 484 int index = path.lastIndexOf(':'); 486 if (index == -1) { 487 return null; 489 } 490 if (index == path.length() - 1) { 491 path = path.substring(0, index); 493 index = path.lastIndexOf(':'); 494 } 495 String fileName = path.substring(0, index); 497 try { 498 String lineNumber = path.substring(index + 1); 499 int line = Integer.parseInt(lineNumber); 500 IFile file = getFileForLocation(fileName, buildFileParent); 501 if (file != null) { 502 return new FileLink(file, null, -1, -1, line); 503 } 504 } catch (NumberFormatException e) { 505 } 506 507 return null; 508 } 509 510 524 public static IFile getFileForLocation(String path, File buildFileParent) { 525 if (path == null) { 526 return null; 527 } 528 IPath filePath= new Path(path); 529 IFile file = null; 530 IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath); 531 if (files.length > 0) { 532 file= files[0]; 533 } 534 if (file == null) { 535 File relativeFile= null; 537 try { 538 relativeFile= FileUtils.getFileUtils().resolveFile(buildFileParent, path); 540 filePath= new Path(relativeFile.getAbsolutePath()); 541 files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath); 542 if (files.length > 0) { 543 file= files[0]; 544 } else { 545 return null; 546 } 547 } catch (BuildException be) { 548 return null; 549 } 550 } 551 552 if (file.exists()) { 553 return file; 554 } 555 File ioFile= file.getLocation().toFile(); 556 if (ioFile.exists()) { try { 558 files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(ioFile.getCanonicalPath())); 559 if (files.length > 0) { 560 return files[0]; 561 } 562 } catch (IOException e) { 563 } 564 } 565 566 return null; 567 } 568 569 578 public static void migrateToNewClasspathFormat(ILaunchConfiguration configuration) throws CoreException { 579 String oldClasspath = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_CUSTOM_CLASSPATH, (String )null); 580 String oldAntHome = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_HOME, (String )null); 581 String provider = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, (String )null); 582 if (oldClasspath != null || oldAntHome != null || provider == null) { 583 ILaunchConfigurationWorkingCopy workingCopy = null; 584 if (configuration.isWorkingCopy()) { 585 workingCopy = (ILaunchConfigurationWorkingCopy) configuration; 586 } else { 587 workingCopy = configuration.getWorkingCopy(); 588 } 589 workingCopy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_CUSTOM_CLASSPATH, (String )null); 590 workingCopy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_HOME, (String )null); 591 workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); 593 if (oldAntHome != null) { 594 IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(workingCopy); 595 List mementos = new ArrayList (entries.length); 596 for (int i = 0; i < entries.length; i++) { 597 IRuntimeClasspathEntry entry = entries[i]; 598 if (entry.getType() == IRuntimeClasspathEntry.OTHER) { 599 IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2) entry; 600 if (entry2.getTypeId().equals(AntHomeClasspathEntry.TYPE_ID)) { 601 AntHomeClasspathEntry homeEntry = new AntHomeClasspathEntry(oldAntHome); 602 mementos.add(homeEntry.getMemento()); 603 continue; 604 } 605 } 606 mementos.add(entry.getMemento()); 607 } 608 workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); 609 workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, mementos); 610 } 611 workingCopy.doSave(); 612 } 613 } 614 615 private static int getOffset(int line, int column, ITextEditor editor) { 616 IDocumentProvider provider= editor.getDocumentProvider(); 617 IEditorInput input= editor.getEditorInput(); 618 try { 619 provider.connect(input); 620 } catch (CoreException e) { 621 return -1; 622 } 623 try { 624 IDocument document= provider.getDocument(input); 625 if (document != null) { 626 if (column > -1) { 627 return document.getLineOffset(line - 1) + column - 1 - 2; 629 } 630 return document.getLineOffset(line - 1); 631 } 632 } catch (BadLocationException e) { 633 } finally { 634 provider.disconnect(input); 635 } 636 return -1; 637 } 638 639 646 public static void openInEditor(IWorkbenchPage page, IEditorDescriptor editorDescriptor, AntElementNode node) { 647 IEditorPart editorPart= null; 648 IFile fileResource = node.getIFile(); 649 try { 650 if (editorDescriptor == null) { 651 editorPart= page.openEditor(new FileEditorInput(fileResource), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); 652 } else { 653 editorPart= page.openEditor(new FileEditorInput(fileResource), editorDescriptor.getId()); 654 } 655 } catch (PartInitException e) { 656 AntUIPlugin.log(MessageFormat.format(AntUIModelMessages.AntUtil_0, new String []{fileResource.getLocation().toOSString()}), e); 657 } 658 659 if (editorPart instanceof AntEditor) { 660 AntEditor editor= (AntEditor)editorPart; 661 if (node.getImportNode() != null) { 662 AntModel model= editor.getAntModel(); 663 AntProjectNode project= model.getProjectNode(); 664 if (project == null) { 665 return; 666 } 667 int[] info= node.getExternalInfo(); 668 int offset= getOffset(info[0], info[1], editor); 669 node= project.getNode(offset); 670 } 671 editor.setSelection(node, true); 672 } 673 } 674 675 681 public static void openInEditor(IWorkbenchPage page, AntElementNode node) { 682 IFile file= node.getIFile(); 683 IEditorDescriptor editorDesc; 684 try { 685 editorDesc = IDE.getEditorDescriptor(file); 686 } catch (PartInitException e) { 687 return; 688 } 689 openInEditor(page, editorDesc, node); 690 } 691 692 698 public static void openBrowser(final String urlString, final Shell shell, final String errorDialogTitle) { 699 shell.getDisplay().syncExec(new Runnable () { 700 public void run() { 701 IWorkbenchBrowserSupport support= PlatformUI.getWorkbench().getBrowserSupport(); 702 try { 703 IWebBrowser browser= support.createBrowser(fgBrowserId); 704 fgBrowserId= browser.getId(); 705 browser.openURL(new URL (urlString)); 706 return; 707 } catch (PartInitException e) { 708 AntUIPlugin.log(e.getStatus()); 709 } catch (MalformedURLException e) { 710 AntUIPlugin.log(e); 711 } 712 713 String platform= SWT.getPlatform(); 714 boolean succeeded= true; 715 if ("motif".equals(platform) || "gtk".equals(platform)) { Program program= Program.findProgram("html"); if (program == null) { 718 program= Program.findProgram("htm"); } 720 if (program != null) { 721 succeeded= program.execute(urlString.toString()); 722 } 723 } else { 724 succeeded= Program.launch(urlString.toString()); 725 } 726 if (!succeeded) { 727 MessageDialog.openInformation(shell, errorDialogTitle, AntUIModelMessages.AntUtil_1); 728 } 729 } 730 }); 731 } 732 733 public static boolean isSeparateJREAntBuild(ILaunchConfiguration configuration) { 734 boolean separateJRE= true; 735 try { 736 separateJRE = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String )null) != null; 738 } catch (CoreException e) { 739 AntUIPlugin.log(AntUIModelMessages.AntUtil_2, e); 740 } 741 742 return separateJRE; 743 } 744 745 public static void linkBuildFailedMessage(String message, IProcess process) { 746 String fileName = null; 747 String lineNumber = ""; int fileStart = 0; 749 int index = message.indexOf("xml"); if (index > 0) { 751 int numberStart= index + 4; 752 int numberEnd= message.indexOf(':', numberStart); 753 int fileEnd = index + 3; 754 if (numberStart > 0 && fileEnd > 0) { 755 fileName = message.substring(fileStart, fileEnd).trim(); 756 if (numberEnd > 0) { 757 lineNumber = message.substring(numberStart, numberEnd).trim(); 758 } 759 } 760 } 761 762 if (fileName != null) { 763 int num = -1; 764 try { 765 num = Integer.parseInt(lineNumber); 766 } catch (NumberFormatException e) { 767 } 768 IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileName)); 769 IFile file= null; 770 if (files.length > 0) { 771 file= files[0]; 772 } 773 if (file != null && file.exists()) { 774 FileLink link = new FileLink(file, null, -1, -1, num); 775 TaskLinkManager.addTaskHyperlink(process, link, new Region(0, message.length()), message); 776 } 777 } 778 } 779 } | Popular Tags |