Merge: Geertjan's changes up to 4500
authorJaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:26 +0200
changeset 51130e099942d8
parent 50 019f1e9f7741
child 52 4257f4cf226b
Merge: Geertjan's changes up to 4500
samples/messagedigest/build.xml
samples/messagedigest/nbproject/project.xml
samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java
samples/messagedigest/src-new-api/org/apidesign/api/security/Digest.java
samples/messagedigest/src-test/test/CountingDigestor.java
samples/messagedigest/src-test/test/OldAPIToNewAPITest.java
     1.1 --- a/samples/messagedigest/build.xml	Sat Jun 14 09:52:26 2008 +0200
     1.2 +++ b/samples/messagedigest/build.xml	Sat Jun 14 09:52:26 2008 +0200
     1.3 @@ -9,28 +9,30 @@
     1.4              <param name="version" value="new-api"/>
     1.5          </antcall>
     1.6          <antcall target="-build-one">
     1.7 -            <param name="version" value="new-spi"/>
     1.8 +            <param name="version" value="bridge"/>
     1.9              <param name="cp" value="build/new-api/classes"/>
    1.10          </antcall>
    1.11 -        <antcall target="-build-one">
    1.12 -            <param name="version" value="bridge"/>
    1.13 -            <param name="cp" value="build/new-api/classes:build/new-spi/classes"/>
    1.14 -        </antcall>
    1.15          
    1.16          <antcall target="-build-one">
    1.17              <param name="version" value="test"/>
    1.18 -            <param name="cp" value="build/new-api/classes:build/new-spi/classes:${junit.jar}"/>
    1.19 +            <param name="cp" value="build/new-api/classes:${junit.jar}"/>
    1.20          </antcall>
    1.21      </target>
    1.22      
    1.23 -    <target name="test" depends="build">
    1.24 +    <target name="test">
    1.25 +        <antcall target="-do-test">
    1.26 +            <param name="nodebug" value="true"/>
    1.27 +        </antcall>
    1.28 +    </target>
    1.29 +        
    1.30 +    <target name="-do-test" depends="build">
    1.31          <echo level="info" message="Running the tests with bridge enabled. This should succeeds."/>
    1.32          <antcall target="-run-one">
    1.33 -            <param name="test.cp" value="build/new-api/classes:build/new-spi/classes:build/bridge/classes"/>
    1.34 +            <param name="test.cp" value="build/new-api/classes:build/bridge/classes"/>
    1.35          </antcall>
    1.36          <echo level="info" message="Running the tests without bridge module. This should fail."/>
    1.37          <antcall target="-run-one">
    1.38 -            <param name="test.cp" value="build/new-api/classes:build/new-spi/classes"/>
    1.39 +            <param name="test.cp" value="build/new-api/classes"/>
    1.40          </antcall>
    1.41      </target>
    1.42      
    1.43 @@ -41,13 +43,25 @@
    1.44          
    1.45          <property name="junit.jar" location="../libs/dist/junit-4.4.jar"/>
    1.46      </target>
    1.47 +
    1.48 +    <target name="-debug-one" if="netbeans.home" unless="nodebug">
    1.49 +        <nbjpdastart addressproperty="jpda.address" name="MessageDigest and Bridges" transport="dt_socket" >
    1.50 +            <sourcepath path="src-new-api:src-bridge:src-test:build/test/classes"/>
    1.51 +            <classpath path="build/new-api/classes:build/bridge/classes:build/test/classes"/>
    1.52 +        </nbjpdastart>
    1.53 +        <property name="debug1" value="-Xdebug"/>
    1.54 +        <property name="debug2" value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
    1.55 +    </target>
    1.56      
    1.57 -    <target name="-run-one">
    1.58 +    <target name="-run-one" depends="-debug-one">
    1.59 +        <property name="debug1" value="-Dn1"/>
    1.60 +        <property name="debug2" value="-Dn2"/>
    1.61 +        <property name="include" value="**/*Test"/>
    1.62          <mkdir dir="build/testresults"/>
    1.63          <junit dir="build/test/classes" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
    1.64              <batchtest todir="build/testresults">
    1.65                  <fileset dir="build/test/classes">
    1.66 -                    <filename name="**/*Test.class"/>
    1.67 +                    <filename name="${include}.class"/>
    1.68                  </fileset>
    1.69              </batchtest>
    1.70              <classpath>
    1.71 @@ -57,6 +71,8 @@
    1.72              </classpath>
    1.73              <formatter type="brief" usefile="false"/>
    1.74              <formatter type="xml"/>
    1.75 +            <jvmarg value="${debug1}"/>
    1.76 +            <jvmarg value="${debug2}"/>
    1.77          </junit>
    1.78      </target>
    1.79      
    1.80 @@ -70,6 +86,7 @@
    1.81              destdir="build/${version}/classes" 
    1.82              source="1.5" target="1.5"
    1.83              classpath="${cp}"
    1.84 +            debug="true" debuglevel="lines,vars,source"
    1.85          />
    1.86          <copy todir="build/${version}/classes">
    1.87              <fileset dir="src-${version}">
     2.1 --- a/samples/messagedigest/nbproject/project.xml	Sat Jun 14 09:52:26 2008 +0200
     2.2 +++ b/samples/messagedigest/nbproject/project.xml	Sat Jun 14 09:52:26 2008 +0200
     2.3 @@ -3,7 +3,7 @@
     2.4      <type>org.netbeans.modules.ant.freeform</type>
     2.5      <configuration>
     2.6          <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
     2.7 -            <name>bridges</name>
     2.8 +            <name>MessageDigest and Bridges</name>
     2.9          </general-data>
    2.10          <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2">
    2.11              <!-- Do not use Project Properties customizer when editing this file manually. -->
    2.12 @@ -17,12 +17,6 @@
    2.13                      <encoding>UTF-8</encoding>
    2.14                  </source-folder>
    2.15                  <source-folder>
    2.16 -                    <label>src-new-spi</label>
    2.17 -                    <type>java</type>
    2.18 -                    <location>src-new-spi</location>
    2.19 -                    <encoding>UTF-8</encoding>
    2.20 -                </source-folder>
    2.21 -                <source-folder>
    2.22                      <label>src-bridge</label>
    2.23                      <type>java</type>
    2.24                      <location>src-bridge</location>
    2.25 @@ -34,6 +28,11 @@
    2.26                      <location>src-test</location>
    2.27                      <encoding>UTF-8</encoding>
    2.28                  </source-folder>
    2.29 +                <source-folder>
    2.30 +                    <label>MessageDigest and Bridges</label>
    2.31 +                    <location>.</location>
    2.32 +                    <encoding>UTF-8</encoding>
    2.33 +                </source-folder>
    2.34              </folders>
    2.35              <ide-actions>
    2.36                  <action name="build">
    2.37 @@ -49,23 +48,45 @@
    2.38                      <target>clean</target>
    2.39                      <target>build</target>
    2.40                  </action>
    2.41 +                <action name="debug.single">
    2.42 +                    <target>-do-test</target>
    2.43 +                    <context>
    2.44 +                        <property>include</property>
    2.45 +                        <folder>src-test</folder>
    2.46 +                        <format>relative-path-noext</format>
    2.47 +                        <arity>
    2.48 +                            <one-file-only/>
    2.49 +                        </arity>
    2.50 +                    </context>
    2.51 +                </action>
    2.52              </ide-actions>
    2.53 +            <export>
    2.54 +                <type>folder</type>
    2.55 +                <location>build/bridge/classes</location>
    2.56 +                <build-target>build</build-target>
    2.57 +            </export>
    2.58 +            <export>
    2.59 +                <type>folder</type>
    2.60 +                <location>build/new-api/classes</location>
    2.61 +                <build-target>build</build-target>
    2.62 +            </export>
    2.63 +            <export>
    2.64 +                <type>folder</type>
    2.65 +                <location>build/test/classes</location>
    2.66 +                <build-target>build</build-target>
    2.67 +            </export>
    2.68              <view>
    2.69                  <items>
    2.70                      <source-folder style="packages">
    2.71 -                        <label>New API for Clients</label>
    2.72 +                        <label>src-new-api</label>
    2.73                          <location>src-new-api</location>
    2.74                      </source-folder>
    2.75                      <source-folder style="packages">
    2.76 -                        <label>New API for Providers</label>
    2.77 -                        <location>src-new-spi</location>
    2.78 -                    </source-folder>
    2.79 -                    <source-folder style="packages">
    2.80 -                        <label>Bridge</label>
    2.81 +                        <label>src-bridge</label>
    2.82                          <location>src-bridge</location>
    2.83                      </source-folder>
    2.84                      <source-folder style="packages">
    2.85 -                        <label>Tests</label>
    2.86 +                        <label>test</label>
    2.87                          <location>src-test</location>
    2.88                      </source-folder>
    2.89                      <source-file>
    2.90 @@ -77,27 +98,27 @@
    2.91                      <ide-action name="rebuild"/>
    2.92                      <ide-action name="clean"/>
    2.93                      <ide-action name="test"/>
    2.94 +                    <ide-action name="debug"/>
    2.95                  </context-menu>
    2.96              </view>
    2.97 +            <subprojects/>
    2.98          </general-data>
    2.99          <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1">
   2.100              <compilation-unit>
   2.101                  <package-root>src-new-api</package-root>
   2.102 +                <built-to>build/bridge/classes</built-to>
   2.103 +                <built-to>build/new-api/classes</built-to>
   2.104 +                <built-to>build/test/classes</built-to>
   2.105                  <source-level>1.5</source-level>
   2.106              </compilation-unit>
   2.107              <compilation-unit>
   2.108 -                <package-root>src-new-spi</package-root>
   2.109 +                <package-root>src-bridge</package-root>
   2.110                  <classpath mode="compile">src-new-api</classpath>
   2.111                  <source-level>1.5</source-level>
   2.112              </compilation-unit>
   2.113              <compilation-unit>
   2.114 -                <package-root>src-bridge</package-root>
   2.115 -                <classpath mode="compile">src-new-api:src-new-spi</classpath>
   2.116 -                <source-level>1.5</source-level>
   2.117 -            </compilation-unit>
   2.118 -            <compilation-unit>
   2.119                  <package-root>src-test</package-root>
   2.120 -                <classpath mode="compile">src-api1.0:../libs/dist/junit-4.4.jar</classpath>
   2.121 +                <classpath mode="compile">src-new-api:../libs/dist/junit-4.4.jar</classpath>
   2.122                  <source-level>1.5</source-level>
   2.123              </compilation-unit>
   2.124          </java-data>
     3.1 --- a/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java	Sat Jun 14 09:52:26 2008 +0200
     3.2 +++ b/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java	Sat Jun 14 09:52:26 2008 +0200
     3.3 @@ -19,23 +19,37 @@
     3.4   *
     3.5   * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.6   */
     3.7 -public class BridgeToOld extends Provider {
     3.8 +// BEGIN: day.end.bridges.BridgeToOld
     3.9 +public final class BridgeToOld extends Provider {
    3.10  
    3.11      public BridgeToOld() {
    3.12          super("spi.Digestor", 1.0, "");
    3.13          Security.addProvider(this);
    3.14      }
    3.15 +
    3.16 +    // BEGIN: day.end.bridges.cycle
    3.17 +    private ThreadLocal<Boolean> searching = new ThreadLocal<Boolean>();
    3.18 +    final boolean isSearching() {
    3.19 +        return Boolean.TRUE.equals(searching.get());
    3.20 +    }
    3.21      
    3.22      @Override
    3.23      public synchronized Service getService(String type, String algorithm) {
    3.24 -        if ("MessageDigest".equals(type)) {
    3.25 -            Digest dig = Digest.getInstance(algorithm);
    3.26 -            if (dig != null) {
    3.27 -                return new ServiceImpl(dig, this, type, algorithm, "", Collections.<String>emptyList(), Collections.<String,String>emptyMap());
    3.28 +        Boolean prev = searching.get();
    3.29 +        try {
    3.30 +            searching.set(Boolean.TRUE);
    3.31 +            if ("MessageDigest".equals(type)) {
    3.32 +                Digest dig = Digest.getInstance(algorithm);
    3.33 +                if (dig != null) {
    3.34 +                    return new ServiceImpl(dig, this, type, algorithm, "", Collections.<String>emptyList(), Collections.<String,String>emptyMap());
    3.35 +                }
    3.36              }
    3.37 +            return null;
    3.38 +        } finally {
    3.39 +            searching.set(prev);
    3.40          }
    3.41 -        return null;
    3.42      }
    3.43 +    // END: day.end.bridges.cycle
    3.44  
    3.45      private static class ServiceImpl<Data> extends Service {
    3.46          Digest dig;
    3.47 @@ -80,3 +94,4 @@
    3.48      }
    3.49  
    3.50  }
    3.51 +// END: day.end.bridges.BridgeToOld
     4.1 --- a/samples/messagedigest/src-new-api/org/apidesign/api/security/Digest.java	Sat Jun 14 09:52:26 2008 +0200
     4.2 +++ b/samples/messagedigest/src-new-api/org/apidesign/api/security/Digest.java	Sat Jun 14 09:52:26 2008 +0200
     4.3 @@ -2,28 +2,28 @@
     4.4  package org.apidesign.api.security;
     4.5  
     4.6  import java.nio.ByteBuffer;
     4.7 -import org.apidesign.impl.security.friendapi.DigestImplementation;
     4.8 -import org.apidesign.impl.security.friendapi.DigestProvider;
     4.9  import java.util.ServiceLoader;
    4.10 +import org.apidesign.spi.security.Digestor;
    4.11  
    4.12 -/** MessageDigest extends MessageDigestSpi, that means the javadoc
    4.13 +/** Simplified version of a Digest class that allows to compute a fingerprint
    4.14 + * for buffer of data.
    4.15   *
    4.16 - * @author Jaroslav Tulach
    4.17 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    4.18   */
    4.19  // BEGIN: day.end.bridges.Digest
    4.20  public final class Digest {
    4.21 -    private final DigestImplementation impl;
    4.22 +    private final DigestImplementation<?> impl;
    4.23      
    4.24      /** Factory method is better than constructor */
    4.25 -    private Digest(DigestImplementation impl) {
    4.26 +    private Digest(DigestImplementation<?> impl) {
    4.27          this.impl = impl;
    4.28      }
    4.29      
    4.30      /** Factory method to create digest for an algorithm.
    4.31       */
    4.32      public static Digest getInstance(String algorithm) {
    4.33 -        for (DigestProvider dp : ServiceLoader.load(DigestProvider.class)) {
    4.34 -            DigestImplementation impl = dp.create(algorithm);
    4.35 +        for (Digestor<?> digestor : ServiceLoader.load(Digestor.class)) {
    4.36 +            DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);
    4.37              if (impl != null) {
    4.38                  return new Digest(impl);
    4.39              }
    4.40 @@ -37,8 +37,7 @@
    4.41      //
    4.42      
    4.43      public byte[] digest(ByteBuffer bb) {
    4.44 -        impl.update(bb);
    4.45 -        return impl.digest();
    4.46 +        return impl.digest(bb);
    4.47      }
    4.48  }
    4.49  // END: day.end.bridges.Digest
     5.1 --- a/samples/messagedigest/src-test/test/CountingDigestor.java	Sat Jun 14 09:52:26 2008 +0200
     5.2 +++ b/samples/messagedigest/src-test/test/CountingDigestor.java	Sat Jun 14 09:52:26 2008 +0200
     5.3 @@ -10,10 +10,10 @@
     5.4  
     5.5  /**
     5.6   *
     5.7 - * @author jarda
     5.8 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.9   */
    5.10 +// BEGIN: day.end.bridges.CountingDigestor
    5.11  public final class CountingDigestor extends Digestor<int[]> {
    5.12 -
    5.13      @Override
    5.14      protected byte[] digest(int[] data) {
    5.15          int i = data[0];
    5.16 @@ -31,5 +31,5 @@
    5.17          data[0] += input.remaining();
    5.18          input.position(input.position() + input.remaining());
    5.19      }
    5.20 -
    5.21  }
    5.22 +// END: day.end.bridges.CountingDigestor
    5.23 \ No newline at end of file
     6.1 --- a/samples/messagedigest/src-test/test/OldAPIToNewAPITest.java	Sat Jun 14 09:52:26 2008 +0200
     6.2 +++ b/samples/messagedigest/src-test/test/OldAPIToNewAPITest.java	Sat Jun 14 09:52:26 2008 +0200
     6.3 @@ -43,6 +43,7 @@
     6.4  
     6.5      @Test
     6.6      public void generateHashUsingMessageDigest() throws Exception {
     6.7 +        // BEGIN: day.end.bridges.BridgeToOldRegister
     6.8          // The java.security.Providers cannot be registered in META-INF/services
     6.9          // that is why one needs to either configure various properties or
    6.10          // make some dummy call that will initialize our bridge class.
    6.11 @@ -51,6 +52,7 @@
    6.12          //
    6.13          // This is the call:
    6.14          Digest initialize = Digest.getInstance("MD5");
    6.15 +        // END: day.end.bridges.BridgeToOldRegister
    6.16          
    6.17          MessageDigest md = MessageDigest.getInstance("cnt");
    6.18          byte[] res = md.digest(arr);