# HG changeset patch # User timkelly # Date 1274381824 18000 # Node ID c70ff7f198876368c78c12966d947216ab52280f # Parent 1fd5209125b8e9d63434421b5a9c424805db05f0 more api changes for sbs query config design diff -r 1fd5209125b8 -r c70ff7f19887 builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/SBSv2QueryTests.java --- a/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/SBSv2QueryTests.java Wed May 19 17:52:30 2010 -0500 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/SBSv2QueryTests.java Thu May 20 13:57:04 2010 -0500 @@ -18,7 +18,6 @@ package com.nokia.carbide.cdt.builder.test; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; @@ -32,10 +31,8 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.eclipse.cdt.utils.spawner.EnvironmentReader; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; import org.osgi.framework.Version; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -46,8 +43,7 @@ import com.nokia.carbide.cdt.builder.test.sandbox.ISBSv2ConfigData; import com.nokia.carbide.cdt.builder.test.sandbox.ISBSv2QueryData; -import com.nokia.carbide.cdt.builder.test.sandbox.SBSv2ConfigData; -import com.nokia.carbide.cdt.builder.test.sandbox.SBSv2QueryData; +import com.nokia.carbide.cdt.builder.test.sandbox.SBSv2QueryUtils; import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils; import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; @@ -59,10 +55,6 @@ private long startTime; - private final String QUERY_PRODUCTS_COMMAND = "--query=products"; - private final String QUERY_CONFIG_COMMAND = "--query=config"; - private final String QUERY_COMMAND = "--query=aliases"; - private final String SDK_ID1 = "K_92_WK12"; // SDK with additional aliases and products @Override @@ -85,7 +77,7 @@ startTime = System.currentTimeMillis(); if (sbsAliasBaseQuery == null){ - sbsAliasBaseQuery = getSBSv2QueryData(); + sbsAliasBaseQuery = SBSv2QueryUtils.queryAliasAndProductVariants(); } System.out.println("Time for testQueryProductsFromSDKs(): " + getTimingStats()); @@ -124,82 +116,61 @@ assertEquals(28, allSDKConfigUnion.size()); } - private ISBSv2QueryData getSBSv2QueryData() { - List argListConfigQuery = new ArrayList(); - List argListProductQuery = new ArrayList(); - argListConfigQuery.add(QUERY_COMMAND); - SBSv2QueryData sbsQueryData = new SBSv2QueryData(); + /** + * Query data for a single configuration + * @throws Exception + */ + public void testQuerySingleConfig() throws Exception { - /////// Invoke Raptor once with no EPOCROOT - Properties envVars = EnvironmentReader.getEnvVars(); - envVars.setProperty("EPOCROOT", "FOOBAR"); - String queryResult = getSBSQueryOutput(argListConfigQuery, createEnvStringList(envVars)); - - HashMap sbsAliasMap = parseQueryAliasResult(queryResult); - - for (String aliasKey : sbsAliasMap.keySet()){ - String meaning = sbsAliasMap.get(aliasKey); - SBSv2ConfigData oneSBSConfig = new SBSv2ConfigData(aliasKey, meaning, null); - sbsQueryData.addConfigurationData(oneSBSConfig); - } + assertNotNull(sbsAliasBaseQuery); + + startTime = System.currentTimeMillis(); - /////// Do for each SDK to build up the alias list... - for (ISymbianSDK sdk : SDKCorePlugin.getSDKManager().getSDKList()){ - IPath epocRoot = new Path(sdk.getEPOCROOT()); - if ((sdk.getOSVersion().getMajor() <= 9 && sdk.getOSVersion().getMinor() <5) - || !epocRoot.toFile().exists()){ - - continue; // skip it, the sdk is not supported or broken - } - - envVars = EnvironmentReader.getEnvVars(); - envVars.setProperty("EPOCROOT", sdk.getEPOCROOT()); - - queryResult = getSBSQueryOutput(argListConfigQuery, createEnvStringList(envVars)); - - sbsAliasMap = parseQueryAliasResult(queryResult); - - for (String aliasKey : sbsAliasMap.keySet()){ - String meaning = sbsAliasMap.get(aliasKey); - SBSv2ConfigData oneSBSConfig = new SBSv2ConfigData(aliasKey, meaning, sdk); - sbsQueryData.addConfigurationData(oneSBSConfig); - } - - // Now get the products for each SDK - argListProductQuery.add(QUERY_PRODUCTS_COMMAND); - queryResult = getSBSQueryOutput(argListProductQuery, createEnvStringList(envVars)); - List productList = parseQueryProductsResults(queryResult); - sbsQueryData.addProductListForSDK(sdk, productList); - } + ISBSv2ConfigData config = sbsAliasBaseQuery.getSBSConfigByAlias("armv5_udeb"); + assertNotNull(config); + assertEquals("/epoc32/release/armv5/udeb", config.getReleaseDirectory(null)); + assertEquals("armv5", config.getTraditionalPlatform(null)); + assertEquals("udeb", config.getTraditionalTarget(null)); - return sbsQueryData; + config = sbsAliasBaseQuery.getSBSConfigByAlias("armv5_udeb_gcce"); + assertNotNull(config); + // TODO: This should fail if 'SBS_GCCE432BIN is not set + // So we should have one test that will fail with known error message + // and another that will pass when an env var is set correctly. + // e.g. test two different versions of GCCE aliases. +// assertEquals("/epoc32/release/armv5/udeb", config.getReleaseDirectory(null)); +// assertEquals("armv5", config.getTraditionalPlatform(null)); +// assertEquals("udeb", config.getTraditionalTarget(null)); } + /** * TODO: The SBS API FOR THIS QUERY IS UNDER CONSTRUCTION..... * TODO; This test should be run on individual %EPOCROOT% values * @throws Exception */ - public void testQueryConfigs() throws Exception { + public void testQueryMultipleConfigs() throws Exception { assertNotNull(sbsAliasBaseQuery); - + startTime = System.currentTimeMillis(); - List argList = new ArrayList(); - for (ISBSv2ConfigData baseConfig: sbsAliasBaseQuery.getBaseSBSConfigurations()){ - argList.add(QUERY_CONFIG_COMMAND + "[" + baseConfig.getBuildAlias() + "]"); - } + List aliasOrMeaningArray = new ArrayList(); + aliasOrMeaningArray.add("armv5_udeb"); + aliasOrMeaningArray.add("arm.9e.udeb.rvct2_2"); + HashMap releaseMap = SBSv2QueryUtils.queryConfigTargetInfo(aliasOrMeaningArray , null); + + assertEquals(2, releaseMap.size()); - String queryResult = getSBSQueryOutput(argList, null); - assertTrue("No output found from " + QUERY_CONFIG_COMMAND, queryResult.length() > 0); - - HashMap outputMap = parseQueryConfigResults(queryResult); - assertTrue("No configs were found in query for : " + QUERY_CONFIG_COMMAND, outputMap.size() > 0); - - System.out.println("Time for testQueryProductsFromSDKs(): " + getTimingStats()); - +// String queryResult = getSBSQueryOutput(argList, null); +// assertTrue("No output found from " + SBSv2QueryUtils.QUERY_CONFIG_COMMAND, queryResult.length() > 0); +// +// HashMap outputMap = parseQueryConfigResults(queryResult); +// assertTrue("No configs were found in query for : " + SBSv2QueryUtils.QUERY_CONFIG_COMMAND, outputMap.size() > 0); +// +// System.out.println("Time for testQueryProductsFromSDKs(): " + getTimingStats()); +// } /** @@ -220,16 +191,16 @@ testQueryAliases(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); - testQueryConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); + testQueryMultipleConfigs(); testQueryProductsFromSDKs(); testQueryProductsFromSDKs(); @@ -247,175 +218,6 @@ System.out.println("Time for testStressQueryTest(): " + getTimingStats()); } - private List parseQueryProductsResults(String queryResult) { - List productList = new ArrayList(); - - try { - Element root = null; - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - parser.setErrorHandler(new DefaultHandler()); - - StringReader reader = new StringReader( queryResult ); - InputSource inputSource = new InputSource( reader ); - root = parser.parse(inputSource).getDocumentElement(); - - NodeList children = root.getChildNodes(); - for (int i=0; i< children.getLength(); i++) { - Node aliasNode = children.item(i); - if (aliasNode.getNodeName().equals("product")){ - NamedNodeMap productAttribs = aliasNode.getAttributes(); - String name = productAttribs.getNamedItem("name").getNodeValue(); - //System.out.println("ALIAS QUERY ==> " + dottedName + " <==> " + alias); - productList.add(name); - } - } - - } catch (Exception e) { - e.printStackTrace(); - Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); - } - - return productList; - } - - private HashMap parseQueryAliasResult(String queryResult) { - /* Alias to dotted name config */ - HashMap sbsAliasMap = new HashMap(); - - try { - Element root = null; - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - parser.setErrorHandler(new DefaultHandler()); - - StringReader reader = new StringReader( queryResult ); - InputSource inputSource = new InputSource( reader ); - root = parser.parse(inputSource).getDocumentElement(); - - NodeList children = root.getChildNodes(); - for (int i=0; i< children.getLength(); i++) { - Node aliasNode = children.item(i); - if (aliasNode.getNodeName().equals("alias")){ - NamedNodeMap meaning = aliasNode.getAttributes(); - String dottedName = meaning.getNamedItem("meaning").getNodeValue(); - String alias = meaning.getNamedItem("name").getNodeValue(); - //System.out.println("ALIAS QUERY ==> " + dottedName + " <==> " + alias); - sbsAliasMap.put(alias, dottedName); - } - } - - } catch (Exception e) { - e.printStackTrace(); - Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); - } - - - return sbsAliasMap; - } - - private HashMap parseQueryConfigResults(String queryResult) { - /* Alias to output directory */ - HashMap sbsAliasMap = new HashMap(); - - try { - Element root = null; - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - parser.setErrorHandler(new DefaultHandler()); - - StringReader reader = new StringReader( queryResult ); - InputSource inputSource = new InputSource( reader ); - root = parser.parse(inputSource).getDocumentElement(); - - NodeList children = root.getChildNodes(); - for (int i=0; i< children.getLength(); i++) { - Node aliasNode = children.item(i); - if (aliasNode.getNodeName().equals("config")){ - NamedNodeMap meaning = aliasNode.getAttributes(); - String outputpath = meaning.getNamedItem("outputpath").getNodeValue(); - String fullName = meaning.getNamedItem("fullname").getNodeValue(); - //System.out.println("ALIAS QUERY ==> " + dottedName + " <==> " + alias); - sbsAliasMap.put(fullName, outputpath); - } - } - - } catch (Exception e) { - e.printStackTrace(); - Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); - } - - - return sbsAliasMap; - } - - - private String getSBSQueryOutput(List queryCommandList, String[] env) { - String overallOutput = ""; - - Runtime rt = Runtime.getRuntime(); - IPath sbsPath = SBSv2Utils.getSBSPath(); - Process p = null; - List args = new ArrayList(); - args.add(sbsPath.toOSString()); - args.addAll(queryCommandList); - try { - p = rt.exec(args.toArray(new String[args.size()]), env); - } catch (IOException e) { - // no such process, SBSv2 not available - Logging.log( - SDKCorePlugin.getDefault(), - Logging.newSimpleStatus( - 0, - IStatus.WARNING, - MessageFormat - .format( - "Could not find or launch Raptor script ''{0}''; SBSv2 support will not be available", - sbsPath), e)); - } - if (p != null) { - BufferedReader br = new BufferedReader(new InputStreamReader(p - .getInputStream())); - - String stdErrLine = null; - try { - - // Only try for 30 seconds then bail in case Raptor hangs - int maxTries = 60; - int numTries = 0; - while (numTries < maxTries) { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - // ignore - } - if (br.ready()) { - while ((stdErrLine = br.readLine()) != null) { - overallOutput += stdErrLine; - numTries = maxTries; - } - - } - numTries++; - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - return overallOutput; - } - - private static String[] createEnvStringList(Properties envProps) { - String[] env = null; - List envList = new ArrayList(); - Enumeration names = envProps.propertyNames(); - if (names != null) { - while (names.hasMoreElements()) { - String key = (String) names.nextElement(); - envList.add(key + "=" + envProps.getProperty(key)); - } - env = (String[]) envList.toArray(new String[envList.size()]); - } - return env; - } public String getTimingStats(){ if (startTime != 0){ diff -r 1fd5209125b8 -r c70ff7f19887 builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/ISBSv2ConfigData.java --- a/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/ISBSv2ConfigData.java Wed May 19 17:52:30 2010 -0500 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/ISBSv2ConfigData.java Thu May 20 13:57:04 2010 -0500 @@ -11,13 +11,13 @@ String getMeaning(); - String getReleaseDirectory(); + String getReleaseDirectory(ISymbianSDK sdk); - ISBSv2ConfigPreprocessorInfo getBuildData(); + ISBSv2ConfigPreprocessorInfo getBuildData(ISymbianSDK sdk); - String getTraditionalTarget(); + String getTraditionalTarget(ISymbianSDK sdk); - String getTraditionalPlatform(); + String getTraditionalPlatform(ISymbianSDK sdk); List getSupportedSDKs(); diff -r 1fd5209125b8 -r c70ff7f19887 builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/SBSv2ConfigData.java --- a/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/SBSv2ConfigData.java Wed May 19 17:52:30 2010 -0500 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/SBSv2ConfigData.java Thu May 20 13:57:04 2010 -0500 @@ -1,14 +1,29 @@ package com.nokia.carbide.cdt.builder.test.sandbox; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; public class SBSv2ConfigData implements ISBSv2ConfigData { + /** + * A unique build alias. There can only be one alias definition, but an SDK can change the meaning of the alias + */ String buildAlias; + /* + * The dotted name for the alias. One build alias can have multiple meanings, each defined in an SDK + */ String meaning; + + String target = null; + String platform = null; + String releaseDirectory = null; + /** A configuration that was discovered without using a valid EPOCROOT during an sbs query */ private boolean isBaseConfig; List supportedSDKs = new ArrayList(); @@ -30,33 +45,68 @@ @Override public String getMeaning() { + // TODO: What do you do if the meaning is different for another SDK? + // We need to figure out when there is a meaning conflict, and when to resolve it + // A different meaning can mean different output directory and dotted names, + // potentially different indexer data return meaning; } @Override - public String getReleaseDirectory() { - // TODO Here's this may need to be dynamically determined... - //Maybe need ISymbianSDK param? - return null; + public String getReleaseDirectory(ISymbianSDK sdk) { + if (releaseDirectory == null){ + initDefaultConfigTargetInfo(sdk); + } + return releaseDirectory; + } + + private void initDefaultConfigTargetInfo(ISymbianSDK sdk) { + List aliasOrMeaningArray = new ArrayList(); + aliasOrMeaningArray.add(buildAlias); + HashMap configResponse = SBSv2QueryUtils.queryConfigTargetInfo(aliasOrMeaningArray, sdk); + String releaseTree = configResponse.get(meaning); + if (releaseTree == null){ + // TODO: Throw Exception + return; + } + IPath releasePath = new Path(releaseTree); + int epoc32SegmentIndex = 0; + for (String segment : releasePath.segments()){ + if (segment.toLowerCase().equals("epoc32")) + break; + epoc32SegmentIndex++; + } + platform = releasePath.segment(epoc32SegmentIndex+2); + target = releasePath.segment(epoc32SegmentIndex+3); + String device = releasePath.getDevice(); + releaseDirectory = releasePath.removeFirstSegments(epoc32SegmentIndex).toPortableString(); + releaseDirectory = releaseDirectory.replace(device, ""); + } @Override - public ISBSv2ConfigPreprocessorInfo getBuildData() { + public ISBSv2ConfigPreprocessorInfo getBuildData(ISymbianSDK sdk) { // TODO Auto-generated method stub return null; } @Override - public String getTraditionalTarget() { - // TODO NOT SURE IF THIS WILL BE NEEDED - return null; + public String getTraditionalTarget(ISymbianSDK sdk) { + if (target == null){ + initDefaultConfigTargetInfo(sdk); + } + + return target; } @Override - public String getTraditionalPlatform() { - // TODO NOT SURE IF THIS WILL BE NEEDED - return null; + public String getTraditionalPlatform(ISymbianSDK sdk) { + if (platform == null){ + initDefaultConfigTargetInfo(sdk); + } + + return platform; } @Override diff -r 1fd5209125b8 -r c70ff7f19887 builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/SBSv2QueryUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/sandbox/SBSv2QueryUtils.java Thu May 20 13:57:04 2010 -0500 @@ -0,0 +1,288 @@ +package com.nokia.carbide.cdt.builder.test.sandbox; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.cdt.utils.spawner.EnvironmentReader; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.helpers.DefaultHandler; + +import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils; +import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; +import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; +import com.nokia.cpp.internal.api.utils.core.Logging; + +public class SBSv2QueryUtils { + + public static final String QUERY_PRODUCTS_COMMAND = "--query=products"; + public static final String QUERY_CONFIG_COMMAND = "--query=config"; + public static final String QUERY_COMMAND = "--query=aliases"; + + public static ISBSv2QueryData queryAliasAndProductVariants() { + List argListConfigQuery = new ArrayList(); + List argListProductQuery = new ArrayList(); + argListConfigQuery.add(QUERY_COMMAND); + SBSv2QueryData sbsQueryData = new SBSv2QueryData(); + + /////// Invoke Raptor once with no EPOCROOT + Properties envVars = EnvironmentReader.getEnvVars(); + envVars.setProperty("EPOCROOT", "FOOBAR"); + String queryResult = getSBSQueryOutput(argListConfigQuery, createEnvStringList(envVars)); + + HashMap sbsAliasMap = parseQueryAliasResult(queryResult); + + for (String aliasKey : sbsAliasMap.keySet()){ + String meaning = sbsAliasMap.get(aliasKey); + SBSv2ConfigData oneSBSConfig = new SBSv2ConfigData(aliasKey, meaning, null); + sbsQueryData.addConfigurationData(oneSBSConfig); + } + + /////// Do for each SDK to build up the alias list... + for (ISymbianSDK sdk : SDKCorePlugin.getSDKManager().getSDKList()){ + IPath epocRoot = new Path(sdk.getEPOCROOT()); + if ((sdk.getOSVersion().getMajor() <= 9 && sdk.getOSVersion().getMinor() <5) + || !epocRoot.toFile().exists()){ + + continue; // skip it, the sdk is not supported or broken + } + + envVars = EnvironmentReader.getEnvVars(); + envVars.setProperty("EPOCROOT", sdk.getEPOCROOT()); + + queryResult = getSBSQueryOutput(argListConfigQuery, createEnvStringList(envVars)); + + sbsAliasMap = parseQueryAliasResult(queryResult); + + for (String aliasKey : sbsAliasMap.keySet()){ + String meaning = sbsAliasMap.get(aliasKey); + SBSv2ConfigData oneSBSConfig = new SBSv2ConfigData(aliasKey, meaning, sdk); + sbsQueryData.addConfigurationData(oneSBSConfig); + } + + // Now get the products for each SDK + argListProductQuery.add(QUERY_PRODUCTS_COMMAND); + queryResult = getSBSQueryOutput(argListProductQuery, createEnvStringList(envVars)); + List productList = parseQueryProductsResults(queryResult); + sbsQueryData.addProductListForSDK(sdk, productList); + } + + return sbsQueryData; + } + + public static HashMap queryConfigTargetInfo(List aliasOrMeaningArray, ISymbianSDK sdk){ + + List argListConfigQuery = new ArrayList(); + + for (String alias : aliasOrMeaningArray){ + argListConfigQuery.add(QUERY_CONFIG_COMMAND + "[" + alias + "]"); + } + + Properties envVars = null; + if (sdk != null){ + File epocRoot = new File(sdk.getEPOCROOT()); + if (epocRoot.exists()){ + envVars = EnvironmentReader.getEnvVars(); + envVars.setProperty("EPOCROOT", sdk.getEPOCROOT()); + } + } + String queryResult = getSBSQueryOutput(argListConfigQuery, createEnvStringList(envVars)); + + return parseQueryConfigResults(queryResult); + } + + private static String[] createEnvStringList(Properties envProps) { + + if (envProps == null){ + return null; + } + String[] env = null; + List envList = new ArrayList(); + Enumeration names = envProps.propertyNames(); + if (names != null) { + while (names.hasMoreElements()) { + String key = (String) names.nextElement(); + envList.add(key + "=" + envProps.getProperty(key)); + } + env = (String[]) envList.toArray(new String[envList.size()]); + } + return env; + } + + private static String getSBSQueryOutput(List queryCommandList, String[] env) { + String overallOutput = ""; + + Runtime rt = Runtime.getRuntime(); + IPath sbsPath = SBSv2Utils.getSBSPath(); + Process p = null; + List args = new ArrayList(); + args.add(sbsPath.toOSString()); + args.addAll(queryCommandList); + try { + p = rt.exec(args.toArray(new String[args.size()]), env); + } catch (IOException e) { + // no such process, SBSv2 not available + Logging.log( + SDKCorePlugin.getDefault(), + Logging.newSimpleStatus( + 0, + IStatus.WARNING, + MessageFormat + .format( + "Could not find or launch Raptor script ''{0}''; SBSv2 support will not be available", + sbsPath), e)); + } + if (p != null) { + BufferedReader br = new BufferedReader(new InputStreamReader(p + .getInputStream())); + + String stdErrLine = null; + try { + + // Only try for 30 seconds then bail in case Raptor hangs + int maxTries = 60; + int numTries = 0; + while (numTries < maxTries) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // ignore + } + if (br.ready()) { + while ((stdErrLine = br.readLine()) != null) { + overallOutput += stdErrLine; + numTries = maxTries; + } + + } + numTries++; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + return overallOutput; + } + + private static HashMap parseQueryAliasResult(String queryResult) { + /* Alias to dotted name config */ + HashMap sbsAliasMap = new HashMap(); + + try { + Element root = null; + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + parser.setErrorHandler(new DefaultHandler()); + + StringReader reader = new StringReader( queryResult ); + InputSource inputSource = new InputSource( reader ); + root = parser.parse(inputSource).getDocumentElement(); + + NodeList children = root.getChildNodes(); + for (int i=0; i< children.getLength(); i++) { + Node aliasNode = children.item(i); + if (aliasNode.getNodeName().equals("alias")){ + NamedNodeMap meaning = aliasNode.getAttributes(); + String dottedName = meaning.getNamedItem("meaning").getNodeValue(); + String alias = meaning.getNamedItem("name").getNodeValue(); + //System.out.println("ALIAS QUERY ==> " + dottedName + " <==> " + alias); + sbsAliasMap.put(alias, dottedName); + } + } + + } catch (Exception e) { + e.printStackTrace(); + Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); + } + + + return sbsAliasMap; + } + + private static HashMap parseQueryConfigResults(String queryResult) { + /* Alias to output directory */ + HashMap sbsAliasMap = new HashMap(); + + try { + Element root = null; + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + parser.setErrorHandler(new DefaultHandler()); + + StringReader reader = new StringReader( queryResult ); + InputSource inputSource = new InputSource( reader ); + root = parser.parse(inputSource).getDocumentElement(); + + NodeList children = root.getChildNodes(); + for (int i=0; i< children.getLength(); i++) { + Node aliasNode = children.item(i); + if (aliasNode.getNodeName().equals("config")){ + NamedNodeMap meaning = aliasNode.getAttributes(); + String outputpath = meaning.getNamedItem("outputpath").getNodeValue(); + String fullName = meaning.getNamedItem("fullname").getNodeValue(); + //System.out.println("ALIAS QUERY ==> " + dottedName + " <==> " + alias); + sbsAliasMap.put(fullName, outputpath); + } + } + + } catch (Exception e) { + e.printStackTrace(); + Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); + } + + + return sbsAliasMap; + } + + private static List parseQueryProductsResults(String queryResult) { + List productList = new ArrayList(); + + try { + Element root = null; + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + parser.setErrorHandler(new DefaultHandler()); + + StringReader reader = new StringReader( queryResult ); + InputSource inputSource = new InputSource( reader ); + root = parser.parse(inputSource).getDocumentElement(); + + NodeList children = root.getChildNodes(); + for (int i=0; i< children.getLength(); i++) { + Node aliasNode = children.item(i); + if (aliasNode.getNodeName().equals("product")){ + NamedNodeMap productAttribs = aliasNode.getAttributes(); + String name = productAttribs.getNamedItem("name").getNodeValue(); + //System.out.println("ALIAS QUERY ==> " + dottedName + " <==> " + alias); + productList.add(name); + } + } + + } catch (Exception e) { + e.printStackTrace(); + Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); + } + + return productList; + } + + + + +}