+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- predefined macro values:
- * BOARD - selected board name by UI
- * BUILD_OPTION - selected build option by UI
- * TOOLCHAIN_PATH - user defined toolchain path by UI
--->
-<build name="sidk_s5jt200">
- <!-- path attribute value must be relative path from project root -->
- <!-- Don't touch command name. IDE use command with name -->
- <commands>
- <command name="config linux" command="./configure.sh" path="os/tools" shellcmd="true">
- <param name="buildOption" value="${BOARD}/${BUILD_OPTION}"/>
- </command>
- <command name="build" command="make" path="os" shellcmd="true">
- <param name="V" value="V=1"/>
- </command>
- <command name="buildWithToolchain" command=". ./setenv.sh ${TOOLCHAIN_PATH};cd ..;make V=1" path="os/tools" shellcmd="true" shell="/bin/bash"/>
- <command name="clean" command="make clean" path="os" shellcmd="true">
- <param name="clean" value="clean"/>
- </command>
- </commands>
- <executors> <!-- execute command sequentially on build -->
- <executor name="linux default excutor" os="linux" bit="all">
- <commandref name="config linux"/>
- <commandref name="build"/>
- </executor>
- </executors>
-</build>
package org.tizen.rt.product.meta.util;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
+import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+import org.tizen.rt.product.meta.RtMetaPlugin;
import org.tizen.rt.product.meta.model.build.Build;
import org.tizen.rt.product.meta.model.debug.Debugs;
import org.tizen.rt.product.meta.model.flash.Flash;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
/**
* @since 2017. 5. 18.
*/
public class MetaModelUtil {
+ private enum TYPE {
+ BUILD, FLASH, DEBUG
+ }
+
private MetaModelUtil() {
}
return showModel(Debugs.class, debugModel);
}
+ private static void validate(InputStream xmlFileStream, InputStream xsdFileStream)
+ throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
+ if (xmlFileStream == null) {
+ throw new FileNotFoundException("XML file stream is null"); // $NON-NLS-1
+ } else if (xsdFileStream == null) {
+ throw new FileNotFoundException("XSD file stream is null"); // $NON-NLS-1
+ }
+
+ // parse an XML document into a DOM tree
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = parser.parse(xmlFileStream);
+
+ // create a SchemaFactory capable of understanding WXS schemas
+ SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+
+ // load a WXS schema, represented by a Schema instance
+ Source schemaFile = new StreamSource(xsdFileStream);
+ Schema schema = factory.newSchema(schemaFile);
+
+ // create a Validator instance, which can be used to validate an instance document
+ Validator validator = schema.newValidator();
+
+ // validate the DOM tree
+ try {
+ validator.validate(new DOMSource(document));
+ } catch (SAXException e) {
+ throw e;
+ }
+ }
+
+ private static void validateFile(File xmlFile, TYPE type)
+ throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
+ if (xmlFile == null) {
+ throw new FileNotFoundException("XML file is null"); // $NON-NLS-1
+ }
+
+ FileInputStream xmlFileStream = new FileInputStream(xmlFile);
+
+ try {
+ switch (type) {
+ case BUILD:
+ validateBuildFile(xmlFileStream);
+ break;
+ case FLASH:
+ validateFlashFile(xmlFileStream);
+ break;
+ case DEBUG:
+ validateDebugFile(xmlFileStream);
+ break;
+ default:
+ break;
+ }
+ } catch (SAXException e) {
+ throw e;
+ } finally {
+ if (xmlFileStream != null) {
+ try {
+ xmlFileStream.close();
+ } catch (IOException e) {
+ // Do nothing
+ }
+ }
+ }
+ }
+
+ public static void validateBuildFile(File xmlFile)
+ throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
+ validateFile(xmlFile, TYPE.BUILD);
+ }
+
+ public static void validateFlashFile(File xmlFile)
+ throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
+ validateFile(xmlFile, TYPE.FLASH);
+ }
+
+ public static void validateDebugFile(File xmlFile)
+ throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
+ validateFile(xmlFile, TYPE.DEBUG);
+ }
+
+ public static void validateBuildFile(InputStream xmlFileStream)
+ throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+ InputStream xsdFileStream = RtMetaPlugin.class.getResourceAsStream("resources/buildSpec.xsd"); // $NON-NLS-1
+ validate(xmlFileStream, xsdFileStream);
+ }
+
+ public static void validateFlashFile(InputStream xmlFileStream)
+ throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+ InputStream xsdFileStream = RtMetaPlugin.class.getResourceAsStream("resources/flashSpec.xsd"); // $NON-NLS-1
+ validate(xmlFileStream, xsdFileStream);
+ }
+
+ public static void validateDebugFile(InputStream xmlFileStream)
+ throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+ InputStream xsdFileStream = RtMetaPlugin.class.getResourceAsStream("resources/debugSpec.xsd"); // $NON-NLS-1
+ validate(xmlFileStream, xsdFileStream);
+ }
+
}
*/
package org.tizen.rt.product.meta.model;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
import org.junit.Assert;
import org.junit.Test;
+import org.tizen.rt.product.meta.RtMetaPlugin;
import org.tizen.rt.product.meta.model.build.Build;
import org.tizen.rt.product.meta.model.debug.Debugs;
import org.tizen.rt.product.meta.model.flash.Flash;
import org.tizen.rt.product.meta.util.MetaModelUtil;
+import org.xml.sax.SAXException;
/**
* @since 2017. 5. 18.
@Test
public void buildModelTest() throws JAXBException {
- InputStream is = LoadModelTest.class.getResourceAsStream("buildSpec.xml");
+ InputStream is = RtMetaPlugin.class.getResourceAsStream("resources/buildSpec.xml");
Build model = MetaModelUtil.loadBuildModel(is);
Assert.assertNotNull(model);
@Test
public void flashModelTest() throws JAXBException {
- InputStream is = LoadModelTest.class.getResourceAsStream("flashSpec.xml");
+ InputStream is = RtMetaPlugin.class.getResourceAsStream("resources/flashSpec.xml");
Flash model = MetaModelUtil.loadFlashModel(is);
Assert.assertNotNull(model);
@Test
public void debugModelTest() throws JAXBException {
- InputStream is = LoadModelTest.class.getResourceAsStream("debugSpec.xml");
+ InputStream is = RtMetaPlugin.class.getResourceAsStream("resources/debugSpec.xml");
Debugs model = MetaModelUtil.loadDebugModel(is);
Assert.assertNotNull(model);
System.out.println(result);
}
+ @Test
+ public void validateBuildFile() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+ InputStream xmlFileStream = RtMetaPlugin.class.getResourceAsStream("resources/buildSpec.xml");
+
+ MetaModelUtil.validateBuildFile(xmlFileStream);
+ }
+
+ @Test
+ public void validateFlashFile() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+ InputStream xmlFileStream = RtMetaPlugin.class.getResourceAsStream("resources/flashSpec.xml");
+
+ MetaModelUtil.validateFlashFile(xmlFileStream);
+ }
+
+ @Test
+ public void validateDebugFile() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+ InputStream xmlFileStream = RtMetaPlugin.class.getResourceAsStream("resources/debugSpec.xml");
+
+ MetaModelUtil.validateDebugFile(xmlFileStream);
+ }
+
}