Last active
April 21, 2017 04:11
-
-
Save chrishantha/18cb0dbdef29539d63f7 to your computer and use it in GitHub Desktop.
CompareEclipseProfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.TreeSet; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import javax.xml.parsers.ParserConfigurationException; | |
import org.w3c.dom.Document; | |
import org.w3c.dom.Element; | |
import org.w3c.dom.Node; | |
import org.w3c.dom.NodeList; | |
import org.xml.sax.SAXException; | |
public class CompareEclipseProfile { | |
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException { | |
if (args.length != 2) { | |
System.err.println("Please provide two eclipse profile XML files"); | |
} | |
String file1 = args[0]; | |
String file2 = args[1]; | |
Map<String, String> formatterProfileMap1 = getSettings(getXMLDocument(file1)); | |
Map<String, String> formatterProfileMap2 = getSettings(getXMLDocument(file2)); | |
Set<String> settingIDsIn1 = new TreeSet<String>(formatterProfileMap1.keySet()); | |
Set<String> settingIDsIn2 = new TreeSet<String>(formatterProfileMap2.keySet()); | |
Set<String> commonKeys = new TreeSet<String>(settingIDsIn1); | |
commonKeys.retainAll(settingIDsIn2); | |
System.out.println("Diff"); | |
for (String string : commonKeys) { | |
// System.out.println(string); | |
String value1 = formatterProfileMap1.get(string); | |
String value2 = formatterProfileMap2.get(string); | |
if (value1.equals(value2)) { | |
// System.out.println("Values are equal"); | |
} else { | |
System.out.format("%s='%s' -> '%s'%n", string, value1, value2); | |
} | |
} | |
} | |
private static Document getXMLDocument(String path) throws SAXException, IOException, ParserConfigurationException { | |
File fXmlFile = new File(path); | |
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | |
Document doc = dBuilder.parse(fXmlFile); | |
doc.getDocumentElement().normalize(); | |
return doc; | |
} | |
private static Map<String, String> getSettings(Document formatterProfile) { | |
Map<String, String> settingsMap = new HashMap<String, String>(); | |
NodeList nList = formatterProfile.getElementsByTagName("setting"); | |
for (int temp = 0; temp < nList.getLength(); temp++) { | |
Node nNode = nList.item(temp); | |
if (nNode.getNodeType() == Node.ELEMENT_NODE) { | |
Element eElement = (Element) nNode; | |
String id = eElement.getAttribute("id"); | |
String value = eElement.getAttribute("value"); | |
settingsMap.put(id, value); | |
} | |
} | |
return settingsMap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
java CompareEclipseProfile ~/Desktop/WSO2_Eclipse_Code_Formatter.xml ~/Desktop/WSO2_Eclipse_Code_Formatter-New.xml