14
14
* Bachmann electrontic GmbH - 510425 parallel mode requires threadCount>1 or useUnlimitedThreads=true
15
15
* Christoph Läubrich - [Bug 529929] improve error message in case of failures
16
16
* - [Bug 572420] Tycho-Surefire should be executable for eclipse-plugin package type
17
+ * - [Issue 790] Support printing of bundle wirings in tycho-surefire-plugin
18
+ * - [Issue 849] JAVA_HOME check is not OS independent
19
+ * - [Issue 790] Support printing of bundle wirings in tycho-surefire-plugin
17
20
******************************************************************************/
18
21
package org .eclipse .tycho .surefire ;
19
22
20
23
import java .io .BufferedOutputStream ;
21
24
import java .io .File ;
25
+ import java .io .FileFilter ;
22
26
import java .io .FileOutputStream ;
23
27
import java .io .IOException ;
24
28
import java .net .MalformedURLException ;
34
38
import java .util .Set ;
35
39
import java .util .StringJoiner ;
36
40
41
+ import org .apache .commons .io .FilenameUtils ;
37
42
import org .apache .maven .artifact .Artifact ;
38
43
import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
39
44
import org .apache .maven .artifact .resolver .ArtifactResolutionRequest ;
102
107
103
108
public abstract class AbstractTestMojo extends AbstractMojo {
104
109
110
+ private static final String SYSTEM_JDK = "jdk" ;
111
+
105
112
private static String [] UNIX_SIGNAL_NAMES = { "not a signal" , // padding, signals start with 1
106
113
"SIGHUP" , "SIGINT" , "SIGQUIT" , "SIGILL" , "SIGTRAP" , "SIGABRT" , "SIGBUS" , "SIGFPE" , "SIGKILL" , "SIGUSR1" ,
107
114
"SIGSEGV" , "SIGUSR2" , "SIGPIPE" , "SIGALRM" , "SIGTERM" , "SIGSTKFLT" , "SIGCHLD" , "SIGCONT" , "SIGSTOP" ,
@@ -110,6 +117,8 @@ public abstract class AbstractTestMojo extends AbstractMojo {
110
117
111
118
private static final Object LOCK = new Object ();
112
119
120
+ private static final String [] JAVA_EXECUTABLES = { "java" , "java.exe" };
121
+
113
122
/**
114
123
* Root directory (<a href=
115
124
* "https://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html#osgiinstallarea"
@@ -1127,7 +1136,7 @@ private String decodeReturnCode(int result) {
1127
1136
protected Toolchain getToolchain () throws MojoExecutionException {
1128
1137
if (JDKUsage .SYSTEM .equals (useJDK )) {
1129
1138
if (toolchainManager != null ) {
1130
- return toolchainManager .getToolchainFromBuildContext ("jdk" , session );
1139
+ return toolchainManager .getToolchainFromBuildContext (SYSTEM_JDK , session );
1131
1140
}
1132
1141
return null ;
1133
1142
}
@@ -1209,16 +1218,44 @@ protected String getJavaExecutable() throws MojoExecutionException {
1209
1218
}
1210
1219
String javaHome = System .getenv ("JAVA_HOME" );
1211
1220
if (javaHome != null && !javaHome .isBlank ()) {
1212
- File file = new File (javaHome , "bin/java" );
1213
- if (file .exists ()) {
1214
- getLog ().info ("Could not find the Toolchain, using java from JAVA_HOME instead" );
1215
- return file .getAbsolutePath ();
1221
+ File java = getJavaFromJavaHome (javaHome );
1222
+ if (java != null ) {
1223
+ getLog ().info ("Could not find a java toolchain of type " + SYSTEM_JDK
1224
+ + ", using java from JAVA_HOME instead (" + java .getAbsolutePath () + ")" );
1225
+ return java .getAbsolutePath ();
1216
1226
}
1227
+ getLog ().info ("Could not find a java toolchain of type " + SYSTEM_JDK
1228
+ + " and JAVA_HOME seem to not point to a valid location, trying java from PATH instead (current JAVA_HOME="
1229
+ + javaHome + ")" );
1230
+ } else {
1231
+ getLog ().info ("Could not find a java toolchain of type " + SYSTEM_JDK
1232
+ + " and JAVA_HOME is not set, trying java from PATH instead" );
1217
1233
}
1218
- getLog ().info ("Could not find the Toolchain nor JAVA_HOME, trying java from PATH instead" );
1219
1234
return "java" ;
1220
1235
}
1221
1236
1237
+ private File getJavaFromJavaHome (String javaHome ) {
1238
+ File javaBin = new File (javaHome , "bin" );
1239
+ for (String executable : JAVA_EXECUTABLES ) {
1240
+ File java = new File (javaBin , executable );
1241
+ if (java .isFile ()) {
1242
+ return java ;
1243
+ }
1244
+ }
1245
+ //last resort just in case other extension or case-sensitive file-system...
1246
+ File [] listFiles = javaBin .listFiles (new FileFilter () {
1247
+
1248
+ @ Override
1249
+ public boolean accept (File pathname ) {
1250
+ return pathname .isFile () && FilenameUtils .getBaseName (pathname .getName ().toLowerCase ()).equals ("java" );
1251
+ }
1252
+ });
1253
+ if (listFiles != null && listFiles .length > 0 ) {
1254
+ return listFiles [0 ];
1255
+ }
1256
+ return null ;
1257
+ }
1258
+
1222
1259
private Map <String , String > getMergedSystemProperties () {
1223
1260
Map <String , String > result = new LinkedHashMap <>();
1224
1261
// bug 415489: use osgi.clean=true by default
0 commit comments