File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
src/test/java/net/bytebuddy Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1818 <packages .list>net.bytebuddy.agent,net.bytebuddy.agent.utility.nullability</packages .list>
1919 <native .compiler.32>i686-w64-mingw32-gcc</native .compiler.32>
2020 <native .compiler.64>x86_64-w64-mingw32-gcc</native .compiler.64>
21+ <net .bytebuddy.test.jnapath/>
2122 </properties >
2223
2324 <name >Byte Buddy agent</name >
8990 </resource >
9091 </resources >
9192 <plugins >
93+ <!-- Allow for specifying a custom library path for JNA. -->
94+ <plugin >
95+ <groupId >org.apache.maven.plugins</groupId >
96+ <artifactId >maven-surefire-plugin</artifactId >
97+ <version >${version.plugin.surefire} </version >
98+ <configuration combine.children=" append" >
99+ <argLine >-Djna.library.path=${net.bytebuddy.test.jnapath} </argLine >
100+ </configuration >
101+ </plugin >
92102 <!-- Create manifest file which is required for creating an OSGi bundle. -->
93103 <plugin >
94104 <groupId >org.apache.maven.plugins</groupId >
Original file line number Diff line number Diff line change 11package net .bytebuddy .agent ;
22
33import net .bytebuddy .dynamic .ClassFileLocator ;
4+ import net .bytebuddy .test .utility .JnaRule ;
45import org .junit .After ;
56import org .junit .Before ;
7+ import org .junit .Rule ;
68import org .junit .Test ;
9+ import org .junit .rules .TestRule ;
710
811import java .io .File ;
912import java .io .FileOutputStream ;
@@ -20,6 +23,9 @@ public class VirtualMachineAttachmentTest {
2023
2124 private static final String FOO = "foo" ;
2225
26+ @ Rule
27+ public TestRule jnaRule = new JnaRule ();
28+
2329 private File agent ;
2430
2531 @ Before
Original file line number Diff line number Diff line change 1+ package net .bytebuddy .test .utility ;
2+
3+ import com .sun .jna .Library ;
4+ import com .sun .jna .Native ;
5+ import com .sun .jna .Platform ;
6+ import org .junit .rules .TestRule ;
7+ import org .junit .runner .Description ;
8+ import org .junit .runners .model .Statement ;
9+
10+ import java .util .logging .Logger ;
11+
12+ public class JnaRule implements TestRule {
13+
14+ private final boolean available ;
15+
16+ @ SuppressWarnings ("deprecation" )
17+ public JnaRule () {
18+ boolean available ;
19+ try {
20+ Native .loadLibrary ((Platform .isWindows () ? "msvcrt" : "c" ), CLibrary .class );
21+ available = true ;
22+ } catch (Throwable ignored ) {
23+ available = false ;
24+ }
25+ this .available = available ;
26+ }
27+
28+ public Statement apply (Statement base , Description description ) {
29+ return available
30+ ? base
31+ : new NoOpStatement ();
32+ }
33+
34+ private static class NoOpStatement extends Statement {
35+
36+ public void evaluate () {
37+ Logger .getLogger ("net.bytebuddy" ).info ("Omitting test case: JNA not available" );
38+ }
39+ }
40+
41+ public interface CLibrary extends Library {
42+
43+ @ SuppressWarnings ("unused" )
44+ void printf (String format , Object ... args );
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments