forwarding java corecomm compilation output via messagelist

This commit is contained in:
fros4943 2007-05-11 10:02:13 +00:00
parent 8585881f6c
commit 80ec85abad

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: CoreComm.java,v 1.8 2007/05/10 16:59:00 fros4943 Exp $ * $Id: CoreComm.java,v 1.9 2007/05/11 10:02:13 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -35,6 +35,7 @@ import java.net.*;
import java.util.Vector; import java.util.Vector;
import se.sics.cooja.MoteType.MoteTypeCreationException; import se.sics.cooja.MoteType.MoteTypeCreationException;
import se.sics.cooja.dialogs.MessageList;
/** /**
* The purpose of corecomm's is communicating with a compiled Contiki system * The purpose of corecomm's is communicating with a compiled Contiki system
@ -180,45 +181,82 @@ public abstract class CoreComm {
} }
/** /**
* Compile given Java source file. * Compiles Java class.
* *
* @param className Class name * @param className Java class name (without extension)
* @return True if success, false otherwise * @throws MoteTypeCreationException If Java class compilation error occurrs
*/ */
private static boolean compileSourceFile(String className) { private static void compileSourceFile(String className)
throws MoteTypeCreationException {
MessageList compilationOutput = new MessageList();
OutputStream compilationStandardStream = compilationOutput
.getInputStream(MessageList.NORMAL);
OutputStream compilationErrorStream = compilationOutput
.getInputStream(MessageList.ERROR);
File classFile = new File("se/sics/cooja/corecomm/" + className + ".class"); File classFile = new File("se/sics/cooja/corecomm/" + className + ".class");
try { try {
String[] cmd = new String[]{ int b;
GUI.getExternalToolsSetting("PATH_JAVAC"), String[] cmd = new String[] { GUI.getExternalToolsSetting("PATH_JAVAC"),
"se/sics/cooja/corecomm/" + className + ".java"}; "-version", "se/sics/cooja/corecomm/" + className + ".java" };
Process p = Runtime.getRuntime().exec(cmd, null, null); Process p = Runtime.getRuntime().exec(cmd, null, null);
InputStream outputStream = p.getInputStream();
InputStream errorStream = p.getErrorStream();
while ((b = outputStream.read()) >= 0) {
compilationStandardStream.write(b);
}
while ((b = errorStream.read()) >= 0) {
compilationErrorStream.write(b);
}
p.waitFor(); p.waitFor();
if (classFile.exists()) if (classFile.exists())
return true; return;
// Try including cooja.jar // Try including cooja.jar
cmd = new String[]{ cmd = new String[] {
GUI.getExternalToolsSetting("PATH_JAVAC"), GUI.getExternalToolsSetting("PATH_JAVAC"),
"-version",
"se/sics/cooja/corecomm/" + className + ".java", "se/sics/cooja/corecomm/" + className + ".java",
"-cp", "-cp",
GUI.getExternalToolsSetting("PATH_CONTIKI") + "/tools/cooja/dist/cooja.jar"}; GUI.getExternalToolsSetting("PATH_CONTIKI")
+ "/tools/cooja/dist/cooja.jar" };
p = Runtime.getRuntime().exec(cmd, null, null); p = Runtime.getRuntime().exec(cmd, null, null);
outputStream = p.getInputStream();
errorStream = p.getErrorStream();
while ((b = outputStream.read()) >= 0) {
compilationStandardStream.write(b);
}
while ((b = errorStream.read()) >= 0) {
compilationErrorStream.write(b);
}
p.waitFor(); p.waitFor();
if (classFile.exists()) if (classFile.exists())
return true; return;
} catch (IOException e) { } catch (IOException e) {
return false; MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
"Could not compile corecomm source file: " + className + ".java")
.initCause(e);
exception.setCompilationOutput(compilationOutput);
throw exception;
} catch (InterruptedException e) { } catch (InterruptedException e) {
return false; MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
"Could not compile corecomm source file: " + className + ".java")
.initCause(e);
exception.setCompilationOutput(compilationOutput);
throw exception;
} }
return false; MoteTypeCreationException exception = new MoteTypeCreationException(
"Could not compile corecomm source file: " + className + ".java");
exception.setCompilationOutput(compilationOutput);
throw exception;
} }
/** /**
@ -257,8 +295,7 @@ public abstract class CoreComm {
if (!generateLibSourceFile(className)) if (!generateLibSourceFile(className))
throw new MoteTypeCreationException("Could not generate corecomm source file: " + className + ".java"); throw new MoteTypeCreationException("Could not generate corecomm source file: " + className + ".java");
if (!compileSourceFile(className)) compileSourceFile(className);
throw new MoteTypeCreationException("Could not compile corecomm source file: " + className + ".java");
Class newCoreCommClass = loadClassFile(className); Class newCoreCommClass = loadClassFile(className);
if (newCoreCommClass == null) if (newCoreCommClass == null)