From bae8173c12a4fa92cc1cbcbeb6c8c2ceb198279e Mon Sep 17 00:00:00 2001 From: "shihyun.kim" Date: Tue, 13 May 2014 13:37:54 +0900 Subject: [PATCH] Add log of performance. Delete unnecessary library Change-Id: I7d6cf8faab669e59172e56ff540dbcbe94d2f6fe Signed-off-by: shihyun.kim --- TPK/org.tizen.tpklib/src/org/tizen/tpklib/TPK.java | 145 ++- .../src/org/tizen/tpklib/model/PluginManager.java | 968 ++++++++++----------- 2 files changed, 555 insertions(+), 558 deletions(-) diff --git a/TPK/org.tizen.tpklib/src/org/tizen/tpklib/TPK.java b/TPK/org.tizen.tpklib/src/org/tizen/tpklib/TPK.java index e30170c..340d8cb 100644 --- a/TPK/org.tizen.tpklib/src/org/tizen/tpklib/TPK.java +++ b/TPK/org.tizen.tpklib/src/org/tizen/tpklib/TPK.java @@ -1,73 +1,72 @@ -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 excludeList, List 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; + +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 excludeList, List includeList) { + + TPKSystem tSystem = new TPKSystem(); + boolean bRet = tSystem.packaging(buildDir, arch, pkgName, prjName, + artifactName, pkgVersion, stripper, strIP, llvmIR, sign, + excludeList, includeList); + + if (Performance.doPerformance) { + TPK.log.info("Test time => \n" + getPerformanceData()); + } + + return bRet; + } + + public boolean packaging(BuildOption bOption) { + return 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); + } + + 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; + } +} diff --git a/TPK/org.tizen.tpklib/src/org/tizen/tpklib/model/PluginManager.java b/TPK/org.tizen.tpklib/src/org/tizen/tpklib/model/PluginManager.java index d3ce039..0a9caa0 100644 --- a/TPK/org.tizen.tpklib/src/org/tizen/tpklib/model/PluginManager.java +++ b/TPK/org.tizen.tpklib/src/org/tizen/tpklib/model/PluginManager.java @@ -1,485 +1,483 @@ -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 rootstrapList = new ArrayList(); - List toolchainList = new ArrayList(); - List targetList = new ArrayList(); - - private Log log = TPK.log; - - private PluginManager() { - } - - public void init() { - List pluginFileList = getPluginFileList(); - loadPlugin(pluginFileList); - } - - private void loadPlugin(List 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 getRootstrapList() { - return rootstrapList; - } - - public List getToolchainList() { - return toolchainList; - } - - public List getTargetList() { - return targetList; - } - - public List getPluginList() { - List pList = new ArrayList(); - - 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 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 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 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; + +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.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 rootstrapList = new ArrayList(); + List toolchainList = new ArrayList(); + List targetList = new ArrayList(); + + private Log log = TPK.log; + + private PluginManager() { + } + + public void init() { + List pluginFileList = getPluginFileList(); + loadPlugin(pluginFileList); + } + + private void loadPlugin(List 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 getRootstrapList() { + return rootstrapList; + } + + public List getToolchainList() { + return toolchainList; + } + + public List getTargetList() { + return targetList; + } + + public List getPluginList() { + List pList = new ArrayList(); + + 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 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 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 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; + } +} -- 2.7.4