From f2b75376d9d282f21208c1b1247f8c2da5ee8920 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 26 Jun 2008 15:22:33 +0000 Subject: [PATCH 01/28] From fecdbe9cce451687e05a440560deade4b62ebca8 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 26 Jun 2008 15:24:23 +0000 Subject: [PATCH 02/28] --- classwords.apt | 10 ---------- classworlds-aj.zip | Bin 8005 -> 0 bytes 2 files changed, 10 deletions(-) delete mode 100644 classwords.apt delete mode 100644 classworlds-aj.zip diff --git a/classwords.apt b/classwords.apt deleted file mode 100644 index ac96bcd..0000000 --- a/classwords.apt +++ /dev/null @@ -1,10 +0,0 @@ -A Classworld is for an application -A Realm is for - - A shared level - - An isolated context like a plugin, or extension - -Where we can search any of those Realms -ClassWorld - R0 R1 R2 - -The ClassWorld is necessary if you want to have multiple roots to search. Have to decide if that's useful. If it's not diff --git a/classworlds-aj.zip b/classworlds-aj.zip deleted file mode 100644 index 7f76d11f9a9e6505bfa97821bc9847d9407c8a6a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8005 zcmchcRZtvCx3+N&u3@m??#=`V?(XjHgS!NG_ux)ofS^Hx6ChZy!DVoF3uo`|zxeh! z_1C%j>a2CsUDe%hS6{5^_gSh6@Cf)YD1W6OW)~OCKSKSlv4x`<2;}YJ?q~^OHM3_2 zxm&P1nb|qB+nafrvAek2uv@rTTG^U;g4qADlKm6N)yl#{%Gu1^(aKWd?<3T$%p9HA z{@yjI@9zSU#(gs>G-twZ$vT zZ&#b4m%i{D-a;Jj_^^uGjfNy&N&E&RvKs^puP^ZK-MqTZ{)8iS?uSZQ;^+dmx5&JC zcU#+;O9b%wA-V`692*f%pC7WY8zd3b!13pLqk9Nc?@0U2&%yu#5Z-$WX+yFD&(n0U z|5B7cPQx_(mGIIq7}Ky3Ke6l-UJi2M%4&}L4K-YN%e^i9NjJV%fCc^+`dLIUy7K1t zuy(4k7U(6Xcu={Pstf`@T5It@Xg=n#6TZZ#1ziBC?Alx?%9gu0nH=bak`ObArz$4x zWg-qvoU$C8h@bvU+gxb)(3yxV==}ND4`d!XLmQuIZSOeZnNdt|-ew}vfjZBtWLMOz zY}OHsB+GmB`yypU)<)NdEu1dc_wGH-1Wn}dUt6^%^!=tE=yRK4*(4d zt@u4$xzZ)A&cTzB%`7BT>6r07Yg0|GgCiVq&Yar7bY?nBHk0NH4Rq1mXB`Y_gKw~h zQtxnnTo`g45n|jkdMPa~ECEWhIbj_wfV0TScw!lw>F zzI|L}WVVS%gxh|^nmMxy0}!a4_?U2laKX_YAXbr}=r6D^$!zgC#zt9{p7=a|jPyhy z5O~J3EPt@?HD)Nlk6j%k!iVc5%ge=TAuv+LOMghc9K|M?z9X{4ZDBhbepwqzcewB@ zf+}6ydf9-8yG0X!!~FU+bm}C-NaOmQv`srWo*6Fj3{13tx0=rmMd~V0mN}rRg>NaomqLFY^7L zz-U}Vs`c5#VlDkx%_|1U@If}eKM_uif1+H+O$n~{^t>lO6Csbx=eGyfYA&1sNW)t| zy|^Ew?>zd}fpnYHad2;0?5iUWfyxhWpCm$rB_Hm?v#vKTRaAHwA3*v1GuYWN@k6#=^!18i>? zQ7VOXl=Pgpalw-|@9boZm&N%xF)uztWG2>nWqC_AGLdH>ayATv%=!~li%Af0KmZ7Q4`MjjqhM|*7_!UZ99YeJ{P^vx~@6gC0_YEDWbHioY z^eJ0v+$A+H43(@AlfXgZB%TBH+ZJ?llKS?}xevxfvCvV2eylTIj{33bedCQQ zAQ*|PFxBz+eaomIl9F86n`#yF7F$_iK6AA9ZC#^UTmJb>zMI<7XJrJ8q4NXuQ|+fe zFmP6#d&L>pnYWXq4bbvqBPuPzM`n3n&8J>ESZq3-K3;g+keeguIX2!8^XH1CP%)PT zCeT`>IaS|s_k*;^-pmC+p|>mt;Zh2GySA{cVyE?TRuYa zwBze6hLy0u&B!WqfBnj)^ih7;i+#rFfcAhKHNHkt^3j~_ITqoxYqt8P$d9Jn2frK< za8}6&TzPELukE6)a$-8N2N$$ITAQDT%Um}~_!dw;t3yYPzN;g;(Xwr*lBE%0`_@?A zyN$UXqC{1gsNS>4&Uv>axS;%TeN>vNuSpV*IlI(1@wv9^u!?2j44!;@rO!Ay_eyt^EFR%BaWVI!5ZfB#7tHoHlLQnIj3|kT zT@M+&e@aT;6=9scLrc(aWJY}rCdSX{X5f{B$S*7?DH>|q;nOlRf2G>^uWO(r;b9A580?O1F%Bs!^tA z7Xh^NwCDb=6u4FyRF$l~u@j?E#G+T+8(?U_IoYbx~vra?7`FpZ()vk!!rCoU$gLSGoAb<;%(iX7iv=f;$fT z4*S8X3dks#!sRmN=rAy_OfWF2|0h3uoxe@Ozkc{%wH;g_eE6^RCT=+Rw(2Nev&gaK zdTM&sxaO_9hdBHj@(S@^wXwp}Ppl>0o-ys{8?!uY+sefTqVK=>Pj%>&Wl}v;K~qV1 z&#jc$h)U+V>+tm(09w$ef}I-^ft&dK%H6~A34QH2Jx0*RprVrEd9yC6w-o)y=Oklt zirzDd-cyRg>9N{5{@(mAUFE-+)!y6;aGyKNY!W4cn!B`y0%md#vOEqb)S8lcGLGWv z8Vy*b0wL55ER0-cxm4BV`eR-D$>E|`;%znAo=!9KG)MVD7&!d%Y-mcI9d?W2a^GQd zm9(R^q3Qg3I%Ay#bU%v+!hHZfuDi3HwnX6mKhB+*HFWIGu@l3cmeZN)T2c-nnKgO@ z9TQ~pc&vZYJm%7^n%Ry7t&|Fg=oBDz@~xGs0kh8l2d9Ih3XL3^9iUc$v)q_AJ}dMD>QmRMJo>27xKr>{}$6nNs}byX3a5hPk`IAKd& z@N!iivJ<%(0Yz=)JI)shMLFi*F+-Y^0xpnwIZdT#GZ<~VAjffXhox8;Ug;79^R;kI zXG$9$TET9AeV`q<|mzI+IxUzKuZjL6IzwxV2~5UF$GG9Dk7 z_g^a=!*Z=1JS~_|O!rZ_4|D}rJ5Kj}H19~?uBV7-!aNFQ_n;tsL4evOI?Gv^kkGp8 zq2BHZKT4nHkz)u)i;2&qA|-M0*FaT`^Uglzc(>a^_Uw9lHG1z&E#F4P>9c?p0zj1t z<3W^TIeg>G4}jTClDzl|mZt>7-Kd=yBEvMIca4~-(O9!I@#aw?fmh}%ghLq+AIfbFiR448;!;?yEg)a}&i7Eg+OH6LXQ!pE$K zIlu*u3JY1(lrL@(c|mEu3?93DdtqW%G@Ts}s)e-lO7h5`(H#rE!IMiE-Wa1s%HoGv zKtg`yH_@4g^w|dFj#<(aEC@eS6fQqMuCgr2AjuhfoRXM^ z44>TNe_ARl=D%Yjo&c`4K~uO75(}jr9is;l1;_?bRc1fWND*V2sqLyxlrWz)KaeH- zSnA9io{&lyY%ULl9RVlYQYLiVCL*K8m3X9Ha0s{`aOM9Xo4!$>lbKuQ0K0E#5E}tB zcfwD@6y_8n_fsx^ckby)m@h%;zq?hT5T%jj;Dh6EdQC%rO*q?{RsgLxH>H4lH~|_y zN5%H`R(Zyui`E_7z4cCvm!PXi9hiPc$5Kut&W)+~+sWS5T<482qCil~j&pD*?6|AY zj`K#(tPNDe&&B0IHnvIV7=pYq1e@}+K|s^GO*6Z8sUjGgYzkG%CX7&i{l!l;ro=H% z0~9;v*K-X=-ZjEq({x*+Du6!qwB3!UD`%CI_IA%bAZzH=+%!7+1$jfl3q|ybd8*ZL zZfZyLbeM2UxFZUG2kpn#ig-1kH$O}%5`F$k`dWPw%L>xm%K_&8!Is3j@rf|tZt@Wa z>3g5|d$cS)>mE(=-01Z!jS}a{%H%*-mF@@Bg$I#CO{Eq?(S93r2WOhal0V@Ug_aM6 z(I@kNpf8Aj7hht|BH3327?>-x|E>7y{%7#YzsSnJ7>lBdnWdHc|AQ=g!GA-R*S{c( zJw8T(hAsVM3-b4|jLgGq0lljf_0=MjX@ZWXY}K+p3a@#Ip6Bl6at8IX{BLqtl}M;R z3knK+uf4piJ8=K_yD>A$xhRRE?uz5*9LiArJWJz2Ynn4YKX6Ox@eIRjYRb3)2@^KU zBGu#1xc7w(NFs3YZo~-B^p;ja?{7{X9v){dlVnCjr{^eCdPWK<7_i;2#|f4xv~Qdm zWWp_5lm{SEQ?tKDiAiTIKO9O|oLj}u?8y&0q}4G{West;ThYx4zt7G-9jBbQ;>joQ z%^pNp)3m%WSAL|LU{HWQcFUHNgv7*9#2O;u(*!l9yRrFbC&j}z-~$Ct<^r?XL&Bf< z8Qt~iJ_%q2(n9DLT2l|XCiG^Ql+J#LA$_c)cYmR^`y#34PBGlJOYfRtV`aaf4yEUK ztnRSz9EMuUr97n)`{@(vDOXQO5${N$sw8n`GcO-0cHq(b9{ijr%M{`@k<|M^$iP}s ziLce}_+o=n*mBw*uSXo`fnhVdH%$IOf)B<~zLT9u74B%M|5nlPTV{IL;Wuo^ko`6x zc^zt4ghI|$*gGR?7T_L=nJh=@oh|DA9JaAm_OV#CFYobk`MJ_iu`UZO*}QB(kx}SZ zo-{@LrS#$TmQJZU%Nj4m*nmd-!{?9JTW1?eLhPIHy94=L**J(N^Q@#v zf?h^*qq@6~N4p1Atz8`vmj}tbDr{s)U6(_#Wuja%~&%NvBn~eeg}+W@2K82bc@%p z#a6Hko)-eF`0>gX2-kni4*51!6=3-W^P!IPZtQz2GN$NK?~?17`^JqPXS&~AZzc8* z$^rwO1!jOLiIT1UD5X$%wS!6HR>(l!7hgOZu7af-d!Puiq;nDw5_tN~@jN}!LZz7R z_C#bMTi4$10LGkn_`m0ww;n-BI)v_YzKP&@EKrX zT%d~K<`6nN?4RYPWvhpVjRnS_^AxN@!Kdftx3lae5o$P@>4VO2)^@l70ergkJB^=9 ziFz8rN17dzjbTPljl&x~XpDkHmIb|$xUQw?NEpD%-S{6)u6kipd7GDN4Mc1@a=Eo2 zlPb_F*YPu)I1Q8-~2_qn~stX3Yf$`1K>FEPbMju);xv`A5$yi^XrLw8~ z-#loHwdJw>JW&EpXOow!xgG}O{XZAJgite%R=pSGMd&MOvbWc0zNerCc}S}CY_`qx zi_%Ny5I!58vf7A2YY!IXvCT!!)RFouJsw!mGDtT!KW`xE$K~J2hhAWo<8cPcp6eE+ z&!ETdebkcV#q{3Id;W6fJu4viBPr#HW&O*SuCn*)eGM*J zNKfN9#6_zU8k(|Wi_*Qbjx{=6u=Aoz2+S$5xc5%U^K65emqb>2@20HsI)nnS)FHM* z>6pJ+CiVX`8cQVIGO|t6d`JXdT(Wcdd)N2!>e%%eobcA1Ke4;Dn=H=jIugay={CYa zNgrO1FCjr1U1cXoJR0AhN*Z-)`spAFO#I%Ti~E;DpV{STWM}(zDw>!Z@%9Srq2uwh zXdFV*R0$4(l{lkXoN?m4r>^^Ya#L+-Oo5duL{>v@$ ziB?Y;xO>8Xz(J7_kRIaTmzEy%5b+)q%B^SIYXW_BYK=ox3=!L*PmFrMQ$p>to5MSL z?ie<@Bt+5C!#FYmsOs`))?FKhgx+9#GNOpXBItJ`b6M<70p+qJaVQ`E%vNzqH*2bJ z2{!S&P8GqEt%f5rMK~za$}$^X{nbLhh`+YXje| zBp_zS5asQahMq~m3z;@D5-y;9Q&6s1Koee7fZT135*gC65#2vKX;%Ad5s#PCbQ zN|-?CDUSk1>4YWi&eiLOw31W$5XzyitOQ~|S7YEG&49=SOR=%l!KIZWYeHgufh0^N z-q=;E>hk7;ZC*y7HScbJ;~EKR!kR9)r#Ajxtkf$^y!0O1Q${RAvEeRzfp9b~M7KUH zChpVw-n&J8f@oC82WD}FHCx#gsXKDV971dn3@Iqhv&fkck1cY35#)O&FAE})c1?jg z4ELCXK|io8@W>2_-7X_7`%s0^gV`G(w38CIxyw^F;S5wCZ<5M{Ea zT&TokMs)PzlR;lkTtXmg?9)5dKrDui8YehG-$!Hz6DyM<`frE|R7@7qazU^cVSnM0 zqqxVTyUwo6!e-NE;+Y71_R23)1jfU3{7gFrfFl33vnK=kQTg6t%{w z--$g{2x1-+46_!q{3 zqx;)Qz{26f{JT~APsHc;`S1GMf8F>$rT=fN^gs3g`8I!h hsegwF&VNMz|Ld$&6%djBR)YU4BVl1+s>%MI{TJJK0v!MV From 4bf86da71ef574ad843c8a6a27e7f30251cc7355 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 26 Jun 2008 15:27:35 +0000 Subject: [PATCH 03/28] --- .../classworlds/BytesURLConnection.java | 36 ---- .../classworlds/BytesURLStreamHandler.java | 29 ---- .../org/codehaus/classworlds/ClassRealm.java | 111 ------------ .../classworlds/ClassRealmAdapter.java | 148 ---------------- .../classworlds/ClassRealmReverseAdapter.java | 142 --------------- .../org/codehaus/classworlds/ClassWorld.java | 63 ------- .../classworlds/ClassWorldAdapter.java | 107 ------------ .../classworlds/ClassWorldException.java | 105 ----------- .../classworlds/ClassWorldReverseAdapter.java | 106 ----------- .../classworlds/ConfigurationException.java | 78 --------- .../codehaus/classworlds/Configurator.java | 123 ------------- .../classworlds/ConfiguratorAdapter.java | 84 --------- .../classworlds/DefaultClassRealm.java | 154 ---------------- .../classworlds/DuplicateRealmException.java | 97 ----------- .../org/codehaus/classworlds/Launcher.java | 46 ----- .../classworlds/NoSuchRealmException.java | 97 ----------- .../codehaus/classworlds/ClassWorldTest.java | 150 ---------------- .../classworlds/DefaultClassRealmTest.java | 164 ------------------ .../codehaus/classworlds/LauncherTest.java | 156 ----------------- 19 files changed, 1996 deletions(-) delete mode 100644 src/main/java/org/codehaus/classworlds/BytesURLConnection.java delete mode 100644 src/main/java/org/codehaus/classworlds/BytesURLStreamHandler.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassRealm.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassRealmAdapter.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassRealmReverseAdapter.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassWorld.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassWorldAdapter.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassWorldException.java delete mode 100644 src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java delete mode 100644 src/main/java/org/codehaus/classworlds/ConfigurationException.java delete mode 100644 src/main/java/org/codehaus/classworlds/Configurator.java delete mode 100644 src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java delete mode 100644 src/main/java/org/codehaus/classworlds/DefaultClassRealm.java delete mode 100644 src/main/java/org/codehaus/classworlds/DuplicateRealmException.java delete mode 100644 src/main/java/org/codehaus/classworlds/Launcher.java delete mode 100644 src/main/java/org/codehaus/classworlds/NoSuchRealmException.java delete mode 100644 src/test/java/org/codehaus/classworlds/ClassWorldTest.java delete mode 100644 src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java delete mode 100644 src/test/java/org/codehaus/classworlds/LauncherTest.java diff --git a/src/main/java/org/codehaus/classworlds/BytesURLConnection.java b/src/main/java/org/codehaus/classworlds/BytesURLConnection.java deleted file mode 100644 index f8803b5..0000000 --- a/src/main/java/org/codehaus/classworlds/BytesURLConnection.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.codehaus.classworlds; - -import java.net.URLConnection; -import java.net.URL; -import java.io.InputStream; -import java.io.ByteArrayInputStream; - -/** - * @author Hani Suleiman (hani@formicary.net) - *

