KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.borland.primetime.build.BuildTask;
25 import com.borland.primetime.build.BuildProcess;
26 import com.borland.primetime.node.Project;
27 import com.borland.primetime.node.TextFileNode;
28 import com.borland.jbuilder.node.JBProject;
29
30 import java.util.Vector;
31 import java.util.ResourceBundle;
32 import java.io.File;
33 import org.enhydra.kelp.ant.node.AntProject;
34 import java.io.*;
35
36 import org.apache.tools.ant.BuildException;
37
38 /**
39  * BuildTask implementation for calling DODS.
40  *
41  */

42 public class DODSBuildTask
43     extends BuildTask {
44
45   public static final String SHARED_KEY = new String("DODS_TASK");
46   private BuildProcess buildProcess;
47
48   /**
49    * Constructor declaration
50    *
51    */

52   public DODSBuildTask() {}
53
54   /**
55    * Generate the DOM class using DODS.
56    */

57   public boolean build(BuildProcess buildProcess) {
58     this.buildProcess = buildProcess;
59     String prjPath = buildProcess.getProject().getProjectPath().getFullName();
60     try {
61       AntProject antProject = new AntProject(prjPath);
62       buildProcess.fireBuildStatus("DODS Generating...", true);
63       String enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR);
64       String execLine = enhydraDir + "/bin/ant";
65       if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
66         execLine += ".bat";
67       }
68       Process process = Runtime.getRuntime().exec(execLine + " dods", null,
69                                                   new File(prjPath));
70       InputStream inputStream = process.getInputStream();
71       BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
72           inputStream));
73       InputStream errorStream = process.getErrorStream();
74       BufferedReader errorBufferedReader = new BufferedReader(new
75           InputStreamReader(errorStream));
76       File logFile = null;
77       FileWriter logFileWriter = null;
78       BufferedWriter logBuffer = null;
79       PrintWriter logPrint = null;
80
81       String s = null;
82       String er = null;
83       /*
84               boolean finished = false;
85               // another build processes need to wait this batch to finish
86               while (!finished) {
87                 finished = true;
88                 try {
89                   process.exitValue();
90                 }
91                 catch (Exception ex) {
92                   finished = false;
93                 }
94               }
95        */

96       (new ErrorReader(errorBufferedReader)).start();
97       Thread er1 = new Thread();
98       while ( (s = bufferedReader.readLine()) != null) {
99         System.out.println(s);
100       }
101       int k = process.waitFor();
102       if (k != 0)
103         throw (new BuildException("Loader: Error occured!"));
104
105       process.destroy(); // vl 28.07.03
106

107     }
108     catch (Exception ex) {
109       ex.printStackTrace();
110       return false;
111     }
112
113     return true;
114   }
115   class ErrorReader extends Thread {
116
117     BufferedReader er;
118
119     public ErrorReader(BufferedReader bufferedreader) {
120       er = bufferedreader;
121       //System.out.println("Making ER");
122
}
123
124     public void run() {
125       try {
126         for (; !er.ready(); Thread.sleep(100L)) {}
127         String s;
128         while ( (s = er.readLine()) != null) {
129           System.out.println(s);
130         }
131       }
132       catch (Exception exception) {
133
134       }
135     }
136   }
137
138 }
Popular Tags