You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/06/25 05:19:20 UTC

cvs commit: jakarta-avalon-excalibur/jprocess/src/xdocs/stylesheets project.xml

donaldp     2002/06/24 20:19:20

  Added:       jprocess .cvsignore ant.properties.sample build.xml
                        default.properties
               jprocess/src/java/org/apache/excalibur/jprocess
                        DemuxPolicy.java DemuxProperties.java
                        JavaProcess.java JavaProcessContextPolicy.java
                        PolicyRedirector.java StdioRedirector.java
                        SysPropertiesRedirector.java
               jprocess/src/test/org/apache/excalibur/jprocess/test
                        DemuxPolicyTestCase.java
                        DemuxPropertiesTestCase.java
               jprocess/src/xdocs index.xml
               jprocess/src/xdocs/stylesheets project.xml
  Log:
  Add in JProcess component extracted from myrmidon
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/jprocess/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  ant.properties
  build
  checkstyle.cache
  distributions
  dist
  excalibur-*
  *.el
  *.ipr
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/ant.properties.sample
  
  Index: ant.properties.sample
  ===================================================================
  # -----------------------------------------------------------------------------
  # Component ant.properties.sample
  #
  # This is an example "ant.properties" file, used to customize the building of
  # the component for your local environment.  It defines the location of all
  # external modules that this component depend on.  Copy this file to
  # "ant.properties" in the source directory, and customize it as needed.
  #
  # The ant.properties values in this directory apply only to this component.
  # It is overridden by ../ant.properties and ~/build.properties
  # It overrides all default.properties files and ~/.ant.properties
  #
  # $Id: ant.properties.sample,v 1.1 2002/06/25 03:19:20 donaldp Exp $
  # -----------------------------------------------------------------------------
  
  # ----- Compile Control Flags -----
  build.debug=on
  build.optimize=off
  build.deprecation=off
  #build.compiler=jikes
  
  # ----- Base Directory in which all the packages are stored -----
  base.path=${basedir}/../..
  
  # --------------------------------------------------
  #                REQUIRED LIBRARIES
  # --------------------------------------------------
  
  
  
  # --------------------------------------------------
  #                OPTIONAL LIBRARIES
  # --------------------------------------------------
  
  # ----- JUnit Unit Test Suite, version 3.7 or later. -----
  #  Not needed if junit.jar is in $ANT_HOME/lib 
  junit.home=${base.path}/junit3.7
  junit.lib=${junit.home}
  junit.jar=${junit.lib}/junit.jar
  
  
  # ----- Checkstyle, version 2.1 or later -----
  # Uncomment the 'do.checkstyle' flag property to enable checkstyle
  # do.checkstyle=
  checkstyle.home=${base.path}/checkstyle-2.1
  checkstyle.lib=${checkstyle.home}
  checkstyle.jar=${checkstyle.lib}/checkstyle-all-2.1.jar
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project name="Excalibur JProcess" default="main" basedir=".">
  
      <property file="${user.home}/build.properties"/>
      <property file="${basedir}/../ant.properties"/>
      <property file="${basedir}/ant.properties"/>
      <property file="${user.home}/.ant.properties"/>
      <property file="${basedir}/../default.properties"/>
      <property file="${basedir}/default.properties"/>
  
      <!-- Classpath for product -->
      <path id="project.class.path">
          <pathelement location="${build.classes}"/>
          <pathelement location="${excalibur-io.jar}"/>
          <pathelement location="${excalibur-threadcontext.jar}"/>
          <pathelement location="${checkstyle.jar}"/>
          <pathelement path="${java.class.path}"/>
      </path>
  
      <path id="tools.class.path">
          <pathelement location="${junit.jar}"/>
          <fileset dir="${jakarta-site.dir}/lib"/>
      </path>
  
      <path id="test.class.path">
          <pathelement location="${build.testclasses}"/>
          <pathelement location="${junit.jar}"/>
          <path refid="project.class.path"/>
      </path>
      <property name="cp" refid="test.class.path"/>
  
      <target name="main" depends="jar" description="Build the project"/>
      <target name="rebuild" depends="clean,main" description="Rebuild the project"/>
  
      <target name="dependencies" description="Check dependencies" unless="skip.dependencies">
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkThreadcontext"/>
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkIO"/>
      </target>
  
      <target name="dependencies-test" depends="dist-jar, dependencies"
          description="Check unit test dependencies" unless="skip.dependencies">
          <!-- Need the jar to prevent recursive deps. -->
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkJUnit"/>
      </target>
  
  
      <!-- Compiles the source code -->
      <target name="compile" depends="dependencies" description="Compiles the source code">
  
          <mkdir dir="${build.classes}"/>
  
          <!-- Compile all classes excluding the tests. -->
          <javac srcdir="${java.dir}"
              destdir="${build.classes}"
              debug="${build.debug}"
              optimize="${build.optimize}"
              deprecation="${build.deprecation}"
              target="1.2">
              <classpath refid="project.class.path" />
              <include name="**/*.java"/>
          </javac>
  
          <!-- copy resources to same location as .class files -->
          <copy todir="${build.classes}">
              <fileset dir="${java.dir}">
                  <exclude name="**/*.java"/>
                  <exclude name="**/package.html"/>
              </fileset>
          </copy>
  
      </target>
  
      <!-- Compiles the unit test source code -->
      <target name="compile-test" depends="compile, dependencies-test" description="Compiles the source code">
          <mkdir dir="${build.testsrc}"/>
  
          <!-- Copy over all of the tests applying test filters -->
          <copy todir="${build.testsrc}">
              <fileset dir="${test.dir}"/>
          </copy>
  
          <mkdir dir="${build.testclasses}"/>
  
          <!-- Compile all test classes. -->
          <javac srcdir="${build.testsrc}"
              destdir="${build.testclasses}"
              debug="${build.debug}"
              optimize="${build.optimize}"
              deprecation="${build.deprecation}"
              target="1.2">
              <classpath refid="test.class.path" />
              <include name="**/*.java"/>
          </javac>
  
          <copy todir="${build.testclasses}">
              <fileset dir="${test.dir}">
                  <exclude name="**/*.java"/>
                  <exclude name="**/package.html"/>
              </fileset>
          </copy>
  
      </target>
  
      <!-- Copies and filters the license. Used by jar and dist -->
      <target name="prepare-conf">
          <mkdir dir="${build.conf}"/>
          <copy todir="${build.conf}" flatten="true">
              <fileset dir="../" includes="LICENSE.txt"/>
              <filterset>
                  <filter token="year" value="${year}"/>
              </filterset>
          </copy>
      </target>
  
      <!-- Creates all the .jar file -->
      <target name="jar" depends="compile, prepare-conf" description="Generates the jar files">
  
          <mkdir dir="${build.lib}"/>
  
          <jar jarfile="${build.lib}/${jar.name}"
              basedir="${build.classes}"
              compress="${build.compress}">
              <manifest>
                  <attribute name="Extension-Name" value="${name}"/>
                  <attribute name="Specification-Vendor" value="Apache Software Foundation"/>
                  <attribute name="Specification-Version" value="1.0"/>
                  <attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
                  <attribute name="Implementation-Version" value="${package-version}"/>
              </manifest>
              <exclude name="**/test/**"/>
              <zipfileset dir="${build.conf}" prefix="META-INF/">
                  <include name="LICENSE.txt"/>
              </zipfileset>
          </jar>
      </target>
  
      <!-- Creates all the Javadocs -->
      <target name="javadocs" depends="compile" description="Generates the javadocs" unless="skip.javadocs">
  
          <mkdir dir="${dist.javadocs}"/>
          <javadoc packagenames="org.apache.*"
              sourcepath="${java.dir}"
              destdir="${dist.javadocs}">
              <classpath refid="project.class.path" />
              <doclet name="com.sun.tools.doclets.standard.Standard">
                  <param name="-author"/>
                  <param name="-version"/>
                  <param name="-doctitle" value="${Name}"/>
                  <param name="-windowtitle" value="${Name} API"/>
                  <param name="-link" value="http://java.sun.com/j2se/1.4/docs/api/"/>
                  <param name="-link" value="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/"/>
                  <param name="-link" value="http://jakarta.apache.org/avalon/api/"/>
                  <param name="-bottom"
                      value="&quot;Copyright &#169; ${year} Apache Jakarta Project. All Rights Reserved.&quot;"/>
              </doclet>
          </javadoc>
      </target>
  
      <target name="test" depends="compile-test" description="Perform the unit tests" unless="skip.tests">
  
          <echo message="Performing Unit Tests" />
  
          <mkdir dir="${build.tests}"/>
  
          <junit fork="true"
              haltonfailure="${junit.failonerror}"
              printsummary="yes"
              dir="${build.tests}">
              <classpath refid="test.class.path"/>
  
              <formatter type="xml"/>    <!-- xml reports for junitreport -->
              <formatter type="plain" usefile="false"/>  <!-- text reports for humans     -->
  
              <batchtest todir="${build.tests}">
                  <fileset dir="${build.testclasses}">
                      <include name="**/test/*TestCase.class"/>
                      <exclude name="**/Abstract*"/>
                  </fileset>
              </batchtest>
          </junit>
  
      </target>
  
      <target name="test-reports" depends="test" description="Generate Reports for the unit tests">
  
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkBSF"/>
  
          <mkdir dir="${build.reports}/junit"/>
  
          <junitreport todir="${build.reports}/junit">
              <fileset dir="${build.tests}">
                  <include name="TEST-*.xml"/>
              </fileset>
              <report format="frames" todir="${build.reports}/junit"/>
          </junitreport>
  
          <!-- Clean up the xml reports used by the junitreport task -->
          <!--
          <delete>
              <fileset dir="${build.tests}" includes="TEST-*.xml"/>
              <fileset dir="${build.tests}" includes="TESTS-*.xml"/>
          </delete>
          -->
  
      </target>
  
      <target name="checkstyle" if="do.checkstyle" description="Checkstyle">
  
          <!-- this invocation of checkstyle requires that checkstyle be downloaded and setup -->
          <!-- thats why you are required to define do.checkstyle property to generate the report -->
          <taskdef name="checkstyle"
              classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
              <classpath refid="project.class.path"/>
          </taskdef>
          <checkstyle
              lcurlyType="nl"
              lcurlyMethod="nl"
              lcurlyOther="nl"
              rcurly="ignore"
              allowProtected="false"
              allowPackage="false"
              allowNoAuthor="false"
              maxLineLen="100"
              maxMethodLen="100"
              maxConstructorLen="100"
              memberPattern="^m_[a-z][a-zA-Z0-9]*$"
              staticPattern="^c_[a-z][a-zA-Z0-9]*$"
              constPattern="(^c_[a-z][a-zA-Z0-9]*$)|([A-Z_]*$)"
              ignoreImportLen="true"
              allowTabs="false"
              javadocScope="protected"
              ignoreWhitespace="true"
              cacheFile="checkstyle.cache"
              failOnViolation="false"
              ignoreCastWhitespace="true">
              <fileset dir="${java.dir}">
                  <include name="**/*.java"/>
              </fileset>
              <formatter type="plain"/>
              <formatter type="xml" toFile="${build.dir}/checkstyle-results.xml"/>
          </checkstyle>
      </target>
  
      <target name="checkstyle-report"
          depends="checkstyle"
          if="do.checkstyle"
          description="Generate Checkstyle Report">
  
          <mkdir dir="${build.reports}/checkstyle"/>
          <property name="checkstyle.pathhack" location="."/>
          <style style="${tools.dir}/etc/checkstyle-frames.xsl" in="${build.dir}/checkstyle-results.xml"
              out="${build.reports}/checkstyle/delete-me.html">
              <param name="pathhack" expression="${checkstyle.pathhack}"/>
          </style>
  
      </target>
  
      <!-- Creates the distribution -->
      <target name="dist"
          depends="dist-jar, test-reports, checkstyle-report, javadocs"
          description="Generates a distribution (jar + javadocs + unit tests + checkstyle reports)">
  
          <copy file="${build.conf}/LICENSE.txt" todir="${dist.dir}"/>
          <copy file="../KEYS" todir="${dist.dir}"/>
  
          <mkdir dir="${dist.base}"/>
  
          <zip zipfile="${dist.base}/${dist.name}-bin.zip" compress="true">
              <zipfileset dir="${dist.dir}" prefix="${dist.name}"/>
          </zip>
  
          <!--
            Not supported by released ant but when it is we should enable this across
            all of the products
          <tar longfile="gnu" tarfile="${dist.base}/${dist.name}-bin.tar">
            <tarfileset dir="${dist.dir}"
                        prefix="${dist.name}"
                        username="avalon"
                        group="avalon"/>
          </tar>
  
          <gzip zipfile="${dist.base}/${dist.name}-bin.tar.gz"
                src="${dist.name}-bin.tar"/>
          <bzip2 zipfile="${dist.base}/${dist.name}-bin.tar.gz"
                 src="${dist.name}-bin.tar"/>
  
          <delete file="${dist.base}/${dist.name}-bin.tar"/>
  
          <checksum fileext=".md5">
            <fileset dir="${dist.base}" />
          </checksum>
          -->
          <delete dir="${dist.dir}" />
  
      </target>
  
      <!-- Creates a mini jar-only distribution -->
      <target name="dist-jar" depends="jar">
          <mkdir dir="${dist.dir}"/>
          <copy todir="${dist.dir}">
              <fileset dir="${build.lib}">
                  <include name="*.jar"/>
              </fileset>
          </copy>
      </target>
  
      <!-- Creates a minimal distribution -->
      <target name="dist.lite"
          depends="dist-jar, test, javadocs"
          description="Generates a minimal distribution (jar + javadocs)">
  
          <copy file="../LICENSE.txt" todir="${dist.dir}"/>
          <copy file="../KEYS" todir="${dist.dir}"/>
  
      </target>
  
      <target name="anakia-avail">
          <available classname="org.apache.velocity.anakia.AnakiaTask"
              property="AnakiaTask.present">
              <classpath refid="tools.class.path"/>
          </available>
      </target>
  
      <target name="anakia-check" depends="anakia-avail" unless="AnakiaTask.present">
          <echo>
              AnakiaTask is not present! Please check to make sure that
              velocity.jar is in your classpath. The easiest way to build
              the documentation is to checkout jakarta-site CVS and specify
              jakarta-site.dir property.
          </echo>
      </target>
  
      <target name="docs" depends="anakia-check" description="Generate documentation and website">
          <taskdef name="anakia"
              classname="org.apache.velocity.anakia.AnakiaTask">
              <classpath refid="tools.class.path"/>
          </taskdef>
  
          <anakia basedir="${xdocs.dir}"
              destdir="${docs.dir}"
              style="docs.vsl"
              projectfile="stylesheets/project.xml"
              includes="**/*.xml"
              excludes="stylesheets/**"
              velocitypropertiesfile="../site/src/stylesheets/velocity.properties"
              />
  
          <copy todir="${docs.dir}" filtering="off">
              <fileset dir="../site/src" includes="css/*.css" />
              <fileset dir="${xdocs.dir}">
                  <include name="**/images/**"/>
                  <include name="**/*.gif"/>
                  <include name="**/*.jpg"/>
                  <include name="**/*.png"/>
                  <include name="**/*.css"/>
                  <include name="**/*.js"/>
              </fileset>
          </copy>
      </target>
  
      <target name="site" depends="javadocs, docs" description=" Places Docs ready for hosting on website">
  
          <mkdir dir="../site/dist/docs/${dir-name}"/>
          <copy todir="../site/dist/docs/${dir-name}">
              <fileset dir="${docs.dir}">
                  <include name="**"/>
              </fileset>
          </copy>
  
      </target>
  
      <!-- Cleans up build and distribution directories -->
      <target name="clean" description="Cleans up the project">
          <delete file="checkstyle.cache"/>
          <delete dir="${build.dir}" />
          <delete dir="${dist.dir}" />
          <delete dir="test" /> <!-- unit testing output directory -->
          <delete>
              <fileset dir="." includes="**/*~" defaultexcludes="no"/>
          </delete>
      </target>
  
      <target name="real-clean" depends="clean" description="Cleans up the project, including distributions">
          <delete dir="${dist.base}" />
      </target>
  
  </project>
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/default.properties
  
  Index: default.properties
  ===================================================================
  # -------------------------------------------------------------------
  # B U I L D  P R O P E R T I E S
  # -------------------------------------------------------------------
  # Specifies default property values
  # Overridden by ../default.properties and all ant.properties
  # Not user-editable; use ant.properties files instead
  
  name=excalibur-jprocess
  Name=Excalibur JProcess
  dir-name=jprocess
  version=0.99
  package-version=0.99
  year=2002
  
  # --------------------------------------------------
  #                REQUIRED LIBRARIES
  # --------------------------------------------------
  
  # ----- Excalibur IO, version 1.1 or later -----
  excalibur-io.home=${basedir}/../io/dist
  excalibur-io.lib=${excalibur-io.home}
  excalibur-io.jar=${excalibur-io.lib}/excalibur-io-1.1.jar
  
  # ----- Excalibur ThreadContext, version 1.1 or later -----
  excalibur-threadcontext.home=${basedir}/../threadcontext/dist
  excalibur-threadcontext.lib=${excalibur-threadcontext.home}
  excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
  
  # --------------------------------------------------
  
  #  Settings used to configure compile environment
  build.debug = on
  build.optimize = off
  build.deprecation = off
  build.compress = false
  junit.failonerror = false
  
  #  location of intermediate products
  build.dir = build
  build.testsrc = ${build.dir}/testsrc
  build.testclasses = ${build.dir}/testclasses
  build.lib = ${build.dir}/lib
  build.conf = ${build.dir}/conf
  build.classes = ${build.dir}/classes
  build.tests = ${build.dir}/tests
  build.reports = ${build.dir}/reports
  
  #  Set the properties for source directories
  src.dir = src
  java.dir = ${src.dir}/java
  conf.dir = ${src.dir}/conf
  test.dir = ${src.dir}/test
  
  #  Set the properties for distribution directories
  dist.dir = dist
  dist.javadocs = ${dist.dir}/docs/api
  
  xdocs.dir = ${src.dir}/xdocs
  docs.dir = ${dist.dir}/docs
  jakarta-site.dir = ../../jakarta-site
  
  #  name of .zip/.tar.gz/.bz2 files and their top-level directory
  dist.name = ${name}-${version}
  
  #  name of jar file
  jar.name = ${name}-${version}.jar
  
  #  property indicating directory where all distribution archives are placed
  dist.base = distributions
  
  depchecker.prefix=.
  
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/DemuxPolicy.java
  
  Index: DemuxPolicy.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.security.CodeSource;
  import java.security.PermissionCollection;
  import java.security.Policy;
  
  /**
   * This is a Policy object that delegates to a Policy objects
   * associated with the current thread.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   */
  public class DemuxPolicy
      extends Policy
  {
      /**
       * The Policy associated with each thread.
       */
      private final InheritableThreadLocal m_policies =
          new InheritableThreadLocal();
  
      /**
       * The default Policy to fall back on if no Policy
       * object bound.
       */
      private final Policy m_defaultPolicy;
  
      /**
       * Create a Policy object that delegates to per-thread
       * Policy objects.
       *
       * @param defaultPolicy the default Policy object
       */
      public DemuxPolicy( final Policy defaultPolicy )
      {
          m_defaultPolicy = defaultPolicy;
      }
  
      /**
       * Bind the specified Policy object to the current thread.
       *
       * @param policy the Policy object to bind
       */
      public Policy bindPolicy( final Policy policy )
      {
          final Policy oldPolicy = (Policy)m_policies.get();
          m_policies.set( policy );
          return oldPolicy;
      }
  
      public PermissionCollection getPermissions( final CodeSource codesource )
      {
          return getCurrentPolicy().getPermissions( codesource );
      }
  
      public void refresh()
      {
          getCurrentPolicy().refresh();
      }
  
      /**
       * Retrieve Policy currently in operation.
       *
       * @return the current policy
       */
      private Policy getCurrentPolicy()
      {
          final Policy policy = (Policy)m_policies.get();
          if( null == policy )
          {
              return m_defaultPolicy;
          }
          else
          {
              return policy;
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/DemuxProperties.java
  
  Index: DemuxProperties.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.io.PrintStream;
  import java.io.PrintWriter;
  import java.util.Enumeration;
  import java.util.Properties;
  
  /**
   * Access to this Properties object is forwarded to a
   * properties that has been associated with this thread.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   */
  public final class DemuxProperties
      extends Properties
  {
      /**
       * The properties objects associated with each thread.
       */
      private final InheritableThreadLocal m_properties =
          new InheritableThreadLocal();
  
      public DemuxProperties( final Properties defaults )
      {
          super( defaults );
      }
  
      /**
       * Bind the specified Properties object to the current thread.
       *
       * @param properties the Properties object to bind
       */
      public Properties bindProperties( final Properties properties )
      {
          final Properties oldProperties = (Properties)m_properties.get();
          m_properties.set( properties );
          return oldProperties;
      }
  
      public Object get( final Object key )
      {
          return getProperties().get( key );
      }
  
      public Object put( final Object key,
                         final Object value )
      {
          return getProperties().put( key, value );
      }
  
      public Object remove( final Object key )
      {
          return getProperties().remove( key );
      }
  
      public final int size()
      {
          return getProperties().size();
      }
  
      public final boolean isEmpty()
      {
          return getProperties().isEmpty();
      }
  
      public Enumeration keys()
      {
          return getProperties().keys();
      }
  
      public Enumeration elements()
      {
          return getProperties().keys();
      }
  
      public boolean contains( final Object value )
      {
          return getProperties().contains( value );
      }
  
      public boolean containsKey( final Object key )
      {
          return getProperties().containsKey( key );
      }
  
      public void clear()
      {
          getProperties().clear();
      }
  
      public Object clone()
      {
          return getProperties().clone();
      }
  
      public String toString()
      {
          return getProperties().toString();
      }
  
      public final String getProperty( final String key )
      {
          return getProperties().getProperty( key );
      }
  
      public final Enumeration propertyNames()
      {
          return getProperties().propertyNames();
      }
  
      public final void list( final PrintStream out )
      {
          getProperties().list( out );
      }
  
      public final void list( final PrintWriter out )
      {
          getProperties().list( out );
      }
  
      /**
       * Utility method to retrieve properties bound to current thread (if any).
       */
      private Properties getProperties()
      {
          final Properties properties = (Properties)m_properties.get();
          if( null != properties )
          {
              return properties;
          }
          else
          {
              return defaults;
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/JavaProcess.java
  
  Index: JavaProcess.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.io.IOException;
  import org.apache.excalibur.threadcontext.ThreadContext;
  
  /**
   * A JavaProcess is an abstraction that allows you to
   * partially isolate java applications from one another
   * and thus run more tasks in memory rather than in forked
   * mode.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   */
  public class JavaProcess
      extends Thread
  {
      /**
       * Flag indicating whether or not all the correct
       * redirectors have been installed correctly.
       */
      private static boolean c_installed;
  
      /**
       * ThreadContext object to be associated with thread.
       */
      private final ThreadContext m_threadContext;
  
      /**
       * Create a thread to run specific target.
       *
       * @param target the target to run
       * @param threadContext the thread context to associate with thread
       */
      public JavaProcess( final Runnable target,
                          final ThreadContext threadContext )
      {
          super( target );
          m_threadContext = threadContext;
      }
  
      /**
       * Create a thread in specified ThreadGroup,
       * to run specific target.
       *
       * @param group the ThreadGroup to run in
       * @param target the target to run
       * @param threadContext the thread context to associate with thread
       */
      public JavaProcess( final ThreadGroup group,
                          final Runnable target,
                          final ThreadContext threadContext )
      {
          super( group, target );
          m_threadContext = threadContext;
      }
  
      /**
       * Install redirectors if they need installing.
       */
      private synchronized static final void install()
      {
          if( !c_installed )
          {
              try
              {
                  StdioRedirector.install();
                  SysPropertiesRedirector.install();
                  c_installed = true;
              }
              catch( final IOException ioe )
              {
                  ioe.printStackTrace();
              }
          }
      }
  
      /**
       * Execute the associated code makign sure
       * that all of the context variables are setup correctly.
       */
      public final void run()
      {
          install();
  
          try
          {
              ThreadContext.setThreadContext( m_threadContext );
              super.run();
          }
          finally
          {
              ThreadContext.setThreadContext( null );
          }
      }
  }
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/JavaProcessContextPolicy.java
  
  Index: JavaProcessContextPolicy.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.URLStreamHandlerFactory;
  import java.util.Map;
  import java.util.Properties;
  import java.security.Policy;
  import javax.naming.spi.InitialContextFactory;
  import org.apache.excalibur.threadcontext.ThreadContextAccessor;
  import org.apache.excalibur.threadcontext.impl.DefaultThreadContextPolicy;
  
  /**
   * This is a basic extension of ThreadContextPolicy that
   * just defines new constants that will be handled.
   *
   * <p>Some more things to think about.</p>
   *
   * <ul>
   *   <li>Register a DemuxSecurityManager that redirects as
   *       appropriate to thread specific SecurityManager.</p>
   *   <li>Register a SecurityManager that noticies permission
   *       checks for top level windows and records all the
   *       windows in a WeakHashMap. Then when context is
   *       deactivated will dispose any still visible/non-disposed
   *       windows.</p>
   *   <li>When a System.exit() call is made throw a ThreadDeath
   *       exception rather than exiting.</p>
   *   <li>Force all threads to be created in a specific
   *       ThreadGroup.</p>
   * </ul>
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   * @todo Implement a Redirector for {@link java.net.URLStreamHandlerFactory}
   *       and {@link javax.naming.spi.InitialContextFactory}
   */
  public class JavaProcessContextPolicy
      extends DefaultThreadContextPolicy
  {
      public static final String INPUT = InputStream.class.getName();
      public static final String OUTPUT = OutputStream.class.getName();
      public static final String ERROR = OutputStream.class.getName() + "/Error";
      public static final String PROPERTIES = Properties.class.getName();
      public static final String URL_FACTORY = URLStreamHandlerFactory.class.getName();
      public static final String JNDI_FACTORY = InitialContextFactory.class.getName();
      public static final String POLICY = Policy.class.getName();
  
      /**
       * Construct the policy object and register the types
       * that it is capable of handling.
       */
      public JavaProcessContextPolicy()
      {
          addEntry( INPUT, InputStream.class, true );
          addEntry( OUTPUT, OutputStream.class, true );
          addEntry( ERROR, OutputStream.class, true );
          addEntry( PROPERTIES, Properties.class, true );
          addEntry( URL_FACTORY, URLStreamHandlerFactory.class, true );
          addEntry( JNDI_FACTORY, InitialContextFactory.class, true );
          addEntry( POLICY, Policy.class, false );
      }
  
      /**
       * The activate method is called when the ThreadContext
       * is associated with a thread. This method sets the ContextClassLoader
       * if CLASSLOADER key is present in context.
       *
       * @param accessor the accessor to retrieve values from ThreadContext
       */
      public void activate( final ThreadContextAccessor accessor,
                            final Map store )
      {
          super.activate( accessor, store );
  
          if( accessor.containsKey( POLICY ) )
          {
              final Policy newPolicy =
                  (Policy)get( accessor, POLICY, null );
  
              final Policy oldPolicy =
                  PolicyRedirector.bindPolicy( newPolicy );
              store.put( POLICY, oldPolicy );
          }
  
          if( accessor.containsKey( INPUT ) )
          {
              final InputStream newStream =
                  (InputStream)get( accessor, INPUT, null );
  
              final InputStream oldStream =
                  StdioRedirector.bindInput( newStream );
              store.put( INPUT, oldStream );
          }
  
          if( accessor.containsKey( OUTPUT ) )
          {
              final OutputStream newStream =
                  (OutputStream)get( accessor, OUTPUT, null );
  
              final OutputStream oldStream =
                  StdioRedirector.bindOutput( newStream );
              store.put( OUTPUT, oldStream );
          }
  
          if( accessor.containsKey( ERROR ) )
          {
              final OutputStream newStream =
                  (OutputStream)get( accessor, ERROR, null );
  
              final OutputStream oldStream =
                  StdioRedirector.bindError( newStream );
              store.put( OUTPUT, oldStream );
          }
  
          if( accessor.containsKey( PROPERTIES ) )
          {
              final Properties newProperties =
                  (Properties)get( accessor, PROPERTIES, null );
  
              final Properties oldProperties =
                  SysPropertiesRedirector.bindProperties( newProperties );
              store.put( PROPERTIES, oldProperties );
          }
      }
  
      /**
       * The deactivate method is called when the ThreadContext is
       * dis-associated with a thread.
       *
       * @param store the store contianign data required to
       *        deactivate context
       */
      public void deactivate( final ThreadContextAccessor accessor,
                              final Map store )
      {
          super.deactivate( accessor, store );
  
          if( accessor.containsKey( POLICY ) )
          {
              final Policy policy =
                  (Policy)store.get( POLICY );
              PolicyRedirector.bindPolicy( policy );
          }
  
          if( accessor.containsKey( INPUT ) )
          {
              final InputStream stream =
                  (InputStream)store.get( INPUT );
              StdioRedirector.bindInput( stream );
          }
  
          if( accessor.containsKey( OUTPUT ) )
          {
              final OutputStream stream =
                  (OutputStream)store.get( OUTPUT );
              StdioRedirector.bindOutput( stream );
          }
  
          if( accessor.containsKey( ERROR ) )
          {
              final OutputStream stream =
                  (OutputStream)store.get( ERROR );
              StdioRedirector.bindError( stream );
          }
  
          if( accessor.containsKey( PROPERTIES ) )
          {
              final Properties properties =
                  (Properties)store.get( PROPERTIES );
              SysPropertiesRedirector.bindProperties( properties );
          }
      }
  }
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/PolicyRedirector.java
  
  Index: PolicyRedirector.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.io.IOException;
  import java.security.Policy;
  import org.apache.excalibur.jprocess.DemuxPolicy;
  
  /**
   * This is a utility class that makes it easy to install redirecting
   * Policy objects. The Policy object will redirect to the Policy object
   * that is associated with the current thread. A Policy becomes
   * associated with the current thread when a user calls the
   * {@link #bindPolicy} method or by inheriting the parent threads Policy
   * when thread is initially created. The default Policy will redirect
   * to the default Policy.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   */
  public final class PolicyRedirector
  {
      private static final String NOT_INSTALLED_ERR =
          "PolicyRedirector not installed";
  
      /**
       * Cached version of original System Policy.
       * (Or at least the Policy that were installed in JVM
       * when this class is loaded and resovled).
       */
      private static final Policy c_systemPolicy = Policy.getPolicy();
  
      private static DemuxPolicy c_policy;
  
      /**
       * Private constructor to block instantiation.
       */
      private PolicyRedirector()
      {
      }
  
      /**
       * Install the Redirector.
       *
       * @return true if installed, false if already installed
       */
      public synchronized static boolean install()
          throws IOException
      {
          if( c_policy == Policy.getPolicy() )
          {
              //Already installed so lets ignore
              return false;
          }
          c_policy = new DemuxPolicy( c_systemPolicy );
  
          Policy.setPolicy( c_policy );
  
          return true;
      }
  
      /**
       * Uninstall the redirector.
       *
       * @return true if uninstalled, false if already uninstalled
       */
      public synchronized static boolean uninstall()
          throws IOException
      {
          if( c_policy != Policy.getPolicy() )
          {
              //Already uninstalled so lets ignore
              return false;
          }
  
          c_policy = null;
          Policy.setPolicy( c_systemPolicy );
  
          return true;
      }
  
      /**
       * Bind the specified Policy object to this thread.
       *
       * @param policy the Policy to bind
       * @throws java.lang.SecurityException if don't have permission to bind
       * @throws java.lang.IllegalStateException if redirector not installed
       */
      public static Policy bindPolicy( final Policy policy )
          throws SecurityException, IllegalStateException
      {
          if( null == policy )
          {
              throw new NullPointerException( "policy" );
          }
          if( null == c_policy )
          {
              throw new IllegalStateException( NOT_INSTALLED_ERR );
          }
  
          final SecurityManager manager = System.getSecurityManager();
          if( null != manager )
          {
              final RuntimePermission permission =
                  new RuntimePermission( "PolicyRedirector.setPolicy" );
              manager.checkPermission( permission );
          }
  
          return c_policy.bindPolicy( policy );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/StdioRedirector.java
  
  Index: StdioRedirector.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.io.FileDescriptor;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import org.apache.avalon.excalibur.io.DemuxInputStream;
  import org.apache.avalon.excalibur.io.DemuxOutputStream;
  
  /**
   * This is a utility class that makes it easy to install redirecting
   * streams into the System.in, System.out and System.err streams.
   * The streams will redirect to streams that are associated with the
   * current thread. A Stream becomes associated with the current thread
   * when a user calls one of the bind*() methods or by inheriting the
   * parent threads stream when thread is initially created. The default
   * streams will redirect to the standard input, standard output and
   * standard error of process.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   */
  public final class StdioRedirector
  {
      private static final String NOT_INSTALLED_ERR = "StdioRedirector not installed";
  
      private static DemuxInputStream c_input;
      private static DemuxOutputStream c_output;
      private static DemuxOutputStream c_error;
  
      private static boolean c_installed;
  
      /**
       * Private constructor to block instantiation.
       */
      private StdioRedirector()
      {
      }
  
      /**
       * Install the redirecting streams into
       * System.in, System.out and System.err
       * and hook them up to internal streams.
       *
       * @return true if installed, false if already installed
       */
      public static boolean install()
      {
          if( c_installed )
          {
              //Already installed so lets ignore
              return false;
          }
          c_input = new DemuxInputStream();
          c_output = new DemuxOutputStream();
          c_error = new DemuxOutputStream();
          c_input.bindStream( new FileInputStream( FileDescriptor.in ) );
          c_output.bindStream( new FileOutputStream( FileDescriptor.out ) );
          c_error.bindStream( new FileOutputStream( FileDescriptor.err ) );
  
          final PrintStream output = new PrintStream( c_output, true );
          final PrintStream error = new PrintStream( c_error, true );
  
          System.setIn( c_input );
          System.setOut( output );
          System.setErr( error );
  
          c_installed = true;
  
          return true;
      }
  
      /**
       * Uninstall the redirecting streams and
       * replace them with streams that point to
       * FileDescriptor.in, FileDescriptor.out and
       * FileDescriptor.err.
       *
       * @return true if uninstalled, false if already uninstalled
       */
      public static boolean uninstall()
      {
          if( !c_installed )
          {
              //Already uninstalled so lets ignore
              return false;
          }
  
          final FileInputStream input = new FileInputStream( FileDescriptor.in );
          final FileOutputStream output = new FileOutputStream( FileDescriptor.out );
          final FileOutputStream error = new FileOutputStream( FileDescriptor.err );
  
          final PrintStream outputStream = new PrintStream( output, true );
          final PrintStream errorStream = new PrintStream( error, true );
  
          c_input = null;
          c_output = null;
          c_error = null;
  
          System.setIn( input );
          System.setOut( outputStream );
          System.setErr( errorStream );
  
          c_installed = false;
  
          return true;
      }
  
      /**
       * Bind the specified stream to standard input in this thread.
       *
       * @param input the stream to bind
       * @throws java.lang.SecurityException if don't have permission to bind to input
       * @throws java.lang.IllegalStateException if redirector not installed
       * @return stream that was previously bound to input
       */
      public static InputStream bindInput( final InputStream input )
          throws SecurityException, IllegalStateException
      {
          if( null == input )
          {
              throw new NullPointerException( "input" );
          }
          if( null == c_input )
          {
              throw new IllegalStateException( NOT_INSTALLED_ERR );
          }
  
          final SecurityManager manager = System.getSecurityManager();
          if( null != manager )
          {
              final RuntimePermission permission =
                  new RuntimePermission( "StdioRedirector.setIn" );
              manager.checkPermission( permission );
          }
  
          return c_input.bindStream( input );
      }
  
      /**
       * Bind the specified stream to standard output in this thread.
       *
       * @param output the stream to bind
       * @throws java.lang.SecurityException if don't have permission to bind to output
       * @throws java.lang.IllegalStateException if redirector not installed
       */
      public static OutputStream bindOutput( final OutputStream output )
          throws SecurityException, IllegalStateException
      {
          if( null == output )
          {
              throw new NullPointerException( "output" );
          }
          if( null == c_output )
          {
              throw new IllegalStateException( NOT_INSTALLED_ERR );
          }
  
          final SecurityManager manager = System.getSecurityManager();
          if( null != manager )
          {
              final RuntimePermission permission =
                  new RuntimePermission( "StdioRedirector.setOut" );
              manager.checkPermission( permission );
          }
  
          return c_output.bindStream( output );
      }
  
      /**
       * Bind the specified stream to standard error in this thread.
       *
       * @param error the stream to bind
       * @throws java.lang.SecurityException if don't have permission to bind to error
       * @throws java.lang.IllegalStateException if redirector not installed
       */
      public static OutputStream bindError( final OutputStream error )
          throws SecurityException, IllegalStateException
      {
          if( null == error )
          {
              throw new NullPointerException( "error" );
          }
          if( null == c_error )
          {
              throw new IllegalStateException( NOT_INSTALLED_ERR );
          }
  
          final SecurityManager manager = System.getSecurityManager();
          if( null != manager )
          {
              final RuntimePermission permission =
                  new RuntimePermission( "StdioRedirector.setErr" );
              manager.checkPermission( permission );
          }
  
          return c_error.bindStream( error );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/java/org/apache/excalibur/jprocess/SysPropertiesRedirector.java
  
  Index: SysPropertiesRedirector.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess;
  
  import java.io.IOException;
  import java.util.Properties;
  import org.apache.excalibur.jprocess.DemuxProperties;
  
  /**
   * This is a utility class that makes it easy to install redirecting
   * Properties objects underlying System.getProeprties() object.
   * The properties object will redirect to the properties object that is
   * associated with the current thread. A properties object becomes
   * associated with the current thread when a user calls one of the
   * bind*() methods or by inheriting the parent threads properties object
   * when thread is initially created. The default  streams will redirect
   * to the default System properties.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 03:19:20 $
   */
  public final class SysPropertiesRedirector
  {
      private static final String NOT_INSTALLED_ERR =
          "SysPropertiesRedirector not installed";
  
      /**
       * Cached version of original System Properties.
       * (Or at least the properties that were installed in JVM
       * when this class is loaded and resovled).
       */
      private static final Properties c_systemProperties =
          System.getProperties();
  
      private static DemuxProperties c_properties;
  
      /**
       * Private constructor to block instantiation.
       */
      private SysPropertiesRedirector()
      {
      }
  
      /**
       * Install the redirecting Properties object.
       *
       * @return true if installed, false if already installed
       */
      public synchronized static boolean install()
          throws IOException
      {
          if( c_properties == System.getProperties() )
          {
              //Already installed so lets ignore
              return false;
          }
          c_properties = new DemuxProperties( c_systemProperties );
  
          System.setProperties( c_properties );
  
          return true;
      }
  
      /**
       * Uninstall the redirecting streams and
       * replace them with streams that point to
       * FileDescriptor.in, FileDescriptor.out and
       * FileDescriptor.err.
       *
       * @return true if uninstalled, false if already uninstalled
       */
      public synchronized static boolean uninstall()
          throws IOException
      {
          if( c_properties != System.getProperties() )
          {
              //Already uninstalled so lets ignore
              return false;
          }
  
          c_properties = null;
          System.setProperties( c_systemProperties );
  
          return true;
      }
  
      /**
       * Bind the specified Properties object to this thread.
       *
       * @param properties the stream to bind
       * @throws java.lang.SecurityException if don't have permission to bind to input
       * @throws java.lang.IllegalStateException if redirector not installed
       */
      public static Properties bindProperties( final Properties properties )
          throws SecurityException, IllegalStateException
      {
          if( null == properties )
          {
              throw new NullPointerException( "properties" );
          }
          if( null == c_properties )
          {
              throw new IllegalStateException( NOT_INSTALLED_ERR );
          }
  
          final SecurityManager manager = System.getSecurityManager();
          if( null != manager )
          {
              final RuntimePermission permission =
                  new RuntimePermission( "SysPropertiesRedirector.setProperties" );
              manager.checkPermission( permission );
          }
  
          return c_properties.bindProperties( properties );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/test/org/apache/excalibur/jprocess/test/DemuxPolicyTestCase.java
  
  Index: DemuxPolicyTestCase.java
  ===================================================================
  /*
   * Copyright  The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess.test;
  
  import java.security.CodeSource;
  import java.security.PermissionCollection;
  import java.security.Permissions;
  import java.security.Policy;
  import java.util.HashMap;
  import java.util.Iterator;
  import junit.framework.TestCase;
  import org.apache.excalibur.jprocess.DemuxPolicy;
  
  /**
   * Basic unit tests for the multiplexing Policy.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public final class DemuxPolicyTestCase
      extends TestCase
  {
      private static final String T1 = "Thread1";
      private static final String T2 = "Thread2";
      private static final String T3 = "Thread3";
      private static final String T4 = "Thread4";
  
      private final HashMap m_threadMap = new HashMap();
  
      public DemuxPolicyTestCase( final String name )
      {
          super( name );
      }
  
      private void doStart()
          throws Exception
      {
          final Iterator iterator = m_threadMap.keySet().iterator();
          while( iterator.hasNext() )
          {
              final String name = (String)iterator.next();
              final Thread thread = (Thread)m_threadMap.get( name );
              thread.start();
          }
      }
  
      private void doJoin()
          throws Exception
      {
          final Iterator iterator = m_threadMap.keySet().iterator();
          while( iterator.hasNext() )
          {
              final String name = (String)iterator.next();
              final Thread thread = (Thread)m_threadMap.get( name );
              thread.join();
          }
      }
  
      private void startThread( final String name,
                                final DemuxPolicy demux )
          throws Exception
      {
          final PolicyThread thread =
              new PolicyThread( name, new TestPolicy( name ), demux );
          m_threadMap.put( name, thread );
      }
  
      public void testProperties()
          throws Exception
      {
          final DemuxPolicy policy = new DemuxPolicy( null );
          startThread( T1, policy );
          startThread( T2, policy );
          startThread( T3, policy );
          startThread( T4, policy );
  
          doStart();
          doJoin();
  
          final PermissionCollection permissions1 = getPermissions( T1 );
          final PermissionCollection permissions2 = getPermissions( T2 );
          final PermissionCollection permissions3 = getPermissions( T3 );
          final PermissionCollection permissions4 = getPermissions( T4 );
          assertTrue( "PolicyName1", permissions1.implies( new RuntimePermission( T1 ) ) );
          assertTrue( "PolicyName2", permissions2.implies( new RuntimePermission( T2 ) ) );
          assertTrue( "PolicyName3", permissions3.implies( new RuntimePermission( T3 ) ) );
          assertTrue( "PolicyName4", permissions4.implies( new RuntimePermission( T4 ) ) );
      }
  
      private PermissionCollection getPermissions( final String threadName )
      {
          final PolicyThread thread =
              (PolicyThread)m_threadMap.get( threadName );
          assertNotNull( "getPolicyThread()", thread );
  
          return thread.getPermissionCollection();
      }
  
      private static class PolicyThread
          extends Thread
      {
          private final TestPolicy m_policy;
          private final DemuxPolicy m_demux;
          private PermissionCollection m_result;
  
          PolicyThread( final String name,
                        final TestPolicy policy,
                        final DemuxPolicy demux )
          {
              super( name );
              m_policy = policy;
              m_demux = demux;
          }
  
          PermissionCollection getPermissionCollection()
          {
              return m_result;
          }
  
          public void run()
          {
              m_demux.bindPolicy( m_policy );
              m_result = m_demux.getPermissions( null );
          }
      }
  
      private static class TestPolicy
          extends Policy
      {
          private final String m_name;
  
          TestPolicy( final String name )
          {
              m_name = name;
          }
  
          String getName()
          {
              return m_name;
          }
  
          public PermissionCollection getPermissions( CodeSource codesource )
          {
              final Permissions permissions = new Permissions();
              permissions.add( new RuntimePermission( m_name ) );
              return permissions;
          }
  
          public void refresh()
          {
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/test/org/apache/excalibur/jprocess/test/DemuxPropertiesTestCase.java
  
  Index: DemuxPropertiesTestCase.java
  ===================================================================
  /*
   * Copyright  The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.jprocess.test;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Properties;
  import junit.framework.TestCase;
  import org.apache.excalibur.jprocess.DemuxProperties;
  
  /**
   * Basic unit tests for the multiplexing properties.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public final class DemuxPropertiesTestCase
      extends TestCase
  {
      private static final String T1 = "Thread1";
      private static final String T2 = "Thread2";
      private static final String T3 = "Thread3";
      private static final String T4 = "Thread4";
  
      private static final String KEY1 = "Key1";
      private static final String KEY2 = "Key2";
      private static final String KEY3 = "Key3";
      private static final String KEY4 = "Key4";
  
      private static final String DATA1 = "Data1";
      private static final String DATA2 = "Data2";
      private static final String DATA3 = "Data3";
      private static final String DATA4 = "Data4";
  
      private final HashMap m_threadMap = new HashMap();
  
      public DemuxPropertiesTestCase( final String name )
      {
          super( name );
      }
  
      private void doStart()
          throws Exception
      {
          final Iterator iterator = m_threadMap.keySet().iterator();
          while( iterator.hasNext() )
          {
              final String name = (String)iterator.next();
              final Thread thread = (Thread)m_threadMap.get( name );
              thread.start();
          }
      }
  
      private void doJoin()
          throws Exception
      {
          final Iterator iterator = m_threadMap.keySet().iterator();
          while( iterator.hasNext() )
          {
              final String name = (String)iterator.next();
              final Thread thread = (Thread)m_threadMap.get( name );
              thread.join();
          }
      }
  
      private void startThread( final String name,
                                final DemuxProperties demux )
          throws Exception
      {
          final PropertyThread thread =
              new PropertyThread( name, new Properties(), demux );
          m_threadMap.put( name, thread );
      }
  
      public void testProperties()
          throws Exception
      {
          final DemuxProperties properties = new DemuxProperties( new Properties() );
          startThread( T1, properties );
          startThread( T2, properties );
          startThread( T3, properties );
          startThread( T4, properties );
  
          doStart();
          doJoin();
  
          final Properties properties1 = getProperties( T1 );
          assertEquals( "Data1/1", T1 + DATA1, properties1.getProperty( KEY1 ) );
          assertEquals( "Data1/2", T1 + DATA2, properties1.getProperty( KEY2 ) );
          assertEquals( "Data1/3", T1 + DATA3, properties1.getProperty( KEY3 ) );
          assertEquals( "Data1/4", T1 + DATA4, properties1.getProperty( KEY4 ) );
  
          final Properties properties2 = getProperties( T2 );
          assertEquals( "Data2/1", T2 + DATA1, properties2.getProperty( KEY1 ) );
          assertEquals( "Data2/2", T2 + DATA2, properties2.getProperty( KEY2 ) );
          assertEquals( "Data2/3", T2 + DATA3, properties2.getProperty( KEY3 ) );
          assertEquals( "Data2/4", T2 + DATA4, properties2.getProperty( KEY4 ) );
  
          final Properties properties3 = getProperties( T3 );
          assertEquals( "Data3/1", T3 + DATA1, properties3.getProperty( KEY1 ) );
          assertEquals( "Data3/2", T3 + DATA2, properties3.getProperty( KEY2 ) );
          assertEquals( "Data3/3", T3 + DATA3, properties3.getProperty( KEY3 ) );
          assertEquals( "Data3/4", T3 + DATA4, properties3.getProperty( KEY4 ) );
  
          final Properties properties4 = getProperties( T4 );
          assertEquals( "Data4/1", T4 + DATA1, properties4.getProperty( KEY1 ) );
          assertEquals( "Data4/2", T4 + DATA2, properties4.getProperty( KEY2 ) );
          assertEquals( "Data4/3", T4 + DATA3, properties4.getProperty( KEY3 ) );
          assertEquals( "Data4/4", T4 + DATA4, properties4.getProperty( KEY4 ) );
      }
  
      private Properties getProperties( final String threadName )
      {
          final PropertyThread thread =
              (PropertyThread)m_threadMap.get( threadName );
          assertNotNull( "getProperties()", thread );
  
          return thread.getProperties();
      }
  
      private static class PropertyThread
          extends Thread
      {
          private final Properties m_properties;
          private final DemuxProperties m_demux;
  
          PropertyThread( final String name,
                          final Properties properties,
                          final DemuxProperties demux )
          {
              super( name );
              m_properties = properties;
              m_demux = demux;
          }
  
          Properties getProperties()
          {
              return m_properties;
          }
  
          public void run()
          {
              m_demux.bindProperties( m_properties );
              m_demux.setProperty( KEY1, getName() + DATA1 );
              m_demux.setProperty( KEY2, getName() + DATA2 );
              m_demux.setProperty( KEY3, getName() + DATA3 );
              m_demux.setProperty( KEY4, getName() + DATA4 );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/xdocs/index.xml
  
  Index: index.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <document>
      <properties>
          <title>Excalibur JProcess - Overview</title>
          <author email="peter@apache.org">Peter Donald</author>
      </properties>
      <body>
          <section name="Introduction">
              <p>
                Excalibur's JProcess toolkit is designed to be used to isolate
                one java thread from another java thread. It does this by
              </p>
          </section>
      </body>
  </document>
  
  
  
  1.1                  jakarta-avalon-excalibur/jprocess/src/xdocs/stylesheets/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <project
      href="http://jakarta.apache.org/avalon/???"
      name="Excalibur ???">
  
      <title>Excalibur ??</title>
      <body>
          <item href="/../index.html" name="Back to Excalibur"/>
          <menu name="About">
              <item name="Overview" href="/index.html"/>
              <item name="Excalibur Home" href="http://jakarta.apache.org/avalon/excalibur/index.html"/>
              <item name="Download" href="http://jakarta.apache.org/builds/jakarta-avalon-excalibur/release/???"/>
              <item name="API Docs" href="/api/index.html"/>
          </menu>
      </body>
  </project>
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>