Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Problems Creating a New Language Settings Provider

Hi

I'm creating a new language settings provider that extends:

org.eclipse.cdt.core.LanguageSettingsProvider

It is an ICBuildOutputParser, which reads settings from an XML file after the build inside the "shutdown" method.

The new settings, however, only appear in the UI (Project -> Properties -> Preprocessor Include Paths,
 Macros, Etc. -> Entries Tab -> GNU C) under certain conditions, such as:

1) Moving the new provider to first place in the list
2) Deleting other providers
3) Debugging with breakpoints inside the post-build storing of settings (race condition?).

Attached is a sample provider that reproduces the problem. It works fine without the one-second sleep before
the call to "super.loadEntries" The real provider, though, does quite a bit of work inside the shutdown method
It also works fine if it is moved to first place.

Here is the extension XML:

      <provider
            class="org.eclipse.ptp.internal.rdt.sync.cdt.core.SampleBuildOutputParser"
            id="org.eclipse.ptp.rdt.sync.core.SampleBuildOutputParser"
            name="Sample Build Output Parser"
            prefer-non-shared="true">
      </provider>

Are there other commands I should be running? I have also tried:

serializeLanguageSettings(configDesc);
serializeLanguageSettingsInBackground(configDesc);

after the load but without success.

Please let me know if you have some suggestions. Do you think there is something wrong with my
implementation or that this is a bug in CDT?


Thanks
John Eblen
Eclipse PTP Developer

package org.eclipse.ptp.internal.rdt.sync.cdt.core;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.cdt.core.language.settings.providers.ICBuildOutputParser;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider;
import org.eclipse.cdt.core.language.settings.providers.IWorkingDirectoryTracker;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.core.runtime.CoreException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class SampleBuildOutputParser extends LanguageSettingsSerializableProvider implements ICBuildOutputParser, ILanguageSettingsEditableProvider {
	@Override
	public SampleBuildOutputParser clone() throws CloneNotSupportedException {
		return (SampleBuildOutputParser) super.clone();
	}

	@Override
	public SampleBuildOutputParser cloneShallow() throws CloneNotSupportedException {
		return (SampleBuildOutputParser) super.cloneShallow();
	}

	@Override
	public void startup(ICConfigurationDescription cfgDescription, IWorkingDirectoryTracker cwdTracker) throws CoreException {
	}

	@Override
	public boolean processLine(String line) {
		return false;
	}

	@Override
	public void shutdown() {
		super.clear();

		// Create a sample XML input stream
		String sampleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" //$NON-NLS-1$
				             + "<provider>" //$NON-NLS-1$
				             +     "<language id=\"org.eclipse.cdt.core.gcc\">" //$NON-NLS-1$
				             +         "<entry kind=\"macro\" name=\"__SAMPLE_VAR__\" value=\"1\">" //$NON-NLS-1$
				             +             "<flag value=\"BUILTIN|READONLY\"/>" //$NON-NLS-1$
				             +         "</entry>" //$NON-NLS-1$
				             +     "</language>" //$NON-NLS-1$
				             + "</provider>"; //$NON-NLS-1$
		InputStream sampleXMLStream = null;
		try {
			sampleXMLStream = new ByteArrayInputStream(sampleXML.getBytes("UTF-8")); //$NON-NLS-1$
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}

		// Parse XML
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder;
		try {
			builder = factory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			// Should never happen since no configuring was done
			throw new RuntimeException(e); 
		}
		Document doc = null;
		try {
			doc = builder.parse(sampleXMLStream);
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		// Sleep to reproduce bug
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		// Load as a new macro entry
		super.loadEntries(doc.getDocumentElement());
	}
}

Back to the top