import java.util.Scanner;
import java.io.File;
import java.io.IOException;

import org.apache.tools.ant.BuildException;

import com.salesforce.ant.SFDCAntTask;
import com.sforce.soap.apex.ExecuteAnonymousResult;
import com.sforce.soap.apex.SoapConnection;
import com.sforce.ws.ConnectionException;

public class AnonymousExecuter extends SFDCAntTask {
	String code;
    public void setCode(String c) {
        code = c;
    }

    String fileName;
    public void setFileName(String fn) {
    	fileName = fn;
    }

    public void execute() {
    	try {
    		if (fileName != null && ! fileName.isEmpty()) {
		    	code = new Scanner(new File(fileName)).useDelimiter("\\A").next();
			}
			System.out.println(code);

    		SoapConnection connection = getApexConnection();
            ExecuteAnonymousResult result = connection.executeAnonymous(code);
            if (result.isSuccess()) {
                log("Success");
            } else {
                throw new BuildException(result.getExceptionMessage());
            }
        } catch (ConnectionException e) {
            log("Note: use ant -verbose to get more information on the failure");
            throw new BuildException("Failed: " + e.getMessage(), e);
		} catch (IOException ioe) {
			log(ioe.getMessage());
		}
    }
}

@@ -258,16 +258,181 @@
 ction;%0D%0A
+import com.sforce.soap.apex.LogInfo;%0D%0Aimport com.sforce.soap.apex.LogCategoryLevel;%0D%0Aimport com.sforce.soap.apex.LogCategory;%0D%0Aimport com.sforce.soap.apex.LogType;%0D%0A
 import c
@@ -876,38 +876,8 @@
 %09%09%7D%0D
-%0A%09%09%09System.out.println(code);%0D
 %0A%0D%0A 
@@ -927,24 +927,439 @@
 nection();%0D%0A
+%0D%0A            LogInfo infoApex = new LogInfo();%0D%0A            infoApex.setCategory(LogCategory.Apex_code);%0D%0A            infoApex.setLevel(LogCategoryLevel.Finest);%0D%0A%0D%0A            LogInfo infoDB = new LogInfo();%0D%0A            infoDB.setCategory(LogCategory.Db);%0D%0A            infoDB.setLevel(LogCategoryLevel.Finest);%0D%0A%0D%0A            connection.setDebuggingHeader(new LogInfo%5B%5D %7B infoApex, infoDB %7D, LogType.Detail);%0D%0A%0D%0A
             
@@ -1461,24 +1461,91 @@
 ccess()) %7B%0D%0A
+                log(connection.getDebuggingInfo().getDebugLog());%0D%0A
             

Debug logs for apex code and db