- * Date: Oct 20, 2003 - * Time: 12:46:01 AM - */ -public class BytesURLConnection extends URLConnection -{ - protected byte[] content; - - protected int offset; - - protected int length; - - public BytesURLConnection( URL url, byte[] content ) - { - super( url ); - this.content = content; - } - - public void connect() - { - } - - public InputStream getInputStream() - { - return new ByteArrayInputStream( content ); - } -} \ No newline at end of file diff --git a/src/main/java/org/codehaus/classworlds/BytesURLStreamHandler.java b/src/main/java/org/codehaus/classworlds/BytesURLStreamHandler.java deleted file mode 100644 index b40e90c..0000000 --- a/src/main/java/org/codehaus/classworlds/BytesURLStreamHandler.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.codehaus.classworlds; - -import java.net.URLStreamHandler; -import java.net.URLConnection; -import java.net.URL; - -/** - * @author Hani Suleiman (hani@formicary.net) - * Date: Oct 20, 2003 - * Time: 12:45:18 AM - */ -public class BytesURLStreamHandler extends URLStreamHandler -{ - byte[] content; - - int offset; - - int length; - - public BytesURLStreamHandler( byte[] content ) - { - this.content = content; - } - - public URLConnection openConnection( URL url ) - { - return new BytesURLConnection( url, content ); - } -} \ No newline at end of file diff --git a/src/main/java/org/codehaus/classworlds/ClassRealm.java b/src/main/java/org/codehaus/classworlds/ClassRealm.java deleted file mode 100644 index a965c42..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassRealm.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; - -/** - * Autonomous sub-portion of a ClassWorld. - *

- *

- * This class most closed maps to the ClassLoader - * role from Java and in facts can provide a ClassLoader - * view of itself using {@link #getClassLoader}. - *

- * - * @author bob mcwhirter - * @author Jason van Zyl - * @version $Id$ - */ -public interface ClassRealm -{ - String getId(); - - ClassWorld getWorld(); - - void importFrom( String realmId, String pkgName ) - throws NoSuchRealmException; - - void addConstituent( URL constituent ); - - ClassRealm locateSourceRealm( String className ); - - void setParent( ClassRealm classRealm ); - - ClassRealm createChildRealm( String id ) - throws DuplicateRealmException; - - ClassLoader getClassLoader(); - - ClassRealm getParent(); - - URL[] getConstituents(); - - // ---------------------------------------------------------------------- - // Classloading - // ---------------------------------------------------------------------- - - Class loadClass( String name ) - throws ClassNotFoundException; - - // ---------------------------------------------------------------------- - // Resource handling - // ---------------------------------------------------------------------- - - URL getResource( String name ); - - Enumeration findResources( String name ) - throws IOException; - - InputStream getResourceAsStream( String name ); - - void display(); -} - diff --git a/src/main/java/org/codehaus/classworlds/ClassRealmAdapter.java b/src/main/java/org/codehaus/classworlds/ClassRealmAdapter.java deleted file mode 100644 index 3184d78..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassRealmAdapter.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.codehaus.classworlds; - -import java.net.URL; -import java.util.Enumeration; -import java.util.HashMap; -import java.io.IOException; -import java.io.InputStream; - -/** - * An adapter for ClassRealms - * - * @author Andrew Williams - * @version $Id$ - */ -public class ClassRealmAdapter - implements ClassRealm -{ - private static HashMap instances = new HashMap(); - - public static ClassRealmAdapter getInstance( org.codehaus.plexus.classworlds.realm.ClassRealm newRealm ) - { - if ( instances.containsKey( newRealm ) ) - return (ClassRealmAdapter) instances.get( newRealm ); - - ClassRealmAdapter adapter = new ClassRealmAdapter( newRealm ); - instances.put( newRealm, adapter ); - - return adapter; - } - - private org.codehaus.plexus.classworlds.realm.ClassRealm realm; - - private ClassRealmAdapter( org.codehaus.plexus.classworlds.realm.ClassRealm newRealm ) - { - this.realm = newRealm; - } - - public String getId() - { - return realm.getId(); - } - - public ClassWorld getWorld() - { - return ClassWorldAdapter.getInstance( realm.getWorld() ); - } - - public void importFrom( String realmId, - String pkgName ) - throws NoSuchRealmException - { - try - { - realm.importFrom( realmId, pkgName ); - } - catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) - { - throw new NoSuchRealmException( getWorld(), e.getId() ); - } - } - - public void addConstituent( URL constituent ) - { - realm.addURL( constituent ); - } - - public ClassRealm locateSourceRealm( String className ) - { - return ClassRealmAdapter.getInstance( realm.locateSourceRealm( - className ) ); - } - - public void setParent( ClassRealm classRealm ) - { - if ( classRealm != null ) - { - realm.setParentRealm( ClassRealmReverseAdapter.getInstance( classRealm ) ); - } - } - - public ClassRealm createChildRealm( String id ) - throws DuplicateRealmException - { - try - { - return ClassRealmAdapter.getInstance( realm.createChildRealm( id ) ); - } - catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) - { - throw new DuplicateRealmException( getWorld(), e.getId() ); - } - } - - public ClassLoader getClassLoader() - { - return realm; - } - - public ClassRealm getParent() - { - return ClassRealmAdapter.getInstance( realm.getParentRealm() ); - } - - public ClassRealm getParentRealm() - { - return ClassRealmAdapter.getInstance( realm.getParentRealm() ); - } - - public URL[] getConstituents() - { - return realm.getURLs(); - } - - public Class loadClass( String name ) - throws ClassNotFoundException - { - return realm.loadClass( name ); - } - - public URL getResource( String name ) - { - return realm.getResource( name ); - } - - public Enumeration findResources( String name ) - throws IOException - { - return realm.findResources( name ); - } - - public InputStream getResourceAsStream( String name ) - { - return realm.getResourceAsStream( name ); - } - - public void display() - { - realm.display(); - } - - public boolean equals(Object o) - { - if ( !( o instanceof ClassRealm ) ) - return false; - - return getId().equals( ( (ClassRealm) o ).getId() ); - } -} diff --git a/src/main/java/org/codehaus/classworlds/ClassRealmReverseAdapter.java b/src/main/java/org/codehaus/classworlds/ClassRealmReverseAdapter.java deleted file mode 100644 index a9a8b7e..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassRealmReverseAdapter.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.codehaus.classworlds; - -import java.util.HashMap; -import java.util.Enumeration; -import java.net.URL; -import java.io.IOException; -import java.io.InputStream; - -/** - * A reverse adapter for ClassRealms - * - * @author Andrew Williams - * @version $Id$ - */ -public class ClassRealmReverseAdapter - extends org.codehaus.plexus.classworlds.realm.ClassRealm -{ - private static HashMap instances = new HashMap(); - - public static ClassRealmReverseAdapter getInstance( ClassRealm oldRealm ) - { - if ( instances.containsKey( oldRealm ) ) - return (ClassRealmReverseAdapter) instances.get( oldRealm ); - - ClassRealmReverseAdapter adapter = new ClassRealmReverseAdapter( oldRealm ); - instances.put( oldRealm, adapter ); - - return adapter; - } - - private ClassRealm realm; - - private ClassRealmReverseAdapter( ClassRealm oldRealm ) - { - super( ClassWorldReverseAdapter.getInstance( oldRealm.getWorld() ), - oldRealm.getId(), oldRealm.getClassLoader() ); - this.realm = oldRealm; - } - - public String getId() - { - return realm.getId(); - } - - public org.codehaus.plexus.classworlds.ClassWorld getWorld() - { - return ClassWorldReverseAdapter.getInstance( realm.getWorld() ); - } - - public void importFrom( String realmId, - String pkgName ) - throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException - { - try - { - realm.importFrom( realmId, pkgName ); - } - catch ( NoSuchRealmException e ) - { - throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( getWorld(), e.getId() ); - } - } - - public void addURL( URL constituent ) - { - realm.addConstituent( constituent ); - } - - public org.codehaus.plexus.classworlds.realm.ClassRealm locateSourceRealm( String className ) - { - return getInstance( realm.locateSourceRealm( - className ) ); - } - - public void setParentRealm( org.codehaus.plexus.classworlds.realm.ClassRealm classRealm ) - { - realm.setParent( ClassRealmAdapter.getInstance( classRealm ) ); - } - - public org.codehaus.plexus.classworlds.realm.ClassRealm createChildRealm( String id ) - throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException - { - try - { - return getInstance( realm.createChildRealm( id ) ); - } - catch ( DuplicateRealmException e ) - { - throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( getWorld(), e.getId() ); - } - } - - public ClassLoader getClassLoader() - { - return realm.getClassLoader(); - } - - public org.codehaus.plexus.classworlds.realm.ClassRealm getParentRealm() - { - return getInstance( realm.getParent() ); - } - - public URL[] getURLs() - { - return realm.getConstituents(); - } - - public Class loadClass( String name ) - throws ClassNotFoundException - { - return realm.loadClass( name ); - } - - public URL getResource( String name ) - { - return realm.getResource( name ); - } - - public Enumeration findResources( String name ) - throws IOException - { - return realm.findResources( name ); - } - - public InputStream getResourceAsStream( String name ) - { - return realm.getResourceAsStream( name ); - } - - public void display() - { - realm.display(); - } - - public boolean equals(Object o) - { - if ( !( o instanceof ClassRealm ) ) - return false; - - return getId().equals( ( (ClassRealm) o ).getId() ); - } -} diff --git a/src/main/java/org/codehaus/classworlds/ClassWorld.java b/src/main/java/org/codehaus/classworlds/ClassWorld.java deleted file mode 100644 index 00a2ac2..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassWorld.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.codehaus.classworlds; - -import java.util.Collection; - -/** - * A compatibility wrapper for org.codehaus.plexus.classworlds.ClassWorld - * provided for legacy code - * - * @author Andrew Williams - * @version $Id$ - */ -public class ClassWorld -{ - private ClassWorldAdapter adapter; - - public ClassWorld( String realmId, - ClassLoader classLoader ) - { - adapter = ClassWorldAdapter.getInstance( - new org.codehaus.plexus.classworlds.ClassWorld( realmId, classLoader ) ); - } - - public ClassWorld() - { - adapter = ClassWorldAdapter.getInstance( - new org.codehaus.plexus.classworlds.ClassWorld( ) ); - } - - public ClassWorld( boolean ignore ) - { - /* fake */ - } - - public ClassRealm newRealm( String id ) - throws DuplicateRealmException - { - return adapter.newRealm( id ); - } - - public ClassRealm newRealm( String id, - ClassLoader classLoader ) - throws DuplicateRealmException - { - return adapter.newRealm( id, classLoader ); - } - - public void disposeRealm( String id ) - throws NoSuchRealmException - { - adapter.disposeRealm( id ); - } - - public ClassRealm getRealm( String id ) - throws NoSuchRealmException - { - return adapter.getRealm( id ); - } - - public Collection getRealms() - { - return adapter.getRealms(); - } -} diff --git a/src/main/java/org/codehaus/classworlds/ClassWorldAdapter.java b/src/main/java/org/codehaus/classworlds/ClassWorldAdapter.java deleted file mode 100644 index 523dd01..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassWorldAdapter.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.codehaus.classworlds; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Vector; -import java.util.Iterator; - -/** - * An adapter for ClassWorlds - * - * @author Andrew Williams - * @version $Id$ - */ -public class ClassWorldAdapter - extends ClassWorld -{ - private static HashMap instances = new HashMap(); - - public static ClassWorldAdapter getInstance( org.codehaus.plexus.classworlds.ClassWorld newWorld ) - { - if ( instances.containsKey( newWorld ) ) - return (ClassWorldAdapter) instances.get( newWorld ); - - ClassWorldAdapter adapter = new ClassWorldAdapter( newWorld ); - instances.put( newWorld, adapter ); - - return adapter; - } - - private org.codehaus.plexus.classworlds.ClassWorld world; - - private ClassWorldAdapter( org.codehaus.plexus.classworlds.ClassWorld newWorld ) - { - super( false ); - this.world = newWorld; - } - - public ClassRealm newRealm( String id ) - throws DuplicateRealmException - { - try - { - return ClassRealmAdapter.getInstance( world.newRealm( id ) ); - } - catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) - { - throw new DuplicateRealmException( this, e.getId() ); - } - } - - public ClassRealm newRealm( String id, - ClassLoader classLoader ) - throws DuplicateRealmException - { - try - { - return ClassRealmAdapter.getInstance( world.newRealm( id, - classLoader ) ); - } - catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) - { - throw new DuplicateRealmException( this, e.getId() ); - } - } - - public void disposeRealm( String id ) - throws NoSuchRealmException - { - try - { - world.disposeRealm( id ); - } - catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) - { - throw new NoSuchRealmException( this, e.getId() ); - } - } - - public ClassRealm getRealm( String id ) - throws NoSuchRealmException - { - try - { - return ClassRealmAdapter.getInstance( world.getRealm( id ) ); - } - catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) - { - throw new NoSuchRealmException( this, e.getId() ); - } - } - - public Collection getRealms() - { - Collection realms = world.getRealms(); - Vector ret = new Vector(); - - Iterator it = realms.iterator(); - while ( it.hasNext() ) - { - org.codehaus.plexus.classworlds.realm.ClassRealm realm = - (org.codehaus.plexus.classworlds.realm.ClassRealm) it.next(); - ret.add( ClassRealmAdapter.getInstance( realm ) ); - } - - return ret; - } -} diff --git a/src/main/java/org/codehaus/classworlds/ClassWorldException.java b/src/main/java/org/codehaus/classworlds/ClassWorldException.java deleted file mode 100644 index cdf48e7..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassWorldException.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -/** - * Base exception for ClassWorld errors. - * - * @author bob mcwhirter - * @version $Id$ - */ -public class ClassWorldException extends Exception -{ - // ------------------------------------------------------------ - // Instance members - // ------------------------------------------------------------ - - /** - * The world. - */ - private ClassWorld world; - - // ------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------ - - /** - * Construct. - * - * @param world The world. - */ - public ClassWorldException( final ClassWorld world ) - { - this.world = world; - } - - /** - * Construct. - * - * @param world The world. - * @param msg The detail message. - */ - public ClassWorldException( final ClassWorld world, final String msg ) - { - super( msg ); - this.world = world; - } - - // ------------------------------------------------------------ - // Instance methods - // ------------------------------------------------------------ - - /** - * Retrieve the world. - * - * @return The world. - */ - public ClassWorld getWorld() - { - return this.world; - } -} diff --git a/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java b/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java deleted file mode 100644 index 3f182ef..0000000 --- a/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.codehaus.classworlds; - -import java.util.HashMap; -import java.util.Collection; -import java.util.Vector; -import java.util.Iterator; - -/** - * A reverse adapter for ClassWorlds - * - * @author Andrew Williams - * @version $Id$ - */ -public class ClassWorldReverseAdapter - extends org.codehaus.plexus.classworlds.ClassWorld -{ - private static HashMap instances = new HashMap(); - - public static ClassWorldReverseAdapter getInstance( ClassWorld oldWorld ) - { - if ( instances.containsKey( oldWorld ) ) - return (ClassWorldReverseAdapter) instances.get( oldWorld ); - - ClassWorldReverseAdapter adapter = new ClassWorldReverseAdapter( oldWorld ); - instances.put( oldWorld, adapter ); - - return adapter; - } - - private ClassWorld world; - - private ClassWorldReverseAdapter( ClassWorld newWorld ) - { - super(); - this.world = newWorld; - } - - public org.codehaus.plexus.classworlds.realm.ClassRealm newRealm( String id ) - throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException - { - try - { - return ClassRealmReverseAdapter.getInstance( world.newRealm( id ) ); - } - catch ( DuplicateRealmException e ) - { - throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( this, e.getId() ); - } - } - - public org.codehaus.plexus.classworlds.realm.ClassRealm newRealm( String id, - ClassLoader classLoader ) - throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException - { - try - { - return ClassRealmReverseAdapter.getInstance( world.newRealm( id, - classLoader ) ); - } - catch ( DuplicateRealmException e ) - { - throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( this, e.getId() ); - } - } - - public void disposeRealm( String id ) - throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException - { - try - { - world.disposeRealm( id ); - } - catch ( NoSuchRealmException e ) - { - throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() ); - } - } - - public org.codehaus.plexus.classworlds.realm.ClassRealm getRealm( String id ) - throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException - { - try - { - return ClassRealmReverseAdapter.getInstance( world.getRealm( id ) ); - } - catch ( NoSuchRealmException e ) - { - throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() ); - } - } - - public Collection getRealms() - { - Collection realms = world.getRealms(); - Vector ret = new Vector(); - - Iterator it = realms.iterator(); - while ( it.hasNext() ) - { - ClassRealm realm = (ClassRealm) it.next(); - ret.add( ClassRealmReverseAdapter.getInstance( realm ) ); - } - - return ret; - } -} diff --git a/src/main/java/org/codehaus/classworlds/ConfigurationException.java b/src/main/java/org/codehaus/classworlds/ConfigurationException.java deleted file mode 100644 index 2faaa0d..0000000 --- a/src/main/java/org/codehaus/classworlds/ConfigurationException.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -/** - * Indicates an error during Launcher configuration. - * - * @author bob mcwhirter - * @version $Id$ - */ -public class ConfigurationException extends Exception -{ - /** - * Construct. - * - * @param msg The message. - */ - public ConfigurationException( String msg ) - { - super( msg ); - } - - /** - * Construct. - * - * @param msg The message. - * @param lineNo The number of configuraton line where the problem occured. - * @param line The configuration line where the problem occured. - */ - public ConfigurationException( String msg, int lineNo, String line ) - { - super( msg + " (" + lineNo + "): " + line ); - } -} diff --git a/src/main/java/org/codehaus/classworlds/Configurator.java b/src/main/java/org/codehaus/classworlds/Configurator.java deleted file mode 100644 index c630158..0000000 --- a/src/main/java/org/codehaus/classworlds/Configurator.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.codehaus.classworlds; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; - -/** - * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Configurator - * provided for legacy code - * - * @author Andrew Williams - * @version $Id$ - */ -public class Configurator -{ - private ConfiguratorAdapter config; - - /** Construct. - * - * @param launcher The launcher to configure. - */ - public Configurator( Launcher launcher ) - { - config = ConfiguratorAdapter.getInstance( - new org.codehaus.plexus.classworlds.launcher.Configurator( launcher ), launcher ); - } - - /** Construct. - * - * @param world The classWorld to configure. - */ - public Configurator( ClassWorld world ) - { - config = ConfiguratorAdapter.getInstance( - new org.codehaus.plexus.classworlds.launcher.Configurator( - ClassWorldReverseAdapter.getInstance( world ) ), world ); - } - - /** set world. - * this setter is provided so you can use the same configurator to configure several "worlds" - * - * @param world The classWorld to configure. - */ - public void setClassWorld( ClassWorld world ) - { - config.setClassWorld( world ); - } - - /** - * Configure from a file. - * - * @param is The config input stream - * @throws IOException If an error occurs reading the config file. - * @throws MalformedURLException If the config file contains invalid URLs. - * @throws ConfigurationException If the config file is corrupt. - * @throws DuplicateRealmException If the config file defines two realms with the same id. - * @throws NoSuchRealmException If the config file defines a main entry point in - * a non-existent realm. - */ - public void configure( InputStream is ) - throws IOException, MalformedURLException, ConfigurationException, DuplicateRealmException, NoSuchRealmException - { - config.configureAdapter( is ); - } - - /** - * Associate parent realms with their children. - */ - protected void associateRealms() - { - config.associateRealms(); - } - - /** - * Load a glob into the specified classloader. - * - * @param line The path configuration line. - * @param realm The realm to populate - * @throws MalformedURLException If the line does not represent - * a valid path element. - * @throws FileNotFoundException If the line does not represent - * a valid path element in the filesystem. - */ - protected void loadGlob( String line, ClassRealm realm ) - throws MalformedURLException, FileNotFoundException - { - loadGlob( line, realm, false ); - } - - /** - * Load a glob into the specified classloader. - * - * @param line The path configuration line. - * @param realm The realm to populate - * @param optionally Whether the path is optional or required - * @throws MalformedURLException If the line does not represent - * a valid path element. - * @throws FileNotFoundException If the line does not represent - * a valid path element in the filesystem. - */ - protected void loadGlob( String line, ClassRealm realm, boolean optionally ) - throws MalformedURLException, FileNotFoundException - { - config.loadGlob( line, realm, optionally ); - } - - /** - * Filter a string for system properties. - * - * @param text The text to filter. - * @return The filtered text. - * @throws ConfigurationException If the property does not - * exist or if there is a syntax error. - */ - protected String filter( String text ) - throws ConfigurationException - { - return config.filter( text ); - } - -} - diff --git a/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java b/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java deleted file mode 100644 index 84023f5..0000000 --- a/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.codehaus.classworlds; - -import java.io.InputStream; -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.HashMap; - -/** - * Created by IntelliJ IDEA. - * - * @uthor: Andrew Williams - * @since: Nov 25, 2006 - * @version: $Id$ - */ -public class ConfiguratorAdapter - extends Configurator -{ - private static HashMap instances = new HashMap(); - - public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig, - Launcher launcher ) - { - if ( instances.containsKey( newConfig ) ) - return (ConfiguratorAdapter) instances.get( newConfig ); - - ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, launcher ); - instances.put( newConfig, adapter ); - - return adapter; - } - - public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig, - ClassWorld world ) - { - if ( instances.containsKey( newConfig ) ) - return (ConfiguratorAdapter) instances.get( newConfig ); - - ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, world ); - instances.put( newConfig, adapter ); - - return adapter; - } - - private org.codehaus.plexus.classworlds.launcher.Configurator config; - - private ConfiguratorAdapter( org.codehaus.plexus.classworlds.launcher.Configurator config, Launcher launcher ) - { - super( launcher ); - this.config = config; - } - - private ConfiguratorAdapter( org.codehaus.plexus.classworlds.launcher.Configurator config, ClassWorld world ) - { - super( world ); - this.config = config; - } - - public void associateRealms() - { - config.associateRealms(); - } - - public void configureAdapter( InputStream is ) - throws IOException, MalformedURLException, ConfigurationException, DuplicateRealmException, NoSuchRealmException - { - try - { - config.configure( is ); - } - catch ( org.codehaus.plexus.classworlds.launcher.ConfigurationException e ) - { - throw new ConfigurationException( e.getMessage() ); - } - catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) - { - throw new DuplicateRealmException( ClassWorldAdapter.getInstance( e.getWorld() ), e.getId() ); - } - catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) - { - throw new NoSuchRealmException( ClassWorldAdapter.getInstance( e.getWorld() ), e.getId() ); - } - } - -} diff --git a/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java b/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java deleted file mode 100644 index ee818b4..0000000 --- a/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.codehaus.classworlds; - -/** - * A compatibility wrapper for org.codehaus.plexus.classworlds.realm.ClassRealm - * provided for legacy code - * - * @author Andrew Williams - * @version $Id$ - */ - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; - -public class DefaultClassRealm - implements ClassRealm -{ - private ClassRealmAdapter adapter; - - public DefaultClassRealm( ClassWorld world, String id ) - { - this( world, id, null ); - } - - public DefaultClassRealm( ClassWorld world, String id, ClassLoader foreignClassLoader ) - { - this.adapter = ClassRealmAdapter.getInstance( - new org.codehaus.plexus.classworlds.realm.ClassRealm( - ClassWorldReverseAdapter.getInstance( world ), id, foreignClassLoader ) ); - } - - public URL[] getConstituents() - { - return adapter.getConstituents(); - } - - public ClassRealm getParent() - { - return adapter.getParentRealm(); - } - - public void setParent( ClassRealm parent ) - { - adapter.setParent( parent ); - } - - public String getId() - { - return adapter.getId(); - } - - public ClassWorld getWorld() - { - return adapter.getWorld(); - } - - public void importFrom( String realmId, String packageName ) - throws NoSuchRealmException - { - adapter.importFrom( realmId, packageName ); - } - - public void addConstituent( URL constituent ) - { - adapter.addConstituent( constituent ); - } - - /** - * Adds a byte[] class definition as a constituent for locating classes. - * Currently uses BytesURLStreamHandler to hold a reference of the byte[] in memory. - * This ensures we have a unifed URL resource model for all constituents. - * The code to cache to disk is commented out - maybe a property to choose which method? - * - * @param constituent class name - * @param b the class definition as a byte[] - */ - public void addConstituent(String constituent, - byte[] b) throws ClassNotFoundException - { - try - { - File path, file; - if (constituent.lastIndexOf('.') != -1) - { - path = new File("byteclass/" + constituent.substring(0, constituent.lastIndexOf('.') + 1).replace('.', File.separatorChar)); - - file = new File(path, constituent.substring(constituent.lastIndexOf('.') + 1) + ".class"); - } - else - { - path = new File("byteclass/"); - - file = new File(path, constituent + ".class"); - } - - addConstituent( new URL( null, - file.toURI().toURL().toExternalForm(), - new BytesURLStreamHandler(b) ) ); - } - catch (java.io.IOException e) - { - throw new ClassNotFoundException( "Couldn't load byte stream.", e ); - } - } - - public ClassRealm locateSourceRealm( String classname ) - { - return adapter.locateSourceRealm( classname ); - } - - public ClassLoader getClassLoader() - { - return adapter.getClassLoader(); - } - - public ClassRealm createChildRealm( String id ) - throws DuplicateRealmException - { - return adapter.createChildRealm( id ); - } - - // ---------------------------------------------------------------------- - // ClassLoader API - // ---------------------------------------------------------------------- - - public Class loadClass( String name ) - throws ClassNotFoundException - { - return adapter.loadClass( name ); - } - - public URL getResource( String name ) - { - return adapter.getResource( name ); - } - - public InputStream getResourceAsStream( String name ) - { - return adapter.getResourceAsStream( name ); - } - - public Enumeration findResources(String name) - throws IOException - { - return adapter.findResources( name ); - } - - public void display() - { - adapter.display(); - } -} diff --git a/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java b/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java deleted file mode 100644 index 8808ade..0000000 --- a/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -/** - * Indicates an attempt to add a ClassRealm to a - * ClassWorld with a duplicate id. - * - * @author bob mcwhirter - * @version $Id$ - */ -public class DuplicateRealmException extends ClassWorldException -{ - // ------------------------------------------------------------ - // Instance members - // ------------------------------------------------------------ - - /** - * The realm id. - */ - private String id; - - // ------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------ - - /** - * Construct. - * - * @param world The world. - * @param id The realm id. - */ - public DuplicateRealmException( ClassWorld world, - String id ) - { - super( world, id ); - this.id = id; - } - - // ------------------------------------------------------------ - // Instance methods - // ------------------------------------------------------------ - - /** - * Retrieve the duplicate realm id. - * - * @return The id. - */ - public String getId() - { - return this.id; - } -} diff --git a/src/main/java/org/codehaus/classworlds/Launcher.java b/src/main/java/org/codehaus/classworlds/Launcher.java deleted file mode 100644 index de4ae59..0000000 --- a/src/main/java/org/codehaus/classworlds/Launcher.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.codehaus.classworlds; - -/** - * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Launcher - * provided for legacy code - * - * @author Andrew Williams - * @version $Id$ - */ -public class Launcher - extends org.codehaus.plexus.classworlds.launcher.Launcher -{ - public Launcher() - { - } - - - // ------------------------------------------------------------ - // Class methods - // ------------------------------------------------------------ - - /** - * Launch the launcher from the command line. - * Will exit using System.exit with an exit code of 0 for success, 100 if there was an unknown exception, - * or some other code for an application error. - * - * @param args The application command-line arguments. - */ - public static void main( String[] args ) - { - org.codehaus.plexus.classworlds.launcher.Launcher.main( args ); - } - - /** - * Launch the launcher. - * - * @param args The application command-line arguments. - * @return an integer exit code - * @throws Exception If an error occurs. - */ - public static int mainWithExitCode( String[] args ) - throws Exception - { - return org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode( args ); - } -} diff --git a/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java b/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java deleted file mode 100644 index a05401b..0000000 --- a/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -/** - * Indicates an attempt to retrieve a ClassRealm from a - * ClassWorld with an invalid id. - * - * @author bob mcwhirter - * @version $Id$ - */ -public class NoSuchRealmException extends ClassWorldException -{ - // ------------------------------------------------------------ - // Instance members - // ------------------------------------------------------------ - - /** - * The realm id. - */ - private String id; - - // ------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------ - - /** - * Construct. - * - * @param world The world. - * @param id The realm id. - */ - public NoSuchRealmException( ClassWorld world, - String id ) - { - super( world, id ); - this.id = id; - } - - // ------------------------------------------------------------ - // Instance methods - // ------------------------------------------------------------ - - /** - * Retrieve the invalid realm id. - * - * @return The id. - */ - public String getId() - { - return this.id; - } -} diff --git a/src/test/java/org/codehaus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/classworlds/ClassWorldTest.java deleted file mode 100644 index 93f6f35..0000000 --- a/src/test/java/org/codehaus/classworlds/ClassWorldTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -import junit.framework.TestCase; - -public class ClassWorldTest extends TestCase -{ - private ClassWorld world; - - public ClassWorldTest( String name ) - { - super( name ); - } - - public void setUp() - { - this.world = new ClassWorld(); - } - - public void tearDown() - { - this.world = null; - } - - public void testEmpty() - { - assertTrue( this.world.getRealms().isEmpty() ); - } - - public void testNewRealm() throws Exception - { - ClassRealm realm = this.world.newRealm( "foo" ); - - assertNotNull( realm ); - } - - public void testGetRealm() throws Exception - { - ClassRealm realm = this.world.newRealm( "foo" ); - - assertSame( realm, - this.world.getRealm( "foo" ) ); - } - - public void testNewRealm_Duplicate() throws Exception - { - try - { - this.world.newRealm( "foo" ); - this.world.newRealm( "foo" ); - - fail( "throw DuplicateRealmException" ); - } - catch ( DuplicateRealmException e ) - { - // expected and correct - -// TODO decide if these tests should be re-enabled, usign the wrappers they simply don't make sense -// assertSame( this.world, -// e.getWorld() ); - - assertEquals( "foo", - e.getId() ); - } - } - - public void testGetRealm_NoSuch() throws Exception - { - try - { - this.world.getRealm( "foo" ); - fail( "throw NoSuchRealmException" ); - } - catch ( NoSuchRealmException e ) - { - // expected and correct - -// TODO decide if these tests should be re-enabled, usign the wrappers they simply don't make sense -// assertSame( this.world, -// e.getWorld() ); - - assertEquals( "foo", - e.getId() ); - } - } - - public void testGetRealms() throws Exception - { - assertTrue( this.world.getRealms().isEmpty() ); - - ClassRealm foo = this.world.newRealm( "foo" ); - - assertEquals( 1, - this.world.getRealms().size() ); - - assertTrue( this.world.getRealms().contains( foo ) ); - - ClassRealm bar = this.world.newRealm( "bar" ); - - assertEquals( 2, - this.world.getRealms().size() ); - - assertTrue( this.world.getRealms().contains( bar ) ); - } -} diff --git a/src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java b/src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java deleted file mode 100644 index c41f48e..0000000 --- a/src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -import junit.framework.TestCase; - -import java.io.File; -import java.net.URL; - -public class DefaultClassRealmTest - extends TestCase -{ - public DefaultClassRealmTest( String name ) - { - super( name ); - } - - // ---------------------------------------------------------------------- - // Class testing - // ---------------------------------------------------------------------- - - public void testLoadClassFromRealm() - throws Exception - { - DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" ); - - mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) ); - - mainRealm.loadClass( "org.codehaus.plexus.Component0" ); - } - - public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() - throws Exception - { - DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" ); - - mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) ); - - ClassRealm childRealm = mainRealm.createChildRealm( "child" ); - - childRealm.loadClass( "org.codehaus.plexus.Component0" ); - } - - public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() - throws Exception - { - DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" ); - - mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) ); - - ClassRealm childRealm = mainRealm.createChildRealm( "child" ); - - ClassRealm grandchildRealm = childRealm.createChildRealm( "grandchild" ); - - grandchildRealm.loadClass( "org.codehaus.plexus.Component0" ); - } - - public void testLoadNonExistentClass() - throws Exception - { - DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" ); - - mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) ); - - try - { - mainRealm.loadClass( "org.foo.bar.NonExistentClass" ); - - fail( "A ClassNotFoundException should have been thrown!" ); - } - catch ( ClassNotFoundException e ) - { - } - } - - public void testImport() - throws Exception - { - ClassWorld world = new ClassWorld(); - - ClassRealm r0 = world.newRealm( "r0" ); - - ClassRealm r1 = world.newRealm( "r1" ); - - r0.addConstituent( getJarUrl( "component0-1.0.jar" ) ); - - r1.importFrom( "r0", "org.codehaus.plexus" ); - - r1.loadClass( "org.codehaus.plexus.Component0" ); - } - - // ---------------------------------------------------------------------- - // Resource testing - // ---------------------------------------------------------------------- - - public void testResource() - throws Exception - { - DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" ); - - mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) ); - - URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" ); - - assertNotNull( resource ); - } - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - protected URL getJarUrl( String jarName ) - throws Exception - { - File jarFile = new File( System.getProperty( "basedir" ), "src/test-jars/" + jarName ); - - return jarFile.toURI().toURL(); - } -} - diff --git a/src/test/java/org/codehaus/classworlds/LauncherTest.java b/src/test/java/org/codehaus/classworlds/LauncherTest.java deleted file mode 100644 index 3bf222a..0000000 --- a/src/test/java/org/codehaus/classworlds/LauncherTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package org.codehaus.classworlds; - -/* - $Id$ - - Copyright 2002 (C) The Werken Company. All Rights Reserved. - - Redistribution and use of this software and associated documentation - ("Software"), with or without modification, are permitted provided - that the following conditions are met: - - 1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - 3. The name "classworlds" must not be used to endorse or promote - products derived from this Software without prior written - permission of The Werken Company. For written permission, - please contact bob@werken.com. - - 4. Products derived from this Software may not be called "classworlds" - nor may "classworlds" appear in their names without prior written - permission of The Werken Company. "classworlds" is a registered - trademark of The Werken Company. - - 5. Due credit should be given to The Werken Company. - (http://classworlds.werken.com/). - - THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - */ - -import junit.framework.TestCase; - -import java.io.File; -import java.io.FileInputStream; - -public class LauncherTest - extends TestCase -{ - private Launcher launcher; - - public LauncherTest( String name ) - { - super( name ); - } - - public void setUp() - { - System.setProperty( "java.protocol.handler.pkgs", "org.codehaus.classworlds.protocol" ); - - this.launcher = new Launcher(); - } - - public void tearDown() - { - this.launcher = null; - } - - public void testConfigure_Valid() throws Exception - { - launcher.configure( getConfigPath( "valid-launch.conf" ) ); - - Class mainClass = launcher.getMainClass(); - - assertNotNull( mainClass ); - - assertEquals( "a.A", mainClass.getName() ); - - assertEquals( "app", launcher.getMainRealm().getId() ); - } - - public void testLaunch_ValidStandard() throws Exception - { - launcher.configure( getConfigPath( "valid-launch.conf" ) ); - - launcher.launch( new String[]{} ); - } - - public void testLaunch_ValidStandardExitCode() throws Exception - { - launcher.configure( getConfigPath( "valid-launch-exitCode.conf" ) ); - - launcher.launch( new String[]{} ); - - assertEquals( "check exit code", 15, launcher.getExitCode() ); - } - - public void testLaunch_ValidEnhanced() throws Exception - { - launcher.configure( getConfigPath( "valid-enh-launch.conf" ) ); - - launcher.launch( new String[]{} ); - } - - public void testLaunch_ValidEnhancedExitCode() throws Exception - { - launcher.configure( getConfigPath( "valid-enh-launch-exitCode.conf" ) ); - - launcher.launch( new String[]{} ); - - assertEquals( "check exit code", 45, launcher.getExitCode() ); - } - - public void testLaunch_NoSuchMethod() throws Exception - { - launcher.configure( getConfigPath( "launch-nomethod.conf" ) ); - - try - { - launcher.launch( new String[]{} ); - fail( "should have thrown NoSuchMethodException" ); - } - catch ( NoSuchMethodException e ) - { - // expected and correct - } - } - - public void testLaunch_ClassNotFound() throws Exception - { - launcher.configure( getConfigPath( "launch-noclass.conf" ) ); - - try - { - launcher.launch( new String[]{} ); - fail( "throw ClassNotFoundException" ); - } - catch ( ClassNotFoundException e ) - { - // expected and correct - } - } - - private FileInputStream getConfigPath( String name ) - throws Exception - { - return new FileInputStream( new File( new File( System.getProperty( "basedir" ), "src/test/test-data" ), name ) ); - } -} From ce5ced670bd90428b4b3f5851ecf7746e7557e59 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Mon, 30 Jun 2008 01:23:20 +0000 Subject: [PATCH 04/28] o pushing all logic for looking up a class or resource in a particular way (like from the child, parent, imports ...) and making a strategy the simple ordering of those ways with any additional logic. --- .../plexus/classworlds/ClassWorld.java | 32 ++-- .../plexus/classworlds/realm/ClassRealm.java | 172 +++++++++++++----- .../plexus/classworlds/realm/Entry.java | 76 +++----- .../strategy/AbstractStrategy.java | 3 +- .../classworlds/strategy/DefaultStrategy.java | 10 - .../classworlds/strategy/ForeignStrategy.java | 14 +- .../classworlds/strategy/StrategyFactory.java | 63 ------- .../classworlds/{ => strategy}/UrlUtils.java | 4 +- 8 files changed, 181 insertions(+), 193 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java rename src/main/java/org/codehaus/plexus/classworlds/{ => strategy}/UrlUtils.java (94%) diff --git a/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java b/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java index 57f7195..1e8986f 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java +++ b/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java @@ -2,18 +2,16 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.util.ArrayList; @@ -28,7 +26,7 @@ /** * A collection of ClassRealms, indexed by id. - * + * * @author bob mcwhirter * @version $Id$ */ @@ -36,8 +34,7 @@ public class ClassWorld { private Map realms; - public ClassWorld( String realmId, - ClassLoader classLoader ) + public ClassWorld( String realmId, ClassLoader classLoader ) { this(); @@ -62,8 +59,7 @@ public ClassRealm newRealm( String id ) return newRealm( id, null ); } - public synchronized ClassRealm newRealm( String id, - ClassLoader classLoader ) + public synchronized ClassRealm newRealm( String id, ClassLoader classLoader ) throws DuplicateRealmException { if ( realms.containsKey( id ) ) @@ -108,6 +104,6 @@ public synchronized ClassRealm getRealm( String id ) public synchronized Collection getRealms() { - return Collections.unmodifiableList( new ArrayList(realms.values()) ); + return Collections.unmodifiableList( new ArrayList( realms.values() ) ); } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index af0ce3f..76e3cba 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -2,22 +2,22 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ +import org.codehaus.plexus.classworlds.strategy.DefaultStrategy; +import org.codehaus.plexus.classworlds.strategy.ForeignStrategy; import org.codehaus.plexus.classworlds.strategy.Strategy; -import org.codehaus.plexus.classworlds.strategy.StrategyFactory; +import org.codehaus.plexus.classworlds.strategy.UrlUtils; import org.codehaus.plexus.classworlds.ClassWorld; import java.io.IOException; @@ -29,19 +29,7 @@ import java.util.Iterator; import java.util.TreeSet; - /** - * Implementation of ClassRealm. The realm is the class loading gateway. - * The search is proceded as follows: - *
    - *
  1. Search the parent class loader (passed via the constructor) if there - * is one.
  2. - *
  3. Search the imports.
  4. - *
  5. Search this realm's constituents.
  6. - *
  7. Search the parent realm.
  8. - *
- * - * @author bob mcwhirter * @author Jason van Zyl * @version $Id$ */ @@ -49,34 +37,35 @@ public class ClassRealm extends URLClassLoader { private ClassWorld world; - private String id; + /** Packages this ClassRealm is willing to make visible to outside callers. */ + private TreeSet exports; + + /** Pacakges this ClassRealm wants to import from other realms. */ private TreeSet imports; private Strategy strategy; - private ClassRealm parent; - public ClassRealm( ClassWorld world, - String id ) + public ClassRealm( ClassWorld world, String id ) { this( world, id, null ); } - public ClassRealm( ClassWorld world, - String id, - ClassLoader foreignClassLoader ) + public ClassRealm( ClassWorld world, String id, ClassLoader foreignClassLoader ) { - super( new URL[]{}, foreignClassLoader ); + super( new URL[] {}, foreignClassLoader ); this.world = world; this.id = id; + exports = new TreeSet(); + imports = new TreeSet(); - strategy = StrategyFactory.getStrategy( this, foreignClassLoader ); + strategy = getStrategy( this, foreignClassLoader ); if ( foreignClassLoader != null && foreignClassLoader instanceof ClassRealm ) { @@ -94,14 +83,28 @@ public ClassWorld getWorld() return this.world; } - public void importFrom( String realmId, - String packageName ) + public void importFrom( String realmId, String packageName ) throws NoSuchRealmException { imports.add( new Entry( getWorld().getRealm( realmId ), packageName ) ); imports.add( new Entry( getWorld().getRealm( realmId ), packageName.replace( '.', '/' ) ) ); } + public ClassRealm getImportRealm( String classname ) + { + for ( Iterator iterator = imports.iterator(); iterator.hasNext(); ) + { + Entry entry = (Entry) iterator.next(); + + if ( entry.matches( classname ) ) + { + return entry.getRealm(); + } + } + + return null; + } + public ClassRealm locateSourceRealm( String classname ) { for ( Iterator iterator = imports.iterator(); iterator.hasNext(); ) @@ -134,7 +137,7 @@ public ClassRealm getParentRealm() public ClassRealm createChildRealm( String id ) throws DuplicateRealmException - { + { ClassRealm childRealm = getWorld().newRealm( id, this ); childRealm.setParentRealm( this ); @@ -190,6 +193,55 @@ public Enumeration findRealmResources( String name ) return super.findResources( name ); } + //--------------------------------------------------------------------------------------------- + // Search methods that can be ordered by strategies + //--------------------------------------------------------------------------------------------- + + public Class loadClassFromImport( String name ) + { + ClassRealm importRealm = getImportRealm( name ); + + if ( importRealm != null ) + { + try + { + return importRealm.loadClass( name ); + } + catch ( ClassNotFoundException e ) + { + return null; + } + } + + return null; + } + + public Class loadClassFromSelf( String name ) + { + Class clazz; + + try + { + clazz = findClass( name ); + } + catch ( ClassNotFoundException e ) + { + return null; + } + + if ( true ) + { + resolveClass( clazz ); + } + + return clazz; + } + + public Class loadClassFromParent( String name ) + { + return getParentRealm().loadClassFromSelf( name ); + } + // ---------------------------------------------------------------------- // We delegate to the Strategy here so that we can change the behavior // of any existing ClassRealm. @@ -198,12 +250,17 @@ public Enumeration findRealmResources( String name ) public Class loadClass( String name ) throws ClassNotFoundException { + if ( name.startsWith( "org.codehaus.plexus.classworlds." ) ) + { + return getWorld().getClass().getClassLoader().loadClass( name ); + } + return strategy.loadClass( name ); } public URL getResource( String name ) { - return strategy.getResource( name ); + return strategy.getResource( UrlUtils.normalizeUrlPath( name ) ); } public InputStream getResourceAsStream( String name ) @@ -214,7 +271,7 @@ public InputStream getResourceAsStream( String name ) public Enumeration findResources( String name ) throws IOException { - return strategy.findResources( name ); + return strategy.findResources( UrlUtils.normalizeUrlPath( name ) ); } // ---------------------------------------------------------------------------- @@ -259,16 +316,49 @@ private void showUrls( ClassRealm classRealm ) } } - public boolean equals(Object o) + public boolean equals( Object o ) { if ( !( o instanceof ClassRealm ) ) + { return false; + } return getId().equals( ( (ClassRealm) o ).getId() ); } public String toString() { - return "ClassRealm[" + getId() + ", parent: " + getParentRealm() + "]"; + return "ClassRealm[" + getId() + ", parent: " + getParentRealm() + "]"; } + + // These need to be simplified or the strategy being passed in knowingly by the user + + public Strategy getStrategy( ClassRealm realm ) + { + return getStrategy( realm, "default", null ); + } + + public Strategy getStrategy( ClassRealm realm, ClassLoader foreign ) + { + return getStrategy( realm, "default", foreign ); + } + + public Strategy getStrategy( ClassRealm realm, String hint ) + { + return getStrategy( realm, hint, null ); + } + + public static Strategy getStrategy( ClassRealm realm, String hint, ClassLoader foreign ) + { + if ( foreign != null ) + { + return new ForeignStrategy( realm, foreign ); + } + + // Here we shall check hint to load non-default strategies + + Strategy ret = new DefaultStrategy( realm ); + + return ret; + } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java b/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java index c445200..2b21ac0 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java @@ -2,23 +2,21 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ /** * Import description entry. - * + * * @author bob mcwhirter */ public class Entry @@ -28,8 +26,7 @@ public class Entry private final String pkgName; - Entry( ClassRealm realm, - String pkgName ) + Entry( ClassRealm realm, String pkgName ) { this.realm = realm; @@ -42,7 +39,7 @@ public class Entry /** * Retrieve the realm. - * + * * @return The realm. */ ClassRealm getRealm() @@ -52,7 +49,7 @@ ClassRealm getRealm() /** * Retrieve the package name. - * + * * @return The package name. */ String getPackageName() @@ -61,12 +58,10 @@ String getPackageName() } /** - * Determine if the classname matches the package - * described by this entry. - * + * Determine if the classname matches the package described by this entry. + * * @param classname The class name to test. - * @return true if this entry matches the - * classname, otherwise false. + * @return true if this entry matches the classname, otherwise false. */ boolean matches( String classname ) { @@ -78,17 +73,12 @@ boolean matches( String classname ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Compare this entry to another for relative ordering. - *

- *

- * The natural ordering of Entry objects is reverse-alphabetical - * based upon package name. - *

- * + * Compare this entry to another for relative ordering.

The natural ordering of Entry + * objects is reverse-alphabetical based upon package name.

+ * * @param thatObj The object to compare. - * @return -1 if this object sorts before that object, 0 - * if they are equal, or 1 if this object sorts - * after that object. + * @return -1 if this object sorts before that object, 0 if they are equal, or 1 if this object + * sorts after that object. */ public int compareTo( Object thatObj ) { @@ -109,16 +99,12 @@ public int compareTo( Object thatObj ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Test this entry for equality to another. - *

- *

- * Consistent with {@link #compareTo}, this method tests - * for equality purely on the package name. - *

- * + * Test this entry for equality to another.

Consistent with {@link #compareTo}, this + * method tests for equality purely on the package name.

+ * * @param thatObj The object to compare - * @return true if the two objects are - * semantically equivalent, otherwise false. + * @return true if the two objects are semantically equivalent, otherwise + * false. */ public boolean equals( Object thatObj ) { @@ -128,10 +114,8 @@ public boolean equals( Object thatObj ) } /** - *

- * Consistent with {@link #equals}, this method creates a hashCode - * based on the packagename. - *

+ *

Consistent with {@link #equals}, this method creates a hashCode based on the + * packagename.

*/ public int hashCode() { @@ -140,6 +124,6 @@ public int hashCode() public String toString() { - return "Entry[import " + getPackageName() + " from realm " + getRealm() + "]"; + return "Entry[import " + getPackageName() + " from realm " + getRealm() + "]"; } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java index 4843f96..1fae429 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java @@ -1,7 +1,6 @@ package org.codehaus.plexus.classworlds.strategy; import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.classworlds.UrlUtils; /* * Copyright 2001-2006 Codehaus Foundation. @@ -25,7 +24,7 @@ public abstract class AbstractStrategy implements Strategy { - private ClassRealm realm; + protected ClassRealm realm; public AbstractStrategy( ClassRealm realm ) { diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java index 6e20c0d..6d9831d 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java @@ -16,7 +16,6 @@ * limitations under the License. */ -import org.codehaus.plexus.classworlds.UrlUtils; import org.codehaus.plexus.classworlds.realm.ClassRealm; import java.io.IOException; @@ -43,11 +42,6 @@ public DefaultStrategy( ClassRealm realm ) public Class loadClass( String name ) throws ClassNotFoundException { - if ( name.startsWith( "org.codehaus.plexus.classworlds." ) || name.startsWith( "org.codehaus.classworlds." ) ) - { - return getRealm().getWorld().getClass().getClassLoader().loadClass( name ); - } - try { ClassRealm sourceRealm = getRealm().locateSourceRealm( name ); @@ -79,8 +73,6 @@ public Class loadClass( String name ) public URL getResource( String name ) { - name = getNormalizedResource( name ); - URL resource = null; ClassRealm sourceRealm = getRealm().locateSourceRealm( name ); @@ -126,8 +118,6 @@ public InputStream getResourceAsStream( String name ) public Enumeration findResources( String name ) throws IOException { - name = UrlUtils.normalizeUrlPath( name ); - Vector resources = new Vector(); // Load imports diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java index e8e3c79..2ee2839 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java @@ -8,19 +8,15 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * - * @uthor: Andrew Williams - * @since: Nov 22, 2006 - * @version: $Id$ + * @author Jason van Zyl + * @author: Andrew Williams */ public class ForeignStrategy extends DefaultStrategy { private ClassLoader foreign; - public ForeignStrategy( ClassRealm realm, - ClassLoader foreign ) + public ForeignStrategy( ClassRealm realm, ClassLoader foreign ) { super( realm ); @@ -42,8 +38,6 @@ public Class loadClass( String name ) public URL getResource( String name ) { - name = getNormalizedResource( name ); - URL resource; resource = foreign.getResource( name ); @@ -59,8 +53,6 @@ public URL getResource( String name ) public Enumeration findResources( String name ) throws IOException { - name = getNormalizedResource( name ); - Vector resources = new Vector(); // Load from DefaultStrategy diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java deleted file mode 100644 index aefadb6..0000000 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.codehaus.plexus.classworlds.strategy; - -/* - * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.codehaus.plexus.classworlds.realm.ClassRealm; - -/** - * StrategyFactory loads a strategy, either default or from a given hint. - * - * @uthor: Andrew Williams - * @since: Nov 19, 2006 - * @version: $Id$ - */ -public class StrategyFactory -{ - - public static Strategy getStrategy( ClassRealm realm ) - { - return getStrategy( realm, "default", null ); - } - - public static Strategy getStrategy( ClassRealm realm, - ClassLoader foreign ) - { - return getStrategy( realm, "default", foreign ); - } - - public static Strategy getStrategy( ClassRealm realm, - String hint ) - { - return getStrategy( realm, hint, null ); - } - - public static Strategy getStrategy( ClassRealm realm, - String hint, - ClassLoader foreign ) - { - if ( foreign != null ) - { - return new ForeignStrategy( realm, foreign ); - } - - // Here we shall check hint to load non-default strategies - - Strategy ret = new DefaultStrategy( realm ); - - return ret; - } -} diff --git a/src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java similarity index 94% rename from src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java rename to src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java index 07a866b..3049aad 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java @@ -1,4 +1,4 @@ -package org.codehaus.plexus.classworlds; +package org.codehaus.plexus.classworlds.strategy; /* * Copyright 2001-2006 Codehaus Foundation. @@ -21,7 +21,7 @@ import java.net.URLClassLoader; /** - * @author Jason van Zyl + * @author Jason van Zyl * @version $Id$ */ public class UrlUtils From 922870df2a29fbf365ad6e141c8c952d519dc266 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 00:11:23 +0000 Subject: [PATCH 05/28] o moving the sources that are used to create the test JARs out of the way so that when the actual tests cases are compiled these don't show up on the test classpath which make the tests erroneous. --- .../plexus/classworlds/ClassWorldTest.java | 6 -- .../classworlds/realm/ClassRealmImplTest.java | 97 ++++++++----------- .../classworlds/strategy/StrategyTest.java | 2 - src/test/{java => test-jar-source}/a/A.java | 0 src/test/{java => test-jar-source}/a/Aa.java | 0 src/test/{java => test-jar-source}/b/B.java | 0 src/test/{java => test-jar-source}/b/Bb.java | 0 src/test/{java => test-jar-source}/c/C.java | 0 src/test/{java => test-jar-source}/d/D.java | 0 9 files changed, 39 insertions(+), 66 deletions(-) rename src/test/{java => test-jar-source}/a/A.java (100%) rename src/test/{java => test-jar-source}/a/Aa.java (100%) rename src/test/{java => test-jar-source}/b/B.java (100%) rename src/test/{java => test-jar-source}/b/Bb.java (100%) rename src/test/{java => test-jar-source}/c/C.java (100%) rename src/test/{java => test-jar-source}/d/D.java (100%) diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java index 813d484..6927fc8 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java @@ -138,12 +138,6 @@ public void testPLX334() assertTrue(obj.getPath().indexOf( "src/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); resourceCount++; } -// assertEquals( 2, resourceCount ); -// for some reason surefire-plugin 2.3 returned 2 items there: -// for example: -//jar:file:/home/mkleint/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.jar!/META-INF/plexus/components.xml -//jar:file:/home/mkleint/src/plexus-trunk/plexus-classworlds/src/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml -// However only 1 is correct, which is actually returned by the 2.4 surefire-plugin assertEquals( 1, resourceCount ); Class c = plexus.loadClass( "org.codehaus.plexus.Component1" ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java index f7618c6..c9a05c1 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java @@ -2,18 +2,16 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.net.MalformedURLException; @@ -48,11 +46,8 @@ public void testNewRealm() throws Exception { ClassRealm realm = this.world.newRealm( "foo" ); - assertNotNull( realm ); - assertSame( this.world, realm.getWorld() ); - assertEquals( "foo", realm.getId() ); } @@ -60,7 +55,6 @@ public void testLocateSourceRealm_NoImports() throws Exception { ClassRealm realm = new ClassRealm( this.world, "foo" ); - assertSame( realm, realm.locateSourceRealm( "com.werken.Stuff" ) ); } @@ -68,19 +62,13 @@ public void testLocateSourceRealm_SimpleImport() throws Exception { ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); - ClassRealm werkflowRealm = this.world.newRealm( "werkflow" ); - mainRealm.importFrom( "werkflow", "com.werken.werkflow" ); assertSame( werkflowRealm, mainRealm.locateSourceRealm( "com.werken.werkflow.WerkflowEngine" ) ); - assertSame( werkflowRealm, mainRealm.locateSourceRealm( "com.werken.werkflow.process.ProcessManager" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "com.werken.blissed.Process" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "java.lang.Object" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "NoviceProgrammerClass" ) ); } @@ -88,25 +76,17 @@ public void testLocateSourceRealm_MultipleImport() throws Exception { ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); - ClassRealm werkflowRealm = this.world.newRealm( "werkflow" ); - ClassRealm blissedRealm = this.world.newRealm( "blissed" ); mainRealm.importFrom( "werkflow", "com.werken.werkflow" ); - mainRealm.importFrom( "blissed", "com.werken.blissed" ); assertSame( werkflowRealm, mainRealm.locateSourceRealm( "com.werken.werkflow.WerkflowEngine" ) ); - assertSame( werkflowRealm, mainRealm.locateSourceRealm( "com.werken.werkflow.process.ProcessManager" ) ); - assertSame( blissedRealm, mainRealm.locateSourceRealm( "com.werken.blissed.Process" ) ); - assertSame( blissedRealm, mainRealm.locateSourceRealm( "com.werken.blissed.guard.BooleanGuard" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "java.lang.Object" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "NoviceProgrammerClass" ) ); } @@ -114,33 +94,21 @@ public void testLocateSourceRealm_Hierachy() throws Exception { ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); - ClassRealm fooRealm = this.world.newRealm( "foo" ); - ClassRealm fooBarRealm = this.world.newRealm( "fooBar" ); - ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); mainRealm.importFrom( "foo", "foo" ); - mainRealm.importFrom( "fooBar", "foo.bar" ); - mainRealm.importFrom( "fooBarBaz", "foo.bar.baz" ); assertSame( fooRealm, mainRealm.locateSourceRealm( "foo.Goober" ) ); - assertSame( fooRealm, mainRealm.locateSourceRealm( "foo.cheese.Goober" ) ); - assertSame( fooBarRealm, mainRealm.locateSourceRealm( "foo.bar.Goober" ) ); - assertSame( fooBarRealm, mainRealm.locateSourceRealm( "foo.bar.cheese.Goober" ) ); - assertSame( fooBarBazRealm, mainRealm.locateSourceRealm( "foo.bar.baz.Goober" ) ); - assertSame( fooBarBazRealm, mainRealm.locateSourceRealm( "foo.bar.baz.cheese.Goober" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "java.lang.Object" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "NoviceProgrammerClass" ) ); } @@ -148,33 +116,21 @@ public void testLocateSourceRealm_Hierachy_Reverse() throws Exception { ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); - ClassRealm fooBarRealm = this.world.newRealm( "fooBar" ); - ClassRealm fooRealm = this.world.newRealm( "foo" ); - ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); mainRealm.importFrom( "fooBarBaz", "foo.bar.baz" ); - mainRealm.importFrom( "fooBar", "foo.bar" ); - mainRealm.importFrom( "foo", "foo" ); assertSame( fooRealm, mainRealm.locateSourceRealm( "foo.Goober" ) ); - assertSame( fooRealm, mainRealm.locateSourceRealm( "foo.cheese.Goober" ) ); - assertSame( fooBarRealm, mainRealm.locateSourceRealm( "foo.bar.Goober" ) ); - assertSame( fooBarRealm, mainRealm.locateSourceRealm( "foo.bar.cheese.Goober" ) ); - assertSame( fooBarBazRealm, mainRealm.locateSourceRealm( "foo.bar.baz.Goober" ) ); - assertSame( fooBarBazRealm, mainRealm.locateSourceRealm( "foo.bar.baz.cheese.Goober" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "java.lang.Object" ) ); - assertSame( mainRealm, mainRealm.locateSourceRealm( "NoviceProgrammerClass" ) ); } @@ -197,8 +153,6 @@ public void testLoadClass_NonSystemClass() { Class c = mainRealm.loadClass( "com.werken.projectz.UberThing" ); - System.out.println( "c = " + c ); - fail( "A ClassNotFoundException should be thrown!" ); } catch ( ClassNotFoundException e ) @@ -258,10 +212,14 @@ public void testLoadClass_Imported() ClassRealm realmA = this.world.newRealm( "realmA" ); + realmA.display(); + try { - realmA.loadClass( "a.A" ); + Class a = realmA.loadClass( "a.A" ); + System.out.println( realmA.getClassLocation( a )); + fail( "realmA.loadClass(a.A) should have thrown a ClassNotFoundException" ); } catch ( ClassNotFoundException e ) @@ -314,7 +272,6 @@ public void testLoadClass_Package() assertEquals( "p.getName()", "a", p.getName() ); } - public void testLoadClass_Complex() throws Exception { @@ -427,4 +384,28 @@ public void testLoadClass_ClassWorldsClassRepeatedly() assertSame( ClassWorld.class, cls ); } } + + // + + public void testP() + throws Exception + { + ClassRealm realmA = this.world.newRealm( "realmA" ); + ClassRealm realmB = this.world.newRealm( "realmB" ); + ClassRealm realmC = this.world.newRealm( "realmC" ); + + realmA.addURL( getJarUrl( "a.jar" ) ); + realmB.addURL( getJarUrl( "b.jar" ) ); + realmC.addURL( getJarUrl( "c.jar" ) ); + + realmC.importFrom( "realmA", "a" ); + realmC.importFrom( "realmB", "b" ); + realmA.importFrom( "realmC", "c" ); + + Class classAFromSelf = realmA.loadClassFromSelf( "a.A" ); + assertNotNull( classAFromSelf ); + + Class classAFromImport = realmC.loadClassFromImport( "a.A" ); + assertNotNull( classAFromImport ); + } } diff --git a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java index 0eb1819..95a2463 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java @@ -42,9 +42,7 @@ public void setUp() throws Exception { this.world = new ClassWorld(); - this.realm = this.world.newRealm( "realm" ); - this.strategy = this.realm.getStrategy(); realm.addURL( getJarUrl( "component0-1.0.jar" ) ); diff --git a/src/test/java/a/A.java b/src/test/test-jar-source/a/A.java similarity index 100% rename from src/test/java/a/A.java rename to src/test/test-jar-source/a/A.java diff --git a/src/test/java/a/Aa.java b/src/test/test-jar-source/a/Aa.java similarity index 100% rename from src/test/java/a/Aa.java rename to src/test/test-jar-source/a/Aa.java diff --git a/src/test/java/b/B.java b/src/test/test-jar-source/b/B.java similarity index 100% rename from src/test/java/b/B.java rename to src/test/test-jar-source/b/B.java diff --git a/src/test/java/b/Bb.java b/src/test/test-jar-source/b/Bb.java similarity index 100% rename from src/test/java/b/Bb.java rename to src/test/test-jar-source/b/Bb.java diff --git a/src/test/java/c/C.java b/src/test/test-jar-source/c/C.java similarity index 100% rename from src/test/java/c/C.java rename to src/test/test-jar-source/c/C.java diff --git a/src/test/java/d/D.java b/src/test/test-jar-source/d/D.java similarity index 100% rename from src/test/java/d/D.java rename to src/test/test-jar-source/d/D.java From 4942429d1a7c71ae1725cd3515f7103bdd750bfe Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 00:30:22 +0000 Subject: [PATCH 06/28] o rework the ClassRealm so it provides the structure and methods for performing searches from imports, self, or parents. These methods are then ordered in the desired order in a strategy to get the desired behavior. this way the strategy is simply using stable methods in ClassRealm instead of rewriting them in each strategy. --- .../plexus/classworlds/realm/ClassRealm.java | 290 ++++++++++++------ .../classworlds/strategy/DefaultStrategy.java | 112 +++---- 2 files changed, 240 insertions(+), 162 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 76e3cba..0c69ded 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -14,21 +14,24 @@ * the License. */ -import org.codehaus.plexus.classworlds.strategy.DefaultStrategy; -import org.codehaus.plexus.classworlds.strategy.ForeignStrategy; -import org.codehaus.plexus.classworlds.strategy.Strategy; -import org.codehaus.plexus.classworlds.strategy.UrlUtils; -import org.codehaus.plexus.classworlds.ClassWorld; - +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.net.MalformedURLException; +import java.security.CodeSource; +import java.security.ProtectionDomain; import java.util.Enumeration; import java.util.Iterator; import java.util.TreeSet; +import org.codehaus.plexus.classworlds.ClassWorld; +import org.codehaus.plexus.classworlds.strategy.DefaultStrategy; +import org.codehaus.plexus.classworlds.strategy.ForeignStrategy; +import org.codehaus.plexus.classworlds.strategy.Strategy; +import org.codehaus.plexus.classworlds.strategy.UrlUtils; + /** * @author Jason van Zyl * @version $Id$ @@ -46,30 +49,44 @@ public class ClassRealm private TreeSet imports; private Strategy strategy; - private ClassRealm parent; + private ClassRealm parentRealm; public ClassRealm( ClassWorld world, String id ) { - this( world, id, null ); + this( world, id, ClassLoader.getSystemClassLoader(), null ); } - public ClassRealm( ClassWorld world, String id, ClassLoader foreignClassLoader ) + public ClassRealm( ClassWorld world, String id, Strategy strategy ) { - super( new URL[] {}, foreignClassLoader ); + this( world, id, ClassLoader.getSystemClassLoader(), strategy ); + } - this.world = world; + public ClassRealm( ClassWorld world, String id, ClassLoader parent ) + { + this( world, id, parent, null ); + } - this.id = id; + public ClassRealm( ClassWorld world, String id, ClassLoader parent, Strategy strategy ) + { + super( new URL[] {}, parent ); + this.world = world; + this.id = id; exports = new TreeSet(); - imports = new TreeSet(); - strategy = getStrategy( this, foreignClassLoader ); + if ( strategy == null ) + { + this.strategy = new DefaultStrategy( this ); + } + else + { + this.strategy = strategy; + } - if ( foreignClassLoader != null && foreignClassLoader instanceof ClassRealm ) + if ( parent != null && parent instanceof ClassRealm ) { - this.parent = (ClassRealm) foreignClassLoader; + this.parentRealm = (ClassRealm) parent; } } @@ -110,7 +127,6 @@ public ClassRealm locateSourceRealm( String classname ) for ( Iterator iterator = imports.iterator(); iterator.hasNext(); ) { Entry entry = (Entry) iterator.next(); - if ( entry.matches( classname ) ) { return entry.getRealm(); @@ -127,42 +143,24 @@ public Strategy getStrategy() public void setParentRealm( ClassRealm realm ) { - this.parent = realm; + this.parentRealm = realm; } public ClassRealm getParentRealm() { - return parent; + return parentRealm; } public ClassRealm createChildRealm( String id ) throws DuplicateRealmException { ClassRealm childRealm = getWorld().newRealm( id, this ); - childRealm.setParentRealm( this ); - return childRealm; } public void addURL( URL url ) { - String urlStr = url.toExternalForm(); - - if ( urlStr.startsWith( "jar:" ) && urlStr.endsWith( "!/" ) ) - { - urlStr = urlStr.substring( 4, urlStr.length() - 2 ); - - try - { - url = new URL( urlStr ); - } - catch ( MalformedURLException e ) - { - e.printStackTrace(); - } - } - super.addURL( url ); } @@ -171,22 +169,6 @@ public void addURL( URL url ) // the contents of the ClassRealm. // ---------------------------------------------------------------------------- - public Class loadRealmClass( String name ) - throws ClassNotFoundException - { - return super.loadClass( name ); - } - - public URL getRealmResource( String name ) - { - return super.getResource( name ); - } - - public InputStream getRealmResourceAsStream( String name ) - { - return super.getResourceAsStream( name ); - } - public Enumeration findRealmResources( String name ) throws IOException { @@ -200,48 +182,147 @@ public Enumeration findRealmResources( String name ) public Class loadClassFromImport( String name ) { ClassRealm importRealm = getImportRealm( name ); + + Class clazz = null; if ( importRealm != null ) { - try - { - return importRealm.loadClass( name ); - } - catch ( ClassNotFoundException e ) + clazz = importRealm.loadClassFromSelf( name ); + + if ( clazz == null ) { - return null; + clazz = importRealm.loadClassFromParent( name ); } } - - return null; + + return clazz; } public Class loadClassFromSelf( String name ) { Class clazz; - + try { - clazz = findClass( name ); + clazz = findLoadedClass( name ); + + if ( clazz == null ) + { + clazz = findClass( name ); + } } catch ( ClassNotFoundException e ) { return null; } - if ( true ) - { - resolveClass( clazz ); - } + resolveClass( clazz ); return clazz; } public Class loadClassFromParent( String name ) { - return getParentRealm().loadClassFromSelf( name ); + if ( getParent() != null ) + { + try + { + return getParent().loadClass( name ); + } + catch ( ClassNotFoundException e ) + { + return null; + } + } + + return null; + } + + //--------------------------------------------------------------------------------------------- + // Resources + //--------------------------------------------------------------------------------------------- + + public URL loadResourceFromImport( String name ) + { + ClassRealm importRealm = getImportRealm( name ); + + if ( importRealm != null ) + { + return importRealm.findResource( name ); + } + + return null; + } + + public URL loadResourceFromSelf( String name ) + { + URL url = findResource( name ); + + return url; + } + + public URL loadResourceFromParent( String name ) + { + if ( getParent() != null ) + { + return getParent().getResource( name ); + } + + return null; + } + + // Resources + + public Enumeration loadResourcesFromImport( String name ) + { + ClassRealm importRealm = getImportRealm( name ); + + if ( importRealm != null ) + { + try + { + return importRealm.findResources( name ); + } + catch ( IOException e ) + { + return null; + } + } + + return null; } + public Enumeration loadResourcesFromSelf( String name ) + { + try + { + return super.findResources( name ); + } + catch ( IOException e ) + { + return null; + } + } + + + public Enumeration loadResourcesFromParent( String name ) + { + if ( getParent() != null ) + { + try + { + return getParent().getResources( name ); + } + catch ( IOException e ) + { + return null; + } + } + + return null; + } + + // ---------------------------------------------------------------------- // We delegate to the Strategy here so that we can change the behavior // of any existing ClassRealm. @@ -287,6 +368,7 @@ public void display() while ( cr != null ) { System.out.println( "this realm = " + cr.getId() ); + System.out.println( "classloader parent: " + cr.getParent() ); System.out.println( "this strategy = " + this.getStrategy().getClass().getName() ); showUrls( cr ); @@ -331,34 +413,62 @@ public String toString() return "ClassRealm[" + getId() + ", parent: " + getParentRealm() + "]"; } - // These need to be simplified or the strategy being passed in knowingly by the user - - public Strategy getStrategy( ClassRealm realm ) + public String getClassLocation( final Class clazz ) { - return getStrategy( realm, "default", null ); - } + if ( clazz == null ) + { + return null; + } - public Strategy getStrategy( ClassRealm realm, ClassLoader foreign ) - { - return getStrategy( realm, "default", foreign ); - } + URL result = null; + String classAsResource = clazz.getName().replace( '.', '/' ).concat( ".class" ); - public Strategy getStrategy( ClassRealm realm, String hint ) - { - return getStrategy( realm, hint, null ); - } - - public static Strategy getStrategy( ClassRealm realm, String hint, ClassLoader foreign ) - { - if ( foreign != null ) + ProtectionDomain protectionDomain = clazz.getProtectionDomain(); + // java.lang.Class contract does not specify if 'pd' can ever be null; + // it is not the case for Sun's implementations, but guard against null + // just in case: + if ( protectionDomain != null ) { - return new ForeignStrategy( realm, foreign ); + CodeSource codeSource = protectionDomain.getCodeSource(); + // 'cs' can be null depending on the classloader behavior: + if ( codeSource != null ) + { + result = codeSource.getLocation(); + } + + if ( result != null ) + { + // Convert a code source location into a full class file location + // for some common cases: + if ( "file".equals( result.getProtocol() ) ) + { + try + { + if ( result.toExternalForm().endsWith( ".jar" ) || result.toExternalForm().endsWith( ".zip" ) ) + { + result = new URL( "jar:".concat( result.toExternalForm() ).concat( "!/" ).concat( classAsResource ) ); + } + else if ( new File( result.getFile() ).isDirectory() ) + { + result = new URL( result, classAsResource ); + } + } + catch ( MalformedURLException ignore ) + { + } + } + } } - // Here we shall check hint to load non-default strategies + if ( result == null ) + { + // Try to find 'cls' definition as a resource; this is not + // documented to be legal, but Sun's implementations seem to allow this: + ClassLoader classLoader = clazz.getClassLoader(); - Strategy ret = new DefaultStrategy( realm ); + result = classLoader != null ? classLoader.getResource( classAsResource ) : ClassLoader.getSystemResource( classAsResource ); + } - return ret; + return result.toExternalForm(); } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java index 6d9831d..238d4e6 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java @@ -2,18 +2,16 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import org.codehaus.plexus.classworlds.realm.ClassRealm; @@ -25,10 +23,7 @@ import java.util.Vector; /** - * Load classes directly from the Realm first before attempting to get from the parent. - * - * @uthor: Andrew Williams - * @since: Nov 19, 2006 + * @author Jason van Zyl * @version: $Id$ */ public class DefaultStrategy @@ -42,53 +37,38 @@ public DefaultStrategy( ClassRealm realm ) public Class loadClass( String name ) throws ClassNotFoundException { - try - { - ClassRealm sourceRealm = getRealm().locateSourceRealm( name ); - - if ( sourceRealm != getRealm() ) - { - try - { - return sourceRealm.loadClass( name ); - } - catch ( ClassNotFoundException cnfe ) - { - // Do nothing as we will load directly - } - } + Class clazz = realm.loadClassFromImport( name ); - return getRealm().loadRealmClass( name ); + if ( clazz == null ) + { + clazz = realm.loadClassFromSelf( name ); } - catch ( ClassNotFoundException e ) + + if ( clazz == null ) { - if ( getRealm().getParentRealm() != null ) - { - return getRealm().getParentRealm().loadClass( name ); - } + clazz = realm.loadClassFromParent( name ); + } - throw e; + if ( clazz == null ) + { + throw new ClassNotFoundException( name ); } + + return clazz; } public URL getResource( String name ) { - URL resource = null; + URL resource = realm.loadResourceFromImport( name ); - ClassRealm sourceRealm = getRealm().locateSourceRealm( name ); - - if ( !sourceRealm.equals( getRealm() ) ) - { - resource = sourceRealm.getResource( name ); - } if ( resource == null ) { - resource = getRealm().getRealmResource( name ); + resource = realm.loadResourceFromSelf( name ); } - if ( resource == null && getRealm().getParentRealm() != null ) + if ( resource == null ) { - resource = getRealm().getParentRealm().getRealmResource( name ); + resource = realm.loadResourceFromParent( name ); } return resource; @@ -120,33 +100,21 @@ public Enumeration findResources( String name ) { Vector resources = new Vector(); - // Load imports - ClassRealm sourceRealm = getRealm().locateSourceRealm( name ); - - if ( sourceRealm != getRealm() ) - { - // Attempt to load directly first, then go to the imported packages. - for ( Enumeration res = sourceRealm.findResources( name ); res.hasMoreElements(); ) - { - resources.addElement( res.nextElement() ); - } - } - - // Load from our realm - for ( Enumeration direct = getRealm().findRealmResources( name ); direct.hasMoreElements(); ) - { - resources.addElement( direct.nextElement() ); - } + loadResourcesFromRealm( resources, realm.loadResourcesFromImport( name ) ); + loadResourcesFromRealm( resources, realm.loadResourcesFromSelf( name ) ); + loadResourcesFromRealm( resources, realm.loadResourcesFromParent( name ) ); + + return resources.elements(); + } - // Find resources from the parent realm. - if ( getRealm().getParentRealm() != null ) + private void loadResourcesFromRealm( Vector v, Enumeration e ) + { + if ( e != null ) { - for ( Enumeration parent = getRealm().getParentRealm().findRealmResources( name ); parent.hasMoreElements(); ) + for ( Enumeration a = e; a.hasMoreElements(); ) { - resources.addElement( parent.nextElement() ); - } + v.addElement( a.nextElement() ); } - - return resources.elements(); + } } } From 34911e4d0130732d43560142256b1a2ecf4177a2 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 00:36:26 +0000 Subject: [PATCH 07/28] o When an imported realm is found to use we can't push behavior into this method, we need to use the strategy employed by this particular realm so we need to use the loadClass method which in turn will then invoke the Strategy. Using the self search and then the parent search would break systems that actually wanted something different. --- .../plexus/classworlds/realm/ClassRealm.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 0c69ded..f0690f5 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -182,19 +182,18 @@ public Enumeration findRealmResources( String name ) public Class loadClassFromImport( String name ) { ClassRealm importRealm = getImportRealm( name ); - - Class clazz = null; - + Class clazz = null; if ( importRealm != null ) { - clazz = importRealm.loadClassFromSelf( name ); - - if ( clazz == null ) + try + { + clazz = importRealm.loadClass( name ); + } + catch ( ClassNotFoundException e ) { - clazz = importRealm.loadClassFromParent( name ); + return null; } } - return clazz; } From 04418f72a00d7e9289c2142baf4dd11515d9ed4e Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 00:38:26 +0000 Subject: [PATCH 08/28] o documentation for the getClassLocation method. --- .../org/codehaus/plexus/classworlds/realm/ClassRealm.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index f0690f5..2bec8c4 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -412,6 +412,13 @@ public String toString() return "ClassRealm[" + getId() + ", parent: " + getParentRealm() + "]"; } + /** + * Find the exact URL that a particular class was loaded from. This can be used to debug problems where you need + * to know exactly what JAR, or location in the file system that a class came from. + * + * @param clazz + * @return The location of class that was loaded in URL external form. + */ public String getClassLocation( final Class clazz ) { if ( clazz == null ) From 4b07d40066100e51e5e1e231d3f8b15811013802 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 00:58:21 +0000 Subject: [PATCH 09/28] --- .../plexus/classworlds/realm/ClassRealm.java | 33 +++++++-- .../strategy/AbstractStrategy.java | 5 -- .../classworlds/strategy/ForeignStrategy.java | 72 ------------------- .../plexus/classworlds/strategy/UrlUtils.java | 65 ----------------- .../classworlds/realm/ClassRealmImplTest.java | 6 +- 5 files changed, 30 insertions(+), 151 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java delete mode 100644 src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 2bec8c4..8606305 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -28,9 +28,7 @@ import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.strategy.DefaultStrategy; -import org.codehaus.plexus.classworlds.strategy.ForeignStrategy; import org.codehaus.plexus.classworlds.strategy.Strategy; -import org.codehaus.plexus.classworlds.strategy.UrlUtils; /** * @author Jason van Zyl @@ -340,7 +338,7 @@ public Class loadClass( String name ) public URL getResource( String name ) { - return strategy.getResource( UrlUtils.normalizeUrlPath( name ) ); + return strategy.getResource( normalizeUrlPath( name ) ); } public InputStream getResourceAsStream( String name ) @@ -351,7 +349,7 @@ public InputStream getResourceAsStream( String name ) public Enumeration findResources( String name ) throws IOException { - return strategy.findResources( UrlUtils.normalizeUrlPath( name ) ); + return strategy.findResources( normalizeUrlPath( name ) ); } // ---------------------------------------------------------------------------- @@ -477,4 +475,31 @@ else if ( new File( result.getFile() ).isDirectory() ) return result.toExternalForm(); } + + // Util methods + + public static String normalizeUrlPath( String name ) + { + if ( name.startsWith( "/" ) ) + { + name = name.substring( 1 ); + } + + // Looking for org/codehaus/werkflow/personality/basic/../common/core-idioms.xml + // | i | + // +-------+ remove + // + int i = name.indexOf( "/.." ); + + // Can't be at the beginning because we have no root to refer to so + // we start at 1. + if ( i > 0 ) + { + int j = name.lastIndexOf( "/", i - 1 ); + + name = name.substring( 0, j ) + name.substring( i + 3 ); + } + + return name; + } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java index 1fae429..0c917e0 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java @@ -31,11 +31,6 @@ public AbstractStrategy( ClassRealm realm ) this.realm = realm; } - protected String getNormalizedResource( String name ) - { - return UrlUtils.normalizeUrlPath( name ); - } - public ClassRealm getRealm() { return realm; diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java deleted file mode 100644 index 2ee2839..0000000 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.codehaus.plexus.classworlds.strategy; - -import org.codehaus.plexus.classworlds.realm.ClassRealm; - -import java.io.IOException; -import java.net.URL; -import java.util.Enumeration; -import java.util.Vector; - -/** - * @author Jason van Zyl - * @author: Andrew Williams - */ -public class ForeignStrategy - extends DefaultStrategy -{ - private ClassLoader foreign; - - public ForeignStrategy( ClassRealm realm, ClassLoader foreign ) - { - super( realm ); - - this.foreign = foreign; - } - - public Class loadClass( String name ) - throws ClassNotFoundException - { - try - { - return foreign.loadClass( name ); - } - catch ( ClassNotFoundException e ) - { - return super.loadClass( name ); - } - } - - public URL getResource( String name ) - { - URL resource; - - resource = foreign.getResource( name ); - - if ( resource == null ) - { - resource = super.getResource( name ); - } - - return resource; - } - - public Enumeration findResources( String name ) - throws IOException - { - Vector resources = new Vector(); - - // Load from DefaultStrategy - for ( Enumeration direct = super.findResources( name ); direct.hasMoreElements(); ) - { - resources.addElement( direct.nextElement() ); - } - - // Load from foreign classloader - for ( Enumeration direct = foreign.getResources( name ); direct.hasMoreElements(); ) - { - resources.addElement( direct.nextElement() ); - } - - return resources.elements(); - } -} diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java deleted file mode 100644 index 3049aad..0000000 --- a/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.codehaus.plexus.classworlds.strategy; - -/* - * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Set; -import java.util.HashSet; -import java.net.URLClassLoader; - -/** - * @author Jason van Zyl - * @version $Id$ - */ -public class UrlUtils -{ - public static String normalizeUrlPath( String name ) - { - if ( name.startsWith( "/" ) ) - { - name = name.substring( 1 ); - } - - // Looking for org/codehaus/werkflow/personality/basic/../common/core-idioms.xml - // | i | - // +-------+ remove - // - int i = name.indexOf( "/.." ); - - // Can't be at the beginning because we have no root to refer to so - // we start at 1. - if ( i > 0 ) - { - int j = name.lastIndexOf( "/", i - 1 ); - - name = name.substring( 0, j ) + name.substring( i + 3 ); - } - - return name; - } - - public static Set getURLs( URLClassLoader loader ) - { - Set ret = new HashSet(); - - for ( int i = 0; i < loader.getURLs().length; i++ ) - { - ret.add( loader.getURLs()[i] ); - } - - return ret; - } -} diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java index c9a05c1..19a2835 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java @@ -211,14 +211,10 @@ public void testLoadClass_Imported() ClassRealm mainRealm = this.world.newRealm( "main" ); ClassRealm realmA = this.world.newRealm( "realmA" ); - - realmA.display(); try { - Class a = realmA.loadClass( "a.A" ); - - System.out.println( realmA.getClassLocation( a )); + realmA.loadClass( "a.A" ); fail( "realmA.loadClass(a.A) should have thrown a ClassNotFoundException" ); } From 2135aa09f1f4ab146f22e8fd9e4de1857eedc255 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 02:07:52 +0000 Subject: [PATCH 10/28] o we don't need the special parent realm logic, we'll try to talk in terms of regular classloaders albeit with some special capabilities --- .../org/codehaus/plexus/classworlds/realm/ClassRealm.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 8606305..efe1d70 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -81,11 +81,6 @@ public ClassRealm( ClassWorld world, String id, ClassLoader parent, Strategy str { this.strategy = strategy; } - - if ( parent != null && parent instanceof ClassRealm ) - { - this.parentRealm = (ClassRealm) parent; - } } public String getId() From 133b6e393e5ba2cec44777ca1d0af13323e5b01a Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 05:14:22 +0000 Subject: [PATCH 11/28] o create a model for the realms so that we know before hand what the parent/child relationships are so that we can avoid the parent classloader / parent realm hassle. we will just deal with classloaders and knowing before hand allows us to simply use a constructor to pass in the parent. we also keep the model around which could be adjusted and reloaded. the model will also allow programmatic embedding once it's extracted out of the Configurator. --- .../classworlds/launcher/Configurator.java | 121 +++++++----------- 1 file changed, 45 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java index 61aa239..80863d4 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java +++ b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.TreeSet; /** * Launcher configurator. @@ -50,63 +51,28 @@ public class Configurator { public static final String MAIN_PREFIX = "main is"; - public static final String SET_PREFIX = "set"; - public static final String IMPORT_PREFIX = "import"; - public static final String LOAD_PREFIX = "load"; - /** - * Optionally spec prefix. - */ - public static final String OPTIONALLY_PREFIX = "optionally"; - - /** - * The launcher to configure. - */ + /** The launcher to configure. */ private Launcher launcher; + /** The ClassWorld to create */ private ClassWorld world; - /** - * Processed Realms. - */ + /** Processed Realms. */ private Map configuredRealms; - /** - * Construct. - * - * @param launcher The launcher to configure. - */ public Configurator( Launcher launcher ) { this.launcher = launcher; - - configuredRealms = new HashMap(); + this.configuredRealms = new HashMap(); } - /** - * Construct. - * - * @param world The classWorld to configure. - */ public Configurator( ClassWorld world ) - { - setClassWorld( world ); - } - - /** - * set world. - * this setter is provided so you can use the same configurator to configure several "worlds" - * - * @param world The classWorld to configure. - */ - public void setClassWorld( ClassWorld world ) { this.world = world; - - configuredRealms = new HashMap(); } /** @@ -279,7 +245,8 @@ else if ( line.startsWith( "[" ) ) curRealm = world.newRealm( realmName, foreignClassLoader ); // Stash the configured realm for subsequent association processing. - configuredRealms.put( realmName, curRealm ); + //configuredRealms.put( realmName, curRealm ); + configuredRealms.put( realmName, new RealmConfiguration( realmName ) ); } else if ( line.startsWith( IMPORT_PREFIX ) ) { @@ -335,37 +302,6 @@ else if ( line.startsWith( LOAD_PREFIX ) ) } } } - else if ( line.startsWith( OPTIONALLY_PREFIX ) ) - { - String constituent = line.substring( OPTIONALLY_PREFIX.length() ).trim(); - - constituent = filter( constituent ); - - if ( constituent.indexOf( "*" ) >= 0 ) - { - loadGlob( constituent, curRealm, true ); - } - else - { - File file = new File( constituent ); - - if ( file.exists() ) - { - curRealm.addURL( file.toURI().toURL() ); - } - else - { - try - { - curRealm.addURL( new URL( constituent ) ); - } - catch ( MalformedURLException e ) - { - // swallow - } - } - } - } else { throw new ConfigurationException( "Unhandled configuration", lineNo, line ); @@ -386,8 +322,10 @@ else if ( line.startsWith( OPTIONALLY_PREFIX ) ) // TODO return this to protected when the legacy wrappers can be removed. /** * Associate parent realms with their children. + * @throws DuplicateRealmException + * @throws NoSuchRealmException */ - public void associateRealms() + public void associateRealms() throws DuplicateRealmException, NoSuchRealmException { List sortRealmNames = new ArrayList( configuredRealms.keySet() ); @@ -425,15 +363,19 @@ public int compare( Object o1, { String parentRealmName = realmName.substring( 0, j ); - ClassRealm parentRealm = (ClassRealm) configuredRealms.get( parentRealmName ); + RealmConfiguration parentRealm = (RealmConfiguration) configuredRealms.get( parentRealmName ); if ( parentRealm != null ) { - ClassRealm realm = (ClassRealm) configuredRealms.get( realmName ); + RealmConfiguration realm = (RealmConfiguration) configuredRealms.get( realmName ); - realm.setParentRealm( parentRealm ); + world.newRealm( realm.id, world.getRealm( parentRealm.id ) ); } } + else + { + world.newRealm( realmName ); + } } } @@ -566,7 +508,6 @@ protected String filter( String text ) if ( propName.equals( "basedir" ) && ( propValue == null || propValue.equals( "" ) ) ) { propValue = ( new File( "" ) ).getAbsolutePath(); - } if ( propValue == null ) @@ -595,4 +536,32 @@ private boolean canIgnore( String line ) { return ( line.length() == 0 || line.startsWith( "#" ) ); } + + class RealmConfiguration + { + String id; + TreeSet imports; + TreeSet exports; + TreeSet loads; + + public RealmConfiguration( String id ) + { + this.id = id; + } + + public void addImport( String importStatement ) + { + imports.add( importStatement ); + } + + public void addExport( String exportStatement ) + { + exports.add( exportStatement ); + } + + public void addLoad( String loadStatement ) + { + loads.add( loadStatement ); + } + } } From d8e79cde8a260effaa96e7efbb3b6dd9dffb5eb3 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 05:27:40 +0000 Subject: [PATCH 12/28] o get rid of optional processing, this was added for groovy and it's no longer needed. our runtimes are deterministic on startup and if optional things are required it's done programmatically o the world/realm model is now read in --- .../classworlds/launcher/Configurator.java | 158 ++++++++---------- 1 file changed, 70 insertions(+), 88 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java index 80863d4..34e238b 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java +++ b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java @@ -2,18 +2,16 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import org.codehaus.plexus.classworlds.ClassWorld; @@ -43,7 +41,7 @@ /** * Launcher configurator. - * + * * @author bob mcwhirter * @author Jason van Zyl * @version $Id$ @@ -77,14 +75,15 @@ public Configurator( ClassWorld world ) /** * Configure from a file. - * + * * @param is The config input stream - * @throws IOException If an error occurs reading the config file. - * @throws MalformedURLException If the config file contains invalid URLs. - * @throws ConfigurationException If the config file is corrupt. - * @throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException If the config file defines two realms with the same id. - * @throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException If the config file defines a main entry point in - * a non-existent realm. + * @throws IOException If an error occurs reading the config file. + * @throws MalformedURLException If the config file contains invalid URLs. + * @throws ConfigurationException If the config file is corrupt. + * @throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException If the config file + * defines two realms with the same id. + * @throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException If the config file defines + * a main entry point in a non-existent realm. */ public void configure( InputStream is ) throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException @@ -103,7 +102,7 @@ public void configure( InputStream is ) foreignClassLoader = this.launcher.getSystemClassLoader(); } - ClassRealm curRealm = null; + RealmConfiguration currentRealm = null; String line = null; @@ -242,15 +241,15 @@ else if ( line.startsWith( "[" ) ) String realmName = line.substring( 1, rbrack ); - curRealm = world.newRealm( realmName, foreignClassLoader ); + currentRealm = new RealmConfiguration( realmName ); // Stash the configured realm for subsequent association processing. //configuredRealms.put( realmName, curRealm ); - configuredRealms.put( realmName, new RealmConfiguration( realmName ) ); + configuredRealms.put( realmName, currentRealm ); } else if ( line.startsWith( IMPORT_PREFIX ) ) { - if ( curRealm == null ) + if ( currentRealm == null ) { throw new ConfigurationException( "Unhandled import", lineNo, line ); } @@ -268,18 +267,20 @@ else if ( line.startsWith( IMPORT_PREFIX ) ) String relamName = conf.substring( fromLoc + 4 ).trim(); - curRealm.importFrom( relamName, importSpec ); + currentRealm.addImport( new ImportStatement( relamName, importSpec ) ); } else if ( line.startsWith( LOAD_PREFIX ) ) { String constituent = line.substring( LOAD_PREFIX.length() ).trim(); + currentRealm.addLoad( constituent ); + constituent = filter( constituent ); if ( constituent.indexOf( "*" ) >= 0 ) { - loadGlob( constituent, curRealm ); + loadGlob( constituent, currentRealm ); } else { @@ -287,13 +288,13 @@ else if ( line.startsWith( LOAD_PREFIX ) ) if ( file.exists() ) { - curRealm.addURL( file.toURI().toURL() ); + currentRealm.addLoad( file.toURI().toURL().toExternalForm() ); } else { try { - curRealm.addURL( new URL( constituent ) ); + currentRealm.addLoad( new URL( constituent ).toExternalForm() ); } catch ( MalformedURLException e ) { @@ -309,7 +310,7 @@ else if ( line.startsWith( LOAD_PREFIX ) ) } // Associate child realms to their parents. - associateRealms(); + createRealms(); if ( this.launcher != null ) { @@ -322,18 +323,19 @@ else if ( line.startsWith( LOAD_PREFIX ) ) // TODO return this to protected when the legacy wrappers can be removed. /** * Associate parent realms with their children. - * @throws DuplicateRealmException - * @throws NoSuchRealmException + * + * @throws DuplicateRealmException + * @throws NoSuchRealmException */ - public void associateRealms() throws DuplicateRealmException, NoSuchRealmException + public void createRealms() + throws DuplicateRealmException, NoSuchRealmException { List sortRealmNames = new ArrayList( configuredRealms.keySet() ); // sort by name Comparator comparator = new Comparator() { - public int compare( Object o1, - Object o2 ) + public int compare( Object o1, Object o2 ) { String g1 = (String) o1; String g2 = (String) o2; @@ -381,35 +383,15 @@ public int compare( Object o1, /** * Load a glob into the specified classloader. - * - * @param line The path configuration line. + * + * @param line The path configuration line. * @param realm The realm to populate - * @throws MalformedURLException If the line does not represent - * a valid path element. - * @throws FileNotFoundException If the line does not represent - * a valid path element in the filesystem. - */ - protected void loadGlob( String line, - ClassRealm realm ) - throws MalformedURLException, FileNotFoundException - { - loadGlob( line, realm, false ); - } - - /** - * Load a glob into the specified classloader. - * - * @param line The path configuration line. - * @param realm The realm to populate * @param optionally Whether the path is optional or required - * @throws MalformedURLException If the line does not represent - * a valid path element. - * @throws FileNotFoundException If the line does not represent - * a valid path element in the filesystem. + * @throws MalformedURLException If the line does not represent a valid path element. + * @throws FileNotFoundException If the line does not represent a valid path element in the + * filesystem. */ - protected void loadGlob( String line, - ClassRealm realm, - boolean optionally ) + protected void loadGlob( String line, RealmConfiguration realm ) throws MalformedURLException, FileNotFoundException { File globFile = new File( line ); @@ -417,14 +399,7 @@ protected void loadGlob( String line, File dir = globFile.getParentFile(); if ( !dir.exists() ) { - if ( optionally ) - { - return; - } - else - { - throw new FileNotFoundException( dir.toString() ); - } + throw new FileNotFoundException( dir.toString() ); } String localName = globFile.getName(); @@ -437,8 +412,7 @@ protected void loadGlob( String line, File[] matches = dir.listFiles( new FilenameFilter() { - public boolean accept( File dir, - String name ) + public boolean accept( File dir, String name ) { if ( !name.startsWith( prefix ) ) { @@ -456,17 +430,16 @@ public boolean accept( File dir, for ( int i = 0; i < matches.length; ++i ) { - realm.addURL( matches[i].toURI().toURL() ); + realm.addLoad( matches[i].toURI().toURL().toExternalForm() ); } } /** * Filter a string for system properties. - * + * * @param text The text to filter. * @return The filtered text. - * @throws ConfigurationException If the property does not - * exist or if there is a syntax error. + * @throws ConfigurationException If the property does not exist or if there is a syntax error. */ protected String filter( String text ) throws ConfigurationException @@ -525,43 +498,52 @@ protected String filter( String text ) } /** - * Determine if a line can be ignored because it is - * a comment or simply blank. - * + * Determine if a line can be ignored because it is a comment or simply blank. + * * @param line The line to test. - * @return true if the line is ignorable, - * otherwise false. + * @return true if the line is ignorable, otherwise false. */ private boolean canIgnore( String line ) { return ( line.length() == 0 || line.startsWith( "#" ) ); } - + class RealmConfiguration - { + { String id; TreeSet imports; TreeSet exports; TreeSet loads; - + public RealmConfiguration( String id ) { this.id = id; } - - public void addImport( String importStatement ) - { - imports.add( importStatement ); + + public void addImport( ImportStatement importStatement ) + { + imports.add( importStatement ); } public void addExport( String exportStatement ) { - exports.add( exportStatement ); + exports.add( exportStatement ); } - + public void addLoad( String loadStatement ) { loads.add( loadStatement ); } } + + class ImportStatement + { + public ImportStatement( String relamName, String importSpec ) + { + // TODO Auto-generated constructor stub + } + + String importRealm; + String importSpecification; + } } From 9badbc806083b6430e14f5ed226152b4dea62cf8 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 06:12:26 +0000 Subject: [PATCH 13/28] o the model now fully works with parsing first, processing second. configurator is now two passes. --- .../classworlds/launcher/Configurator.java | 64 ++++++++++++++----- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java index 34e238b..9809c26 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java +++ b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java @@ -241,6 +241,11 @@ else if ( line.startsWith( "[" ) ) String realmName = line.substring( 1, rbrack ); + if ( configuredRealms.containsKey( realmName ) ) + { + throw new DuplicateRealmException(world, realmName ); + } + currentRealm = new RealmConfiguration( realmName ); // Stash the configured realm for subsequent association processing. @@ -274,8 +279,6 @@ else if ( line.startsWith( LOAD_PREFIX ) ) { String constituent = line.substring( LOAD_PREFIX.length() ).trim(); - currentRealm.addLoad( constituent ); - constituent = filter( constituent ); if ( constituent.indexOf( "*" ) >= 0 ) @@ -288,13 +291,13 @@ else if ( line.startsWith( LOAD_PREFIX ) ) if ( file.exists() ) { - currentRealm.addLoad( file.toURI().toURL().toExternalForm() ); + currentRealm.addLoad( file.toURI().toURL().toString() ); } else { try { - currentRealm.addLoad( new URL( constituent ).toExternalForm() ); + currentRealm.addLoad( new URL( constituent ).toString() ); } catch ( MalformedURLException e ) { @@ -326,9 +329,10 @@ else if ( line.startsWith( LOAD_PREFIX ) ) * * @throws DuplicateRealmException * @throws NoSuchRealmException + * @throws MalformedURLException */ public void createRealms() - throws DuplicateRealmException, NoSuchRealmException + throws DuplicateRealmException, NoSuchRealmException, MalformedURLException { List sortRealmNames = new ArrayList( configuredRealms.keySet() ); @@ -365,20 +369,45 @@ public int compare( Object o1, Object o2 ) { String parentRealmName = realmName.substring( 0, j ); - RealmConfiguration parentRealm = (RealmConfiguration) configuredRealms.get( parentRealmName ); + RealmConfiguration parentRealmConfiguration = (RealmConfiguration) configuredRealms.get( parentRealmName ); - if ( parentRealm != null ) + if ( parentRealmConfiguration != null ) { - RealmConfiguration realm = (RealmConfiguration) configuredRealms.get( realmName ); - - world.newRealm( realm.id, world.getRealm( parentRealm.id ) ); + RealmConfiguration realmConfiguration = (RealmConfiguration) configuredRealms.get( realmName ); + world.newRealm( realmConfiguration.id, world.getRealm( parentRealmConfiguration.id ) ); } } else { - world.newRealm( realmName ); + ClassRealm realm = world.newRealm( realmName ); } } + + for ( Iterator i = configuredRealms.values().iterator(); i.hasNext(); ) + { + RealmConfiguration rc = (RealmConfiguration) i.next(); + + configureRealm( world.getRealm( rc.id ), rc ); + } + } + + private void configureRealm( ClassRealm realm, RealmConfiguration realmConfiguration ) + throws NoSuchRealmException, MalformedURLException + { + for ( Iterator i = realmConfiguration.imports.iterator(); i.hasNext(); ) + { + ImportStatement is = (ImportStatement) i.next(); + + realm.importFrom( is.importRealm, is.importSpecification ); + } + + for ( Iterator i = realmConfiguration.loads.iterator(); i.hasNext(); ) + { + String load = (String) i.next(); + + realm.addURL( new URL( load ) ); + } + } /** @@ -430,7 +459,7 @@ public boolean accept( File dir, String name ) for ( int i = 0; i < matches.length; ++i ) { - realm.addLoad( matches[i].toURI().toURL().toExternalForm() ); + realm.addLoad( matches[i].toURI().toURL().toString() ); } } @@ -511,9 +540,9 @@ private boolean canIgnore( String line ) class RealmConfiguration { String id; - TreeSet imports; - TreeSet exports; - TreeSet loads; + TreeSet imports = new TreeSet(); + TreeSet exports = new TreeSet(); + TreeSet loads = new TreeSet(); public RealmConfiguration( String id ) { @@ -538,9 +567,10 @@ public void addLoad( String loadStatement ) class ImportStatement { - public ImportStatement( String relamName, String importSpec ) + public ImportStatement( String importRealm, String importSpecification ) { - // TODO Auto-generated constructor stub + this.importRealm = importRealm; + this.importSpecification = importSpecification; } String importRealm; From 447c16d9cfcd9628fdb2dc3435cf8e169b05cb34 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 13:04:39 +0000 Subject: [PATCH 14/28] --- ClassLoaderRegistry.java | 86 ++++++ ClassScope.java | 276 ++++++++++++++++++ .../plexus/classworlds/realm/ClassRealm.java | 25 +- .../strategy/OsgiBundleStrategy.java | 110 +++++++ .../plexus/classworlds/ClassView.java | 133 --------- .../launcher/ConfiguratorTest.java | 54 ---- 6 files changed, 479 insertions(+), 205 deletions(-) create mode 100644 ClassLoaderRegistry.java create mode 100644 ClassScope.java create mode 100644 src/main/java/org/codehaus/plexus/classworlds/strategy/OsgiBundleStrategy.java delete mode 100644 src/test/java/org/codehaus/plexus/classworlds/ClassView.java diff --git a/ClassLoaderRegistry.java b/ClassLoaderRegistry.java new file mode 100644 index 0000000..bd49852 --- /dev/null +++ b/ClassLoaderRegistry.java @@ -0,0 +1,86 @@ + +package com.vladium.utils; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.WeakHashMap; + +// ---------------------------------------------------------------------------- +/** + * A simple registry API to accompany the java.lang.ClassLoader hack described + * at the end of the article. Add + *

+ * ClassLoaderRegistry.register (this);
+ * 
+ * to the end of both java.lang.ClassLoader constructors (you have to do this + * independently for every JDK version, the same hacked version cannot be used + * across all of them). This class needs to be in the bootstrap classpath to + * work as intended. + * + * @author (C) Vlad Roubtsov, 2003 + */ +public +abstract class ClassLoaderRegistry // this class is not instantiable +{ + // public: ................................................................ + + /** + * Adds 'loader' to the weak set maintained by this registry. + */ + public static void register (final ClassLoader loader) + { + if (loader != null) + { + synchronized (CLASSLOADER_SET) + { + CLASSLOADER_SET.put (loader, null); + } + } + } + + /** + * Returns an enumeration of all class loaders currently registered + * in the JVM. Note that this may not include all class loaders ever' + * created because this registry uses weak keys as class loader references. + * + * @param ClassLoader array [never null]. + */ + public static ClassLoader [] getClassLoaders () + { + final List /* ClassLoader */ resultList = new LinkedList (); + + synchronized (CLASSLOADER_SET) + { + // we are using a weak map: be careful when traversing the key set + // [it's unsafe to use resultList.addAll(CLASSLOADER_SET.keySet())] + + for (Iterator keys = CLASSLOADER_SET.keySet ().iterator (); keys.hasNext (); ) + { + // note that WeakHashMap guarantees that the weak key will not be + // cleared between hasNext() and next(): + resultList.add (keys.next ()); + } + } + + final ClassLoader [] result = new ClassLoader [resultList.size ()]; + resultList.toArray (result); + + return result; + } + + // protected: ............................................................. + + // package: ............................................................... + + // private: ............................................................... + + + private ClassLoaderRegistry () {} // this class is not extendible + + // this field is used as a 'weak set' to avoid interfering with class and + // class loader unloading and garbage collection: + private static final WeakHashMap /* ClassLoader->null */ CLASSLOADER_SET = + new WeakHashMap (); + +} // end of class +// ---------------------------------------------------------------------------- \ No newline at end of file diff --git a/ClassScope.java b/ClassScope.java new file mode 100644 index 0000000..1e6b0b1 --- /dev/null +++ b/ClassScope.java @@ -0,0 +1,276 @@ +package com.vladium.utils; + +import java.io.File; +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.CodeSource; +import java.security.ProtectionDomain; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.Vector; + +// ---------------------------------------------------------------------------- +/** + * A simple static API for listing classes loaded in a JVM. {@link #getClassLocation(Class)} from + * http://www.javaworld.com/javaworld/javaqa/2003-07/01-qa-0711-classsrc.html also thrown in for a + * good measure. See individual methods for further details. + *

+ * + * NOTE: use for testing/debugging only. + * + * @author (C) Vlad Roubtsov, 2003 + */ +public abstract class ClassScope // this class is not instantiable +{ + // public: ................................................................ + + /** + * Given a class loader instance, returns all classes currently loaded by that class loader. + * + * @param defining class loader to inspect [may not be null] + * @return Class array such that every Class has 'loader' as its defining class loader [never + * null, may be empty] + * + * @throws RuntimeException if the "classes" field hack is not possible in this JRE + */ + public static Class[] getLoadedClasses( final ClassLoader loader ) + { + if ( loader == null ) + throw new IllegalArgumentException( "null input: loader" ); + if ( CLASSES_VECTOR_FIELD == null ) + throw new RuntimeException( "ClassScope::getLoadedClasses() cannot be used in this JRE", CVF_FAILURE ); + + try + { + final Vector classes = (Vector) CLASSES_VECTOR_FIELD.get( loader ); + if ( classes == null ) + return EMPTY_CLASS_ARRAY; + + final Class[] result; + + // note: Vector is synchronized in Java 2, which helps us make + // the following into a safe critical section: + + synchronized ( classes ) + { + result = new Class[classes.size()]; + classes.toArray( result ); + } + + return result; + } + // this should not happen if was successful: + catch ( IllegalAccessException e ) + { + e.printStackTrace( System.out ); + + return EMPTY_CLASS_ARRAY; + } + } + + /** + * A convenience multi-loader version of {@link #getLoadedClasses(ClassLoader)}. + * + * @param an array of defining class loaders to inspect [may not be null] + * @return Class array [never null, may be empty] + * + * @throws RuntimeException if the "classes" field hack is not possible in this JRE + */ + public static Class[] getLoadedClasses( final ClassLoader[] loaders ) + { + if ( loaders == null ) + throw new IllegalArgumentException( "null input: loaders" ); + + final List /* Class */resultList = new LinkedList(); + + for ( int l = 0; l < loaders.length; ++l ) + { + final ClassLoader loader = loaders[l]; + if ( loader != null ) + { + final Class[] classes = getLoadedClasses( loaders[l] ); + + resultList.addAll( Arrays.asList( classes ) ); + } + } + + final Class[] result = new Class[resultList.size()]; + resultList.toArray( result ); + + return result; + } + + /** + * Returns the class loader set "relevant" to the calling class, as described in the article. + * Starting with the class that is the caller of this method, it collects all class loaders that + * are loaders for all classes on the call stack and their respective parent loaders. + * + * @return ClassLoader array [never null] + * + * @throws RuntimeException if the caller context resolver could not be instantiated + */ + public static ClassLoader[] getCallerClassLoaderTree() + { + if ( CALLER_RESOLVER == null ) + throw new RuntimeException( "ClassScope::getCallerClassLoaderTree() cannot be used in this JRE", CR_FAILURE ); + + final Class[] callContext = CALLER_RESOLVER.getClassContext(); + + final Set /* ClassLoader */resultSet = new HashSet(); + + for ( int c = 2; c < callContext.length; ++c ) + { + getClassLoaderTree( callContext[c], resultSet ); + } + + final ClassLoader[] result = new ClassLoader[resultSet.size()]; + resultSet.toArray( result ); + + return result; + } + + /** + * Given a Class object, attempts to find its .class location [returns null if no such definiton + * could be found]. + * + * @return URL that points to the class definition [null if not found] + */ + public static URL getClassLocation( final Class cls ) + { + if ( cls == null ) + throw new IllegalArgumentException( "null input: cls" ); + + URL result = null; + final String clsAsResource = cls.getName().replace( '.', '/' ).concat( ".class" ); + + final ProtectionDomain pd = cls.getProtectionDomain(); + // java.lang.Class contract does not specify if 'pd' can ever be null; + // it is not the case for Sun's implementations, but guard against null + // just in case: + if ( pd != null ) + { + final CodeSource cs = pd.getCodeSource(); + // 'cs' can be null depending on the classloader behavior: + if ( cs != null ) + result = cs.getLocation(); + + if ( result != null ) + { + // convert a code source location into a full class file location + // for some common cases: + if ( "file".equals( result.getProtocol() ) ) + { + try + { + if ( result.toExternalForm().endsWith( ".jar" ) || result.toExternalForm().endsWith( ".zip" ) ) + result = new URL( "jar:".concat( result.toExternalForm() ).concat( "!/" ).concat( clsAsResource ) ); + else if ( new File( result.getFile() ).isDirectory() ) + result = new URL( result, clsAsResource ); + } + catch ( MalformedURLException ignore ) + { + } + } + } + } + + if ( result == null ) + { + // try to find 'cls' definition as a resource; this is not + // documented to be legal but Sun's implementations seem to allow this: + final ClassLoader clsLoader = cls.getClassLoader(); + + result = clsLoader != null ? clsLoader.getResource( clsAsResource ) : ClassLoader.getSystemResource( clsAsResource ); + } + + return result; + } + + // protected: ............................................................. + + // package: ............................................................... + + // private: ............................................................... + + /** + * A helper class to get the call context. It subclasses SecurityManager to make + * getClassContext() accessible. An instance of CallerResolver only needs to be created, not + * installed as an actual security manager. + */ + private static final class CallerResolver + extends SecurityManager + { + protected Class[] getClassContext() + { + return super.getClassContext(); + } + + } // end of nested class + + private ClassScope() + { + } // this class is not extendible + + private static void getClassLoaderTree( final Class cls, final Set resultSet ) + { + if ( ( cls != null ) && ( resultSet != null ) ) + { + for ( ClassLoader loader = cls.getClassLoader(); loader != null; loader = loader.getParent() ) + { + resultSet.add( loader ); + } + } + } + + private static final Field CLASSES_VECTOR_FIELD; // set in [can be null] + private static final CallerResolver CALLER_RESOLVER; // set in [can be null] + + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private static final Throwable CVF_FAILURE, CR_FAILURE; // set in + + static + { + Throwable failure = null; + + Field tempf = null; + try + { + // this can fail if this is not a Sun-compatible JVM + // or if the security is too tight: + + tempf = ClassLoader.class.getDeclaredField( "classes" ); + if ( tempf.getType() != Vector.class ) + throw new RuntimeException( "not of type java.util.Vector: " + tempf.getType().getName() ); + + tempf.setAccessible( true ); + } + catch ( Throwable t ) + { + failure = t; + } + CLASSES_VECTOR_FIELD = tempf; + CVF_FAILURE = failure; + + failure = null; + CallerResolver tempcr = null; + try + { + // this can fail if the current SecurityManager does not allow + // RuntimePermission ("createSecurityManager"): + + tempcr = new CallerResolver(); + } + catch ( Throwable t ) + { + failure = t; + } + CALLER_RESOLVER = tempcr; + CR_FAILURE = failure; + } + +} // end of class +// ---------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index efe1d70..b58fd93 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -37,7 +37,10 @@ public class ClassRealm extends URLClassLoader { + /** The ClassWorld we live in. */ private ClassWorld world; + + /** The unique id of our ClassRealm */ private String id; /** Packages this ClassRealm is willing to make visible to outside callers. */ @@ -46,8 +49,8 @@ public class ClassRealm /** Pacakges this ClassRealm wants to import from other realms. */ private TreeSet imports; + /** The strategy we are using to load classes and resources. */ private Strategy strategy; - private ClassRealm parentRealm; public ClassRealm( ClassWorld world, String id ) { @@ -92,7 +95,7 @@ public ClassWorld getWorld() { return this.world; } - + public void importFrom( String realmId, String packageName ) throws NoSuchRealmException { @@ -134,22 +137,10 @@ public Strategy getStrategy() return strategy; } - public void setParentRealm( ClassRealm realm ) - { - this.parentRealm = realm; - } - - public ClassRealm getParentRealm() - { - return parentRealm; - } - public ClassRealm createChildRealm( String id ) throws DuplicateRealmException { - ClassRealm childRealm = getWorld().newRealm( id, this ); - childRealm.setParentRealm( this ); - return childRealm; + return getWorld().newRealm( id, this ); } public void addURL( URL url ) @@ -366,8 +357,6 @@ public void display() showUrls( cr ); System.out.println( "\n" ); - - cr = cr.getParentRealm(); } System.out.println( "-----------------------------------------------------" ); @@ -402,7 +391,7 @@ public boolean equals( Object o ) public String toString() { - return "ClassRealm[" + getId() + ", parent: " + getParentRealm() + "]"; + return "ClassRealm[" + getId() + ", parent: " + getParent() + "]"; } /** diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/OsgiBundleStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/OsgiBundleStrategy.java new file mode 100644 index 0000000..dac577a --- /dev/null +++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/OsgiBundleStrategy.java @@ -0,0 +1,110 @@ +package org.codehaus.plexus.classworlds.strategy; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.Vector; + +import org.codehaus.plexus.classworlds.realm.ClassRealm; + +public class OsgiBundleStrategy + extends AbstractStrategy +{ + // java.* from parent + // imported packages [Import-Package header with explicit constraints on the exporter] + // requires bundle [Required-Bundle] + // self [Bundle-Classpath header] + // attached fragments + // + // We need to trya and be OSGi r4 compliant in the loading of all the bundles so that we can try to + // load eclipse without requiring equinox. Or any other OSGi container for that matter. + public OsgiBundleStrategy( ClassRealm realm ) + { + super( realm ); + } + + public Class loadClass( String name ) + throws ClassNotFoundException + { + Class clazz = realm.loadClassFromImport( name ); + + if ( clazz == null ) + { + clazz = realm.loadClassFromSelf( name ); + } + + if ( clazz == null ) + { + clazz = realm.loadClassFromParent( name ); + } + + if ( clazz == null ) + { + throw new ClassNotFoundException( name ); + } + + return clazz; + } + + public URL getResource( String name ) + { + URL resource = realm.loadResourceFromImport( name ); + + if ( resource == null ) + { + resource = realm.loadResourceFromSelf( name ); + } + + if ( resource == null ) + { + resource = realm.loadResourceFromParent( name ); + } + + return resource; + } + + public InputStream getResourceAsStream( String name ) + { + URL url = getResource( name ); + + InputStream is = null; + + if ( url != null ) + { + try + { + is = url.openStream(); + } + catch ( IOException e ) + { + // do nothing + } + } + + return is; + } + + public Enumeration findResources( String name ) + throws IOException + { + Vector resources = new Vector(); + + loadResourcesFromRealm( resources, realm.loadResourcesFromImport( name ) ); + loadResourcesFromRealm( resources, realm.loadResourcesFromSelf( name ) ); + loadResourcesFromRealm( resources, realm.loadResourcesFromParent( name ) ); + + return resources.elements(); + } + + private void loadResourcesFromRealm( Vector v, Enumeration e ) + { + if ( e != null ) + { + for ( Enumeration a = e; a.hasMoreElements(); ) + { + v.addElement( a.nextElement() ); + } + } + } +} diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassView.java b/src/test/java/org/codehaus/plexus/classworlds/ClassView.java deleted file mode 100644 index fe8565e..0000000 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassView.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.codehaus.plexus.classworlds; - -/* - * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -public class ClassView -{ - /** - * * Formats Class information for debug output purposes. - * * - * * @param clz the Class to print information for - * * - * * @return a String describing the Class in detail - */ - public static String toString( Class clz ) - { - if ( clz.isPrimitive() ) - { - return clz.toString(); - } - else if ( clz.isArray() ) - { - return "Array of " + toString( clz.getComponentType() ); - } - else if ( clz.isInterface() ) - { - return toInterfaceString( clz, "" ); - } - else - { - return toClassString( clz, "" ); - } - } - - /** - * * Formats Class information for debug output purposes. - * * - * * @param clz the Class to print information for - * * @param sIndent the indentation to precede each line of output - * * - * * @return a String describing the Class in detail - */ - private static String toClassString( Class clz, - String sIndent ) - { - StringBuffer sb = new StringBuffer(); - sb.append( sIndent ) - .append( "Class " ) - .append( clz.getName() ) - .append( " (" ) - .append( toString( clz.getClassLoader() ) ) - .append( ')' ); - - sIndent += " "; - - Class[] aclz = clz.getInterfaces(); - for ( int i = 0, c = aclz.length; i < c; ++i ) - { - sb.append( '\n' ) - .append( toInterfaceString( aclz[i], sIndent ) ); - } - - clz = clz.getSuperclass(); - if ( clz != null ) - { - sb.append( '\n' ) - .append( toClassString( clz, sIndent ) ); - } - - return sb.toString(); - } - - /** - * * Formats interface information for debug output purposes. - * * - * * @param clz the interface Class to print information for - * * @param sIndent the indentation to precede each line of output - * * - * * @return a String describing the interface Class in detail - */ - private static String toInterfaceString( Class clz, - String sIndent ) - { - StringBuffer sb = new StringBuffer(); - sb.append( sIndent ) - .append( "Interface " ) - .append( clz.getName() ) - .append( " (" ) - .append( toString( clz.getClassLoader() ) ) - .append( ')' ); - - Class[] aclz = clz.getInterfaces(); - for ( int i = 0, c = aclz.length; i < c; ++i ) - { - clz = aclz[i]; - - sb.append( '\n' ) - .append( toInterfaceString( clz, sIndent + " " ) ); - } - - return sb.toString(); - } - - /** - * * Format a description for the specified ClassLoader object. - * * - * * @param loader the ClassLoader instance (or null) - * * - * * @return a String description of the ClassLoader - */ - private static String toString( ClassLoader loader ) - { - if ( loader == null ) - { - return "System ClassLoader"; - } - - return "ClassLoader class=" + loader.getClass().getName() + ", hashCode=" + loader.hashCode(); - } -} diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java index f15200d..60b2825 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java @@ -176,60 +176,6 @@ public void testConfigure_Valid() assertArrayContains( urls, new File( basedir, "src/test/test-data/c.jar" ).toURI().toURL() ); } - public void testConfigure_Optionally_NonExistent() - throws Exception - { - this.configurator.configure( getConfigPath( "optionally-nonexistent.conf" ) ); - - assertEquals( "org.apache.maven.app.App", this.launcher.getMainClassName() ); - - assertEquals( "opt", this.launcher.getMainRealmName() ); - - ClassWorld world = this.launcher.getWorld(); - - Collection realms = world.getRealms(); - - assertEquals( 1, realms.size() ); - - assertNotNull( world.getRealm( "opt" ) ); - - ClassRealm optRealm = world.getRealm( "opt" ); - - Strategy strat = optRealm.getStrategy(); - - URL[] urls = optRealm.getURLs(); - - assertEquals( "no urls", 0, urls.length ); - } - - public void testConfigure_Optionally_Existent() - throws Exception - { - this.configurator.configure( getConfigPath( "optionally-existent.conf" ) ); - - assertEquals( "org.apache.maven.app.App", this.launcher.getMainClassName() ); - - assertEquals( "opt", this.launcher.getMainRealmName() ); - - ClassWorld world = this.launcher.getWorld(); - - Collection realms = world.getRealms(); - - assertEquals( 1, realms.size() ); - - assertNotNull( world.getRealm( "opt" ) ); - - ClassRealm optRealm = world.getRealm( "opt" ); - - Strategy strat = optRealm.getStrategy(); - - URL[] urls = optRealm.getURLs(); - - assertEquals( "one url", 1, urls.length ); - - assertSame( optRealm, optRealm.locateSourceRealm( "org.xml.sax.SAXException" ) ); - } - public void testConfigure_Unhandled() throws Exception { From 73dd6dd2dda10b8c93d5f89993d2142ab4b504c7 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 13:19:20 +0000 Subject: [PATCH 15/28] o condensing all realm tests into one class --- .../AbstractClassWorldsTestCase.java | 40 ------ .../plexus/classworlds/ClassWorldTest.java | 49 ++++--- .../launcher/ConfiguratorTest.java | 5 +- .../classworlds/launcher/LauncherTest.java | 5 +- ...RealmImplTest.java => ClassRealmTest.java} | 131 ++++++++++++----- .../realm/DefaultClassRealmTest.java | 134 ------------------ .../plexus/classworlds/realm/EntryTest.java | 5 +- 7 files changed, 129 insertions(+), 240 deletions(-) delete mode 100644 src/test/java/org/codehaus/plexus/classworlds/AbstractClassWorldsTestCase.java rename src/test/java/org/codehaus/plexus/classworlds/realm/{ClassRealmImplTest.java => ClassRealmTest.java} (79%) delete mode 100644 src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java diff --git a/src/test/java/org/codehaus/plexus/classworlds/AbstractClassWorldsTestCase.java b/src/test/java/org/codehaus/plexus/classworlds/AbstractClassWorldsTestCase.java deleted file mode 100644 index 4a0d9a2..0000000 --- a/src/test/java/org/codehaus/plexus/classworlds/AbstractClassWorldsTestCase.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.codehaus.plexus.classworlds; - -import junit.framework.TestCase; - -import java.net.URL; -import java.net.MalformedURLException; - -/* - * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author Jason van Zyl - */ -public abstract class AbstractClassWorldsTestCase - extends TestCase -{ - public AbstractClassWorldsTestCase( String string ) - { - super( string ); - } - - public static URL getTestResourceUrl( String resourceName ) - throws MalformedURLException - { - return TestUtil.getTestResourceUrl( resourceName ); - } -} diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java index 6927fc8..a84a9b8 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java @@ -2,30 +2,32 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.io.File; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; + +import junit.framework.TestCase; + import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; import org.codehaus.plexus.classworlds.realm.ClassRealm; public class ClassWorldTest - extends AbstractClassWorldsTestCase + extends TestCase { private ClassWorld world; @@ -120,9 +122,9 @@ public void testGetRealms() assertTrue( this.world.getRealms().contains( bar ) ); } - - public void testPLX334() - throws Exception + + public void testPLX334() + throws Exception { ClassLoader loader = new URLClassLoader( new URL[] { getJarUrl( "component1-1.0.jar" ) } ); ClassRealm nb = world.newRealm( "netbeans", loader ); @@ -135,21 +137,26 @@ public void testPLX334() for ( Enumeration resources = e; resources.hasMoreElements(); ) { URL obj = (URL) resources.nextElement(); - assertTrue(obj.getPath().indexOf( "src/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); + assertTrue( obj.getPath().indexOf( "src/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); resourceCount++; } - + assertEquals( 1, resourceCount ); Class c = plexus.loadClass( "org.codehaus.plexus.Component1" ); assertNotNull( c ); - + } - + protected URL getJarUrl( String jarName ) throws Exception { File jarFile = new File( TestUtil.getBasedir(), "src/test-jars/" + jarName ); return jarFile.toURI().toURL(); } - + + public static URL getTestResourceUrl( String resourceName ) + throws MalformedURLException + { + return TestUtil.getTestResourceUrl( resourceName ); + } } diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java index 60b2825..4d3a2a0 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java @@ -22,15 +22,16 @@ import java.net.URL; import java.util.Collection; +import junit.framework.TestCase; + import org.codehaus.plexus.classworlds.strategy.Strategy; -import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.TestUtil; public class ConfiguratorTest - extends AbstractClassWorldsTestCase + extends TestCase { private Launcher launcher; private Configurator configurator; diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java index 2072a60..5ab384f 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java @@ -19,11 +19,12 @@ import java.io.File; import java.io.FileInputStream; -import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; +import junit.framework.TestCase; + import org.codehaus.plexus.classworlds.TestUtil; public class LauncherTest - extends AbstractClassWorldsTestCase + extends TestCase { private Launcher launcher; diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java similarity index 79% rename from src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java rename to src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java index 19a2835..8e6100b 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java @@ -14,20 +14,22 @@ * the License. */ +import java.io.File; import java.net.MalformedURLException; import java.net.URL; -import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; +import junit.framework.TestCase; + import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.TestUtil; -public class ClassRealmImplTest - extends AbstractClassWorldsTestCase +public class ClassRealmTest + extends TestCase { private ClassWorld world; - public ClassRealmImplTest( String name ) + public ClassRealmTest( String name ) { super( name ); } @@ -138,9 +140,7 @@ public void testLoadClass_SystemClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); - Class cls = mainRealm.loadClass( "java.lang.Object" ); - assertNotNull( cls ); } @@ -152,7 +152,6 @@ public void testLoadClass_NonSystemClass() try { Class c = mainRealm.loadClass( "com.werken.projectz.UberThing" ); - fail( "A ClassNotFoundException should be thrown!" ); } catch ( ClassNotFoundException e ) @@ -165,11 +164,8 @@ public void testLoadClass_ClassWorldsClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); - Class cls = mainRealm.loadClass( "org.codehaus.plexus.classworlds.ClassWorld" ); - assertNotNull( cls ); - assertSame( ClassWorld.class, cls ); } @@ -177,7 +173,6 @@ public void testLoadClass_Local() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); - try { mainRealm.loadClass( "a.A" ); @@ -188,11 +183,8 @@ public void testLoadClass_Local() } mainRealm.addURL( getJarUrl( "a.jar" ) ); - Class classA = mainRealm.loadClass( "a.A" ); - assertNotNull( classA ); - ClassRealm otherRealm = this.world.newRealm( "other" ); try @@ -209,13 +201,11 @@ public void testLoadClass_Imported() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); - ClassRealm realmA = this.world.newRealm( "realmA" ); try { - realmA.loadClass( "a.A" ); - + realmA.loadClass( "a.A" ); fail( "realmA.loadClass(a.A) should have thrown a ClassNotFoundException" ); } catch ( ClassNotFoundException e ) @@ -228,7 +218,6 @@ public void testLoadClass_Imported() try { mainRealm.loadClass( "a.A" ); - fail( "mainRealm.loadClass(a.A) should have thrown a ClassNotFoundException" ); } catch ( ClassNotFoundException e ) @@ -237,19 +226,12 @@ public void testLoadClass_Imported() } mainRealm.importFrom( "realmA", "a" ); - Class classA = realmA.loadClass( "a.A" ); - assertNotNull( classA ); - assertEquals( realmA, classA.getClassLoader() ); - Class classMain = mainRealm.loadClass( "a.A" ); - assertNotNull( classMain ); - assertEquals( realmA, classMain.getClassLoader() ); - assertSame( classA, classMain ); } @@ -294,37 +276,25 @@ public void testLoadClass_Complex() assertNotNull( classC_C ); assertEquals( realmA, classA_A.getClassLoader() ); - assertEquals( realmB, classB_B.getClassLoader() ); - assertEquals( realmC, classC_C.getClassLoader() ); // load from C Class classA_C = realmC.loadClass( "a.A" ); - assertNotNull( classA_C ); - assertSame( classA_A, classA_C ); - assertEquals( realmA, classA_C.getClassLoader() ); - Class classB_C = realmC.loadClass( "b.B" ); - assertNotNull( classB_C ); - assertSame( classB_B, classB_C ); - assertEquals( realmB, classB_C.getClassLoader() ); // load from A Class classC_A = realmA.loadClass( "c.C" ); - assertNotNull( classC_A ); - assertSame( classC_C, classC_A ); - assertEquals( realmC, classC_A.getClassLoader() ); try @@ -374,9 +344,7 @@ public void testLoadClass_ClassWorldsClassRepeatedly() for ( int i = 0; i < 100; i++ ) { Class cls = mainRealm.loadClass( "org.codehaus.plexus.classworlds.ClassWorld" ); - assertNotNull( cls ); - assertSame( ClassWorld.class, cls ); } } @@ -404,4 +372,89 @@ public void testP() Class classAFromImport = realmC.loadClassFromImport( "a.A" ); assertNotNull( classAFromImport ); } + + // From original ClassRealmImplTest + + // ---------------------------------------------------------------------- + // Class testing + // ---------------------------------------------------------------------- + + public void testLoadClassFromRealm() + throws Exception + { + ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); + mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + mainRealm.loadClass( "org.codehaus.plexus.Component0" ); + } + + public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() + throws Exception + { + ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); + mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + ClassRealm childRealm = mainRealm.createChildRealm( "child" ); + childRealm.loadClass( "org.codehaus.plexus.Component0" ); + } + + public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() + throws Exception + { + ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); + mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + ClassRealm childRealm = mainRealm.createChildRealm( "child" ); + ClassRealm grandchildRealm = childRealm.createChildRealm( "grandchild" ); + grandchildRealm.loadClass( "org.codehaus.plexus.Component0" ); + } + + public void testLoadNonExistentClass() + throws Exception + { + ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); + mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + + try + { + mainRealm.loadClass( "org.foo.bar.NonExistentClass" ); + fail( "A ClassNotFoundException should have been thrown!" ); + } + catch ( ClassNotFoundException e ) + { + } + } + + public void testImport() + throws Exception + { + ClassWorld world = new ClassWorld(); + ClassRealm r0 = world.newRealm( "r0" ); + ClassRealm r1 = world.newRealm( "r1" ); + + r0.addURL( getJarUrl2( "component0-1.0.jar" ) ); + r1.importFrom( "r0", "org.codehaus.plexus" ); + r1.loadClass( "org.codehaus.plexus.Component0" ); + } + + // ---------------------------------------------------------------------- + // Resource testing + // ---------------------------------------------------------------------- + + public void testResource() + throws Exception + { + ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); + mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" ); + assertNotNull( resource ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + protected URL getJarUrl2( String jarName ) + throws Exception + { + File jarFile = new File( System.getProperty( "basedir" ), "src/test-jars/" + jarName ); + return jarFile.toURI().toURL(); + } } diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java deleted file mode 100644 index d3b4db2..0000000 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.codehaus.plexus.classworlds.realm; - -/* - * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.File; -import java.net.URL; - -import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; -import org.codehaus.plexus.classworlds.ClassWorld; - -public class DefaultClassRealmTest - extends AbstractClassWorldsTestCase -{ - public DefaultClassRealmTest( String name ) - { - super( name ); - } - - // ---------------------------------------------------------------------- - // Class testing - // ---------------------------------------------------------------------- - - public void testLoadClassFromRealm() - throws Exception - { - ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - - mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); - - mainRealm.loadClass( "org.codehaus.plexus.Component0" ); - } - - public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() - throws Exception - { - ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - - mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); - - ClassRealm childRealm = mainRealm.createChildRealm( "child" ); - - childRealm.loadClass( "org.codehaus.plexus.Component0" ); - } - - public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() - throws Exception - { - ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - - mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); - - ClassRealm childRealm = mainRealm.createChildRealm( "child" ); - - ClassRealm grandchildRealm = childRealm.createChildRealm( "grandchild" ); - - grandchildRealm.loadClass( "org.codehaus.plexus.Component0" ); - } - - public void testLoadNonExistentClass() - throws Exception - { - ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - - mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); - - try - { - mainRealm.loadClass( "org.foo.bar.NonExistentClass" ); - - fail( "A ClassNotFoundException should have been thrown!" ); - } - catch ( ClassNotFoundException e ) - { - } - } - - public void testImport() - throws Exception - { - ClassWorld world = new ClassWorld(); - - ClassRealm r0 = world.newRealm( "r0" ); - - ClassRealm r1 = world.newRealm( "r1" ); - - r0.addURL( getJarUrl( "component0-1.0.jar" ) ); - - r1.importFrom( "r0", "org.codehaus.plexus" ); - - r1.loadClass( "org.codehaus.plexus.Component0" ); - } - - // ---------------------------------------------------------------------- - // Resource testing - // ---------------------------------------------------------------------- - - public void testResource() - throws Exception - { - ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - - mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); - - URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" ); - - assertNotNull( resource ); - } - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - protected URL getJarUrl( String jarName ) - throws Exception - { - File jarFile = new File( System.getProperty( "basedir" ), "src/test-jars/" + jarName ); - - return jarFile.toURI().toURL(); - } -} diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java index be99c46..901c7b9 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java @@ -16,7 +16,8 @@ * limitations under the License. */ -import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; +import junit.framework.TestCase; + import org.codehaus.plexus.classworlds.ClassWorld; /** @@ -24,7 +25,7 @@ * @version $Id$ */ public class EntryTest - extends AbstractClassWorldsTestCase + extends TestCase { /** From 5f5885af43e098fbc2a73815326b707cf5b987e1 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Wed, 2 Jul 2008 14:48:30 +0000 Subject: [PATCH 16/28] --- .../plexus/classworlds/ClassWorldTest.java | 21 ++---------- .../codehaus/plexus/classworlds/TestUtil.java | 32 ++++++++++-------- .../classworlds/realm/ClassRealmTest.java | 26 +++++++------- .../classworlds/strategy/StrategyTest.java | 13 ++----- src/{ => test}/test-jars/component0-1.0.jar | Bin src/{ => test}/test-jars/component1-1.0.jar | Bin src/{ => test}/test-jars/component2-1.0.jar | Bin src/{ => test}/test-jars/component3-1.0.jar | Bin src/{ => test}/test-jars/component4-1.0.jar | Bin 9 files changed, 36 insertions(+), 56 deletions(-) rename src/{ => test}/test-jars/component0-1.0.jar (100%) rename src/{ => test}/test-jars/component1-1.0.jar (100%) rename src/{ => test}/test-jars/component2-1.0.jar (100%) rename src/{ => test}/test-jars/component3-1.0.jar (100%) rename src/{ => test}/test-jars/component4-1.0.jar (100%) diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java index a84a9b8..de42810 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java @@ -14,17 +14,15 @@ * the License. */ -import java.io.File; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import junit.framework.TestCase; +import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; -import org.codehaus.plexus.classworlds.realm.ClassRealm; public class ClassWorldTest extends TestCase @@ -126,7 +124,7 @@ public void testGetRealms() public void testPLX334() throws Exception { - ClassLoader loader = new URLClassLoader( new URL[] { getJarUrl( "component1-1.0.jar" ) } ); + ClassLoader loader = new URLClassLoader( new URL[] { TestUtil.getTestJar( "component1-1.0.jar" ) } ); ClassRealm nb = world.newRealm( "netbeans", loader ); ClassRealm plexus = world.newRealm( "plexus" ); plexus.importFrom( "netbeans", "META-INF/plexus" ); @@ -137,7 +135,7 @@ public void testPLX334() for ( Enumeration resources = e; resources.hasMoreElements(); ) { URL obj = (URL) resources.nextElement(); - assertTrue( obj.getPath().indexOf( "src/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); + assertTrue( obj.getPath().indexOf( "src/test/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); resourceCount++; } @@ -146,17 +144,4 @@ public void testPLX334() assertNotNull( c ); } - - protected URL getJarUrl( String jarName ) - throws Exception - { - File jarFile = new File( TestUtil.getBasedir(), "src/test-jars/" + jarName ); - return jarFile.toURI().toURL(); - } - - public static URL getTestResourceUrl( String resourceName ) - throws MalformedURLException - { - return TestUtil.getTestResourceUrl( resourceName ); - } } diff --git a/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java b/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java index f37410b..b4d4abb 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java +++ b/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java @@ -2,18 +2,16 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.io.File; @@ -30,11 +28,17 @@ public static URL getTestResourceUrl( String resourceName ) throws MalformedURLException { File baseDir = new File( getBasedir() ); - File testDir = new File( baseDir, "src/test/test-data" ); - File resourceFile = new File( testDir, resourceName ); + return resourceFile.toURI().toURL(); + } + public static URL getTestJar( String resourceName ) + throws MalformedURLException + { + File baseDir = new File( getBasedir() ); + File testDir = new File( baseDir, "src/test/test-jars" ); + File resourceFile = new File( testDir, resourceName ); return resourceFile.toURI().toURL(); } diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java index 8e6100b..b388f6b 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java @@ -202,10 +202,10 @@ public void testLoadClass_Imported() { ClassRealm mainRealm = this.world.newRealm( "main" ); ClassRealm realmA = this.world.newRealm( "realmA" ); - + try { - realmA.loadClass( "a.A" ); + realmA.loadClass( "a.A" ); fail( "realmA.loadClass(a.A) should have thrown a ClassNotFoundException" ); } catch ( ClassNotFoundException e ) @@ -330,12 +330,6 @@ public void testLoadClass_Complex() } } - protected URL getJarUrl( String jarName ) - throws MalformedURLException - { - return TestUtil.getTestResourceUrl( jarName ); - } - public void testLoadClass_ClassWorldsClassRepeatedly() throws Exception { @@ -372,9 +366,9 @@ public void testP() Class classAFromImport = realmC.loadClassFromImport( "a.A" ); assertNotNull( classAFromImport ); } - + // From original ClassRealmImplTest - + // ---------------------------------------------------------------------- // Class testing // ---------------------------------------------------------------------- @@ -428,7 +422,7 @@ public void testImport() ClassWorld world = new ClassWorld(); ClassRealm r0 = world.newRealm( "r0" ); ClassRealm r1 = world.newRealm( "r1" ); - + r0.addURL( getJarUrl2( "component0-1.0.jar" ) ); r1.importFrom( "r0", "org.codehaus.plexus" ); r1.loadClass( "org.codehaus.plexus.Component0" ); @@ -451,10 +445,16 @@ public void testResource() // // ---------------------------------------------------------------------- + protected URL getJarUrl( String jarName ) + throws MalformedURLException + { + return TestUtil.getTestResourceUrl( jarName ); + } + protected URL getJarUrl2( String jarName ) throws Exception { - File jarFile = new File( System.getProperty( "basedir" ), "src/test-jars/" + jarName ); + File jarFile = new File( System.getProperty( "basedir" ), "src/test/test-jars/" + jarName ); return jarFile.toURI().toURL(); - } + } } diff --git a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java index 95a2463..90a1fdd 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java @@ -45,7 +45,7 @@ public void setUp() this.realm = this.world.newRealm( "realm" ); this.strategy = this.realm.getStrategy(); - realm.addURL( getJarUrl( "component0-1.0.jar" ) ); + realm.addURL( TestUtil.getTestJar( "component0-1.0.jar" ) ); } public void testLoadingOfApplicationClass() @@ -118,7 +118,7 @@ public void testGetSystemResource() public void testFindResources() throws Exception { - realm.addURL( getJarUrl( "component1-1.0.jar" ) ); + realm.addURL( TestUtil.getTestJar( "component1-1.0.jar" ) ); Enumeration e = strategy.findResources( "META-INF/plexus/components.xml" ); @@ -149,15 +149,6 @@ public void testGetResourceAsStream() assertTrue( content.startsWith( "" ) ); } - - protected URL getJarUrl( String jarName ) - throws Exception - { - File jarFile = new File( TestUtil.getBasedir(), "src/test-jars/" + jarName ); - - return jarFile.toURI().toURL(); - } - protected String getContent( InputStream in ) throws Exception { diff --git a/src/test-jars/component0-1.0.jar b/src/test/test-jars/component0-1.0.jar similarity index 100% rename from src/test-jars/component0-1.0.jar rename to src/test/test-jars/component0-1.0.jar diff --git a/src/test-jars/component1-1.0.jar b/src/test/test-jars/component1-1.0.jar similarity index 100% rename from src/test-jars/component1-1.0.jar rename to src/test/test-jars/component1-1.0.jar diff --git a/src/test-jars/component2-1.0.jar b/src/test/test-jars/component2-1.0.jar similarity index 100% rename from src/test-jars/component2-1.0.jar rename to src/test/test-jars/component2-1.0.jar diff --git a/src/test-jars/component3-1.0.jar b/src/test/test-jars/component3-1.0.jar similarity index 100% rename from src/test-jars/component3-1.0.jar rename to src/test/test-jars/component3-1.0.jar diff --git a/src/test-jars/component4-1.0.jar b/src/test/test-jars/component4-1.0.jar similarity index 100% rename from src/test-jars/component4-1.0.jar rename to src/test/test-jars/component4-1.0.jar From 5548083d1657cbeb819af2e9f4440fa0a749a00e Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 00:09:36 +0000 Subject: [PATCH 17/28] cleaing up test data --- .../plexus/classworlds/realm/EntryTest.java | 2 -- .../{test-jar-source => test-data-source}/a/A.java | 0 .../{test-jar-source => test-data-source}/a/Aa.java | 0 .../{test-jar-source => test-data-source}/b/B.java | 0 .../{test-jar-source => test-data-source}/b/Bb.java | 0 .../{test-jar-source => test-data-source}/c/C.java | 0 .../{test-jar-source => test-data-source}/d/D.java | 0 .../components}/component0-1.0.jar | Bin .../components}/component1-1.0.jar | Bin .../components}/component2-1.0.jar | Bin .../components}/component3-1.0.jar | Bin .../components}/component4-1.0.jar | Bin 12 files changed, 2 deletions(-) rename src/test/{test-jar-source => test-data-source}/a/A.java (100%) rename src/test/{test-jar-source => test-data-source}/a/Aa.java (100%) rename src/test/{test-jar-source => test-data-source}/b/B.java (100%) rename src/test/{test-jar-source => test-data-source}/b/Bb.java (100%) rename src/test/{test-jar-source => test-data-source}/c/C.java (100%) rename src/test/{test-jar-source => test-data-source}/d/D.java (100%) rename src/test/{test-jars => test-data/components}/component0-1.0.jar (100%) rename src/test/{test-jars => test-data/components}/component1-1.0.jar (100%) rename src/test/{test-jars => test-data/components}/component2-1.0.jar (100%) rename src/test/{test-jars => test-data/components}/component3-1.0.jar (100%) rename src/test/{test-jars => test-data/components}/component4-1.0.jar (100%) diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java index 901c7b9..8284011 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java @@ -68,6 +68,4 @@ public void testEquals() assertTrue( "entry1 == entry2", entry1.equals( entry2 ) ); assertTrue( "entry1.hashCode() == entry2.hashCode()", entry1.hashCode() == entry2.hashCode() ); } - - } diff --git a/src/test/test-jar-source/a/A.java b/src/test/test-data-source/a/A.java similarity index 100% rename from src/test/test-jar-source/a/A.java rename to src/test/test-data-source/a/A.java diff --git a/src/test/test-jar-source/a/Aa.java b/src/test/test-data-source/a/Aa.java similarity index 100% rename from src/test/test-jar-source/a/Aa.java rename to src/test/test-data-source/a/Aa.java diff --git a/src/test/test-jar-source/b/B.java b/src/test/test-data-source/b/B.java similarity index 100% rename from src/test/test-jar-source/b/B.java rename to src/test/test-data-source/b/B.java diff --git a/src/test/test-jar-source/b/Bb.java b/src/test/test-data-source/b/Bb.java similarity index 100% rename from src/test/test-jar-source/b/Bb.java rename to src/test/test-data-source/b/Bb.java diff --git a/src/test/test-jar-source/c/C.java b/src/test/test-data-source/c/C.java similarity index 100% rename from src/test/test-jar-source/c/C.java rename to src/test/test-data-source/c/C.java diff --git a/src/test/test-jar-source/d/D.java b/src/test/test-data-source/d/D.java similarity index 100% rename from src/test/test-jar-source/d/D.java rename to src/test/test-data-source/d/D.java diff --git a/src/test/test-jars/component0-1.0.jar b/src/test/test-data/components/component0-1.0.jar similarity index 100% rename from src/test/test-jars/component0-1.0.jar rename to src/test/test-data/components/component0-1.0.jar diff --git a/src/test/test-jars/component1-1.0.jar b/src/test/test-data/components/component1-1.0.jar similarity index 100% rename from src/test/test-jars/component1-1.0.jar rename to src/test/test-data/components/component1-1.0.jar diff --git a/src/test/test-jars/component2-1.0.jar b/src/test/test-data/components/component2-1.0.jar similarity index 100% rename from src/test/test-jars/component2-1.0.jar rename to src/test/test-data/components/component2-1.0.jar diff --git a/src/test/test-jars/component3-1.0.jar b/src/test/test-data/components/component3-1.0.jar similarity index 100% rename from src/test/test-jars/component3-1.0.jar rename to src/test/test-data/components/component3-1.0.jar diff --git a/src/test/test-jars/component4-1.0.jar b/src/test/test-data/components/component4-1.0.jar similarity index 100% rename from src/test/test-jars/component4-1.0.jar rename to src/test/test-data/components/component4-1.0.jar From 8a0ef56f9841fb29fdcf54bbb744eba645f159df Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 00:30:51 +0000 Subject: [PATCH 18/28] --- .../plexus/classworlds/ClassWorldTest.java | 4 +- .../codehaus/plexus/classworlds/TestUtil.java | 6 +-- .../classworlds/realm/ClassRealmTest.java | 50 ++++++------------- .../classworlds/strategy/StrategyTest.java | 4 +- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java index de42810..643b767 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java @@ -124,7 +124,7 @@ public void testGetRealms() public void testPLX334() throws Exception { - ClassLoader loader = new URLClassLoader( new URL[] { TestUtil.getTestJar( "component1-1.0.jar" ) } ); + ClassLoader loader = new URLClassLoader( new URL[] { TestUtil.getTestComponent( "component1-1.0.jar" ) } ); ClassRealm nb = world.newRealm( "netbeans", loader ); ClassRealm plexus = world.newRealm( "plexus" ); plexus.importFrom( "netbeans", "META-INF/plexus" ); @@ -135,7 +135,7 @@ public void testPLX334() for ( Enumeration resources = e; resources.hasMoreElements(); ) { URL obj = (URL) resources.nextElement(); - assertTrue( obj.getPath().indexOf( "src/test/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); + assertTrue( obj.getPath().indexOf( "src/test/test-data/components/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); resourceCount++; } diff --git a/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java b/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java index b4d4abb..cc0e52d 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java +++ b/src/test/java/org/codehaus/plexus/classworlds/TestUtil.java @@ -24,7 +24,7 @@ */ public class TestUtil { - public static URL getTestResourceUrl( String resourceName ) + public static URL getJarUrl( String resourceName ) throws MalformedURLException { File baseDir = new File( getBasedir() ); @@ -33,11 +33,11 @@ public static URL getTestResourceUrl( String resourceName ) return resourceFile.toURI().toURL(); } - public static URL getTestJar( String resourceName ) + public static URL getTestComponent( String resourceName ) throws MalformedURLException { File baseDir = new File( getBasedir() ); - File testDir = new File( baseDir, "src/test/test-jars" ); + File testDir = new File( baseDir, "src/test/test-data/components" ); File resourceFile = new File( testDir, resourceName ); return resourceFile.toURI().toURL(); } diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java index b388f6b..0e88447 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java @@ -14,9 +14,6 @@ * the License. */ -import java.io.File; -import java.net.MalformedURLException; - import java.net.URL; import junit.framework.TestCase; @@ -182,7 +179,7 @@ public void testLoadClass_Local() // expected and correct } - mainRealm.addURL( getJarUrl( "a.jar" ) ); + mainRealm.addURL( TestUtil.getJarUrl( "a.jar" ) ); Class classA = mainRealm.loadClass( "a.A" ); assertNotNull( classA ); ClassRealm otherRealm = this.world.newRealm( "other" ); @@ -213,7 +210,7 @@ public void testLoadClass_Imported() // expected and correct } - realmA.addURL( getJarUrl( "a.jar" ) ); + realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); try { @@ -239,7 +236,7 @@ public void testLoadClass_Package() throws Exception { ClassRealm realmA = this.world.newRealm( "realmA" ); - realmA.addURL( getJarUrl( "a.jar" ) ); + realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); Class clazz = realmA.loadClass( "a.A" ); assertNotNull( clazz ); @@ -257,9 +254,9 @@ public void testLoadClass_Complex() ClassRealm realmB = this.world.newRealm( "realmB" ); ClassRealm realmC = this.world.newRealm( "realmC" ); - realmA.addURL( getJarUrl( "a.jar" ) ); - realmB.addURL( getJarUrl( "b.jar" ) ); - realmC.addURL( getJarUrl( "c.jar" ) ); + realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); + realmB.addURL( TestUtil.getJarUrl( "b.jar" ) ); + realmC.addURL( TestUtil.getJarUrl( "c.jar" ) ); realmC.importFrom( "realmA", "a" ); @@ -352,9 +349,9 @@ public void testP() ClassRealm realmB = this.world.newRealm( "realmB" ); ClassRealm realmC = this.world.newRealm( "realmC" ); - realmA.addURL( getJarUrl( "a.jar" ) ); - realmB.addURL( getJarUrl( "b.jar" ) ); - realmC.addURL( getJarUrl( "c.jar" ) ); + realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); + realmB.addURL( TestUtil.getJarUrl( "b.jar" ) ); + realmC.addURL( TestUtil.getJarUrl( "c.jar" ) ); realmC.importFrom( "realmA", "a" ); realmC.importFrom( "realmB", "b" ); @@ -377,7 +374,7 @@ public void testLoadClassFromRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + mainRealm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); mainRealm.loadClass( "org.codehaus.plexus.Component0" ); } @@ -385,7 +382,7 @@ public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + mainRealm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); childRealm.loadClass( "org.codehaus.plexus.Component0" ); } @@ -394,7 +391,7 @@ public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + mainRealm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); ClassRealm grandchildRealm = childRealm.createChildRealm( "grandchild" ); grandchildRealm.loadClass( "org.codehaus.plexus.Component0" ); @@ -404,7 +401,7 @@ public void testLoadNonExistentClass() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + mainRealm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); try { @@ -423,7 +420,7 @@ public void testImport() ClassRealm r0 = world.newRealm( "r0" ); ClassRealm r1 = world.newRealm( "r1" ); - r0.addURL( getJarUrl2( "component0-1.0.jar" ) ); + r0.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); r1.importFrom( "r0", "org.codehaus.plexus" ); r1.loadClass( "org.codehaus.plexus.Component0" ); } @@ -436,25 +433,8 @@ public void testResource() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main" ); - mainRealm.addURL( getJarUrl2( "component0-1.0.jar" ) ); + mainRealm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" ); assertNotNull( resource ); } - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - protected URL getJarUrl( String jarName ) - throws MalformedURLException - { - return TestUtil.getTestResourceUrl( jarName ); - } - - protected URL getJarUrl2( String jarName ) - throws Exception - { - File jarFile = new File( System.getProperty( "basedir" ), "src/test/test-jars/" + jarName ); - return jarFile.toURI().toURL(); - } } diff --git a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java index 90a1fdd..fa4662b 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java @@ -45,7 +45,7 @@ public void setUp() this.realm = this.world.newRealm( "realm" ); this.strategy = this.realm.getStrategy(); - realm.addURL( TestUtil.getTestJar( "component0-1.0.jar" ) ); + realm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); } public void testLoadingOfApplicationClass() @@ -118,7 +118,7 @@ public void testGetSystemResource() public void testFindResources() throws Exception { - realm.addURL( TestUtil.getTestJar( "component1-1.0.jar" ) ); + realm.addURL( TestUtil.getTestComponent( "component1-1.0.jar" ) ); Enumeration e = strategy.findResources( "META-INF/plexus/components.xml" ); From 6b60a335e5ff9799e0ee9a435c54f9bc57ff861b Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 14:27:26 +0000 Subject: [PATCH 19/28] sorting out launcher configurations --- .../classworlds/realm/ClassRealmTest.java | 66 +++++++++---------- src/test/test-data/{ => conf}/dupe-main.conf | 0 src/test/test-data/{ => conf}/dupe-realm.conf | 0 .../test-data/{ => conf}/early-import.conf | 0 .../test-data/{ => conf}/inheritance.conf | 0 .../test-data/{ => conf}/launch-noclass.conf | 0 .../test-data/{ => conf}/launch-nomethod.conf | 0 .../{ => conf}/optionally-existent.conf | 0 .../{ => conf}/optionally-nonexistent.conf | 0 .../test-data/{ => conf}/realm-syntax.conf | 0 .../{ => conf}/set-using-existent.conf | 0 .../{ => conf}/set-using-missing.conf | 0 .../{ => conf}/set-using-nonexistent.conf | 0 src/test/test-data/{ => conf}/unhandled.conf | 0 .../{ => conf}/valid-enh-launch-exitCode.conf | 0 .../{ => conf}/valid-enh-launch.conf | 0 .../{ => conf}/valid-launch-exitCode.conf | 0 .../test-data/{ => conf}/valid-launch.conf | 0 src/test/test-data/{ => conf}/valid.conf | 0 19 files changed, 32 insertions(+), 34 deletions(-) rename src/test/test-data/{ => conf}/dupe-main.conf (100%) rename src/test/test-data/{ => conf}/dupe-realm.conf (100%) rename src/test/test-data/{ => conf}/early-import.conf (100%) rename src/test/test-data/{ => conf}/inheritance.conf (100%) rename src/test/test-data/{ => conf}/launch-noclass.conf (100%) rename src/test/test-data/{ => conf}/launch-nomethod.conf (100%) rename src/test/test-data/{ => conf}/optionally-existent.conf (100%) rename src/test/test-data/{ => conf}/optionally-nonexistent.conf (100%) rename src/test/test-data/{ => conf}/realm-syntax.conf (100%) rename src/test/test-data/{ => conf}/set-using-existent.conf (100%) rename src/test/test-data/{ => conf}/set-using-missing.conf (100%) rename src/test/test-data/{ => conf}/set-using-nonexistent.conf (100%) rename src/test/test-data/{ => conf}/unhandled.conf (100%) rename src/test/test-data/{ => conf}/valid-enh-launch-exitCode.conf (100%) rename src/test/test-data/{ => conf}/valid-enh-launch.conf (100%) rename src/test/test-data/{ => conf}/valid-launch-exitCode.conf (100%) rename src/test/test-data/{ => conf}/valid-launch.conf (100%) rename src/test/test-data/{ => conf}/valid.conf (100%) diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java index 0e88447..8e05af4 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java @@ -44,24 +44,24 @@ public void tearDown() public void testNewRealm() throws Exception { - ClassRealm realm = this.world.newRealm( "foo" ); + ClassRealm realm = world.newRealm( "foo" ); assertNotNull( realm ); - assertSame( this.world, realm.getWorld() ); + assertSame( world, realm.getWorld() ); assertEquals( "foo", realm.getId() ); } public void testLocateSourceRealm_NoImports() throws Exception { - ClassRealm realm = new ClassRealm( this.world, "foo" ); + ClassRealm realm = new ClassRealm( world, "foo" ); assertSame( realm, realm.locateSourceRealm( "com.werken.Stuff" ) ); } public void testLocateSourceRealm_SimpleImport() throws Exception { - ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); - ClassRealm werkflowRealm = this.world.newRealm( "werkflow" ); + ClassRealm mainRealm = world.newRealm( "main" ); + ClassRealm werkflowRealm = world.newRealm( "werkflow" ); mainRealm.importFrom( "werkflow", "com.werken.werkflow" ); assertSame( werkflowRealm, mainRealm.locateSourceRealm( "com.werken.werkflow.WerkflowEngine" ) ); @@ -74,9 +74,9 @@ public void testLocateSourceRealm_SimpleImport() public void testLocateSourceRealm_MultipleImport() throws Exception { - ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); - ClassRealm werkflowRealm = this.world.newRealm( "werkflow" ); - ClassRealm blissedRealm = this.world.newRealm( "blissed" ); + ClassRealm mainRealm = world.newRealm( "main" ); + ClassRealm werkflowRealm = world.newRealm( "werkflow" ); + ClassRealm blissedRealm = world.newRealm( "blissed" ); mainRealm.importFrom( "werkflow", "com.werken.werkflow" ); mainRealm.importFrom( "blissed", "com.werken.blissed" ); @@ -89,13 +89,13 @@ public void testLocateSourceRealm_MultipleImport() assertSame( mainRealm, mainRealm.locateSourceRealm( "NoviceProgrammerClass" ) ); } - public void testLocateSourceRealm_Hierachy() + public void testLocateSourceRealm_Hierarchy() throws Exception { - ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); - ClassRealm fooRealm = this.world.newRealm( "foo" ); - ClassRealm fooBarRealm = this.world.newRealm( "fooBar" ); - ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); + ClassRealm mainRealm = world.newRealm( "main" ); + ClassRealm fooRealm = world.newRealm( "foo" ); + ClassRealm fooBarRealm = world.newRealm( "fooBar" ); + ClassRealm fooBarBazRealm = world.newRealm( "fooBarBaz" ); mainRealm.importFrom( "foo", "foo" ); mainRealm.importFrom( "fooBar", "foo.bar" ); @@ -114,10 +114,10 @@ public void testLocateSourceRealm_Hierachy() public void testLocateSourceRealm_Hierachy_Reverse() throws Exception { - ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); - ClassRealm fooBarRealm = this.world.newRealm( "fooBar" ); - ClassRealm fooRealm = this.world.newRealm( "foo" ); - ClassRealm mainRealm = (ClassRealm) this.world.newRealm( "main" ); + ClassRealm fooBarBazRealm = world.newRealm( "fooBarBaz" ); + ClassRealm fooBarRealm = world.newRealm( "fooBar" ); + ClassRealm fooRealm = world.newRealm( "foo" ); + ClassRealm mainRealm = world.newRealm( "main" ); mainRealm.importFrom( "fooBarBaz", "foo.bar.baz" ); mainRealm.importFrom( "fooBar", "foo.bar" ); @@ -136,7 +136,7 @@ public void testLocateSourceRealm_Hierachy_Reverse() public void testLoadClass_SystemClass() throws Exception { - ClassRealm mainRealm = this.world.newRealm( "main" ); + ClassRealm mainRealm = world.newRealm( "main" ); Class cls = mainRealm.loadClass( "java.lang.Object" ); assertNotNull( cls ); } @@ -144,7 +144,7 @@ public void testLoadClass_SystemClass() public void testLoadClass_NonSystemClass() throws Exception { - ClassRealm mainRealm = this.world.newRealm( "main" ); + ClassRealm mainRealm = world.newRealm( "main" ); try { @@ -160,7 +160,7 @@ public void testLoadClass_NonSystemClass() public void testLoadClass_ClassWorldsClass() throws Exception { - ClassRealm mainRealm = this.world.newRealm( "main" ); + ClassRealm mainRealm = world.newRealm( "main" ); Class cls = mainRealm.loadClass( "org.codehaus.plexus.classworlds.ClassWorld" ); assertNotNull( cls ); assertSame( ClassWorld.class, cls ); @@ -169,7 +169,7 @@ public void testLoadClass_ClassWorldsClass() public void testLoadClass_Local() throws Exception { - ClassRealm mainRealm = this.world.newRealm( "main" ); + ClassRealm mainRealm = world.newRealm( "main" ); try { mainRealm.loadClass( "a.A" ); @@ -182,7 +182,7 @@ public void testLoadClass_Local() mainRealm.addURL( TestUtil.getJarUrl( "a.jar" ) ); Class classA = mainRealm.loadClass( "a.A" ); assertNotNull( classA ); - ClassRealm otherRealm = this.world.newRealm( "other" ); + ClassRealm otherRealm = world.newRealm( "other" ); try { @@ -197,8 +197,8 @@ public void testLoadClass_Local() public void testLoadClass_Imported() throws Exception { - ClassRealm mainRealm = this.world.newRealm( "main" ); - ClassRealm realmA = this.world.newRealm( "realmA" ); + ClassRealm mainRealm = world.newRealm( "main" ); + ClassRealm realmA = world.newRealm( "realmA" ); try { @@ -235,7 +235,7 @@ public void testLoadClass_Imported() public void testLoadClass_Package() throws Exception { - ClassRealm realmA = this.world.newRealm( "realmA" ); + ClassRealm realmA = world.newRealm( "realmA" ); realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); Class clazz = realmA.loadClass( "a.A" ); @@ -250,18 +250,16 @@ public void testLoadClass_Package() public void testLoadClass_Complex() throws Exception { - ClassRealm realmA = this.world.newRealm( "realmA" ); - ClassRealm realmB = this.world.newRealm( "realmB" ); - ClassRealm realmC = this.world.newRealm( "realmC" ); + ClassRealm realmA = world.newRealm( "realmA" ); + ClassRealm realmB = world.newRealm( "realmB" ); + ClassRealm realmC = world.newRealm( "realmC" ); realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); realmB.addURL( TestUtil.getJarUrl( "b.jar" ) ); realmC.addURL( TestUtil.getJarUrl( "c.jar" ) ); realmC.importFrom( "realmA", "a" ); - realmC.importFrom( "realmB", "b" ); - realmA.importFrom( "realmC", "c" ); Class classA_A = realmA.loadClass( "a.A" ); @@ -330,7 +328,7 @@ public void testLoadClass_Complex() public void testLoadClass_ClassWorldsClassRepeatedly() throws Exception { - ClassRealm mainRealm = this.world.newRealm( "main" ); + ClassRealm mainRealm = world.newRealm( "main" ); for ( int i = 0; i < 100; i++ ) { @@ -345,9 +343,9 @@ public void testLoadClass_ClassWorldsClassRepeatedly() public void testP() throws Exception { - ClassRealm realmA = this.world.newRealm( "realmA" ); - ClassRealm realmB = this.world.newRealm( "realmB" ); - ClassRealm realmC = this.world.newRealm( "realmC" ); + ClassRealm realmA = world.newRealm( "realmA" ); + ClassRealm realmB = world.newRealm( "realmB" ); + ClassRealm realmC = world.newRealm( "realmC" ); realmA.addURL( TestUtil.getJarUrl( "a.jar" ) ); realmB.addURL( TestUtil.getJarUrl( "b.jar" ) ); diff --git a/src/test/test-data/dupe-main.conf b/src/test/test-data/conf/dupe-main.conf similarity index 100% rename from src/test/test-data/dupe-main.conf rename to src/test/test-data/conf/dupe-main.conf diff --git a/src/test/test-data/dupe-realm.conf b/src/test/test-data/conf/dupe-realm.conf similarity index 100% rename from src/test/test-data/dupe-realm.conf rename to src/test/test-data/conf/dupe-realm.conf diff --git a/src/test/test-data/early-import.conf b/src/test/test-data/conf/early-import.conf similarity index 100% rename from src/test/test-data/early-import.conf rename to src/test/test-data/conf/early-import.conf diff --git a/src/test/test-data/inheritance.conf b/src/test/test-data/conf/inheritance.conf similarity index 100% rename from src/test/test-data/inheritance.conf rename to src/test/test-data/conf/inheritance.conf diff --git a/src/test/test-data/launch-noclass.conf b/src/test/test-data/conf/launch-noclass.conf similarity index 100% rename from src/test/test-data/launch-noclass.conf rename to src/test/test-data/conf/launch-noclass.conf diff --git a/src/test/test-data/launch-nomethod.conf b/src/test/test-data/conf/launch-nomethod.conf similarity index 100% rename from src/test/test-data/launch-nomethod.conf rename to src/test/test-data/conf/launch-nomethod.conf diff --git a/src/test/test-data/optionally-existent.conf b/src/test/test-data/conf/optionally-existent.conf similarity index 100% rename from src/test/test-data/optionally-existent.conf rename to src/test/test-data/conf/optionally-existent.conf diff --git a/src/test/test-data/optionally-nonexistent.conf b/src/test/test-data/conf/optionally-nonexistent.conf similarity index 100% rename from src/test/test-data/optionally-nonexistent.conf rename to src/test/test-data/conf/optionally-nonexistent.conf diff --git a/src/test/test-data/realm-syntax.conf b/src/test/test-data/conf/realm-syntax.conf similarity index 100% rename from src/test/test-data/realm-syntax.conf rename to src/test/test-data/conf/realm-syntax.conf diff --git a/src/test/test-data/set-using-existent.conf b/src/test/test-data/conf/set-using-existent.conf similarity index 100% rename from src/test/test-data/set-using-existent.conf rename to src/test/test-data/conf/set-using-existent.conf diff --git a/src/test/test-data/set-using-missing.conf b/src/test/test-data/conf/set-using-missing.conf similarity index 100% rename from src/test/test-data/set-using-missing.conf rename to src/test/test-data/conf/set-using-missing.conf diff --git a/src/test/test-data/set-using-nonexistent.conf b/src/test/test-data/conf/set-using-nonexistent.conf similarity index 100% rename from src/test/test-data/set-using-nonexistent.conf rename to src/test/test-data/conf/set-using-nonexistent.conf diff --git a/src/test/test-data/unhandled.conf b/src/test/test-data/conf/unhandled.conf similarity index 100% rename from src/test/test-data/unhandled.conf rename to src/test/test-data/conf/unhandled.conf diff --git a/src/test/test-data/valid-enh-launch-exitCode.conf b/src/test/test-data/conf/valid-enh-launch-exitCode.conf similarity index 100% rename from src/test/test-data/valid-enh-launch-exitCode.conf rename to src/test/test-data/conf/valid-enh-launch-exitCode.conf diff --git a/src/test/test-data/valid-enh-launch.conf b/src/test/test-data/conf/valid-enh-launch.conf similarity index 100% rename from src/test/test-data/valid-enh-launch.conf rename to src/test/test-data/conf/valid-enh-launch.conf diff --git a/src/test/test-data/valid-launch-exitCode.conf b/src/test/test-data/conf/valid-launch-exitCode.conf similarity index 100% rename from src/test/test-data/valid-launch-exitCode.conf rename to src/test/test-data/conf/valid-launch-exitCode.conf diff --git a/src/test/test-data/valid-launch.conf b/src/test/test-data/conf/valid-launch.conf similarity index 100% rename from src/test/test-data/valid-launch.conf rename to src/test/test-data/conf/valid-launch.conf diff --git a/src/test/test-data/valid.conf b/src/test/test-data/conf/valid.conf similarity index 100% rename from src/test/test-data/valid.conf rename to src/test/test-data/conf/valid.conf From 7056098a39402f2634a4c1173c46fd4b6202f884 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 14:27:55 +0000 Subject: [PATCH 20/28] --- .../test-data/{conf => launcher-configurations}/dupe-main.conf | 0 .../test-data/{conf => launcher-configurations}/dupe-realm.conf | 0 .../test-data/{conf => launcher-configurations}/early-import.conf | 0 .../test-data/{conf => launcher-configurations}/inheritance.conf | 0 .../{conf => launcher-configurations}/launch-noclass.conf | 0 .../{conf => launcher-configurations}/launch-nomethod.conf | 0 .../{conf => launcher-configurations}/optionally-existent.conf | 0 .../{conf => launcher-configurations}/optionally-nonexistent.conf | 0 .../test-data/{conf => launcher-configurations}/realm-syntax.conf | 0 .../{conf => launcher-configurations}/set-using-existent.conf | 0 .../{conf => launcher-configurations}/set-using-missing.conf | 0 .../{conf => launcher-configurations}/set-using-nonexistent.conf | 0 .../test-data/{conf => launcher-configurations}/unhandled.conf | 0 .../valid-enh-launch-exitCode.conf | 0 .../{conf => launcher-configurations}/valid-enh-launch.conf | 0 .../{conf => launcher-configurations}/valid-launch-exitCode.conf | 0 .../test-data/{conf => launcher-configurations}/valid-launch.conf | 0 src/test/test-data/{conf => launcher-configurations}/valid.conf | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename src/test/test-data/{conf => launcher-configurations}/dupe-main.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/dupe-realm.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/early-import.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/inheritance.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/launch-noclass.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/launch-nomethod.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/optionally-existent.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/optionally-nonexistent.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/realm-syntax.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/set-using-existent.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/set-using-missing.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/set-using-nonexistent.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/unhandled.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/valid-enh-launch-exitCode.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/valid-enh-launch.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/valid-launch-exitCode.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/valid-launch.conf (100%) rename src/test/test-data/{conf => launcher-configurations}/valid.conf (100%) diff --git a/src/test/test-data/conf/dupe-main.conf b/src/test/test-data/launcher-configurations/dupe-main.conf similarity index 100% rename from src/test/test-data/conf/dupe-main.conf rename to src/test/test-data/launcher-configurations/dupe-main.conf diff --git a/src/test/test-data/conf/dupe-realm.conf b/src/test/test-data/launcher-configurations/dupe-realm.conf similarity index 100% rename from src/test/test-data/conf/dupe-realm.conf rename to src/test/test-data/launcher-configurations/dupe-realm.conf diff --git a/src/test/test-data/conf/early-import.conf b/src/test/test-data/launcher-configurations/early-import.conf similarity index 100% rename from src/test/test-data/conf/early-import.conf rename to src/test/test-data/launcher-configurations/early-import.conf diff --git a/src/test/test-data/conf/inheritance.conf b/src/test/test-data/launcher-configurations/inheritance.conf similarity index 100% rename from src/test/test-data/conf/inheritance.conf rename to src/test/test-data/launcher-configurations/inheritance.conf diff --git a/src/test/test-data/conf/launch-noclass.conf b/src/test/test-data/launcher-configurations/launch-noclass.conf similarity index 100% rename from src/test/test-data/conf/launch-noclass.conf rename to src/test/test-data/launcher-configurations/launch-noclass.conf diff --git a/src/test/test-data/conf/launch-nomethod.conf b/src/test/test-data/launcher-configurations/launch-nomethod.conf similarity index 100% rename from src/test/test-data/conf/launch-nomethod.conf rename to src/test/test-data/launcher-configurations/launch-nomethod.conf diff --git a/src/test/test-data/conf/optionally-existent.conf b/src/test/test-data/launcher-configurations/optionally-existent.conf similarity index 100% rename from src/test/test-data/conf/optionally-existent.conf rename to src/test/test-data/launcher-configurations/optionally-existent.conf diff --git a/src/test/test-data/conf/optionally-nonexistent.conf b/src/test/test-data/launcher-configurations/optionally-nonexistent.conf similarity index 100% rename from src/test/test-data/conf/optionally-nonexistent.conf rename to src/test/test-data/launcher-configurations/optionally-nonexistent.conf diff --git a/src/test/test-data/conf/realm-syntax.conf b/src/test/test-data/launcher-configurations/realm-syntax.conf similarity index 100% rename from src/test/test-data/conf/realm-syntax.conf rename to src/test/test-data/launcher-configurations/realm-syntax.conf diff --git a/src/test/test-data/conf/set-using-existent.conf b/src/test/test-data/launcher-configurations/set-using-existent.conf similarity index 100% rename from src/test/test-data/conf/set-using-existent.conf rename to src/test/test-data/launcher-configurations/set-using-existent.conf diff --git a/src/test/test-data/conf/set-using-missing.conf b/src/test/test-data/launcher-configurations/set-using-missing.conf similarity index 100% rename from src/test/test-data/conf/set-using-missing.conf rename to src/test/test-data/launcher-configurations/set-using-missing.conf diff --git a/src/test/test-data/conf/set-using-nonexistent.conf b/src/test/test-data/launcher-configurations/set-using-nonexistent.conf similarity index 100% rename from src/test/test-data/conf/set-using-nonexistent.conf rename to src/test/test-data/launcher-configurations/set-using-nonexistent.conf diff --git a/src/test/test-data/conf/unhandled.conf b/src/test/test-data/launcher-configurations/unhandled.conf similarity index 100% rename from src/test/test-data/conf/unhandled.conf rename to src/test/test-data/launcher-configurations/unhandled.conf diff --git a/src/test/test-data/conf/valid-enh-launch-exitCode.conf b/src/test/test-data/launcher-configurations/valid-enh-launch-exitCode.conf similarity index 100% rename from src/test/test-data/conf/valid-enh-launch-exitCode.conf rename to src/test/test-data/launcher-configurations/valid-enh-launch-exitCode.conf diff --git a/src/test/test-data/conf/valid-enh-launch.conf b/src/test/test-data/launcher-configurations/valid-enh-launch.conf similarity index 100% rename from src/test/test-data/conf/valid-enh-launch.conf rename to src/test/test-data/launcher-configurations/valid-enh-launch.conf diff --git a/src/test/test-data/conf/valid-launch-exitCode.conf b/src/test/test-data/launcher-configurations/valid-launch-exitCode.conf similarity index 100% rename from src/test/test-data/conf/valid-launch-exitCode.conf rename to src/test/test-data/launcher-configurations/valid-launch-exitCode.conf diff --git a/src/test/test-data/conf/valid-launch.conf b/src/test/test-data/launcher-configurations/valid-launch.conf similarity index 100% rename from src/test/test-data/conf/valid-launch.conf rename to src/test/test-data/launcher-configurations/valid-launch.conf diff --git a/src/test/test-data/conf/valid.conf b/src/test/test-data/launcher-configurations/valid.conf similarity index 100% rename from src/test/test-data/conf/valid.conf rename to src/test/test-data/launcher-configurations/valid.conf From 00fe74763d867e93936bd7683e5136b3d0709c59 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 14:33:55 +0000 Subject: [PATCH 21/28] --- .../launcher/ConfiguratorTest.java | 72 ++++--------------- .../classworlds/launcher/LauncherTest.java | 9 +-- .../set-using-existent.properties | 0 3 files changed, 16 insertions(+), 65 deletions(-) rename src/test/test-data/{ => launcher-configurations}/set-using-existent.properties (100%) diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java index 4d3a2a0..26f4906 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java @@ -2,18 +2,16 @@ /* * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.io.File; @@ -24,11 +22,10 @@ import junit.framework.TestCase; -import org.codehaus.plexus.classworlds.strategy.Strategy; -import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; -import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.TestUtil; +import org.codehaus.plexus.classworlds.realm.ClassRealm; +import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; public class ConfiguratorTest extends TestCase @@ -139,7 +136,6 @@ public void testConfigure_Valid() this.configurator.configure( getConfigPath( "valid.conf" ) ); assertEquals( "org.apache.maven.app.App", this.launcher.getMainClassName() ); - assertEquals( "maven", this.launcher.getMainRealmName() ); ClassWorld world = this.launcher.getWorld(); @@ -158,16 +154,10 @@ public void testConfigure_Valid() ClassRealm globRealm = world.getRealm( "glob" ); assertSame( antRealm, antRealm.locateSourceRealm( "org.apache.tools.Ant" ) ); - assertSame( xmlRealm, antRealm.locateSourceRealm( "org.xml.sax.SAXException" ) ); - assertSame( mavenRealm, mavenRealm.locateSourceRealm( "org.apache.maven.app.App" ) ); - assertSame( xmlRealm, mavenRealm.locateSourceRealm( "org.xml.sax.SAXException" ) ); - // Test the glob support - Strategy strat = globRealm.getStrategy(); - URL[] urls = globRealm.getURLs(); String basedir = TestUtil.getBasedir(); @@ -211,9 +201,7 @@ public void testFilter_Solitary() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); - String result = this.configurator.filter( "${classworlds.test.prop}" ); - assertEquals( "test prop value", result ); } @@ -221,9 +209,7 @@ public void testFilter_AtStart() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); - String result = this.configurator.filter( "${classworlds.test.prop}cheese" ); - assertEquals( "test prop valuecheese", result ); } @@ -231,9 +217,7 @@ public void testFilter_AtEnd() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); - String result = this.configurator.filter( "cheese${classworlds.test.prop}" ); - assertEquals( "cheesetest prop value", result ); } @@ -241,12 +225,8 @@ public void testFilter_Multiple() throws Exception { System.setProperty( "classworlds.test.prop.one", "test prop value one" ); - System.setProperty( "classworlds.test.prop.two", "test prop value two" ); - - String result = - this.configurator.filter( "I like ${classworlds.test.prop.one} and ${classworlds.test.prop.two} a lot" ); - + String result = this.configurator.filter( "I like ${classworlds.test.prop.one} and ${classworlds.test.prop.two} a lot" ); assertEquals( "I like test prop value one and test prop value two a lot", result ); } @@ -269,9 +249,7 @@ public void testFilter_InMiddle() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); - String result = this.configurator.filter( "cheese${classworlds.test.prop}toast" ); - assertEquals( "cheesetest prop valuetoast", result ); } @@ -279,9 +257,7 @@ public void testSet_Using_Existent() throws Exception { assertNull( System.getProperty( "set.using.existent" ) ); - this.configurator.configure( getConfigPath( "set-using-existent.conf" ) ); - assertEquals( "testSet_Using_Existent", System.getProperty( "set.using.existent" ) ); } @@ -289,9 +265,7 @@ public void testSet_Using_NonExistent() throws Exception { assertNull( System.getProperty( "set.using.nonexistent" ) ); - this.configurator.configure( getConfigPath( "set-using-nonexistent.conf" ) ); - assertNull( System.getProperty( "set.using.nonexistent" ) ); } @@ -299,9 +273,7 @@ public void testSet_Using_NonExistent_Default() throws Exception { assertNull( System.getProperty( "set.using.nonexistent.default" ) ); - this.configurator.configure( getConfigPath( "set-using-nonexistent.conf" ) ); - assertEquals( "testSet_Using_NonExistent_Default", System.getProperty( "set.using.nonexistent.default" ) ); } @@ -310,9 +282,7 @@ public void testSet_Using_NonExistent_Override() { assertNull( System.getProperty( "set.using.default" ) ); System.setProperty( "set.using.default", "testSet_Using_NonExistent_Override" ); - this.configurator.configure( getConfigPath( "set-using-nonexistent.conf" ) ); - assertEquals( "testSet_Using_NonExistent_Override", System.getProperty( "set.using.default" ) ); } @@ -321,9 +291,7 @@ public void testSet_Using_Existent_Override() { assertNull( System.getProperty( "set.using.existent" ) ); System.setProperty( "set.using.existent", "testSet_Using_Existent_Override" ); - this.configurator.configure( getConfigPath( "set-using-existent.conf" ) ); - assertEquals( "testSet_Using_Existent_Override", System.getProperty( "set.using.existent" ) ); } @@ -331,9 +299,7 @@ public void testSet_Using_Existent_Default() throws Exception { assertNull( System.getProperty( "set.using.default" ) ); - this.configurator.configure( getConfigPath( "set-using-existent.conf" ) ); - assertEquals( "testSet_Using_Existent_Default", System.getProperty( "set.using.default" ) ); } @@ -341,9 +307,7 @@ public void testSet_Using_Missing_Default() throws Exception { assertNull( System.getProperty( "set.using.missing" ) ); - this.configurator.configure( getConfigPath( "set-using-missing.conf" ) ); - assertEquals( "testSet_Using_Missing_Default", System.getProperty( "set.using.missing" ) ); } @@ -352,9 +316,7 @@ public void testSet_Using_Missing_Override() { assertNull( System.getProperty( "set.using.missing" ) ); System.setProperty( "set.using.missing", "testSet_Using_Missing_Override" ); - this.configurator.configure( getConfigPath( "set-using-missing.conf" ) ); - assertEquals( "testSet_Using_Missing_Override", System.getProperty( "set.using.missing" ) ); } @@ -362,21 +324,17 @@ public void testSet_Using_Filtered_Default() throws Exception { assertNull( System.getProperty( "set.using.filtered.default" ) ); - this.configurator.configure( getConfigPath( "set-using-missing.conf" ) ); - assertEquals( System.getProperty( "user.home" ) + "/m2", System.getProperty( "set.using.filtered.default" ) ); } private FileInputStream getConfigPath( String name ) throws Exception { - return new FileInputStream( - new File( new File( TestUtil.getBasedir(), "src/test/test-data" ), name ) ); + return new FileInputStream( new File( new File( TestUtil.getBasedir(), "src/test/test-data/launcher-configurations" ), name ) ); } - private void assertArrayContains( URL[] array, - URL url ) + private void assertArrayContains( URL[] array, URL url ) throws Exception { for ( int i = 0; i < array.length; ++i ) diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java index 5ab384f..db8d230 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java @@ -36,7 +36,6 @@ public LauncherTest( String name ) public void setUp() { System.setProperty( "java.protocol.handler.pkgs", "org.codehaus.classworlds.protocol" ); - this.launcher = new Launcher(); } @@ -49,13 +48,10 @@ public void testConfigure_Valid() throws Exception { launcher.configure( getConfigPath( "valid-launch.conf" ) ); - Class mainClass = launcher.getMainClass(); assertNotNull( mainClass ); - assertEquals( "a.A", mainClass.getName() ); - assertEquals( "app", launcher.getMainRealm().getId() ); } @@ -63,7 +59,6 @@ public void testLaunch_ValidStandard() throws Exception { launcher.configure( getConfigPath( "valid-launch.conf" ) ); - launcher.launch( new String[]{} ); } @@ -71,7 +66,6 @@ public void testLaunch_ValidStandardExitCode() throws Exception { launcher.configure( getConfigPath( "valid-launch-exitCode.conf" ) ); - launcher.launch( new String[]{} ); assertEquals( "check exit code", 15, launcher.getExitCode() ); @@ -89,7 +83,6 @@ public void testLaunch_ValidEnhancedExitCode() throws Exception { launcher.configure( getConfigPath( "valid-enh-launch-exitCode.conf" ) ); - launcher.launch( new String[]{} ); assertEquals( "check exit code", 45, launcher.getExitCode() ); @@ -132,6 +125,6 @@ private FileInputStream getConfigPath( String name ) { String basedir = TestUtil.getBasedir(); - return new FileInputStream( new File( new File( basedir, "src/test/test-data" ), name ) ); + return new FileInputStream( new File( new File( basedir, "src/test/test-data/launcher-configurations" ), name ) ); } } diff --git a/src/test/test-data/set-using-existent.properties b/src/test/test-data/launcher-configurations/set-using-existent.properties similarity index 100% rename from src/test/test-data/set-using-existent.properties rename to src/test/test-data/launcher-configurations/set-using-existent.properties From 4b8f4c494c17c63bc619448ea0f70b74608a67d4 Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 14:37:07 +0000 Subject: [PATCH 22/28] --- .../test-data/launcher-configurations/set-using-existent.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test-data/launcher-configurations/set-using-existent.conf b/src/test/test-data/launcher-configurations/set-using-existent.conf index d5d4a52..16c88a0 100644 --- a/src/test/test-data/launcher-configurations/set-using-existent.conf +++ b/src/test/test-data/launcher-configurations/set-using-existent.conf @@ -8,8 +8,8 @@ main is org.apache.maven.app.App from opt # ------------------------------------------------------------ # Set properties # ------------------------------------------------------------ -set set.using.existent using ${basedir}/src/test/test-data/set-using-existent.properties -set set.using.default using ${basedir}/src/test/test-data/set-using-existent.properties default testSet_Using_Existent_Default +set set.using.existent using ${basedir}/src/test/test-data/launcher-configurations/set-using-existent.properties +set set.using.default using ${basedir}/src/test/test-data/launcher-configurations/set-using-existent.properties default testSet_Using_Existent_Default # ------------------------------------------------------------ # Start defining realms From f81cd433576c00f12afa6bb6f0e92f150bc4ccdc Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 14:42:38 +0000 Subject: [PATCH 23/28] --- src/test/test-data/a.properties | 18 ------------------ src/test/test-data/b_old.jar | Bin 1225 -> 0 bytes src/test/test-data/nested.properties | 18 ------------------ 3 files changed, 36 deletions(-) delete mode 100644 src/test/test-data/a.properties delete mode 100644 src/test/test-data/b_old.jar delete mode 100644 src/test/test-data/nested.properties diff --git a/src/test/test-data/a.properties b/src/test/test-data/a.properties deleted file mode 100644 index d0e2fad..0000000 --- a/src/test/test-data/a.properties +++ /dev/null @@ -1,18 +0,0 @@ -################################################################################ -# -# Copyright 2001-2006 The Codehaus Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -a properties diff --git a/src/test/test-data/b_old.jar b/src/test/test-data/b_old.jar deleted file mode 100644 index 6ea6947e33233aaa0062fa2066586d8e86cebd94..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1225 zcmWIWW@h1H00EUr7A9Z@l;8x?zOEsTx}JV+`T;;?A`BcrsEnpe1X-D{qo1dnYjB93 zuiIzeGpBvLb@eXtdh2SPJ9B<>kiiw>2TzO6I13f(c=(+22xaJERQ3JZBU-U@PIr*7 zcTjN2TrEc_pD#U+cy&rA^Z1CGG@Z-9FwB^VF_78y_+2SjCcq(?BFFv<-oBjTK z_6$51xG%U|KfbYFxXC=IbyYsc*?&KK9{8N9^s?v)nRst)c;PDflsUyqg{O9&Ne|MV z{9j~l)k3W%>7z+9MY|@gQfT?RJVSH-(i5o@J2TgYPHYWaX*_Ym52tn76Q68a73Veg zytbj?$Hkq_yBn`aW|#fHpuiHX^zcpmET37^vga<@ernB|UUs+btn7O6v&7Z6Y@ht@ zaq6rq7Ou_mC+D!8aJX4DCw7ziw|7USUtHZ*yN$8>L09AT8xL1(WlWrIov=Gy+bto( z@`vv?or;vsy}rV~EjC>KseWObalg*K&%B^emrpTSDbL8ja14lXCks$q07Eqi8ms}f z-iI9|>ehJ*_g*~~w%eLxZ9@Kw1rr`!Xi{L2)haF6wM236B((z1FaA3%IQjlD)KB?w zFZ9i$2fXi}fBslBKmNTuL)(kW4HrrapFEmzQ1Wz4SU68uy+Qhh8kO zMGM994!TXg^W`PaziY4cqEri8g-u?}|B~I1spHzdOEA@KXXQ7xZ&}y$T>Fg*91nQE z3AlQzVS~4Hz#U`Z;|VhkM*aJFTK}%$hm8xrnPtCueBeiP#$oey?QHjdvVj8E%6Foo zDllMAg9De5NrV}9<^+Z?5C|~5bp+8!Srw!Wky(**2`IC|z>-FFAQP?)DeDG!BP_<2 zn;<5DEIt8bg7OxsjmRkkl)GSHN#hG36Q0-5wITZ*;%kV;C5?8#Jd8+80p6@^AQ@I5 MlmLd)Y-SJ-07pZXF#rGn diff --git a/src/test/test-data/nested.properties b/src/test/test-data/nested.properties deleted file mode 100644 index 0462a15..0000000 --- a/src/test/test-data/nested.properties +++ /dev/null @@ -1,18 +0,0 @@ -################################################################################ -# -# Copyright 2001-2006 The Codehaus Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -nested.properties From 2eada73dff375d338bb152c33227d6a3cec0911c Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 17:20:19 +0000 Subject: [PATCH 24/28] o close off access to the strategy in the realm --- .../plexus/classworlds/realm/ClassRealm.java | 7 +-- ...tegyTest.java => DefaultStrategyTest.java} | 48 ++++--------------- 2 files changed, 11 insertions(+), 44 deletions(-) rename src/test/java/org/codehaus/plexus/classworlds/strategy/{StrategyTest.java => DefaultStrategyTest.java} (93%) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index b58fd93..524ddbf 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -132,11 +132,6 @@ public ClassRealm locateSourceRealm( String classname ) return this; } - public Strategy getStrategy() - { - return strategy; - } - public ClassRealm createChildRealm( String id ) throws DuplicateRealmException { @@ -352,7 +347,7 @@ public void display() { System.out.println( "this realm = " + cr.getId() ); System.out.println( "classloader parent: " + cr.getParent() ); - System.out.println( "this strategy = " + this.getStrategy().getClass().getName() ); + System.out.println( "this strategy = " + strategy.getClass().getName() ); showUrls( cr ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java b/src/test/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategyTest.java similarity index 93% rename from src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java rename to src/test/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategyTest.java index fa4662b..2596612 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategyTest.java @@ -16,34 +16,29 @@ * limitations under the License. */ -import junit.framework.TestCase; -import org.codehaus.plexus.classworlds.ClassWorld; -import org.codehaus.plexus.classworlds.TestUtil; -import org.codehaus.plexus.classworlds.realm.ClassRealm; - -import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Enumeration; -// jars within jars -// hierarchy vs graph +import junit.framework.TestCase; + +import org.codehaus.plexus.classworlds.ClassWorld; +import org.codehaus.plexus.classworlds.TestUtil; +import org.codehaus.plexus.classworlds.realm.ClassRealm; -public class StrategyTest +public class DefaultStrategyTest extends TestCase { - private ClassWorld world; - + private ClassWorld world; private ClassRealm realm; - private Strategy strategy; public void setUp() throws Exception { this.world = new ClassWorld(); - this.realm = this.world.newRealm( "realm" ); - this.strategy = this.realm.getStrategy(); + this.realm = new ClassRealm( world, "realm" ); + this.strategy = new DefaultStrategy( realm ); realm.addURL( TestUtil.getTestComponent( "component0-1.0.jar" ) ); } @@ -52,7 +47,6 @@ public void testLoadingOfApplicationClass() throws Exception { Class c = strategy.loadClass( "org.codehaus.plexus.Component0" ); - assertNotNull( c ); } @@ -60,13 +54,9 @@ public void testLoadingOfApplicationClassThenDoingItAgain() throws Exception { Class c; - c = strategy.loadClass( "org.codehaus.plexus.Component0" ); - assertNotNull( c ); - c = strategy.loadClass( "org.codehaus.plexus.Component0" ); - assertNotNull( c ); } @@ -75,7 +65,6 @@ public void testLoadingOfSystemClass() throws Exception { Class c = strategy.loadClass( "java.lang.Object" ); - assertNotNull( c ); } @@ -85,7 +74,6 @@ public void testLoadingOfNonExistentClass() try { strategy.loadClass( "org.codehaus.plexus.NonExistentComponent" ); - fail( "Should have thrown a ClassNotFoundException!" ); } catch ( ClassNotFoundException e ) @@ -98,11 +86,8 @@ public void testGetApplicationResource() throws Exception { URL resource = strategy.getResource( "META-INF/plexus/components.xml" ); - assertNotNull( resource ); - String content = getContent( resource.openStream() ); - assertTrue( content.startsWith( "" ) ); } @@ -110,7 +95,6 @@ public void testGetSystemResource() throws Exception { URL resource = strategy.getResource( "java/lang/Object.class" ); - assertNotNull( resource ); } @@ -119,20 +103,15 @@ public void testFindResources() throws Exception { realm.addURL( TestUtil.getTestComponent( "component1-1.0.jar" ) ); - Enumeration e = strategy.findResources( "META-INF/plexus/components.xml" ); - assertNotNull( e ); - int resourceCount = 0; for ( Enumeration resources = e; resources.hasMoreElements(); ) { resources.nextElement(); - resourceCount++; - } - + } assertEquals( 2, resourceCount ); } @@ -141,11 +120,8 @@ public void testGetResourceAsStream() throws Exception { InputStream is = strategy.getResourceAsStream( "META-INF/plexus/components.xml" ); - assertNotNull( is ); - String content = getContent( is ); - assertTrue( content.startsWith( "" ) ); } @@ -153,16 +129,12 @@ protected String getContent( InputStream in ) throws Exception { byte[] buffer = new byte[1024]; - int read = 0; - StringBuffer content = new StringBuffer(); - while ( ( read = in.read( buffer, 0, 1024 ) ) >= 0 ) { content.append( new String( buffer, 0, read ) ); } - return content.toString(); } } From 2b791d895b4a3cab7ca0841e7bdb9a3a3382c0ce Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Thu, 3 Jul 2008 22:03:54 +0000 Subject: [PATCH 25/28] o keep the references from import -> realm in the realm itself to prevent a large number of references in the entries, this makes it easier to manage references when removing realms and doesn't leave any strong connections lying around. --- .../plexus/classworlds/ClassWorld.java | 11 ++ .../plexus/classworlds/realm/ClassRealm.java | 168 ++++++++++++++---- .../plexus/classworlds/realm/Entry.java | 129 -------------- .../plexus/classworlds/ClassWorldTest.java | 6 - .../plexus/classworlds/realm/EntryTest.java | 20 +-- 5 files changed, 149 insertions(+), 185 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java diff --git a/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java b/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java index 1e8986f..50aeef7 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java +++ b/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java @@ -85,12 +85,23 @@ public synchronized ClassRealm newRealm( String id, ClassLoader classLoader ) return realm; } + //TODO: the import statements are not updated to reflect the removal of the realm. public synchronized void disposeRealm( String id ) throws NoSuchRealmException { realms.remove( id ); } + public synchronized ClassRealm getClassRealm( String id ) + { + if ( realms.containsKey( id ) ) + { + return (ClassRealm) realms.get( id ); + } + + return null; + } + public synchronized ClassRealm getRealm( String id ) throws NoSuchRealmException { diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 524ddbf..8f7594e 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -24,12 +24,16 @@ import java.security.ProtectionDomain; import java.util.Enumeration; import java.util.Iterator; +import java.util.Map; +import java.util.Set; import java.util.TreeSet; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.strategy.DefaultStrategy; import org.codehaus.plexus.classworlds.strategy.Strategy; +import com.sun.tools.jdi.LinkedHashMap; + /** * @author Jason van Zyl * @version $Id$ @@ -39,16 +43,19 @@ public class ClassRealm { /** The ClassWorld we live in. */ private ClassWorld world; - + /** The unique id of our ClassRealm */ private String id; /** Packages this ClassRealm is willing to make visible to outside callers. */ - private TreeSet exports; + private Set exports; /** Pacakges this ClassRealm wants to import from other realms. */ - private TreeSet imports; - + private Set imports; + + /** Map of packages to import from given realms */ + private Map importRealmMappings; + /** The strategy we are using to load classes and resources. */ private Strategy strategy; @@ -73,8 +80,9 @@ public ClassRealm( ClassWorld world, String id, ClassLoader parent, Strategy str this.world = world; this.id = id; - exports = new TreeSet(); - imports = new TreeSet(); + this.exports = new TreeSet(); + this.imports = new TreeSet(); + this.importRealmMappings = new LinkedHashMap(); if ( strategy == null ) { @@ -95,12 +103,17 @@ public ClassWorld getWorld() { return this.world; } - + public void importFrom( String realmId, String packageName ) throws NoSuchRealmException { - imports.add( new Entry( getWorld().getRealm( realmId ), packageName ) ); - imports.add( new Entry( getWorld().getRealm( realmId ), packageName.replace( '.', '/' ) ) ); + Entry e = new Entry( packageName ); + imports.add( e ); + importRealmMappings.put( e.pkgName, realmId ); + + Entry e1 = new Entry( packageName.replace( '.', '/' ) ); + imports.add( e1 ); + importRealmMappings.put( e1.pkgName, realmId ); } public ClassRealm getImportRealm( String classname ) @@ -111,7 +124,7 @@ public ClassRealm getImportRealm( String classname ) if ( entry.matches( classname ) ) { - return entry.getRealm(); + return world.getClassRealm( (String) importRealmMappings.get( entry.pkgName ) ); } } @@ -120,16 +133,14 @@ public ClassRealm getImportRealm( String classname ) public ClassRealm locateSourceRealm( String classname ) { - for ( Iterator iterator = imports.iterator(); iterator.hasNext(); ) + ClassRealm importRealm = getImportRealm( classname ); + + if ( importRealm != null ) { - Entry entry = (Entry) iterator.next(); - if ( entry.matches( classname ) ) - { - return entry.getRealm(); - } + return importRealm; } - - return this; + + return this; } public ClassRealm createChildRealm( String id ) @@ -157,11 +168,11 @@ public Enumeration findRealmResources( String name ) //--------------------------------------------------------------------------------------------- // Search methods that can be ordered by strategies //--------------------------------------------------------------------------------------------- - + public Class loadClassFromImport( String name ) { ClassRealm importRealm = getImportRealm( name ); - Class clazz = null; + Class clazz = null; if ( importRealm != null ) { try @@ -187,7 +198,7 @@ public Class loadClassFromSelf( String name ) if ( clazz == null ) { clazz = findClass( name ); - } + } } catch ( ClassNotFoundException e ) { @@ -214,12 +225,12 @@ public Class loadClassFromParent( String name ) } return null; - } - + } + //--------------------------------------------------------------------------------------------- // Resources //--------------------------------------------------------------------------------------------- - + public URL loadResourceFromImport( String name ) { ClassRealm importRealm = getImportRealm( name ); @@ -247,10 +258,10 @@ public URL loadResourceFromParent( String name ) } return null; - } + } // Resources - + public Enumeration loadResourcesFromImport( String name ) { ClassRealm importRealm = getImportRealm( name ); @@ -279,9 +290,8 @@ public Enumeration loadResourcesFromSelf( String name ) catch ( IOException e ) { return null; - } + } } - public Enumeration loadResourcesFromParent( String name ) { @@ -298,9 +308,8 @@ public Enumeration loadResourcesFromParent( String name ) } return null; - } - - + } + // ---------------------------------------------------------------------- // We delegate to the Strategy here so that we can change the behavior // of any existing ClassRealm. @@ -388,10 +397,11 @@ public String toString() { return "ClassRealm[" + getId() + ", parent: " + getParent() + "]"; } - + /** - * Find the exact URL that a particular class was loaded from. This can be used to debug problems where you need - * to know exactly what JAR, or location in the file system that a class came from. + * Find the exact URL that a particular class was loaded from. This can be used to debug + * problems where you need to know exactly what JAR, or location in the file system that a class + * came from. * * @param clazz * @return The location of class that was loaded in URL external form. @@ -453,10 +463,10 @@ else if ( new File( result.getFile() ).isDirectory() ) } return result.toExternalForm(); - } - + } + // Util methods - + public static String normalizeUrlPath( String name ) { if ( name.startsWith( "/" ) ) @@ -480,5 +490,87 @@ public static String normalizeUrlPath( String name ) } return name; - } + } + + public static class Entry + implements Comparable + { + private final String pkgName; + + Entry( String pkgName ) + { + this.pkgName = pkgName; + } + + String getPackageName() + { + return this.pkgName; + } + + /** + * Determine if the classname matches the package described by this entry. + * + * @param classname The class name to test. + * @return true if this entry matches the classname, otherwise + * false. + */ + boolean matches( String classname ) + { + return classname.startsWith( getPackageName() ); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // java.lang.Comparable + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + /** + * Compare this entry to another for relative ordering.

The natural ordering of + * Entry objects is reverse-alphabetical based upon package name.

+ * + * @param thatObj The object to compare. + * @return -1 if this object sorts before that object, 0 if they are equal, or 1 if this + * object sorts after that object. + */ + public int compareTo( Object thatObj ) + { + Entry that = (Entry) thatObj; + + // We are reverse sorting this list, so that + // we get longer matches first: + // + // com.werken.foo.bar + // com.werken.foo + // com.werken + + return ( getPackageName().compareTo( that.getPackageName() ) ) * -1; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // java.lang.Object + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + /** + * Test this entry for equality to another.

Consistent with {@link #compareTo}, + * this method tests for equality purely on the package name.

+ * + * @param thatObj The object to compare + * @return true if the two objects are semantically equivalent, otherwise + * false. + */ + public boolean equals( Object thatObj ) + { + Entry that = (Entry) thatObj; + + return getPackageName().equals( that.getPackageName() ); + } + + /** + *

Consistent with {@link #equals}, this method creates a hashCode based on the + * packagename.

+ */ + public int hashCode() + { + return getPackageName().hashCode(); + } + } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java b/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java deleted file mode 100644 index 2b21ac0..0000000 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.codehaus.plexus.classworlds.realm; - -/* - * Copyright 2001-2006 Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -/** - * Import description entry. - * - * @author bob mcwhirter - */ -public class Entry - implements Comparable -{ - private final ClassRealm realm; - - private final String pkgName; - - Entry( ClassRealm realm, String pkgName ) - { - this.realm = realm; - - this.pkgName = pkgName; - } - - // ------------------------------------------------------------ - // Instance methods - // ------------------------------------------------------------ - - /** - * Retrieve the realm. - * - * @return The realm. - */ - ClassRealm getRealm() - { - return this.realm; - } - - /** - * Retrieve the package name. - * - * @return The package name. - */ - String getPackageName() - { - return this.pkgName; - } - - /** - * Determine if the classname matches the package described by this entry. - * - * @param classname The class name to test. - * @return true if this entry matches the classname, otherwise false. - */ - boolean matches( String classname ) - { - return classname.startsWith( getPackageName() ); - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // java.lang.Comparable - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Compare this entry to another for relative ordering.

The natural ordering of Entry - * objects is reverse-alphabetical based upon package name.

- * - * @param thatObj The object to compare. - * @return -1 if this object sorts before that object, 0 if they are equal, or 1 if this object - * sorts after that object. - */ - public int compareTo( Object thatObj ) - { - Entry that = (Entry) thatObj; - - // We are reverse sorting this list, so that - // we get longer matches first: - // - // com.werken.foo.bar - // com.werken.foo - // com.werken - - return ( getPackageName().compareTo( that.getPackageName() ) ) * -1; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // java.lang.Object - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Test this entry for equality to another.

Consistent with {@link #compareTo}, this - * method tests for equality purely on the package name.

- * - * @param thatObj The object to compare - * @return true if the two objects are semantically equivalent, otherwise - * false. - */ - public boolean equals( Object thatObj ) - { - Entry that = (Entry) thatObj; - - return getPackageName().equals( that.getPackageName() ); - } - - /** - *

Consistent with {@link #equals}, this method creates a hashCode based on the - * packagename.

- */ - public int hashCode() - { - return getPackageName().hashCode(); - } - - public String toString() - { - return "Entry[import " + getPackageName() + " from realm " + getRealm() + "]"; - } -} diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java index 643b767..e35a26e 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java @@ -107,17 +107,11 @@ public void testGetRealms() throws Exception { assertTrue( this.world.getRealms().isEmpty() ); - ClassRealm foo = this.world.newRealm( "foo" ); - assertEquals( 1, this.world.getRealms().size() ); - assertTrue( this.world.getRealms().contains( foo ) ); - ClassRealm bar = this.world.newRealm( "bar" ); - assertEquals( 2, this.world.getRealms().size() ); - assertTrue( this.world.getRealms().contains( bar ) ); } diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java index 8284011..59f22fe 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java @@ -19,15 +19,11 @@ import junit.framework.TestCase; import org.codehaus.plexus.classworlds.ClassWorld; +import org.codehaus.plexus.classworlds.realm.ClassRealm.Entry; -/** - * @author Ben Walding - * @version $Id$ - */ public class EntryTest extends TestCase { - /** * Constructor for EntryTest. * @@ -42,10 +38,10 @@ public void testCompareTo() throws Exception { ClassWorld cw = new ClassWorld(); - ClassRealm r = (ClassRealm) cw.newRealm( "test1" ); + ClassRealm r = cw.newRealm( "test1" ); - Entry entry1 = new Entry( r, "org.test" ); - Entry entry2 = new Entry( r, "org.test.impl" ); + Entry entry1 = new Entry( "org.test" ); + Entry entry2 = new Entry( "org.test.impl" ); assertTrue( "org.test > org.test.impl", entry1.compareTo( entry2 ) > 0 ); } @@ -59,11 +55,11 @@ public void testEquals() throws Exception { ClassWorld cw = new ClassWorld(); - ClassRealm r1 = (ClassRealm) cw.newRealm( "test1" ); - ClassRealm r2 = (ClassRealm) cw.newRealm( "test2" ); + ClassRealm r1 = cw.newRealm( "test1" ); + ClassRealm r2 = cw.newRealm( "test2" ); - Entry entry1 = new Entry( r1, "org.test" ); - Entry entry2 = new Entry( r2, "org.test" ); + Entry entry1 = new Entry( "org.test" ); + Entry entry2 = new Entry( "org.test" ); assertTrue( "entry1 == entry2", entry1.equals( entry2 ) ); assertTrue( "entry1.hashCode() == entry2.hashCode()", entry1.hashCode() == entry2.hashCode() ); From f1c08865829716b6ab274de1aedc6850470a41fe Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Fri, 4 Jul 2008 00:17:35 +0000 Subject: [PATCH 26/28] o separate out the configuration for a realm so that the model can be used for the launcher and a realm constructor --- .../classworlds/launcher/Configurator.java | 93 ++++++------------- .../ClassRealmConfiguration.java | 51 ++++++++++ .../realm/configuration/ClassRealmImport.java | 23 +++++ .../classworlds/realm/ClassRealmTest.java | 5 + 4 files changed, 105 insertions(+), 67 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java create mode 100644 src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java diff --git a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java index 9809c26..073b43c 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java +++ b/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java @@ -14,11 +14,6 @@ * the License. */ -import org.codehaus.plexus.classworlds.ClassWorld; -import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; -import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; -import org.codehaus.plexus.classworlds.realm.ClassRealm; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -37,7 +32,13 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.TreeSet; + +import org.codehaus.plexus.classworlds.ClassWorld; +import org.codehaus.plexus.classworlds.realm.ClassRealm; +import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; +import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; +import org.codehaus.plexus.classworlds.realm.configuration.ClassRealmConfiguration; +import org.codehaus.plexus.classworlds.realm.configuration.ClassRealmImport; /** * Launcher configurator. @@ -102,7 +103,7 @@ public void configure( InputStream is ) foreignClassLoader = this.launcher.getSystemClassLoader(); } - RealmConfiguration currentRealm = null; + ClassRealmConfiguration currentRealm = null; String line = null; @@ -246,7 +247,7 @@ else if ( line.startsWith( "[" ) ) throw new DuplicateRealmException(world, realmName ); } - currentRealm = new RealmConfiguration( realmName ); + currentRealm = new ClassRealmConfiguration( realmName ); // Stash the configured realm for subsequent association processing. //configuredRealms.put( realmName, curRealm ); @@ -268,11 +269,11 @@ else if ( line.startsWith( IMPORT_PREFIX ) ) throw new ConfigurationException( "Missing from clause", lineNo, line ); } - String importSpec = conf.substring( 0, fromLoc ).trim(); - - String relamName = conf.substring( fromLoc + 4 ).trim(); - - currentRealm.addImport( new ImportStatement( relamName, importSpec ) ); + String importSpecification = conf.substring( 0, fromLoc ).trim(); + + String realmName = conf.substring( fromLoc + 4 ).trim(); + + currentRealm.addImport( realmName, importSpecification ); } else if ( line.startsWith( LOAD_PREFIX ) ) @@ -323,7 +324,6 @@ else if ( line.startsWith( LOAD_PREFIX ) ) reader.close(); } - // TODO return this to protected when the legacy wrappers can be removed. /** * Associate parent realms with their children. * @@ -331,7 +331,7 @@ else if ( line.startsWith( LOAD_PREFIX ) ) * @throws NoSuchRealmException * @throws MalformedURLException */ - public void createRealms() + protected void createRealms() throws DuplicateRealmException, NoSuchRealmException, MalformedURLException { List sortRealmNames = new ArrayList( configuredRealms.keySet() ); @@ -369,12 +369,12 @@ public int compare( Object o1, Object o2 ) { String parentRealmName = realmName.substring( 0, j ); - RealmConfiguration parentRealmConfiguration = (RealmConfiguration) configuredRealms.get( parentRealmName ); + ClassRealmConfiguration parentRealmConfiguration = (ClassRealmConfiguration) configuredRealms.get( parentRealmName ); if ( parentRealmConfiguration != null ) { - RealmConfiguration realmConfiguration = (RealmConfiguration) configuredRealms.get( realmName ); - world.newRealm( realmConfiguration.id, world.getRealm( parentRealmConfiguration.id ) ); + ClassRealmConfiguration realmConfiguration = (ClassRealmConfiguration) configuredRealms.get( realmName ); + world.newRealm( realmConfiguration.getId(), world.getRealm( parentRealmConfiguration.getId() ) ); } } else @@ -385,29 +385,28 @@ public int compare( Object o1, Object o2 ) for ( Iterator i = configuredRealms.values().iterator(); i.hasNext(); ) { - RealmConfiguration rc = (RealmConfiguration) i.next(); + ClassRealmConfiguration rc = (ClassRealmConfiguration) i.next(); - configureRealm( world.getRealm( rc.id ), rc ); + configureRealm( world.getRealm( rc.getId() ), rc ); } } - private void configureRealm( ClassRealm realm, RealmConfiguration realmConfiguration ) + private void configureRealm( ClassRealm realm, ClassRealmConfiguration realmConfiguration ) throws NoSuchRealmException, MalformedURLException { - for ( Iterator i = realmConfiguration.imports.iterator(); i.hasNext(); ) + for ( Iterator i = realmConfiguration.getImports().iterator(); i.hasNext(); ) { - ImportStatement is = (ImportStatement) i.next(); + ClassRealmImport is = (ClassRealmImport) i.next(); - realm.importFrom( is.importRealm, is.importSpecification ); + realm.importFrom( is.getImportRealm(), is.getImportSpecification() ); } - for ( Iterator i = realmConfiguration.loads.iterator(); i.hasNext(); ) + for ( Iterator i = realmConfiguration.getLoads().iterator(); i.hasNext(); ) { String load = (String) i.next(); realm.addURL( new URL( load ) ); } - } /** @@ -420,7 +419,7 @@ private void configureRealm( ClassRealm realm, RealmConfiguration realmConfigura * @throws FileNotFoundException If the line does not represent a valid path element in the * filesystem. */ - protected void loadGlob( String line, RealmConfiguration realm ) + protected void loadGlob( String line, ClassRealmConfiguration realm ) throws MalformedURLException, FileNotFoundException { File globFile = new File( line ); @@ -536,44 +535,4 @@ private boolean canIgnore( String line ) { return ( line.length() == 0 || line.startsWith( "#" ) ); } - - class RealmConfiguration - { - String id; - TreeSet imports = new TreeSet(); - TreeSet exports = new TreeSet(); - TreeSet loads = new TreeSet(); - - public RealmConfiguration( String id ) - { - this.id = id; - } - - public void addImport( ImportStatement importStatement ) - { - imports.add( importStatement ); - } - - public void addExport( String exportStatement ) - { - exports.add( exportStatement ); - } - - public void addLoad( String loadStatement ) - { - loads.add( loadStatement ); - } - } - - class ImportStatement - { - public ImportStatement( String importRealm, String importSpecification ) - { - this.importRealm = importRealm; - this.importSpecification = importSpecification; - } - - String importRealm; - String importSpecification; - } } diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java new file mode 100644 index 0000000..8e6ec3c --- /dev/null +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java @@ -0,0 +1,51 @@ +package org.codehaus.plexus.classworlds.realm.configuration; + +import java.util.TreeSet; + +public class ClassRealmConfiguration +{ + String id; + TreeSet imports = new TreeSet(); + TreeSet exports = new TreeSet(); + TreeSet loads = new TreeSet(); + + public ClassRealmConfiguration( String id ) + { + this.id = id; + } + + public void addImport( String importRealm, String importSpecification ) + { + imports.add( new ClassRealmImport( importRealm, importSpecification ) ); + } + + public void addExport( String exportStatement ) + { + exports.add( exportStatement ); + } + + public void addLoad( String loadStatement ) + { + loads.add( loadStatement ); + } + + public String getId() + { + return id; + } + + public TreeSet getImports() + { + return imports; + } + + public TreeSet getExports() + { + return exports; + } + + public TreeSet getLoads() + { + return loads; + } +} \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java new file mode 100644 index 0000000..03315b3 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java @@ -0,0 +1,23 @@ +package org.codehaus.plexus.classworlds.realm.configuration; + +public class ClassRealmImport +{ + String importRealm; + String importSpecification; + + public ClassRealmImport( String importRealm, String importSpecification ) + { + this.importRealm = importRealm; + this.importSpecification = importSpecification; + } + + public String getImportRealm() + { + return importRealm; + } + + public String getImportSpecification() + { + return importSpecification; + } +} \ No newline at end of file diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java index 8e05af4..97d3024 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java @@ -435,4 +435,9 @@ public void testResource() URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" ); assertNotNull( resource ); } + + // ---------------------------------------------------------------------- + // Exports + // ---------------------------------------------------------------------- + } From e9c0433589db71bf35b8e05ae5301eb415c5b7cc Mon Sep 17 00:00:00 2001 From: jvanzyl Date: Fri, 4 Jul 2008 00:31:25 +0000 Subject: [PATCH 27/28] o do the the . -> / replacement on the import search instead of adding two entries in the import table --- .../plexus/classworlds/realm/ClassRealm.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 8f7594e..98c8e50 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -107,13 +107,9 @@ public ClassWorld getWorld() public void importFrom( String realmId, String packageName ) throws NoSuchRealmException { - Entry e = new Entry( packageName ); - imports.add( e ); - importRealmMappings.put( e.pkgName, realmId ); - - Entry e1 = new Entry( packageName.replace( '.', '/' ) ); - imports.add( e1 ); - importRealmMappings.put( e1.pkgName, realmId ); + Entry entry = new Entry( packageName ); + imports.add( entry ); + importRealmMappings.put( entry.pkgName, realmId ); } public ClassRealm getImportRealm( String classname ) @@ -122,7 +118,7 @@ public ClassRealm getImportRealm( String classname ) { Entry entry = (Entry) iterator.next(); - if ( entry.matches( classname ) ) + if ( entry.matches( classname ) || entry.matches( classname.replace( '.', '/' ) ) ) { return world.getClassRealm( (String) importRealmMappings.get( entry.pkgName ) ); } From 9e48266c0c64cb1539a96ea40a019656a5cc54dc Mon Sep 17 00:00:00 2001 From: bentmann Date: Mon, 4 May 2009 17:01:25 +0000 Subject: [PATCH 28/28] o Fixed import --- .../java/org/codehaus/plexus/classworlds/realm/ClassRealm.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java index 98c8e50..6671320 100644 --- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java +++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java @@ -24,6 +24,7 @@ import java.security.ProtectionDomain; import java.util.Enumeration; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -32,8 +33,6 @@ import org.codehaus.plexus.classworlds.strategy.DefaultStrategy; import org.codehaus.plexus.classworlds.strategy.Strategy; -import com.sun.tools.jdi.LinkedHashMap; - /** * @author Jason van Zyl * @version $Id$