1 package org.apache.maven.shared.transfer.dependencies.collect.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollectorException;
23
24 import java.lang.reflect.InvocationTargetException;
25
26
27
28
29 final class Invoker
30 {
31 private Invoker()
32 {
33
34 }
35
36 public static <T> T invoke( Object object, String method ) throws DependencyCollectorException
37 {
38 try
39 {
40 @SuppressWarnings( "unchecked" )
41 T invoke = (T) object.getClass().getMethod( method ).invoke( object );
42 return invoke;
43 }
44 catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException e )
45 {
46 throw new DependencyCollectorException( e.getMessage(), e );
47 }
48 }
49
50 public static <T> T invoke( Class<?> objectClazz, String staticMethod, Class<?> argClazz, Object arg )
51 throws DependencyCollectorException
52 {
53 try
54 {
55 @SuppressWarnings( "unchecked" )
56 T invoke = (T) objectClazz.getMethod( staticMethod, argClazz ).invoke( null, arg );
57 return invoke;
58 }
59 catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException e )
60 {
61 throw new DependencyCollectorException( e.getMessage(), e );
62 }
63 }
64
65
66
67
68
69
70
71
72
73 public static <T> T invoke( Class<?> objectClazz, String staticMethod, Class<?>[] argClasses, Object[] args )
74 throws DependencyCollectorException
75 {
76 if ( args.length != argClasses.length )
77 {
78 throw new IllegalArgumentException( "The number of elements in argClasses and args are not the same." );
79 }
80
81 try
82 {
83 @SuppressWarnings( "unchecked" )
84 T invoke = (T) objectClazz.getMethod( staticMethod, argClasses ).invoke( null, args );
85 return invoke;
86 }
87 catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException e )
88 {
89 throw new DependencyCollectorException( e.getMessage(), e );
90 }
91 }
92
93 }