Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.ant.internal.ui.launchConfigurations;
 
 
 import java.util.List;
 import java.util.Map;
 
Manages task links per process. As messages are logged to the console from build events, hyperlinks are created to link task names to the associated ant buildfile. The build logger registers a task hyperlink with this manager for each build event associated with a task. When the associated line is later appended to the console, the corresponding text region in the console document is determined (as the length of a console document can not be determined beforehand), and the hyperlink is added to the document. The new line is added to the console, information from that line may be stored to process future incoming tasks hyperlinks.
 
 public class TaskLinkManager {

A map of processes to lists of queued task hyperlink entries
 
 	private static Map fgProcessToLinks;

A map of processes to lists of queued new line regions
 
 	private static Map fgProcessToNewLines;
 	
 	private static List fgAntBuilds;
 	
 	private static class HyperlinkEntry {
 		private IHyperlink fLink;
 		private IRegion fRegion;
 		private String fMessage;
 		
 		public HyperlinkEntry(IHyperlink linkIRegion regionString message) {
 			 = link;
 			 = region;	
 			 = message;
 		}
 		
 		public IRegion getRegion() {
 			return ;
 		}
 		
 		public IHyperlink getLink() {
 			return ;
 		}
 		
 		public String getMessage() {
 			return ;
 		}
 	}
 	
 	private static class LineEntry {
 		private IConsole fConsole;
 		private IRegion fRegion;
 	
 		public LineEntry(IConsole consoleIRegion region) {
 			 = console;
 			 = region;	
 		}
 	
 		public IRegion getRegion() {
 			return ;
 		}
 	
 		public IConsole getConsole() {
 			return ;
 		}
 	}

Not to be called.
 
 	private TaskLinkManager() {
		super();
	}

Registers a hyperlink for the given process and task name. The given region is relative to the beginning of the line (not the document).

Parameters:
process the process associated with the link
link the link for the process
region The region within the line
message The message related to the link
	public static synchronized void addTaskHyperlink(IProcess processIHyperlink linkIRegion regionString message) {
		if ( != null) {
			List newLines = (List).get(process);
			if (newLines != null) {
				for (int index= 0; index < newLines.size(); index++) {
					LineEntry newLine = (LineEntrynewLines.get(index);
					if (addLink(newLine.getConsole(), linknewLine.getRegion(), regionmessage)) {
						newLines.subList(0, index + 1).clear();
						return;
					}
				}
			}
		}
		if ( == null) {
		}
		List links = (List).get(process);
		if (links == null) {
			links = new ArrayList(10);
			.put(processlinks);
		}
		links.add(new HyperlinkEntry(linkregionmessage));
	}
	private static boolean addLink(IConsole consoleIHyperlink linkIRegion lineRegionIRegion regionString message) {
		int length = region.getLength();
		String text;
		try {
			text = console.getDocument().get(lineRegion.getOffset(), lineRegion.getLength());
catch (BadLocationException e) {
			return false;
		}
		if (text.trim().equals(message)) {
			int offset = lineRegion.getOffset() + region.getOffset();
			console.addLink(linkoffsetlength);
			return true;
		}
		return false;
	}

A new line has been added to the given console. Adds any task hyperlink associated with the line, to the console. The new line may be stored to process future incoming tasks hyperlinks.

Parameters:
console
newLine
	public static synchronized void processNewLine(IConsole consoleIRegion newLine) {
		IProcess process = console.getProcess();
		if ( != null && .contains(process)) {
			if (linkBuildFileMessage(consolenewLine)) {
				return;
			}
		}
		if ( == null) {
			addNewLine(consolenewLineprocess);
			return;
		}
		List links = (List).get(process);
		if (links == null) {
			addNewLine(consolenewLineprocess);
			return;
		}
		for (int index= 0; index < links.size(); index++) {
			HyperlinkEntry link = (HyperlinkEntrylinks.get(index);
			if (addLink(consolelink.getLink(), newLinelink.getRegion(), link.getMessage())) {
				links.subList(0, index + 1).clear();
				return;
			}
		}
	}
	private static void addNewLine(IConsole consoleIRegion newLineIProcess process) {
		if ( == null) {
		}
		List newLines = (List).get(process);
		if (newLines == null) {
			newLinesnew ArrayList();
		}
		newLines.add(new LineEntry(consolenewLine));
		.put(processnewLines);
	}

Disposes any information stored for the given process.

Parameters:
process
	public static void dispose(IProcess process) {
		if ( != null) {
		}
		if ( != null) {
		}
		if ( != null) {
		}
	}

Registers the specified process as an Ant build process. Allows for the generation of the "Buildfile: somefile" link in the Ant output.

Parameters:
process
	public static synchronized void registerAntBuild(IProcess process) {
		if ( != null) {
			List newLines = (List).get(process);
			if (newLines != null) {
				for (Iterator iter = newLines.iterator(); iter.hasNext();) {
					LineEntry newLine = (LineEntryiter.next();
					if (linkBuildFileMessage(newLine.getConsole(), newLine.getRegion())){
						iter.remove();
						return;
					}
				}
			}
		}
		if ( == null) {
		}
		.add(process);
	}
	private static boolean linkBuildFileMessage(IConsole consoleIRegion region) {
		String message""//$NON-NLS-1$
		int offsetregion.getOffset();
		try {
			message = console.getDocument().get(offsetregion.getLength());
catch (BadLocationException e) {
		}
		if (message.startsWith("Buildfile:")) { //$NON-NLS-1$
			String fileName = message.substring(10).trim();
			IFile file = AntUtil.getFileForLocation(fileNamenull);
			if (file != null) {
				FileLink link = new FileLink(filenull,  -1, -1, -1);
				console.addLink(linkoffset + 11, fileName.length());
				return true;
			}
		}
		return false;
	}
New to GrepCode? Check out our FAQ X