RTSDK : Add utility methods to Meta Model Util class
authordaeryong.park <bdragon.park@samsung.com>
Thu, 8 Jun 2017 07:09:23 +0000 (16:09 +0900)
committerdaeryong.park <bdragon.park@samsung.com>
Thu, 8 Jun 2017 07:09:23 +0000 (16:09 +0900)
- Add method : copy default model file to specific destination and load
with copied file
- Add unit test

Change-Id: I95710f02a234d1b130da573cc0e455c132988336
Signed-off-by: daeryong.park <bdragon.park@samsung.com>
rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/IModelConstants.java [new file with mode: 0644]
rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/util/MetaModelUtil.java
rt-ide/tizen.rt.product.meta/test/src/org/tizen/rt/product/meta/model/LoadModelTest.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/messages.properties
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/IMetaConstants.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/meta/MetaManager.java

diff --git a/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/IModelConstants.java b/rt-ide/tizen.rt.product.meta/src/org/tizen/rt/product/meta/IModelConstants.java
new file mode 100644 (file)
index 0000000..5cd42b7
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.product.meta;
+
+/**
+ * @since 2017. 6. 8.
+ * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
+ */
+public interface IModelConstants {
+
+    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$
+
+}
index a59a2bc..1a3c64c 100755 (executable)
@@ -31,6 +31,10 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 
 import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
@@ -46,6 +50,7 @@ import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
 
+import org.tizen.rt.product.meta.IModelConstants;
 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;
@@ -66,6 +71,49 @@ public class MetaModelUtil {
     private MetaModelUtil() {
     }
 
+    /**
+     * Copy default buildSpec.xml file to destination and load copied buildSpec.xml file
+     * @param destination File full path string
+     * @return Load {@link Build} model instance
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public static Build copyDefaultBuildModelAndLoad(String destination) throws IOException, JAXBException {
+        InputStream source = RtMetaPlugin.class.getResourceAsStream("resources" + File.separator + IModelConstants.FILE_NAME_BUILD_META_XML);
+        return copyDefaultModelAndLoad(Build.class, source, destination);
+    }
+
+    /**
+     * Copy default flashSpec.xml file to destination and load copied flashSpec.xml file
+     * @param destination File full path string
+     * @return Load {@link Flash} model instance
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public static Flash copyDefaultFlashModelAndLoad(String destination) throws IOException, JAXBException {
+        InputStream source = RtMetaPlugin.class.getResourceAsStream("resources" + File.separator + IModelConstants.FILE_NAME_FLASH_META_XML);
+        return copyDefaultModelAndLoad(Flash.class, source, destination);
+    }
+
+    /**
+     * Copy default debusSpec.xml file to destination and load copied debugSpec.xml file
+     * @param destination File full path string
+     * @return Load {@link Debugs} model instance
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public static Debugs copyDefaultDebugModelAndLoad(String destination) throws IOException, JAXBException {
+        InputStream source = RtMetaPlugin.class.getResourceAsStream("resources" + File.separator + IModelConstants.FILE_NAME_DEBUG_META_XML);
+        return copyDefaultModelAndLoad(Debugs.class, source, destination);
+    }
+
+    private static <T> T copyDefaultModelAndLoad(Class<T> clazz, InputStream source, String destination) throws JAXBException, IOException {
+        Path destPath = Paths.get(destination);
+        Files.copy(source, destPath, StandardCopyOption.REPLACE_EXISTING);
+        File destFile = new File(destination);
+        return loadModel(clazz, destFile);
+    }
+
     @SuppressWarnings("unchecked")
     private static <T> T loadModel(Class<T> clazz, File modelXmlFile) throws JAXBException {
         JAXBContext context = JAXBContext.newInstance(clazz);
index b68e89b..25db5f7 100755 (executable)
@@ -25,6 +25,7 @@
  */
 package org.tizen.rt.product.meta.model;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,6 +35,7 @@ import javax.xml.parsers.ParserConfigurationException;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.tizen.rt.product.meta.IModelConstants;
 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;
@@ -101,4 +103,28 @@ public class LoadModelTest {
         MetaModelUtil.validateDebugFile(xmlFileStream);
     }
 
+    @Test
+    public void copyAndLoadBuildModelTest() throws IOException, JAXBException {
+        String fileName = IModelConstants.FILE_NAME_BUILD_META_XML;
+        MetaModelUtil.copyDefaultBuildModelAndLoad(fileName);
+        File file = new File(fileName);
+        file.delete();
+    }
+
+    @Test
+    public void copyAndLoadFlashModelTest() throws IOException, JAXBException {
+        String fileName = IModelConstants.FILE_NAME_FLASH_META_XML;
+        MetaModelUtil.copyDefaultBuildModelAndLoad(fileName);
+        File file = new File(fileName);
+        file.delete();
+    }
+
+    @Test
+    public void copyAndLoadDebugModelTest() throws IOException, JAXBException {
+        String fileName = IModelConstants.FILE_NAME_DEBUG_META_XML;
+        MetaModelUtil.copyDefaultBuildModelAndLoad(fileName);
+        File file = new File(fileName);
+        file.delete();
+    }
+
 }
