Skip to content

Package: JDKToolAdapter

JDKToolAdapter

nameinstructionbranchcomplexitylinemethod
JDKToolAdapter()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute()
M: 30 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getMain()
M: 38 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.ws.test.util;
12:
13: import com.sun.istack.test.Which;
14: import com.sun.xml.ws.test.World;
15: import org.apache.tools.ant.BuildException;
16: import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
17: import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
18: import org.apache.tools.ant.types.Commandline;
19:
20: import java.lang.reflect.Method;
21: import java.util.Collections;
22: import java.util.HashSet;
23: import java.util.Set;
24:
25: /**
26: * {@link CompilerAdapter} that loads tools from the tools realm.
27: *
28: * <p>
29: * The default adapter in Ant assumes that tools.jar is in the current classloader,
30: * which is not the case here.
31: *
32: * @author Kohsuke Kawaguchi
33: */
34: abstract class JDKToolAdapter extends DefaultCompilerAdapter {
35: /**
36: * Run the compilation.
37: *
38: * @exception BuildException if the compilation has problems.
39: */
40: public boolean execute() throws BuildException {
41: Commandline cmd = setupModernJavacCommand();
42:
43: try {
44: int result = (Integer) getMain().invoke(null, (Object)cmd.getArguments());
45:• return result == 0;
46: } catch (Exception ex) {
47: throw new BuildException("Error compiling code", ex);
48: }
49: }
50:
51: private Method getMain() {
52: try {
53: Class<?> clazz = World.tool.getClassLoader()
54: .loadClass(getMainClass());
55:
56:• if(reported.add(clazz))
57: // report where we loaded tools to assist classpath related issues
58: System.out.println("Using "+getToolName()+" from "+ Which.which(clazz));
59:
60: return clazz.getMethod(getMainMethod(), String[].class);
61: } catch( Throwable e ) {
62: e.printStackTrace();
63: throw new AssertionError("Unable to locate "+getToolName()+". Maybe you are using JRE?");
64: }
65:
66: }
67:
68: protected abstract String getMainMethod();
69: protected abstract String getMainClass();
70: protected abstract String getToolName();
71:
72: private static Set<Class> reported = Collections.synchronizedSet(new HashSet<Class>());
73: }