1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Change implementation to save extension form the

CCorePlugin
This commit is contained in:
Alain Magloire 2003-08-31 23:54:38 +00:00
parent 9e854093ca
commit f1966eafe3

View file

@ -13,15 +13,9 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import org.eclipse.cdt.core.resources.ACBuilder; import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.cdt.internal.errorparsers.GASErrorParser;
import org.eclipse.cdt.internal.errorparsers.GCCErrorParser;
import org.eclipse.cdt.internal.errorparsers.GLDErrorParser;
import org.eclipse.cdt.internal.errorparsers.MakeErrorParser;
import org.eclipse.cdt.internal.errorparsers.VCErrorParser;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -31,16 +25,15 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
public class ErrorParserManager extends OutputStream { public class ErrorParserManager extends OutputStream {
private int nOpens;
private static String PREF_ERROR_PARSER = "errorOutputParser"; private int nOpens;
private IProject fProject; private IProject fProject;
private IMarkerGenerator fMarkerGenerator; private IMarkerGenerator fMarkerGenerator;
private Map fFilesInProject; private Map fFilesInProject;
private List fNameConflicts; private List fNameConflicts;
private ArrayList fErrorParsers; private Map fErrorParsers;
private ArrayList fErrors; private ArrayList fErrors;
private Vector fDirectoryStack; private Vector fDirectoryStack;
@ -57,14 +50,26 @@ public class ErrorParserManager extends OutputStream {
} }
public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator) { public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator) {
fProject = project; this(project, markerGenerator, null);
fErrorParsers = new ArrayList();
fMarkerGenerator = markerGenerator;
readPreferences();
initParser();
} }
private void initParser() { public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator, String[] parsersIDs) {
fProject = project;
if (parsersIDs == null) {
fErrorParsers = new HashMap();
readPreferences();
} else {
fErrorParsers = new HashMap(parsersIDs.length);
for (int i = 0; i < parsersIDs.length; i++) {
IErrorParser[] parsers = CCorePlugin.getDefault().getErrorParser(parsersIDs[i]);
fErrorParsers.put(parsersIDs[i], parsers);
}
}
fMarkerGenerator = markerGenerator;
initErrorParserManager();
}
private void initErrorParserManager() {
fFilesInProject = new HashMap(); fFilesInProject = new HashMap();
fNameConflicts = new ArrayList(); fNameConflicts = new ArrayList();
fDirectoryStack = new Vector(); fDirectoryStack = new Vector();
@ -123,57 +128,34 @@ public class ErrorParserManager extends OutputStream {
return fDirectoryStack.size(); return fDirectoryStack.size();
} }
protected void addParser(IErrorParser parser) {
fErrorParsers.add(parser);
}
private void readPreferences() { private void readPreferences() {
fErrorParsers.clear(); fErrorParsers.clear();
String parserNames = CCorePlugin.getDefault().getPluginPreferences().getString(PREF_ERROR_PARSER); String[] parserIDs = CCorePlugin.getDefault().getPreferenceErrorParserIDs();
if (parserNames != null && parserNames.length() > 0) { for (int i = 0; i < parserIDs.length; i++) {
StringTokenizer tok = new StringTokenizer(parserNames, ";"); IErrorParser[] parsers = CCorePlugin.getDefault().getErrorParser(parserIDs[i]);
while (tok.hasMoreElements()) { fErrorParsers.put(parserIDs[i], parsers);
String clName = tok.nextToken();
try {
IErrorParser parser = (IErrorParser) Class.forName(clName).newInstance();
fErrorParsers.add(parser);
}
catch (ClassNotFoundException e) {
// not found
CCorePlugin.log(e);
}
catch (InstantiationException e) {
CCorePlugin.log(e);
}
catch (IllegalAccessException e) {
CCorePlugin.log(e);
}
catch (ClassCastException e) {
CCorePlugin.log(e);
}
}
} }
if (fErrorParsers.size() == 0) { if (fErrorParsers.size() == 0) {
initErrorParsersArray(fErrorParsers); initErrorParsersMap();
}
savePreferences(); savePreferences();
} }
}
private void initErrorParsersArray(List errorParsers) { private void initErrorParsersMap() {
errorParsers.add(new VCErrorParser()); String[] parserIDs = CCorePlugin.getDefault().getAllErrorParsersIDs();
errorParsers.add(new GCCErrorParser()); for (int i = 0; i < parserIDs.length; i++) {
errorParsers.add(new GLDErrorParser()); IErrorParser[] parsers = CCorePlugin.getDefault().getErrorParser(parserIDs[i]);
errorParsers.add(new GASErrorParser()); fErrorParsers.put(parserIDs[i], parsers);
errorParsers.add(new MakeErrorParser()); }
} }
private void savePreferences() { private void savePreferences() {
StringBuffer buf = new StringBuffer(); String[] parserIDs = new String[fErrorParsers.size()];
for (int i = 0; i < fErrorParsers.size(); i++) { Iterator items = fErrorParsers.keySet().iterator();
buf.append(fErrorParsers.get(i).getClass().getName()); for (int i = 0; items.hasNext(); i++) {
buf.append(';'); parserIDs[i] = (String) items.next();
} }
CCorePlugin.getDefault().getPluginPreferences().setValue(PREF_ERROR_PARSER, buf.toString()); CCorePlugin.getDefault().setPreferenceErrorParser(parserIDs);
} }
protected void collectFiles(IContainer parent, List result) { protected void collectFiles(IContainer parent, List result) {
@ -183,13 +165,11 @@ public class ErrorParserManager extends OutputStream {
IResource resource = resources[i]; IResource resource = resources[i];
if (resource instanceof IFile) { if (resource instanceof IFile) {
result.add(resource); result.add(resource);
} } else if (resource instanceof IContainer) {
else if (resource instanceof IContainer) {
collectFiles((IContainer) resource, result); collectFiles((IContainer) resource, result);
} }
} }
} } catch (CoreException e) {
catch (CoreException e) {
CCorePlugin.log(e.getStatus()); CCorePlugin.log(e.getStatus());
} }
} }
@ -198,22 +178,30 @@ public class ErrorParserManager extends OutputStream {
* Parses the input and try to generate error or warning markers * Parses the input and try to generate error or warning markers
*/ */
private void processLine(String line) { private void processLine(String line) {
int top = fErrorParsers.size() - 1; String[] parserIDs = new String[fErrorParsers.size()];
Iterator items = fErrorParsers.keySet().iterator();
for (int i = 0; items.hasNext(); i++) {
parserIDs[i] = (String) items.next();
}
int top = parserIDs.length - 1;
int i = top; int i = top;
do { do {
IErrorParser curr = (IErrorParser) fErrorParsers.get(i); IErrorParser[] parsers = (IErrorParser[]) fErrorParsers.get(parserIDs[i]);
for (int j = 0; j < parsers.length; j++) {
IErrorParser curr = parsers[j];
if (curr.processLine(line, this)) { if (curr.processLine(line, this)) {
if (i != top) { if (i != top) {
// move to top // move to top
Object used = fErrorParsers.remove(i); Object used = fErrorParsers.remove(parserIDs[i]);
fErrorParsers.add(used); fErrorParsers.put(parserIDs[i], used);
savePreferences(); //savePreferences();
} }
return; return;
} }
i--;
} }
while (i >= 0); i--;
} while (i >= 0);
} }
/** /**
@ -242,8 +230,7 @@ public class ErrorParserManager extends OutputStream {
if (fBaseDirectory.isPrefixOf(fp)) { if (fBaseDirectory.isPrefixOf(fp)) {
int segments = fBaseDirectory.matchingFirstSegments(fp); int segments = fBaseDirectory.matchingFirstSegments(fp);
path = fp.removeFirstSegments(segments); path = fp.removeFirstSegments(segments);
} } else {
else {
path = fp; path = fp;
} }
} else { } else {
@ -357,11 +344,9 @@ public class ErrorParserManager extends OutputStream {
public synchronized void write(byte[] b, int off, int len) throws IOException { public synchronized void write(byte[] b, int off, int len) throws IOException {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
} } else if (off != 0 || (len < 0) || (len > b.length)) {
else if (off != 0 || (len < 0) || (len > b.length)) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} } else if (len == 0) {
else if (len == 0) {
return; return;
} }
currentLine.append(new String(b, 0, len)); currentLine.append(new String(b, 0, len));