KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > build > CleanBuildTask


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.kelp.jbuilder.build;
23
24 // JBuilder imports
25
import com.borland.primetime.build.BuildTask;
26 import com.borland.primetime.build.BuildProcess;
27 import com.borland.primetime.node.Project;
28 import com.borland.primetime.node.TextFileNode;
29 import com.borland.jbuilder.node.JBProject;
30
31 // Kelp imports
32

33 // Standard imports
34
import java.util.Vector JavaDoc;
35 import java.util.ResourceBundle JavaDoc;
36 import java.io.File JavaDoc;
37 import org.enhydra.kelp.ant.node.AntProject;
38 import java.io.*;
39 import com.borland.primetime.vfs.Url;
40 import org.enhydra.kelp.jbuilder.node.NodeUtil;
41 import com.borland.primetime.node.LightweightNode;
42
43 /**
44  * BuildTask implementation for calling Clean.
45  *
46  */

47 public class CleanBuildTask extends BuildTask {
48
49     public static final String JavaDoc SHARED_KEY = new String JavaDoc("Clean_TASK");
50
51     /**
52      * Constructor declaration
53      *
54      */

55     public CleanBuildTask() {}
56
57     /**
58      * Generate the DOM class using Clean.
59      */

60     public boolean build(BuildProcess buildProcess) {
61       String JavaDoc prjPath = buildProcess.getProject().getProjectPath().getFullName();
62       try {
63         AntProject antProject = new AntProject(prjPath);
64         buildProcess.fireBuildStatus("Kelp cleaning ...", true);
65         String JavaDoc enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR);
66         String JavaDoc execLine = enhydraDir + "/bin/ant";
67         if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
68           execLine += ".bat";
69         }
70         Process JavaDoc process = Runtime.getRuntime().exec(execLine + " clean", null,
71                                                     new File JavaDoc(prjPath));
72         InputStream inputStream = process.getInputStream();
73         InputStream errorStream = process.getErrorStream();
74         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
75         BufferedReader errorBufferedReader = new BufferedReader(new InputStreamReader(errorStream));
76         File JavaDoc logFile = null;
77         FileWriter logFileWriter = null;
78         BufferedWriter logBuffer = null;
79         PrintWriter logPrint = null;
80
81         String JavaDoc s = null;
82         String JavaDoc er = null;
83 /*
84         while(((s = bufferedReader.readLine()) != null) || ((er = errorBufferedReader.readLine()) != null)){
85           if(s != null){
86             System.out.println(s);
87             s = null;
88           }
89           if(er != null){
90             System.out.println(s);
91             er = null; //must reset becouse second condition is not executed if firs condition is true
92           }
93         }
94 */

95         process.destroy(); // vl 28.07.03
96
Url url = new Url(new File JavaDoc(antProject.getProperty(AntProject.OUTPUT_DIR)));
97         try {
98           LightweightNode nodes[] = buildProcess.getProject()
99               .findNodes(url.getName());
100           for (int i = 0; i < nodes.length; i++) {
101             nodes[i].setParent(null);
102           }
103         }
104         catch (Exception JavaDoc ex) {
105           ex.printStackTrace();
106         }
107       }
108       catch (Exception JavaDoc ex) {
109         ex.printStackTrace();
110       }
111       return true;
112     }
113 }
114
Popular Tags