-package org.tizen.tpklib;
-
-import java.util.List;
-
-import org.tizen.tpklib.constants.TPKConstants;
-import org.tizen.tpklib.core.TPKSystem;
-import org.tizen.tpklib.lib.Log;
-import org.tizen.tpklib.lib.PathUtil;
-import org.tizen.tpklib.lib.Performance;
-import org.tizen.tpklib.model.BuildOption;
-import org.tizen.tpklib.model.Sign;
-
-public class TPK {
- public static Log log = createLog();
- private static TPK tpk = null;
-
- private TPK() {
-
- }
-
- static Log createLog() {
- String logPath = PathUtil.addPath(TPKConstants.SBI_HOME_PATH,
- TPKConstants.TPK_LOG_FILE_NAME);
- return Log.createLog(logPath);
- }
-
- public boolean packaging(String buildDir, String arch, String pkgName,
- String prjName, String artifactName, String pkgVersion,
- String stripper, boolean strIP, boolean llvmIR, Sign sign,
- List<String> excludeList, List<String> includeList) {
-
- TPKSystem tSystem = new TPKSystem();
- return tSystem.packaging(buildDir, arch, pkgName, prjName,
- artifactName, pkgVersion, stripper, strIP, llvmIR, sign,
- excludeList, includeList);
- }
-
- public boolean packaging(BuildOption bOption) {
- long startTime = System.currentTimeMillis();
-
- boolean bRet = packaging(bOption.buildDir, bOption.arch,
- bOption.pkgName, bOption.prjName, bOption.artifactName,
- bOption.pkgVersion, bOption.stripper, bOption.strIP,
- bOption.llvmIR, bOption.sign, bOption.excludeList,
- bOption.includeList);
-
- long endTime = System.currentTimeMillis();
- TPK.log.info("Test time => " + (endTime - startTime));
-
- return bRet;
- }
-
- public void doPerformance() {
- Performance.doPerformance = true;
- }
-
- public void endPerformance() {
- Performance.doPerformance = false;
- }
-
- public String getPerformanceData() {
- StringBuffer buffer = Performance.getAllData();
- return buffer.toString();
- }
-
- public static TPK getInstance() {
- if (tpk == null) {
- tpk = new TPK();
- }
-
- return tpk;
- }
-}
+package org.tizen.tpklib;\r
+\r
+import java.util.List;\r
+\r
+import org.tizen.tpklib.constants.TPKConstants;\r
+import org.tizen.tpklib.core.TPKSystem;\r
+import org.tizen.tpklib.lib.Log;\r
+import org.tizen.tpklib.lib.PathUtil;\r
+import org.tizen.tpklib.lib.Performance;\r
+import org.tizen.tpklib.model.BuildOption;\r
+import org.tizen.tpklib.model.Sign;\r
+\r
+public class TPK {\r
+ public static Log log = createLog();\r
+ private static TPK tpk = null;\r
+\r
+ private TPK() {\r
+\r
+ }\r
+\r
+ static Log createLog() {\r
+ String logPath = PathUtil.addPath(TPKConstants.SBI_HOME_PATH,\r
+ TPKConstants.TPK_LOG_FILE_NAME);\r
+ return Log.createLog(logPath);\r
+ }\r
+\r
+ public boolean packaging(String buildDir, String arch, String pkgName,\r
+ String prjName, String artifactName, String pkgVersion,\r
+ String stripper, boolean strIP, boolean llvmIR, Sign sign,\r
+ List<String> excludeList, List<String> includeList) {\r
+\r
+ TPKSystem tSystem = new TPKSystem();\r
+ boolean bRet = tSystem.packaging(buildDir, arch, pkgName, prjName,\r
+ artifactName, pkgVersion, stripper, strIP, llvmIR, sign,\r
+ excludeList, includeList);\r
+ \r
+ if (Performance.doPerformance) {\r
+ TPK.log.info("Test time => \n" + getPerformanceData());\r
+ }\r
+ \r
+ return bRet;\r
+ }\r
+\r
+ public boolean packaging(BuildOption bOption) {\r
+ return packaging(bOption.buildDir, bOption.arch,\r
+ bOption.pkgName, bOption.prjName, bOption.artifactName,\r
+ bOption.pkgVersion, bOption.stripper, bOption.strIP,\r
+ bOption.llvmIR, bOption.sign, bOption.excludeList,\r
+ bOption.includeList);\r
+ }\r
+ \r
+ public void doPerformance() {\r
+ Performance.doPerformance = true;\r
+ }\r
+ \r
+ public void endPerformance() {\r
+ Performance.doPerformance = false;\r
+ }\r
+ \r
+ public String getPerformanceData() {\r
+ StringBuffer buffer = Performance.getAllData();\r
+ return buffer.toString();\r
+ }\r
+\r
+ public static TPK getInstance() {\r
+ if (tpk == null) {\r
+ tpk = new TPK();\r
+ }\r
+\r
+ return tpk;\r
+ }\r
+}\r
-package org.tizen.tpklib.model;
-
-import org.tizen.tpklib.TPK;
-import org.tizen.tpklib.lib.PathUtil;
-import org.tizen.tpklib.lib.Log;
-import org.tizen.tpklib.model.Tool;
-import org.tizen.tpklib.lib.XmlParser;
-import org.tizen.tpklib.model.SBIConstants;
-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;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.TransformerFactoryConfigurationError;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-public class PluginManager {
- static private PluginManager pm = null;
-
- List<Rootstrap> rootstrapList = new ArrayList<Rootstrap>();
- List<Toolchain> toolchainList = new ArrayList<Toolchain>();
- List<Target> targetList = new ArrayList<Target>();
-
- private Log log = TPK.log;
-
- private PluginManager() {
- }
-
- public void init() {
- List<File> pluginFileList = getPluginFileList();
- loadPlugin(pluginFileList);
- }
-
- private void loadPlugin(List<File> pluginFileList) {
- log.info("Load plugin from file => " + pluginFileList);
-
- for (File pluginFile : pluginFileList) {
- if (!PathUtil.XML_EXTENSION.equalsIgnoreCase(PathUtil
- .getExtension(pluginFile.getName()))) {
- continue;
- }
-
- Document dom = null;
- try {
- dom = XmlParser.parsing(pluginFile);
- } catch (ParserConfigurationException e) {
- log.exception(e);
- return;
- } catch (SAXException e) {
- log.exception(e);
- return;
- } catch (IOException e) {
- log.exception(e);
- return;
- }
-
- Element extensionNode = (Element) dom.getElementsByTagName(
- PluginConstants.ELEMENT_EXTENSION).item(0);
- String value = extensionNode
- .getAttribute(PluginConstants.ATTRIBUTE_POINT);
-
- if (value
- .equalsIgnoreCase(RootstrapConstants.VALUE_EXTENSION_POINT)) {
- rootstrapList.add(new Rootstrap(dom, pluginFile));
- } else if (value
- .equalsIgnoreCase(ToolchainConstants.VALUE_EXTENSION_POINT)) {
- toolchainList.add(new Toolchain(dom, pluginFile));
- } else if (value
- .equalsIgnoreCase(TargetConstants.EXTENSION_POINT_VALUE)) {
- targetList.add(new Target(dom, pluginFile));
- } else {
- log.warn("Unsupported plugin type. => " + value);
- }
- }
- }
-
- private String getPluginPath() {
- return PathUtil.addPath(SBIConstants.SBI_PLUGIN_PATH);
- }
-
- public boolean addRootstrap() {
- // TODO impl
- return false;
- }
-
- public boolean addToolchain() {
- // TODO impl
- return false;
- }
-
- public boolean addTarget() {
- // TODO impl
- return false;
- }
-
- public boolean createTarget(String rId, String cId, String tId) {
- log.info("Create target from rootstrap and toolchain");
- log.info("target id : " + tId);
-
- if (tId == null || tId.isEmpty()) {
- tId = makeTargetId(rId, cId);
- }
-
- if (!isAvailable(rId, cId, tId)) {
- log.error("Cannot create target");
- return false;
- }
-
- Document tDom = null;
- try {
- tDom = DocumentBuilderFactory.newInstance().newDocumentBuilder()
- .newDocument();
- } catch (ParserConfigurationException e) {
- log.exception(e);
- return false;
- }
-
- Element extensionElement = tDom
- .createElement(PluginConstants.ELEMENT_EXTENSION);
- tDom.getDocumentElement();
- tDom.appendChild(extensionElement);
-
- extensionElement.setAttribute(PluginConstants.ATTRIBUTE_POINT,
- TargetConstants.EXTENSION_POINT_VALUE);
-
- Element targetElement = tDom
- .createElement(TargetConstants.ELEMENT_TARGET);
- extensionElement.appendChild(targetElement);
-
- targetElement.setAttribute(PluginConstants.ATTRIBUTE_ID, tId);
- targetElement.setAttribute(PluginConstants.ATTRIBUTE_NAME, tId);
- targetElement.setAttribute(PluginConstants.ATTRIBUTE_ROOTSTRAP_ID, rId);
- targetElement.setAttribute(PluginConstants.ATTRIBUTE_TOOLCHAIN_ID, cId);
-
- String targetFilePath = PathUtil.addPath(SBIConstants.SBI_PLUGIN_PATH,
- tId + ".xml");
- File targetFile = new File(targetFilePath);
-
- if (!savePlugin(tDom, targetFile)) {
- return false;
- }
-
- targetList.add(new Target(tDom, targetFile));
- return true;
- }
-
- private boolean savePlugin(Document dom, File xmlFile) {
- log.info("save plugin to xml file => " + xmlFile);
-
- if (dom == null || xmlFile == null) {
- log.error("Cannot save plugin.");
- return false;
- }
-
- if (xmlFile.exists()) {
- if (xmlFile.delete()) {
- log.error("Cannot delete plugin file => " + xmlFile);
- }
- }
- DOMSource source = new DOMSource(dom);
-
- Transformer transformer = null;
- try {
- transformer = TransformerFactory.newInstance().newTransformer();
- } catch (TransformerConfigurationException e) {
- log.exception(e);
- return false;
- } catch (TransformerFactoryConfigurationError e) {
- log.exception(e);
- return false;
- }
-
- StreamResult result = new StreamResult(xmlFile);
-
- try {
- transformer.transform(source, result);
- } catch (TransformerException e) {
- log.exception(e);
- return false;
- }
-
- return true;
- }
-
- private boolean isAvailable(String rId, String cId, String tId) {
- if (!exist(rootstrapList, rId)) {
- log.error("Cannot find rootstrap id => " + rId);
- log.error("rootstrap list => " + rootstrapList);
- return false;
- }
-
- if (!exist(toolchainList, cId)) {
- log.error("Cannot find toolchain id => " + cId);
- log.error("toolchain list => " + toolchainList);
- return false;
- }
-
- if (!isTargetIdAvailableToCreate(tId)) {
- return false;
- }
-
- return true;
- }
-
- private boolean isTargetIdAvailableToCreate(String id) {
- if (exist(rootstrapList, id)) {
- log.error("ID is not available. => " + id);
- log.error("exist in rootstrap list => " + rootstrapList);
- return false;
- }
-
- if (exist(toolchainList, id)) {
- log.error("ID is not available. => " + id);
- log.error("exist in toolchain list => " + toolchainList);
- return false;
- }
-
- if (exist(targetList, id)) {
- log.error("ID is not available. => " + id);
- log.error("exist in target list => " + targetList);
- return false;
- }
-
- return true;
- }
-
- public boolean removeTarget(String tId) {
- if (tId == null || tId.isEmpty()) {
- log.warn("Target ID is empty => " + tId);
- return false;
- }
-
- Target t = getTarget(tId);
- if (t == null) {
- log.warn("ID do not exist in target list => " + tId);
- log.warn("target list => " + targetList);
- return false;
- }
-
- if (!t.getFile().delete()) {
- log.error("Cannot remove the target file => "
- + t.getFile().getAbsolutePath());
- return false;
- }
-
- targetList.remove(t);
- return true;
- }
-
- private String makeTargetId(String rId, String cId) {
- return rId + "_" + cId;
- }
-
- public Properties getPluginInfo(String pId) {
- Plugin p = getPlugin(pId);
-
- if (p == null) {
- return null;
- }
-
- String point = p.getExtensionPoint();
-
- if (point.equalsIgnoreCase(RootstrapConstants.VALUE_EXTENSION_POINT)) {
- return getRootstrapInfo((Rootstrap) p);
- } else if (point
- .equalsIgnoreCase(ToolchainConstants.VALUE_EXTENSION_POINT)) {
- return getToolchainInfo((Toolchain) p);
- } else if (point
- .equalsIgnoreCase(TargetConstants.EXTENSION_POINT_VALUE)) {
- return getTargetInfo((Target) p);
- } else {
- log.error("Cannot find plugin id => " + pId);
- return null;
- }
- }
-
- public Properties getRootstrapInfo(String rId) {
- Rootstrap r = getRootstrap(rId);
- return getRootstrapInfo(r);
- }
-
- public Properties getToolchainInfo(String cId) {
- Toolchain t = getToolchain(cId);
- return getToolchainInfo(t);
- }
-
- public Properties getTargetInfo(String tId) {
- Target t = getTarget(tId);
- return getTargetInfo(t);
- }
-
- private Properties getRootstrapInfo(Rootstrap rId) {
- // TODO impl
- return null;
- }
-
- private Properties getToolchainInfo(Toolchain cId) {
- // TODO impl
- return null;
- }
-
- private Properties getTargetInfo(Target tId) {
- // TODO impl
- return null;
- }
-
- public boolean savePlugin() {
- // TODO impl
- return false;
- }
-
- public boolean saveRootstrap() {
- // TODO impl
- return false;
- }
-
- public boolean saveToolchain() {
- // TODO impl
- return false;
- }
-
- public boolean saveTarget() {
- // TODO impl
- return false;
- }
-
- public List<Rootstrap> getRootstrapList() {
- return rootstrapList;
- }
-
- public List<Toolchain> getToolchainList() {
- return toolchainList;
- }
-
- public List<Target> getTargetList() {
- return targetList;
- }
-
- public List<Plugin> getPluginList() {
- List<Plugin> pList = new ArrayList<Plugin>();
-
- pList.addAll(rootstrapList);
- pList.addAll(toolchainList);
- pList.addAll(targetList);
-
- return pList;
- }
-
- public Rootstrap getRootstrap(String rId) {
- return (Rootstrap) getPluginById(rootstrapList, rId);
- }
-
- public Toolchain getToolchain(String cId) {
- return (Toolchain) getPluginById(toolchainList, cId);
- }
-
- public Target getTarget(String tId) {
- return (Target) getPluginById(targetList, tId);
- }
-
- public Plugin getPlugin(String pId) {
- return getPluginById(pId);
- }
-
- public Toolchain getToolchainByTargetId(String targetId) {
- if (targetId == null || targetId.isEmpty()) {
- return null;
- }
-
- Target t = getTarget(targetId);
- if (t == null) {
- return null;
- }
-
- Toolchain tChain = getToolchain(t.getToolchainId());
- return tChain;
- }
-
- public Tool getToolByTargetId(String targetId, String toolName) {
- if (targetId == null || targetId.isEmpty()) {
- log.warn("target id is empty.");
- return null;
- }
-
- if (toolName == null || toolName.isEmpty()) {
- log.warn("tool name is empty.");
- return null;
- }
-
- Target t = getTarget(targetId);
- String toolchainId = t.getToolchainId();
-
- Toolchain tc = getToolchain(toolchainId);
- Tool tool = tc.getTool(toolName);
-
- return tool;
- }
-
- private Plugin getPluginById(String pId) {
- if (pId == null || pId.isEmpty()) {
- return null;
- }
-
- return getPluginById(getPluginList(), pId);
- }
-
- private Plugin getPluginById(List<? extends Plugin> pList, String pId) {
- if (pList == null) {
- return getPluginById(pId);
- }
-
- if (pId == null || pId.isEmpty()) {
- return null;
- }
-
- for (Plugin p : pList) {
- String id = p.getId();
-
- if (id == null) {
- continue;
- }
-
- if (p.getId().equals(pId)) {
- return p;
- }
- }
-
- log.warn("Cannot find plugin => " + pId);
- return null;
- }
-
- private boolean exist(List<? extends Plugin> pList, String pId) {
- Plugin p = getPluginById(pList, pId);
-
- if (p != null) {
- return true;
- } else {
- return false;
- }
- }
-
- public boolean isEmpty() {
- if (rootstrapList.isEmpty() && toolchainList.isEmpty()
- && targetList.isEmpty()) {
- return true;
- } else {
- return false;
- }
- }
-
- private List<File> getPluginFileList() {
- String pluginPath = getPluginPath();
- File pluginDirFile = new File(pluginPath);
-
- if (!pluginDirFile.exists()) {
- return Collections.emptyList();
- }
-
- return Arrays.asList(pluginDirFile.listFiles());
- }
-
- static public PluginManager getInstance() {
- if (pm == null) {
- pm = new PluginManager();
- pm.init();
- }
- return pm;
- }
-}
+package org.tizen.tpklib.model;\r
+\r
+import org.tizen.tpklib.TPK;\r
+import org.tizen.tpklib.lib.PathUtil;\r
+import org.tizen.tpklib.lib.Log;\r
+import org.tizen.tpklib.model.Tool;\r
+import org.tizen.tpklib.lib.XmlParser;\r
+import org.tizen.tpklib.model.SBIConstants;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
+import org.xml.sax.SAXException;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.List;\r
+import java.util.Properties;\r
+\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+import javax.xml.parsers.ParserConfigurationException;\r
+import javax.xml.transform.Transformer;\r
+import javax.xml.transform.TransformerConfigurationException;\r
+import javax.xml.transform.TransformerException;\r
+import javax.xml.transform.TransformerFactory;\r
+import javax.xml.transform.TransformerFactoryConfigurationError;\r
+import javax.xml.transform.dom.DOMSource;\r
+import javax.xml.transform.stream.StreamResult;\r
+\r
+public class PluginManager {\r
+ static private PluginManager pm = null;\r
+\r
+ List<Rootstrap> rootstrapList = new ArrayList<Rootstrap>();\r
+ List<Toolchain> toolchainList = new ArrayList<Toolchain>();\r
+ List<Target> targetList = new ArrayList<Target>();\r
+\r
+ private Log log = TPK.log;\r
+\r
+ private PluginManager() {\r
+ }\r
+\r
+ public void init() {\r
+ List<File> pluginFileList = getPluginFileList();\r
+ loadPlugin(pluginFileList);\r
+ }\r
+\r
+ private void loadPlugin(List<File> pluginFileList) {\r
+ log.info("Load plugin from file => " + pluginFileList);\r
+\r
+ for (File pluginFile : pluginFileList) {\r
+ if (!PathUtil.XML_EXTENSION.equalsIgnoreCase(PathUtil\r
+ .getExtension(pluginFile.getName()))) {\r
+ continue;\r
+ }\r
+ \r
+ Document dom = null;\r
+ try {\r
+ dom = XmlParser.parsing(pluginFile);\r
+ } catch (ParserConfigurationException e) {\r
+ log.exception(e);\r
+ return;\r
+ } catch (SAXException e) {\r
+ log.exception(e);\r
+ return;\r
+ } catch (IOException e) {\r
+ log.exception(e);\r
+ return;\r
+ }\r
+\r
+ Element extensionNode = (Element) dom.getElementsByTagName(\r
+ PluginConstants.ELEMENT_EXTENSION).item(0);\r
+ String value = extensionNode\r
+ .getAttribute(PluginConstants.ATTRIBUTE_POINT);\r
+\r
+ if (value\r
+ .equalsIgnoreCase(RootstrapConstants.VALUE_EXTENSION_POINT)) {\r
+ rootstrapList.add(new Rootstrap(dom, pluginFile));\r
+ } else if (value\r
+ .equalsIgnoreCase(ToolchainConstants.VALUE_EXTENSION_POINT)) {\r
+ toolchainList.add(new Toolchain(dom, pluginFile));\r
+ } else if (value\r
+ .equalsIgnoreCase(TargetConstants.EXTENSION_POINT_VALUE)) {\r
+ targetList.add(new Target(dom, pluginFile));\r
+ } else {\r
+ log.warn("Unsupported plugin type. => " + value);\r
+ }\r
+ }\r
+ }\r
+\r
+ private String getPluginPath() {\r
+ return PathUtil.addPath(SBIConstants.SBI_PLUGIN_PATH);\r
+ }\r
+\r
+ public boolean addRootstrap() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public boolean addToolchain() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public boolean addTarget() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public boolean createTarget(String rId, String cId, String tId) {\r
+ log.info("Create target from rootstrap and toolchain");\r
+ log.info("target id : " + tId);\r
+\r
+ if (tId == null || tId.isEmpty()) {\r
+ tId = makeTargetId(rId, cId);\r
+ }\r
+\r
+ if (!isAvailable(rId, cId, tId)) {\r
+ log.error("Cannot create target");\r
+ return false;\r
+ }\r
+\r
+ Document tDom = null;\r
+ try {\r
+ tDom = DocumentBuilderFactory.newInstance().newDocumentBuilder()\r
+ .newDocument();\r
+ } catch (ParserConfigurationException e) {\r
+ log.exception(e);\r
+ return false;\r
+ }\r
+\r
+ Element extensionElement = tDom\r
+ .createElement(PluginConstants.ELEMENT_EXTENSION);\r
+ tDom.getDocumentElement();\r
+ tDom.appendChild(extensionElement);\r
+\r
+ extensionElement.setAttribute(PluginConstants.ATTRIBUTE_POINT,\r
+ TargetConstants.EXTENSION_POINT_VALUE);\r
+\r
+ Element targetElement = tDom\r
+ .createElement(TargetConstants.ELEMENT_TARGET);\r
+ extensionElement.appendChild(targetElement);\r
+\r
+ targetElement.setAttribute(PluginConstants.ATTRIBUTE_ID, tId);\r
+ targetElement.setAttribute(PluginConstants.ATTRIBUTE_NAME, tId);\r
+ targetElement.setAttribute(PluginConstants.ATTRIBUTE_ROOTSTRAP_ID, rId);\r
+ targetElement.setAttribute(PluginConstants.ATTRIBUTE_TOOLCHAIN_ID, cId);\r
+\r
+ String targetFilePath = PathUtil.addPath(SBIConstants.SBI_PLUGIN_PATH,\r
+ tId + ".xml");\r
+ File targetFile = new File(targetFilePath);\r
+\r
+ if (!savePlugin(tDom, targetFile)) {\r
+ return false;\r
+ }\r
+\r
+ targetList.add(new Target(tDom, targetFile));\r
+ return true;\r
+ }\r
+\r
+ private boolean savePlugin(Document dom, File xmlFile) {\r
+ log.info("save plugin to xml file => " + xmlFile);\r
+\r
+ if (dom == null || xmlFile == null) {\r
+ log.error("Cannot save plugin.");\r
+ return false;\r
+ }\r
+\r
+ if (xmlFile.exists()) {\r
+ if (xmlFile.delete()) {\r
+ log.error("Cannot delete plugin file => " + xmlFile);\r
+ }\r
+ }\r
+ DOMSource source = new DOMSource(dom);\r
+\r
+ Transformer transformer = null;\r
+ try {\r
+ transformer = TransformerFactory.newInstance().newTransformer();\r
+ } catch (TransformerConfigurationException e) {\r
+ log.exception(e);\r
+ return false;\r
+ } catch (TransformerFactoryConfigurationError e) {\r
+ log.exception(e);\r
+ return false;\r
+ }\r
+\r
+ StreamResult result = new StreamResult(xmlFile);\r
+\r
+ try {\r
+ transformer.transform(source, result);\r
+ } catch (TransformerException e) {\r
+ log.exception(e);\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ private boolean isAvailable(String rId, String cId, String tId) {\r
+ if (!exist(rootstrapList, rId)) {\r
+ log.error("Cannot find rootstrap id => " + rId);\r
+ log.error("rootstrap list => " + rootstrapList);\r
+ return false;\r
+ }\r
+\r
+ if (!exist(toolchainList, cId)) {\r
+ log.error("Cannot find toolchain id => " + cId);\r
+ log.error("toolchain list => " + toolchainList);\r
+ return false;\r
+ }\r
+\r
+ if (!isTargetIdAvailableToCreate(tId)) {\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ private boolean isTargetIdAvailableToCreate(String id) {\r
+ if (exist(rootstrapList, id)) {\r
+ log.error("ID is not available. => " + id);\r
+ log.error("exist in rootstrap list => " + rootstrapList);\r
+ return false;\r
+ }\r
+\r
+ if (exist(toolchainList, id)) {\r
+ log.error("ID is not available. => " + id);\r
+ log.error("exist in toolchain list => " + toolchainList);\r
+ return false;\r
+ }\r
+\r
+ if (exist(targetList, id)) {\r
+ log.error("ID is not available. => " + id);\r
+ log.error("exist in target list => " + targetList);\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ public boolean removeTarget(String tId) {\r
+ if (tId == null || tId.isEmpty()) {\r
+ log.warn("Target ID is empty => " + tId);\r
+ return false;\r
+ }\r
+\r
+ Target t = getTarget(tId);\r
+ if (t == null) {\r
+ log.warn("ID do not exist in target list => " + tId);\r
+ log.warn("target list => " + targetList);\r
+ return false;\r
+ }\r
+\r
+ if (!t.getFile().delete()) {\r
+ log.error("Cannot remove the target file => "\r
+ + t.getFile().getAbsolutePath());\r
+ return false;\r
+ }\r
+\r
+ targetList.remove(t);\r
+ return true;\r
+ }\r
+\r
+ private String makeTargetId(String rId, String cId) {\r
+ return rId + "_" + cId;\r
+ }\r
+\r
+ public Properties getPluginInfo(String pId) {\r
+ Plugin p = getPlugin(pId);\r
+\r
+ if (p == null) {\r
+ return null;\r
+ }\r
+\r
+ String point = p.getExtensionPoint();\r
+\r
+ if (point.equalsIgnoreCase(RootstrapConstants.VALUE_EXTENSION_POINT)) {\r
+ return getRootstrapInfo((Rootstrap) p);\r
+ } else if (point\r
+ .equalsIgnoreCase(ToolchainConstants.VALUE_EXTENSION_POINT)) {\r
+ return getToolchainInfo((Toolchain) p);\r
+ } else if (point\r
+ .equalsIgnoreCase(TargetConstants.EXTENSION_POINT_VALUE)) {\r
+ return getTargetInfo((Target) p);\r
+ } else {\r
+ log.error("Cannot find plugin id => " + pId);\r
+ return null;\r
+ }\r
+ }\r
+\r
+ public Properties getRootstrapInfo(String rId) {\r
+ Rootstrap r = getRootstrap(rId);\r
+ return getRootstrapInfo(r);\r
+ }\r
+\r
+ public Properties getToolchainInfo(String cId) {\r
+ Toolchain t = getToolchain(cId);\r
+ return getToolchainInfo(t);\r
+ }\r
+\r
+ public Properties getTargetInfo(String tId) {\r
+ Target t = getTarget(tId);\r
+ return getTargetInfo(t);\r
+ }\r
+\r
+ private Properties getRootstrapInfo(Rootstrap rId) {\r
+ // TODO impl\r
+ return null;\r
+ }\r
+\r
+ private Properties getToolchainInfo(Toolchain cId) {\r
+ // TODO impl\r
+ return null;\r
+ }\r
+\r
+ private Properties getTargetInfo(Target tId) {\r
+ // TODO impl\r
+ return null;\r
+ }\r
+\r
+ public boolean savePlugin() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public boolean saveRootstrap() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public boolean saveToolchain() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public boolean saveTarget() {\r
+ // TODO impl\r
+ return false;\r
+ }\r
+\r
+ public List<Rootstrap> getRootstrapList() {\r
+ return rootstrapList;\r
+ }\r
+\r
+ public List<Toolchain> getToolchainList() {\r
+ return toolchainList;\r
+ }\r
+\r
+ public List<Target> getTargetList() {\r
+ return targetList;\r
+ }\r
+\r
+ public List<Plugin> getPluginList() {\r
+ List<Plugin> pList = new ArrayList<Plugin>();\r
+\r
+ pList.addAll(rootstrapList);\r
+ pList.addAll(toolchainList);\r
+ pList.addAll(targetList);\r
+\r
+ return pList;\r
+ }\r
+\r
+ public Rootstrap getRootstrap(String rId) {\r
+ return (Rootstrap) getPluginById(rootstrapList, rId);\r
+ }\r
+\r
+ public Toolchain getToolchain(String cId) {\r
+ return (Toolchain) getPluginById(toolchainList, cId);\r
+ }\r
+\r
+ public Target getTarget(String tId) {\r
+ return (Target) getPluginById(targetList, tId);\r
+ }\r
+\r
+ public Plugin getPlugin(String pId) {\r
+ return getPluginById(pId);\r
+ }\r
+\r
+ public Toolchain getToolchainByTargetId(String targetId) {\r
+ if (targetId == null || targetId.isEmpty()) {\r
+ return null;\r
+ }\r
+\r
+ Target t = getTarget(targetId);\r
+ if (t == null) {\r
+ return null;\r
+ }\r
+\r
+ Toolchain tChain = getToolchain(t.getToolchainId());\r
+ return tChain;\r
+ }\r
+\r
+ public Tool getToolByTargetId(String targetId, String toolName) {\r
+ if (targetId == null || targetId.isEmpty()) {\r
+ log.warn("target id is empty.");\r
+ return null;\r
+ }\r
+\r
+ if (toolName == null || toolName.isEmpty()) {\r
+ log.warn("tool name is empty.");\r
+ return null;\r
+ }\r
+\r
+ Target t = getTarget(targetId);\r
+ String toolchainId = t.getToolchainId();\r
+\r
+ Toolchain tc = getToolchain(toolchainId);\r
+ Tool tool = tc.getTool(toolName);\r
+\r
+ return tool;\r
+ }\r
+\r
+ private Plugin getPluginById(String pId) {\r
+ if (pId == null || pId.isEmpty()) {\r
+ return null;\r
+ }\r
+\r
+ return getPluginById(getPluginList(), pId);\r
+ }\r
+\r
+ private Plugin getPluginById(List<? extends Plugin> pList, String pId) {\r
+ if (pList == null) {\r
+ return getPluginById(pId);\r
+ }\r
+\r
+ if (pId == null || pId.isEmpty()) {\r
+ return null;\r
+ }\r
+\r
+ for (Plugin p : pList) {\r
+ String id = p.getId();\r
+ \r
+ if (id == null) {\r
+ continue;\r
+ }\r
+ \r
+ if (p.getId().equals(pId)) {\r
+ return p;\r
+ }\r
+ }\r
+\r
+ log.warn("Cannot find plugin => " + pId);\r
+ return null;\r
+ }\r
+\r
+ private boolean exist(List<? extends Plugin> pList, String pId) {\r
+ Plugin p = getPluginById(pList, pId);\r
+\r
+ if (p != null) {\r
+ return true;\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public boolean isEmpty() {\r
+ if (rootstrapList.isEmpty() && toolchainList.isEmpty()\r
+ && targetList.isEmpty()) {\r
+ return true;\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ private List<File> getPluginFileList() {\r
+ String pluginPath = getPluginPath();\r
+ File pluginDirFile = new File(pluginPath);\r
+\r
+ if (!pluginDirFile.exists()) {\r
+ return Collections.emptyList();\r
+ }\r
+\r
+ return Arrays.asList(pluginDirFile.listFiles());\r
+ }\r
+\r
+ static public PluginManager getInstance() {\r
+ if (pm == null) {\r
+ pm = new PluginManager();\r
+ pm.init();\r
+ }\r
+ return pm;\r
+ }\r
+}\r