*/
public class MetaModelUtil {
- private enum TYPE {
+ public enum MODEL_TYPE {
BUILD, FLASH, DEBUG
}
}
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);
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
}
}
- 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);
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);
}
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;
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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
+ }
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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$
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+
+
+}