1.1 --- a/samples/messagedigest/build.xml Sat Jun 14 09:52:25 2008 +0200
1.2 +++ b/samples/messagedigest/build.xml Sat Jun 14 09:52:26 2008 +0200
1.3 @@ -9,30 +9,28 @@
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="cp" value="build/new-api/classes"/>
1.9 + </antcall>
1.10 + <antcall target="-build-one">
1.11 <param name="version" value="bridge"/>
1.12 - <param name="cp" value="build/new-api/classes"/>
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:${junit.jar}"/>
1.19 + <param name="cp" value="build/new-api/classes:build/new-spi/classes:${junit.jar}"/>
1.20 </antcall>
1.21 </target>
1.22
1.23 - <target name="test">
1.24 - <antcall target="-do-test">
1.25 - <param name="nodebug" value="true"/>
1.26 - </antcall>
1.27 - </target>
1.28 -
1.29 - <target name="-do-test" depends="build">
1.30 + <target name="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/bridge/classes"/>
1.34 + <param name="test.cp" value="build/new-api/classes:build/new-spi/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"/>
1.39 + <param name="test.cp" value="build/new-api/classes:build/new-spi/classes"/>
1.40 </antcall>
1.41 </target>
1.42
1.43 @@ -43,25 +41,13 @@
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" depends="-debug-one">
1.58 - <property name="debug1" value="-Dn1"/>
1.59 - <property name="debug2" value="-Dn2"/>
1.60 - <property name="include" value="**/*Test"/>
1.61 + <target name="-run-one">
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="${include}.class"/>
1.67 + <filename name="**/*Test.class"/>
1.68 </fileset>
1.69 </batchtest>
1.70 <classpath>
1.71 @@ -71,8 +57,6 @@
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 @@ -86,7 +70,6 @@
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:25 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>MessageDigest and Bridges</name>
2.8 + <name>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,6 +17,12 @@
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 @@ -28,11 +34,6 @@
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 @@ -48,45 +49,23 @@
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>src-new-api</label>
2.72 + <label>New API for Clients</label>
2.73 <location>src-new-api</location>
2.74 </source-folder>
2.75 <source-folder style="packages">
2.76 - <label>src-bridge</label>
2.77 + <label>New API for Providers</label>
2.78 + <location>src-new-spi</location>
2.79 + </source-folder>
2.80 + <source-folder style="packages">
2.81 + <label>Bridge</label>
2.82 <location>src-bridge</location>
2.83 </source-folder>
2.84 <source-folder style="packages">
2.85 - <label>test</label>
2.86 + <label>Tests</label>
2.87 <location>src-test</location>
2.88 </source-folder>
2.89 <source-file>
2.90 @@ -98,27 +77,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 + <classpath mode="compile">src-new-api</classpath>
2.110 <source-level>1.5</source-level>
2.111 </compilation-unit>
2.112 <compilation-unit>
2.113 <package-root>src-bridge</package-root>
2.114 - <classpath mode="compile">src-new-api</classpath>
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-new-api:../libs/dist/junit-4.4.jar</classpath>
2.121 + <classpath mode="compile">src-api1.0:../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/META-INF/services/org.apidesign.impl.security.friendapi.DigestProvider Sat Jun 14 09:52:25 2008 +0200
3.2 +++ b/samples/messagedigest/src-bridge/META-INF/services/org.apidesign.impl.security.friendapi.DigestProvider Sat Jun 14 09:52:26 2008 +0200
3.3 @@ -1,4 +1,3 @@
3.4 -# BEGIN: day.end.bridges.FriendMetaInf
3.5 -# registration in bridge's META-INF/services/friendapi.DigestProvider
3.6 -org.apidesign.impl.security.extension.BridgeToNew
3.7 -# END: day.end.bridges.FriendMetaInf
3.8 +# this shall be in a separate module that provides the "bridge"
3.9 +org.apidesign.impl.security.extension.BridgeToOldAlgorithmsProvider
3.10 +
4.1 --- a/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java Sat Jun 14 09:52:25 2008 +0200
4.2 +++ b/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java Sat Jun 14 09:52:26 2008 +0200
4.3 @@ -19,37 +19,23 @@
4.4 *
4.5 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.6 */
4.7 -// BEGIN: day.end.bridges.BridgeToOld
4.8 -public final class BridgeToOld extends Provider {
4.9 +public class BridgeToOld extends Provider {
4.10
4.11 public BridgeToOld() {
4.12 super("spi.Digestor", 1.0, "");
4.13 Security.addProvider(this);
4.14 }
4.15 -
4.16 - // BEGIN: day.end.bridges.cycle
4.17 - private ThreadLocal<Boolean> searching = new ThreadLocal<Boolean>();
4.18 - final boolean isSearching() {
4.19 - return Boolean.TRUE.equals(searching.get());
4.20 - }
4.21
4.22 @Override
4.23 public synchronized Service getService(String type, String algorithm) {
4.24 - Boolean prev = searching.get();
4.25 - try {
4.26 - searching.set(Boolean.TRUE);
4.27 - if ("MessageDigest".equals(type)) {
4.28 - Digest dig = Digest.getInstance(algorithm);
4.29 - if (dig != null) {
4.30 - return new ServiceImpl(dig, this, type, algorithm, "", Collections.<String>emptyList(), Collections.<String,String>emptyMap());
4.31 - }
4.32 + if ("MessageDigest".equals(type)) {
4.33 + Digest dig = Digest.getInstance(algorithm);
4.34 + if (dig != null) {
4.35 + return new ServiceImpl(dig, this, type, algorithm, "", Collections.<String>emptyList(), Collections.<String,String>emptyMap());
4.36 }
4.37 - return null;
4.38 - } finally {
4.39 - searching.set(prev);
4.40 }
4.41 + return null;
4.42 }
4.43 - // END: day.end.bridges.cycle
4.44
4.45 private static class ServiceImpl<Data> extends Service {
4.46 Digest dig;
4.47 @@ -94,4 +80,3 @@
4.48 }
4.49
4.50 }
4.51 -// END: day.end.bridges.BridgeToOld
5.1 --- a/samples/messagedigest/src-new-api/org/apidesign/api/security/Digest.java Sat Jun 14 09:52:25 2008 +0200
5.2 +++ b/samples/messagedigest/src-new-api/org/apidesign/api/security/Digest.java Sat Jun 14 09:52:26 2008 +0200
5.3 @@ -2,28 +2,28 @@
5.4 package org.apidesign.api.security;
5.5
5.6 import java.nio.ByteBuffer;
5.7 +import org.apidesign.impl.security.friendapi.DigestImplementation;
5.8 +import org.apidesign.impl.security.friendapi.DigestProvider;
5.9 import java.util.ServiceLoader;
5.10 -import org.apidesign.spi.security.Digestor;
5.11
5.12 -/** Simplified version of a Digest class that allows to compute a fingerprint
5.13 - * for buffer of data.
5.14 +/** MessageDigest extends MessageDigestSpi, that means the javadoc
5.15 *
5.16 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.17 + * @author Jaroslav Tulach
5.18 */
5.19 // BEGIN: day.end.bridges.Digest
5.20 public final class Digest {
5.21 - private final DigestImplementation<?> impl;
5.22 + private final DigestImplementation impl;
5.23
5.24 /** Factory method is better than constructor */
5.25 - private Digest(DigestImplementation<?> impl) {
5.26 + private Digest(DigestImplementation impl) {
5.27 this.impl = impl;
5.28 }
5.29
5.30 /** Factory method to create digest for an algorithm.
5.31 */
5.32 public static Digest getInstance(String algorithm) {
5.33 - for (Digestor<?> digestor : ServiceLoader.load(Digestor.class)) {
5.34 - DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);
5.35 + for (DigestProvider dp : ServiceLoader.load(DigestProvider.class)) {
5.36 + DigestImplementation impl = dp.create(algorithm);
5.37 if (impl != null) {
5.38 return new Digest(impl);
5.39 }
5.40 @@ -37,7 +37,8 @@
5.41 //
5.42
5.43 public byte[] digest(ByteBuffer bb) {
5.44 - return impl.digest(bb);
5.45 + impl.update(bb);
5.46 + return impl.digest();
5.47 }
5.48 }
5.49 // END: day.end.bridges.Digest
6.1 --- a/samples/messagedigest/src-test/test/CountingDigestor.java Sat Jun 14 09:52:25 2008 +0200
6.2 +++ b/samples/messagedigest/src-test/test/CountingDigestor.java Sat Jun 14 09:52:26 2008 +0200
6.3 @@ -10,10 +10,10 @@
6.4
6.5 /**
6.6 *
6.7 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.8 + * @author jarda
6.9 */
6.10 -// BEGIN: day.end.bridges.CountingDigestor
6.11 public final class CountingDigestor extends Digestor<int[]> {
6.12 +
6.13 @Override
6.14 protected byte[] digest(int[] data) {
6.15 int i = data[0];
6.16 @@ -31,5 +31,5 @@
6.17 data[0] += input.remaining();
6.18 input.position(input.position() + input.remaining());
6.19 }
6.20 +
6.21 }
6.22 -// END: day.end.bridges.CountingDigestor
6.23 \ No newline at end of file
7.1 --- a/samples/messagedigest/src-test/test/OldAPIToNewAPITest.java Sat Jun 14 09:52:25 2008 +0200
7.2 +++ b/samples/messagedigest/src-test/test/OldAPIToNewAPITest.java Sat Jun 14 09:52:26 2008 +0200
7.3 @@ -43,7 +43,6 @@
7.4
7.5 @Test
7.6 public void generateHashUsingMessageDigest() throws Exception {
7.7 - // BEGIN: day.end.bridges.BridgeToOldRegister
7.8 // The java.security.Providers cannot be registered in META-INF/services
7.9 // that is why one needs to either configure various properties or
7.10 // make some dummy call that will initialize our bridge class.
7.11 @@ -52,7 +51,6 @@
7.12 //
7.13 // This is the call:
7.14 Digest initialize = Digest.getInstance("MD5");
7.15 - // END: day.end.bridges.BridgeToOldRegister
7.16
7.17 MessageDigest md = MessageDigest.getInstance("cnt");
7.18 byte[] res = md.digest(arr);