index 7861101..39a7aa7 100644 (file)
@@ -69,6 +69,7 @@ public class Messages extends NLS {
     public static String RtosFlashWizard_WindowTitle;
 
     public static String FlashHandler_NotFoundBuildInfo;
+    public static String FlashHandler_BuildInfoIsNotNormal;
 
     public static String LaunchShortcut_NotFoundBuildInfo;
     public static String RtosBuildDialogPage_lblNewLabel_text;
index 121f0fa..292b344 100644 (file)
@@ -2,6 +2,7 @@
 #Wed Mar 29 14:25:05 KST 2017
 RtGitImportWizard_WindowTitle=New TizenRT Project from Git
 FlashHandler_NotFoundBuildInfo=Flash execution failed. Please build it first.
+FlashHandler_BuildInfoIsNotNormal=Flash execution failed. Please check the build was done normally.
 LaunchShortcut_NotFoundBuildInfo=Debug execution failed. Please build it first.
 
 NewArtikProjectWizard_CreateOperationLabel=Create new TizenRT project
index 03975e4..75afbbf 100644 (file)
  */
 package org.tizen.rt.ide.meta;
 
+import org.tizen.rt.product.meta.IModelConstants;
+
 /**
  * @since 2017. 5. 25.
  * @author Daeryong Park {@literal <bdragon.park@samsung.com>}
  */
-public interface IMetaConstants {
+public interface IMetaConstants extends IModelConstants {
 
     public String FILE_NAME_BUILD_INFO = "build.info"; //$NON-NLS-1$
     public String PATH_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$
@@ -39,12 +41,4 @@ public interface IMetaConstants {
     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$
-
 }
index 5091e11..157f8ec 100644 (file)
@@ -100,9 +100,15 @@ public class MetaManager implements IMetaConstants {
         }
     }
 
-    private static File getMetaFile(IProject project, String board, String metaFileName) throws MetaNotFoundException {
+    private static String getMetaFilePath(IProject project, String board, String metaFileName) {
         String configPath = project.getLocation().toString() + File.separator + PATH_BUILD_CONFIGS;
-        File metaFile = new File(configPath, board + File.separator + metaFileName);
+        String metaFilePath = configPath + File.separator + board + File.separator + metaFileName;
+        return metaFilePath;
+    }
+
+    private static File getMetaFile(IProject project, String board, String metaFileName) throws MetaNotFoundException {
+        String metaFilePath = getMetaFilePath(project, board, metaFileName);
+        File metaFile = new File(metaFilePath);
         if (metaFile == null || !metaFile.exists()) {
             throw new MetaNotFoundException(metaFileName + " file not exist : " + metaFile.toString()); //$NON-NLS-1$
         }