RTSDK : Added Meta manager for meta model handling
authordaeryong.park <bdragon.park@samsung.com>
Mon, 29 May 2017 05:59:52 +0000 (14:59 +0900)
committerdaeryong.park <bdragon.park@samsung.com>
Mon, 29 May 2017 05:59:52 +0000 (14:59 +0900)
- Added Meta manager for meta model handling
- Added exception classes for meta model handling

Change-Id: If1476bae9c966de138194699813ce0e0f64f52ec
Signed-off-by: daeryong.park <bdragon.park@samsung.com>
rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/util/MetaModelUtil.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/Messages.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/BuildInfoHandlingException.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/InvalidMetaException.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/MetaLoadException.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/MetaNotFoundException.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/BuildInfo.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/BuildInfoManager.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/IMetaConstants.java [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/MetaManager.java [new file with mode: 0644]

index 32af49b..a59a2bc 100755 (executable)
@@ -59,7 +59,7 @@ import org.xml.sax.SAXException;
  */
 public class MetaModelUtil {
 
-    private enum TYPE {
+    public enum MODEL_TYPE {
         BUILD, FLASH, DEBUG
     }
 
@@ -81,12 +81,12 @@ public class MetaModelUtil {
     }
 
     private static <T> String showModel(Class<T> clazz, T model) throws JAXBException {
-        String result = "";
+        String result = ""; //$NON-NLS-1$
         StringWriter writer = new StringWriter();
 
         JAXBContext context = JAXBContext.newInstance(clazz);
         Marshaller marshaller = context.createMarshaller();
-        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
         marshaller.marshal(model, writer);
 
@@ -186,9 +186,9 @@ public class MetaModelUtil {
     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
+            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
+            throw new FileNotFoundException("XSD file stream is null"); //$NON-NLS-1$
         }
 
         // parse an XML document into a DOM tree
@@ -213,10 +213,10 @@ public class MetaModelUtil {
         }
     }
 
-    private static void validateFile(File xmlFile, TYPE type)
+    private static void validateFile(File xmlFile, MODEL_TYPE type)
             throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
         if (xmlFile == null) {
-            throw new FileNotFoundException("XML file is null"); // $NON-NLS-1
+            throw new FileNotFoundException("XML file is null"); //$NON-NLS-1$
         }
 
         FileInputStream xmlFileStream = new FileInputStream(xmlFile);
@@ -250,34 +250,34 @@ public class MetaModelUtil {
 
     public static void validateBuildFile(File xmlFile)
             throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
-        validateFile(xmlFile, TYPE.BUILD);
+        validateFile(xmlFile, MODEL_TYPE.BUILD);
     }
 
     public static void validateFlashFile(File xmlFile)
             throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
-        validateFile(xmlFile, TYPE.FLASH);
+        validateFile(xmlFile, MODEL_TYPE.FLASH);
     }
 
     public static void validateDebugFile(File xmlFile)
             throws ParserConfigurationException, SAXException, IOException, FileNotFoundException {
-        validateFile(xmlFile, TYPE.DEBUG);
+        validateFile(xmlFile, MODEL_TYPE.DEBUG);
     }
 
     public static void validateBuildFile(InputStream xmlFileStream)
             throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
-        InputStream xsdFileStream = RtMetaPlugin.class.getResourceAsStream("resources/buildSpec.xsd"); // $NON-NLS-1
+        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
+        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
+        InputStream xsdFileStream = RtMetaPlugin.class.getResourceAsStream("resources/debugSpec.xsd"); //$NON-NLS-1$
         validate(xmlFileStream, xsdFileStream);
     }
 
index 4217f53..7861101 100644 (file)
@@ -71,7 +71,6 @@ public class Messages extends NLS {
     public static String FlashHandler_NotFoundBuildInfo;
 
     public static String LaunchShortcut_NotFoundBuildInfo;
-    public static String RtosBuildDialogPage_text_text;
     public static String RtosBuildDialogPage_lblNewLabel_text;
     public static String RtosBuildDialogPage_clearToolchainBtn_text;
 
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/BuildInfoHandlingException.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/BuildInfoHandlingException.java
new file mode 100644 (file)
index 0000000..bdc6d1c
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.exception;
+
+import java.io.IOException;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class BuildInfoHandlingException extends IOException {
+
+    private static final long serialVersionUID = 4277509341861974292L;
+
+    /**
+     * @param s
+     */
+    public BuildInfoHandlingException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public BuildInfoHandlingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * @param cause
+     */
+    public BuildInfoHandlingException(Throwable cause) {
+        super(cause);
+    }
+
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/InvalidMetaException.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/InvalidMetaException.java
new file mode 100644 (file)
index 0000000..0d2d882
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.exception;
+
+import java.io.IOException;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class InvalidMetaException extends IOException {
+
+    private static final long serialVersionUID = 34677379758428719L;
+
+    /**
+     * @param message
+     */
+    public InvalidMetaException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public InvalidMetaException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * @param cause
+     */
+    public InvalidMetaException(Throwable cause) {
+        super(cause);
+    }
+
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/MetaLoadException.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/MetaLoadException.java
new file mode 100644 (file)
index 0000000..845ec4e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.exception;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class MetaLoadException extends Exception {
+
+    private static final long serialVersionUID = 689045893522768028L;
+
+    /**
+     * @param message
+     */
+    public MetaLoadException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public MetaLoadException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * @param cause
+     */
+    public MetaLoadException(Throwable cause) {
+        super(cause);
+    }
+
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/MetaNotFoundException.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/exception/MetaNotFoundException.java
new file mode 100644 (file)
index 0000000..b9911e3
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.exception;
+
+import java.io.IOException;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class MetaNotFoundException extends IOException {
+
+    private static final long serialVersionUID = 246309877270245992L;
+
+    /**
+     * @param message
+     */
+    public MetaNotFoundException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public MetaNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * @param cause
+     */
+    public MetaNotFoundException(Throwable cause) {
+        super(cause);
+    }
+
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/BuildInfo.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/BuildInfo.java
new file mode 100644 (file)
index 0000000..449e5a8
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.meta;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class BuildInfo {
+
+    private String board;
+    private String option;
+
+    /**
+     * @param board built board's name
+     * @param option build board's build option
+     */
+    public BuildInfo(String board, String option) {
+        this.board = board;
+        this.option = option;
+    }
+
+    /**
+     * @return the board name
+     */
+    public String getBoard() {
+        return board;
+    }
+
+    /**
+     * @return the built option
+     */
+    public String getOption() {
+        return option;
+    }
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/BuildInfoManager.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/BuildInfoManager.java
new file mode 100644 (file)
index 0000000..ea80914
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.meta;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IProject;
+import org.tizen.rt.ide.exception.BuildInfoHandlingException;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class BuildInfoManager implements IMetaConstants {
+
+    private BuildInfoManager() {
+    }
+
+    /**
+     * @return BuildInfo instance
+     * @throws BuildInfoHandlingException
+     */
+    public static BuildInfo loadBuildInfo(IProject project) throws BuildInfoHandlingException {
+        if (project == null) {
+            throw new BuildInfoHandlingException("Project is null"); //$NON-NLS-1$
+        }
+        String outputPath = project.getLocation().toString() + File.separator + PATH_BUILD_OUTPUT;
+        File file = new File(outputPath, FILE_NAME_BUILD_INFO);
+        if (file == null || !file.exists()) {
+            throw new BuildInfoHandlingException("build.info file not exist : " + outputPath); //$NON-NLS-1$
+        }
+
+        Properties props = new Properties();
+        Reader reader = null;
+
+        try {
+            reader = new FileReader(file);
+            props.load(reader);
+        } catch (IOException e) {
+            throw new BuildInfoHandlingException(e);
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    // Do nothing
+                }
+            }
+        }
+
+        String board = props.getProperty(PROP_NAME_BOARD);
+        String option = props.getProperty(PROP_NAME_OPTION);
+        BuildInfo buildInfo = new BuildInfo(board, option);
+
+        return buildInfo;
+    }
+
+    /**
+     * @param project Project to save the build.info file
+     * @param buildInfo BuildInfo instance containing the build information to write to the build.info file
+     * @throws BuildInfoHandlingException
+     */
+    public static void saveBuildInfo(IProject project, BuildInfo buildInfo) throws BuildInfoHandlingException {
+        if (buildInfo == null) {
+            throw new BuildInfoHandlingException("buildInfo is null"); //$NON-NLS-1$
+        }
+        saveBuildInfo(project, buildInfo.getBoard(), buildInfo.getOption());
+    }
+
+    /**
+     * @param project Project to save the build.info file
+     * @param board The name of the built board to write to the build.info file
+     * @param option The name of the built option to write to the build.info file
+     * @throws BuildInfoHandlingException
+     */
+    public static void saveBuildInfo(IProject project, String board, String option) throws BuildInfoHandlingException {
+        if (project == null) {
+            throw new BuildInfoHandlingException("Project is null"); //$NON-NLS-1$
+        }
+
+        String outputPath = project.getLocation().toString() + File.separator + PATH_BUILD_OUTPUT;
+        File file = new File(outputPath, FILE_NAME_BUILD_INFO);
+        if (file == null || !file.exists()) {
+            throw new BuildInfoHandlingException("build.info file not exist : " + outputPath); //$NON-NLS-1$
+        }
+
+        Properties buildInfo = new Properties();
+        buildInfo.setProperty(PROP_NAME_BOARD, board);
+        buildInfo.setProperty(PROP_NAME_OPTION, option);
+
+        FileWriter writer = null;
+        try {
+            writer = new FileWriter(file);
+            buildInfo.store(writer, PROP_COMMENT_BUILD_INFO);
+        } catch (IOException e) {
+            throw new BuildInfoHandlingException(e);
+        } finally {
+            if (writer != null) {
+                try {
+                    writer.close();
+                } catch (IOException e) {
+                    // Do nothing
+                }
+            }
+        }
+    }
+
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/IMetaConstants.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/IMetaConstants.java
new file mode 100644 (file)
index 0000000..03975e4
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.meta;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public interface IMetaConstants {
+
+    public String FILE_NAME_BUILD_INFO = "build.info"; //$NON-NLS-1$
+    public String PATH_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$
+    public String PATH_BUILD_CONFIGS = "build/configs"; //$NON-NLS-1$
+
+    public String PROP_NAME_BOARD = "board"; //$NON-NLS-1$
+    public String PROP_NAME_OPTION = "option"; //$NON-NLS-1$
+    public String PROP_COMMENT_BUILD_INFO = "Tizen RT build information"; //$NON-NLS-1$
+
+    public String FILE_NAME_BUILD_META_XML = "buildSpec.xml"; //$NON-NLS-1$
+    public String FILE_NAME_FLASH_META_XML = "flashSpec.xml"; //$NON-NLS-1$
+    public String FILE_NAME_DEBUG_META_XML = "debugSpec.xml"; //$NON-NLS-1$
+
+    public String FILE_NAME_BUILD_META_XSD = "buildSpec.xsd"; //$NON-NLS-1$
+    public String FILE_NAME_FLASH_META_XSD = "flashSpec.xsd"; //$NON-NLS-1$
+    public String FILE_NAME_DEBUG_META_XSD = "debugSpec.xsd"; //$NON-NLS-1$
+
+}
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/MetaManager.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/MetaManager.java
new file mode 100644 (file)
index 0000000..5091e11
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Daeryong Park <bdragon.park@samsung.com>
+ * Hyeongseok Heo <harry.heo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd.
+ *
+ */
+package org.tizen.rt.ide.meta;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBException;
+
+import org.eclipse.core.resources.IProject;
+import org.tizen.rt.ide.exception.InvalidMetaException;
+import org.tizen.rt.ide.exception.MetaLoadException;
+import org.tizen.rt.ide.exception.MetaNotFoundException;
+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.tizen.rt.product.meta.util.MetaModelUtil.MODEL_TYPE;
+import org.xml.sax.SAXException;
+
+/**
+ * @since 2017. 5. 25.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public class MetaManager implements IMetaConstants {
+
+    private MetaManager() {
+    }
+
+    public static Build loadBuildMeta(IProject project, String board)
+            throws MetaNotFoundException, InvalidMetaException, MetaLoadException {
+        // buildSpec.xml file load
+        File metaFile = getMetaFile(project, board, FILE_NAME_BUILD_META_XML);
+
+        // schema validation
+        validateMetaFile(MetaModelUtil.MODEL_TYPE.BUILD, metaFile);
+
+        try {
+            // buildSpec.xml model load
+            Build model = MetaModelUtil.loadBuildModel(metaFile);
+            return model;
+        } catch (JAXBException e) {
+            throw new MetaLoadException(e);
+        }
+    }
+
+    public static Flash loadFlashMeta(IProject project, String board)
+            throws MetaNotFoundException, InvalidMetaException, MetaLoadException {
+        // flashSpec.xml file load
+        File metaFile = getMetaFile(project, board, FILE_NAME_FLASH_META_XML);
+
+        // schema validation
+        validateMetaFile(MetaModelUtil.MODEL_TYPE.FLASH, metaFile);
+
+        try {
+            // flashSpec.xml model load
+            Flash model = MetaModelUtil.loadFlashModel(metaFile);
+            return model;
+        } catch (JAXBException e) {
+            throw new MetaLoadException(e);
+        }
+    }
+
+    public static Debugs loadDebugMeta(IProject project, String board)
+            throws MetaNotFoundException, InvalidMetaException, MetaLoadException {
+        // debugSpec.xml file load
+        File metaFile = getMetaFile(project, board, FILE_NAME_DEBUG_META_XML);
+
+        // schema validation
+        validateMetaFile(MetaModelUtil.MODEL_TYPE.DEBUG, metaFile);
+
+        try {
+            // debugSpec.xml model load
+            Debugs model = MetaModelUtil.loadDebugModel(metaFile);
+            return model;
+        } catch (JAXBException e) {
+            throw new MetaLoadException(e);
+        }
+    }
+
+    private static File getMetaFile(IProject project, String board, String metaFileName) throws MetaNotFoundException {
+        String configPath = project.getLocation().toString() + File.separator + PATH_BUILD_CONFIGS;
+        File metaFile = new File(configPath, board + File.separator + metaFileName);
+        if (metaFile == null || !metaFile.exists()) {
+            throw new MetaNotFoundException(metaFileName + " file not exist : " + metaFile.toString()); //$NON-NLS-1$
+        }
+        return metaFile;
+    }
+
+    private static void validateMetaFile(MODEL_TYPE type, File metaFile)
+            throws InvalidMetaException, MetaLoadException {
+        try {
+            switch (type) {
+            case BUILD:
+                MetaModelUtil.validateBuildFile(metaFile);
+                break;
+            case FLASH:
+                MetaModelUtil.validateFlashFile(metaFile);
+                break;
+            case DEBUG:
+                MetaModelUtil.validateDebugFile(metaFile);
+                break;
+            default:
+                break;
+            }
+        } catch (SAXException e) {
+            throw new InvalidMetaException(e);
+        } catch (Exception e) {
+            throw new MetaLoadException(e);
+        }
+    }
+
+
+}