Subversion Repositories XServices

Rev

Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 11... Line 11...
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
-
 
17
package net.brutex.xservices.util;
16
package net.brutex.xservices.util;
Line 18... Line 17...
18
 
17
 
19
import java.io.ByteArrayOutputStream;
18
import java.io.ByteArrayOutputStream;
20
import java.io.PrintStream;
19
import java.io.PrintStream;
21
import java.util.Iterator;
20
import java.util.HashMap;
22
import java.util.Map;
21
import java.util.Map;
-
 
22
import net.brutex.xservices.types.AntProperty;
23
import java.util.Vector;
23
import net.brutex.xservices.types.ReturnCode;
24
import org.apache.tools.ant.BuildException;
-
 
25
import org.apache.tools.ant.BuildListener;
-
 
26
import org.apache.tools.ant.BuildLogger;
24
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.Project;
25
import org.apache.tools.ant.Project;
28
import org.apache.tools.ant.Target;
26
import org.apache.tools.ant.Target;
29
import org.apache.tools.ant.Task;
27
import org.apache.tools.ant.Task;
30
import org.apache.tools.ant.listener.TimestampedLogger;
28
import org.apache.tools.ant.listener.TimestampedLogger;
Line 37... Line 35...
37
public class RunTask {
35
public class RunTask {
Line 38... Line 36...
38
 
36
 
39
    Project antproject;
37
    Project antproject;
40
    Target anttarget;
38
    Target anttarget;
41
    Task anttask;
-
 
42
 
39
    Task anttask;
43
    ByteArrayOutputStream out = new ByteArrayOutputStream();
40
    ByteArrayOutputStream out = new ByteArrayOutputStream();
44
    ByteArrayOutputStream err = new ByteArrayOutputStream();
41
    ByteArrayOutputStream err = new ByteArrayOutputStream();
Line 45... Line 42...
45
    TimestampedLogger log = null;
42
    TimestampedLogger log = null;
Line 53... Line 50...
53
        log.setOutputPrintStream(new PrintStream(out));
50
        log.setOutputPrintStream(new PrintStream(out));
54
        log.setErrorPrintStream(new PrintStream(err));
51
        log.setErrorPrintStream(new PrintStream(err));
55
        log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
52
        log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
Line 56... Line 53...
56
 
53
 
57
        antproject.addBuildListener(log);
54
        antproject.addBuildListener(log);
58
        
55
 
59
        anttarget = new Target();
56
        anttarget = new Target();
60
        anttarget.setName("XBridgeNGDynamicTarget");
57
        anttarget.setName("XBridgeNGDynamicTarget");
61
        anttarget.setProject(antproject);
58
        anttarget.setProject(antproject);
Line 65... Line 62...
65
        prepareTask();
62
        prepareTask();
66
    }
63
    }
Line 67... Line 64...
67
 
64
 
68
    private void prepareTask()
65
    private void prepareTask()
69
            throws BuildException {
66
            throws BuildException {
70
            anttask.init();
67
        anttask.init();
71
            anttask.setProject(antproject);
68
        anttask.setProject(antproject);
72
            anttask.setOwningTarget(anttarget);
69
        anttask.setOwningTarget(anttarget);
73
            anttarget.addTask(anttask);
70
        anttarget.addTask(anttask);
74
            antproject.addOrReplaceTarget(anttarget);
71
        antproject.addOrReplaceTarget(anttarget);
Line 75... Line 72...
75
    }
72
    }
76
 
73
 
-
 
74
    public ReturnCode postTask() {
77
    public Map<String, String> postTask()
75
        int returnCode = 0;
-
 
76
        Map<String, String> origMap = new HashMap<String, String>();
78
            throws BuildException
77
        Map<String, String> newMap = null;
79
        {
78
        origMap.putAll(antproject.getProperties());
80
        try {
79
        try {
81
        antproject.executeTarget(anttarget.getName());
80
            antproject.executeTarget(anttarget.getName());
-
 
81
        } catch (BuildException ex) {
82
        } catch (Exception ex) {
82
            new PrintStream(err).println(ex.getMessage());
83
            new PrintStream(err).println(ex.getMessage());
83
            returnCode = 1;
-
 
84
        }
84
        }
85
        newMap = antproject.getProperties();
85
        Map<String, String> map = antproject.getProperties();
86
 
-
 
87
        for (Map.Entry<String, String> e : origMap.entrySet()) {
-
 
88
            newMap.remove(e.getKey());
86
        map.put("System.stdOut", out.toString());
89
        }
-
 
90
 
-
 
91
        //anttask.execute();
87
        map.put("System.stdErr", err.toString());
92
        return new ReturnCode(returnCode,
-
 
93
                out.toString(),
88
        //anttask.execute();
94
                err.toString(),
89
        return map;
95
                AntProperty.createAntPropertyList(newMap));
90
        
96