Commit b7ac611e authored by Michael Schwarz's avatar Michael Schwarz

Update buildfile to reflect number of expected conflicts

parent 9b418e3c
package de.tum.in.www2.cupplugin.views;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
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.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
public class BuildfileUpdater {
public static void updateExpectedConflicts(IProject project,int number) throws ParserConfigurationException, SAXException, IOException, CoreException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError{
boolean modified = false;
Path path = new Path("build.xml");
IFile file = project.getFile(path);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file.getContents());
if(doc.getElementsByTagName("cup").getLength() != 1){
//TODO: error
}
else {
Node n = doc.getElementsByTagName("cup").item(0);
Node expect = n.getAttributes().getNamedItem("expect");
if(expect == null){
Attr expectedA = doc.createAttribute("expect");
n.getAttributes().setNamedItem(expectedA);
expect = n.getAttributes().getNamedItem("expect");
expect.setTextContent(String.valueOf(number));
modified = true;
}
else if(!expect.getTextContent().equals(String.valueOf(number))){
expect.setTextContent(String.valueOf(number));
modified = true;
}
}
if(modified){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new DOMSource(doc);
Result outputTarget = new StreamResult(outputStream);
TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
file.setContents(is,true,true,null);
is.close();
}
}
}
package de.tum.in.www2.cupplugin.views;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.SWT;
......@@ -26,6 +34,8 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IFileEditorInput;
import org.xml.sax.SAXException;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictResolutionManager;
......@@ -124,7 +134,7 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
public CupConflictsView(Composite realParent, Jumper jumper,CupTextEditor editor) {
super(realParent);
Composite parent = getMain();
this.editor = editor;
......@@ -200,7 +210,23 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
refreshScrolledLayout();
}
private void updateBuildfile(){
//DEBUG
try {
IFileEditorInput input = (IFileEditorInput)editor.getEditorInput();
IFile file = input.getFile();
IProject project = file.getProject();
BuildfileUpdater.updateExpectedConflicts(project,42);
} catch (ParserConfigurationException | SAXException | IOException | CoreException | TransformerException
| TransformerFactoryConfigurationError e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private void updateConflicts(ConflictResolutionManager crm) {
updateBuildfile();
ignoreRRAfterLine = computeIgnoreRRAfter();
List<Conflict> conflicts = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment