import java.io.File;\r
import java.util.Iterator;\r
import java.util.LinkedHashSet;\r
+import java.util.Map;\r
import java.util.Set;\r
import java.util.StringTokenizer;\r
import java.util.Vector;\r
import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.DirectoryScanner;\r
import org.apache.tools.ant.Project;\r
+import org.apache.tools.ant.types.Environment;\r
+import org.apache.tools.ant.types.Path;\r
+import org.apache.tools.ant.types.Environment.Variable;\r
\r
/**\r
* \r
String includePathDelimiter = null;\r
\r
String outputDelimiter = null;\r
-\r
+ \r
+ private static String pathName = null;\r
+ \r
public void command(CCTask cctask, UserDefineDef userdefine) {\r
boolean isGccCommand = userdefine.getFamily().equalsIgnoreCase("GCC");\r
File workdir;\r
// if have source file append source file in command line.\r
//\r
Set allSrcFiles = new LinkedHashSet();\r
+\r
for (int i = 0; i < srcSets.size(); i++) {\r
ConditionalFileSet srcSet = (ConditionalFileSet) srcSets\r
.elementAt(i);\r
// Find matching source files\r
//\r
DirectoryScanner scanner = srcSet.getDirectoryScanner(project);\r
- \r
//\r
// Check each source file - see if it needs compilation\r
//\r
for (int j = 0; j < fileNames.length; j++) {\r
cmd[index++] = fileNames[j];\r
}\r
+ \r
+// StringBuffer logLine = new StringBuffer();\r
+// for(int i = 0; i < cmd.length; i++) {\r
+// logLine.append(cmd[i] + " ");\r
+// }\r
+// project.log(logLine.toString(), Project.MSG_VERBOSE);\r
\r
- int retval = runCommand(cctask, workdir, cmd);\r
+ int retval = 0;\r
\r
+ if (userdefine.getDpath() == null || userdefine.getDpath().trim().length() == 0) {\r
+ retval = runCommand(cctask, workdir, cmd, null);\r
+ } else {\r
+ String existPath = System.getenv(getPathName());\r
+ Environment newEnv = new Environment();\r
+ Variable var = new Variable();\r
+ var.setKey(getPathName());\r
+ var.setPath(new Path(project, userdefine.getDpath() + ";" + existPath));\r
+ newEnv.addVariable(var);\r
+ retval = runCommand(cctask, workdir, cmd, newEnv);\r
+ }\r
+ \r
+\r
if (retval != 0) {\r
throw new BuildException(userdefine.getCmd()\r
+ " failed with return code " + retval, cctask\r
.getLocation());\r
}\r
}\r
+ \r
+ private String getPathName() {\r
+ if (pathName != null) {\r
+ return pathName;\r
+ }\r
+ Map allEnv = System.getenv();\r
+ Iterator iter = allEnv.keySet().iterator();\r
+ while (iter.hasNext()) {\r
+ String key = (String)iter.next();\r
+ if(key.equalsIgnoreCase("PATH")) {\r
+ pathName = key;\r
+ break ;\r
+ }\r
+ }\r
+ return pathName;\r
+ }\r
\r
- protected int runCommand(CCTask task, File workingDir, String[] cmdline)\r
+ protected int runCommand(CCTask task, File workingDir, String[] cmdline, Environment env)\r
throws BuildException {\r
- return CUtil.runCommand(task, workingDir, cmdline, false, null);\r
+ //\r
+ // Write command to File\r
+ //\r
+ return CUtil.runCommand(task, workingDir, cmdline, false, env);\r
\r
}\r
}\r