Mercurial > hg > Members > kono > jpf-core
changeset 18:a9ada67f1799
moved LogConsole to .jpf.tool package
author | Peter Mehlitz <pcmehlitz@gmail.com> |
---|---|
date | Tue, 31 Mar 2015 15:37:44 -0700 |
parents | e15b03204dc7 |
children | 9fea3d8da9aa |
files | .hgignore .idea/misc.xml src/main/gov/nasa/jpf/tool/LogConsole.java |
diffstat | 3 files changed, 164 insertions(+), 136 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon Mar 23 12:54:20 2015 -0700 +++ b/.hgignore Tue Mar 31 15:37:44 2015 -0700 @@ -3,6 +3,8 @@ local.properties .version .idea/workspace.xml +.idea/fileColors.xml +.idea/uiDesigner.xml nbproject/private/* build/* dist/*
--- a/.idea/misc.xml Mon Mar 23 12:54:20 2015 -0700 +++ b/.idea/misc.xml Tue Mar 31 15:37:44 2015 -0700 @@ -38,33 +38,6 @@ <property name="caretWidth" class="java.lang.Integer" /> </properties> </component> - <component name="CompilerConfiguration"> - <option name="DEFAULT_COMPILER" /> - <resourceExtensions /> - <wildcardResourcePatterns> - <entry name="!?*.java" /> - <entry name="!?*.form" /> - <entry name="!?*.class" /> - <entry name="!?*.groovy" /> - <entry name="!?*.scala" /> - <entry name="!?*.flex" /> - <entry name="!?*.kt" /> - <entry name="!?*.clj" /> - </wildcardResourcePatterns> - <annotationProcessing> - <profile default="true" name="Default" enabled="false"> - <processorPath useClasspath="true" /> - </profile> - </annotationProcessing> - </component> - <component name="CopyrightManager" default="" /> - <component name="DaemonCodeAnalyzer"> - <disable_hints /> - </component> - <component name="DependencyValidationManager"> - <option name="SKIP_IMPORT_STATEMENTS" value="false" /> - </component> - <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> <component name="EntryPointsManager"> <entry_points version="2.0" /> </component> @@ -78,118 +51,9 @@ <ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Remove" /> </component> - <component name="ProjectModuleManager"> - <modules /> - </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build" /> </component> - <component name="PropertiesComponent"> - <property name="GoToFile.includeJavaFiles" value="false" /> - <property name="GoToClass.toSaveIncludeLibraries" value="false" /> - <property name="MemberChooser.sorted" value="false" /> - <property name="MemberChooser.showClasses" value="true" /> - <property name="GoToClass.includeLibraries" value="false" /> - <property name="MemberChooser.copyJavadoc" value="false" /> - </component> - <component name="RunManager"> - <configuration default="true" type="Remote" factoryName="Remote"> - <option name="USE_SOCKET_TRANSPORT" value="true" /> - <option name="SERVER_MODE" value="false" /> - <option name="SHMEM_ADDRESS" value="javadebug" /> - <option name="HOST" value="localhost" /> - <option name="PORT" value="5005" /> - <method /> - </configuration> - <configuration default="true" type="JUnit" factoryName="JUnit"> - <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> - <module name="" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" /> - <option name="PACKAGE_NAME" /> - <option name="MAIN_CLASS_NAME" /> - <option name="METHOD_NAME" /> - <option name="TEST_OBJECT" value="class" /> - <option name="VM_PARAMETERS" value="-ea" /> - <option name="PARAMETERS" /> - <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> - <option name="ENV_VARIABLES" /> - <option name="PASS_PARENT_ENVS" value="true" /> - <option name="TEST_SEARCH_SCOPE"> - <value defaultName="moduleWithDependencies" /> - </option> - <envs /> - <patterns /> - <method /> - </configuration> - <configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin"> - <module name="" /> - <option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m" /> - <option name="PROGRAM_PARAMETERS" /> - <method /> - </configuration> - <configuration default="true" type="Applet" factoryName="Applet"> - <module name="" /> - <option name="MAIN_CLASS_NAME" /> - <option name="HTML_FILE_NAME" /> - <option name="HTML_USED" value="false" /> - <option name="WIDTH" value="400" /> - <option name="HEIGHT" value="300" /> - <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" /> - <option name="VM_PARAMETERS" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" /> - <method /> - </configuration> - <configuration default="true" type="TestNG" factoryName="TestNG"> - <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> - <module name="" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" /> - <option name="SUITE_NAME" /> - <option name="PACKAGE_NAME" /> - <option name="MAIN_CLASS_NAME" /> - <option name="METHOD_NAME" /> - <option name="GROUP_NAME" /> - <option name="TEST_OBJECT" value="CLASS" /> - <option name="VM_PARAMETERS" value="-ea" /> - <option name="PARAMETERS" /> - <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> - <option name="OUTPUT_DIRECTORY" /> - <option name="ANNOTATION_TYPE" /> - <option name="ENV_VARIABLES" /> - <option name="PASS_PARENT_ENVS" value="true" /> - <option name="TEST_SEARCH_SCOPE"> - <value defaultName="moduleWithDependencies" /> - </option> - <option name="USE_DEFAULT_REPORTERS" value="false" /> - <option name="PROPERTIES_FILE" /> - <envs /> - <properties /> - <listeners /> - <method /> - </configuration> - <configuration default="true" type="Application" factoryName="Application"> - <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> - <option name="MAIN_CLASS_NAME" /> - <option name="VM_PARAMETERS" /> - <option name="PROGRAM_PARAMETERS" /> - <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" /> - <option name="ENABLE_SWING_INSPECTOR" value="false" /> - <option name="ENV_VARIABLES" /> - <option name="PASS_PARENT_ENVS" value="true" /> - <module name="" /> - <envs /> - <method /> - </configuration> - <list size="0" /> - <configuration name="<template>" type="WebApp" default="true" selected="false"> - <Host>localhost</Host> - <Port>5050</Port> - </configuration> - </component> <component name="masterDetails"> <states> <state key="ProjectJDKs.UI">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/gov/nasa/jpf/tool/LogConsole.java Tue Mar 31 15:37:44 2015 -0700 @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2014, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package gov.nasa.jpf.tool; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * simple logging facility that listens on a socket (e.g. for log output display) + */ +public class LogConsole { + + static int DEF_PORT = 20000; // keep this in sync with the gov.nasa.jpf.util.LogHandler + + class ShutdownHook implements Runnable { + @Override + public void run () { + if (running) { + // not very threadsafe, but worst thing that can happen is we close twice + killed = true; + System.out.println("\nLogConsole killed, shutting down"); + } + try { + cs.close(); + ss.close(); + } catch (Throwable t) { + // not much we can do here anyway + } + } + } + + + boolean running; + + int port; + boolean autoclose; + boolean killed; + + ServerSocket ss; + Socket cs; + + public void run () { + running = true; + Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook())); + + if (port == 0) { + port = DEF_PORT; + } + + try { + ss = new ServerSocket(port); + + try { + do { + System.out.println("LogConsole listening on port: " + port); + + cs = ss.accept(); + BufferedReader in = new BufferedReader( new InputStreamReader(cs.getInputStream())); + String msg; + + System.out.println("LogConsole connected"); + System.out.println("--------------------------------------------------------------------------------"); + try { + + while ((msg = in.readLine()) != null) { + System.out.println(msg); + } + + System.out.println("--------------------------------------------------------------------------------"); + System.out.println("LogConsole disconnected"); + } catch (IOException iox) { + System.err.println(iox); + } + + in.close(); + cs.close(); + } while (!autoclose); + + System.out.println("LogConsole closing"); + + } catch (IOException iox) { + if (!killed) { + System.err.println("Error: LogConsole accept failed on port: " + port); + } + } + + } catch (IOException iox) { + System.err.println("Error: LogConsole cannot listen on port: " + port); + } + + running = false; + } + + public void showUsage () { + System.out.println("LogConsole: socket based console logger"); + System.out.println(" usage: java gov.nasa.jpf.tools.LogConsole {flags} [<port>]"); + System.out.println(" args: -help show this message"); + System.out.println(" -autoclose close the application upon disconnect"); + System.out.println(" <port> optional port number, default: " + DEF_PORT); + } + + boolean processArgs (String[] args) { + for (int i=0; i<args.length; i++) { + if (args[i].charAt(0) == '-') { + if (args[i].equals("-autoclose")) { + args[i] = null; + autoclose = true; + } else if (args[i].equals("-help")) { + showUsage(); + return false; + } else { + System.err.println("Warning: unknown argument (see -help for usage): " + args[i]); + } + } else { + if (args[i].matches("[0-9]+")) { + if (port != 0) { + System.err.println("Error: only one port parameter allowed (see -help for usage): " + args[i]); + return false; + } + + try { + port = Integer.parseInt(args[i]); + } catch (NumberFormatException nfx) { + System.err.println("Error: illegal port spec: " + args[i]); + return false; + } + } else { + System.out.println("Error: unknown argument: " + args[i]); + return false; + } + } + } + + return true; + } + + public static void main (String[] args) { + LogConsole console = new LogConsole(); + + if (console.processArgs(args)) { + console.run(); + } + } +}