1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 23:15:24 +02:00

Added a field to the option schema that allows a browse type to be encoded and a new sequence to the option reference with list values

This commit is contained in:
Sean Evoy 2004-04-05 15:28:23 +00:00
parent a0aed1c95c
commit 66c786380a
9 changed files with 137 additions and 36 deletions

View file

@ -221,6 +221,23 @@ Additional special types exist to flag options of special relevance to the build
</documentation>
</annotation>
</attribute>
<attribute name="browseType">
<annotation>
<documentation>
This value is used for list (and related) options only. If you need a list option to prompt the user to browse for a file or directory when adding a new value, set the value of the attribute accordingly. By default the value is treated as no browsing needed.
</documentation>
</annotation>
<simpleType>
<restriction base="string">
<enumeration value="none">
</enumeration>
<enumeration value="file">
</enumeration>
<enumeration value="directory">
</enumeration>
</restriction>
</simpleType>
</attribute>
</complexType>
</element>
@ -323,6 +340,10 @@ Additional special types exist to flag options of special relevance to the build
</documentation>
</annotation>
<complexType>
<sequence>
<element ref="listOptionValue"/>
<element ref="enumeratedOptionValue"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>

View file

@ -23,8 +23,17 @@ public interface IOption extends IBuildObject {
public static final int PREPROCESSOR_SYMBOLS = 5;
public static final int LIBRARIES = 6;
public static final int OBJECTS = 7;
// Browse type
public static final int BROWSE_NONE = 0;
public static final String NONE = "none"; //$NON-NLS-1$
public static final int BROWSE_FILE = 1;
public static final String FILE = "file"; //$NON-NLS-1$
public static final int BROWSE_DIR = 2;
public static final String DIR = "directory"; //$NON-NLS-1$
// Schema attribute names for option elements
public static final String BROSWE_TYPE = "browseType"; //$NON-NLS-1$
public static final String CATEGORY = "category"; //$NON-NLS-1$
public static final String COMMAND = "command"; //$NON-NLS-1$
public static final String COMMAND_FALSE = "commandFalse"; //$NON-NLS-1$
@ -64,6 +73,11 @@ public interface IOption extends IBuildObject {
*/
public boolean getBooleanValue() throws BuildException;
/**
* @return
*/
public int getBrowseType();
/**
* Answers an array of strings containing the built-in values
* defined for a stringList, includePaths, definedSymbols, or libs

View file

@ -12,8 +12,8 @@ package org.eclipse.cdt.managedbuilder.core;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -23,12 +23,17 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xml.serialize.Method;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
@ -297,37 +302,61 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
*/
public static void saveBuildInfo(IProject project, boolean force) {
// Create document
Document doc = new DocumentImpl();
Element rootElement = doc.createElement(ROOT_ELEM_NAME);
doc.appendChild(rootElement);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element rootElement = doc.createElement(ROOT_ELEM_NAME);
doc.appendChild(rootElement);
// Save the build info
ManagedBuildInfo buildInfo = (ManagedBuildInfo) getBuildInfo(project);
if (buildInfo != null && (force == true || buildInfo.isDirty())) {
buildInfo.serialize(doc, rootElement);
// Save the build info
ManagedBuildInfo buildInfo = (ManagedBuildInfo) getBuildInfo(project);
if (buildInfo != null && (force == true || buildInfo.isDirty())) {
buildInfo.serialize(doc, rootElement);
// Save the document
ByteArrayOutputStream s = new ByteArrayOutputStream();
OutputFormat format = new OutputFormat();
format.setIndenting(true);
format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
String xml = null;
try {
Serializer serializer
= SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(s, "UTF8"), format); //$NON-NLS-1$
serializer.asDOMSerializer().serialize(doc);
xml = s.toString("UTF8"); //$NON-NLS-1$
IFile rscFile = project.getFile(FILE_NAME);
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
// update the resource content
if (rscFile.exists()) {
rscFile.setContents(inputStream, IResource.FORCE, null);
// Transform the document to something we can save in a file
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(stream);
transformer.transform(source, result);
// Save the document
IFile projectFile = project.getFile(FILE_NAME);
InputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
if (projectFile.exists()) {
projectFile.setContents(inputStream, IResource.FORCE, null);
} else {
rscFile.create(inputStream, IResource.FORCE, null);
projectFile.create(inputStream, IResource.FORCE, null);
}
} catch (Exception e) {
return;
// Close the streams
stream.close();
inputStream.close();
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TransformerFactoryConfigurationError e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// The save failed
e.printStackTrace();
} catch (CoreException e) {
// Save to IFile failed
e.printStackTrace();
}
}
@ -411,7 +440,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
throw new BuildException(ManagedBuilderCorePlugin.getResourceString("ManagedBuildManager.error.owner_not_project")); //$NON-NLS-1$
}
// Passed validation
// Passed validation so create the target.
return new Target(resource, parentTarget);
}

View file

@ -28,7 +28,7 @@ import org.eclipse.core.runtime.Plugin;
public class ManagedCProjectNature implements IProjectNature {
public static final String BUILDER_NAME = "genmakebuilder"; //$NON-NLS-1$
public static final String BUILDER_ID = ManagedBuilderCorePlugin.getUniqueIdentifier() + "." + BUILDER_NAME; //$NON-NLS-1$
private static final String MNG_NATURE_ID = ManagedBuilderCorePlugin.getUniqueIdentifier() + ".managedBuildNature"; //$NON-NLS-1$
public static final String MNG_NATURE_ID = ManagedBuilderCorePlugin.getUniqueIdentifier() + ".managedBuildNature"; //$NON-NLS-1$
private IProject project;
/**

View file

@ -94,12 +94,16 @@ public class GeneratedMakefileBuilder extends ACBuilder {
*/
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
String statusMsg = ManagedBuilderCorePlugin.getFormattedString(START, getProject().getName());
IProject[] deps = getProject().getReferencedProjects();
if (statusMsg != null) {
monitor.subTask(statusMsg);
}
// Get the build information
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
if (info == null) {
return deps;
}
if (kind == IncrementalProjectBuilder.FULL_BUILD || info.isDirty()) {
fullBuild(monitor, info);
@ -124,7 +128,6 @@ public class GeneratedMakefileBuilder extends ACBuilder {
// Scrub the build info of all the projects participating in the build
info.setDirty(false);
IProject[] deps = getProject().getReferencedProjects();
for (int i = 0; i < deps.length; i++) {
IProject project = deps[i];
IManagedBuildInfo depInfo = ManagedBuildManager.getBuildInfo(project);

View file

@ -110,6 +110,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
public void addTarget(ITarget target) {
getTargetMap().put(target.getId(), target);
getTargets().add(target);
setDirty(true);
}
/* (non-Javadoc)

View file

@ -30,6 +30,7 @@ public class Option extends BuildObject implements IOption {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
// Private bookeeping attributes
private int browseType;
private List builtIns;
private IOptionCategory category;
private String command;
@ -136,6 +137,17 @@ public class Option extends BuildObject implements IOption {
default :
break;
}
// Determine if there needs to be a browse button
String browseTypeStr = element.getAttribute(BROSWE_TYPE);
if (browseTypeStr == null || browseTypeStr.equals(NONE)) {
browseType = BROWSE_NONE;
} else if (browseTypeStr.equals(FILE)) {
browseType = BROWSE_FILE;
} else if (browseTypeStr.equals(DIR)) {
browseType = BROWSE_DIR;
}
}
public void resolveReferences() {
@ -164,6 +176,13 @@ public class Option extends BuildObject implements IOption {
return bool.booleanValue();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseType()
*/
public int getBrowseType() {
return browseType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getBuiltIns()
*/

View file

@ -335,6 +335,13 @@ public class OptionReference implements IOption {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseType()
*/
public int getBrowseType() {
return option.getBrowseType();
}
private List getBuiltInList() {
if (builtIns == null) {
builtIns = new ArrayList();

View file

@ -87,7 +87,7 @@ public class Target extends BuildObject implements ITarget {
}
setId(owner.getName() + "." + parent.getId() + "." + id); //$NON-NLS-1$ //$NON-NLS-2$
setName(parent.getName());
this.artifactName = parent.getArtifactName();
setArtifactName(parent.getArtifactName());
this.binaryParserId = parent.getBinaryParserId();
this.defaultExtension = parent.getArtifactExtension();
this.isTest = parent.isTestTarget();
@ -226,6 +226,9 @@ public class Target extends BuildObject implements ITarget {
}
}
/**
*
*/
public void resolveReferences() {
if (!resolved) {
resolved = true;
@ -282,6 +285,10 @@ public class Target extends BuildObject implements ITarget {
* @see org.eclipse.cdt.managedbuilder.core.ITarget#resetMakeCommand()
*/
public void resetMakeCommand() {
// Flag target as dirty if the reset actually changes something
if (makeCommand != null) {
setDirty(true);
}
makeCommand = null;
makeArguments = null;
}