mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8048146: sjavac uses unexpected exit code of -1
Changed exit codes for sjavac Reviewed-by: jlahoda
This commit is contained in:
parent
c6e7003173
commit
e85033c628
16 changed files with 84 additions and 76 deletions
|
@ -26,8 +26,6 @@
|
||||||
package com.sun.tools.sjavac;
|
package com.sun.tools.sjavac;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -42,9 +40,8 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.comp.CompilationService;
|
import com.sun.tools.sjavac.comp.CompilationService;
|
||||||
import com.sun.tools.sjavac.options.Options;
|
import com.sun.tools.sjavac.options.Options;
|
||||||
import com.sun.tools.sjavac.pubapi.PubApi;
|
import com.sun.tools.sjavac.pubapi.PubApi;
|
||||||
|
@ -283,7 +280,7 @@ public class CompileJavaPackages implements Transformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the return values.
|
// Check the return values.
|
||||||
if (subResult.returnCode != 0) {
|
if (subResult.result != Result.OK) {
|
||||||
rc = false;
|
rc = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ package com.sun.tools.sjavac.client;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main;
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.AutoFlushWriter;
|
import com.sun.tools.sjavac.AutoFlushWriter;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
import com.sun.tools.sjavac.Util;
|
import com.sun.tools.sjavac.Util;
|
||||||
|
@ -58,7 +60,7 @@ public class ClientMain {
|
||||||
options = Options.parseArgs(args);
|
options = Options.parseArgs(args);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Log.error(e.getMessage());
|
Log.error(e.getMessage());
|
||||||
return -1;
|
return Result.CMDERR.exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.setLogLevel(options.getLogLevel());
|
Log.setLogLevel(options.getLogLevel());
|
||||||
|
@ -73,13 +75,13 @@ public class ClientMain {
|
||||||
Sjavac sjavac = useServer ? new SjavacClient(options) : new SjavacImpl();
|
Sjavac sjavac = useServer ? new SjavacClient(options) : new SjavacImpl();
|
||||||
|
|
||||||
// Perform compilation
|
// Perform compilation
|
||||||
int rc = sjavac.compile(args);
|
Result result = sjavac.compile(args);
|
||||||
|
|
||||||
// If sjavac is running in the foreground we should shut it down at this point
|
// If sjavac is running in the foreground we should shut it down at this point
|
||||||
if (!useServer) {
|
if (!useServer) {
|
||||||
sjavac.shutdown();
|
sjavac.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return result.exitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,23 +26,20 @@
|
||||||
package com.sun.tools.sjavac.client;
|
package com.sun.tools.sjavac.client;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main;
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
import com.sun.tools.sjavac.Util;
|
import com.sun.tools.sjavac.Util;
|
||||||
import com.sun.tools.sjavac.options.OptionHelper;
|
import com.sun.tools.sjavac.options.OptionHelper;
|
||||||
|
@ -116,8 +113,8 @@ public class SjavacClient implements Sjavac {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compile(String[] args) {
|
public Result compile(String[] args) {
|
||||||
int result = -1;
|
Result result = null;
|
||||||
try (Socket socket = tryConnect()) {
|
try (Socket socket = tryConnect()) {
|
||||||
PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
|
PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
@ -150,22 +147,28 @@ public class SjavacClient implements Sjavac {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.equals(SjavacServer.LINE_TYPE_RC)) {
|
if (type.equals(SjavacServer.LINE_TYPE_RC)) {
|
||||||
result = Integer.parseInt(content);
|
result = Main.Result.valueOf(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PortFileInaccessibleException e) {
|
} catch (PortFileInaccessibleException e) {
|
||||||
Log.error("Port file inaccessible.");
|
Log.error("Port file inaccessible.");
|
||||||
result = CompilationSubResult.ERROR_FATAL;
|
result = Result.ERROR;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.error("IOException caught during compilation: " + ioe.getMessage());
|
Log.error("IOException caught during compilation: " + ioe.getMessage());
|
||||||
Log.debug(ioe);
|
Log.debug(ioe);
|
||||||
result = CompilationSubResult.ERROR_FATAL;
|
result = Result.ERROR;
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
Thread.currentThread().interrupt(); // Restore interrupt
|
Thread.currentThread().interrupt(); // Restore interrupt
|
||||||
Log.error("Compilation interrupted.");
|
Log.error("Compilation interrupted.");
|
||||||
Log.debug(ie);
|
Log.debug(ie);
|
||||||
result = CompilationSubResult.ERROR_FATAL;
|
result = Result.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
// No LINE_TYPE_RC was found.
|
||||||
|
result = Result.ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,8 @@ import javax.tools.ToolProvider;
|
||||||
|
|
||||||
import com.sun.tools.javac.api.JavacTaskImpl;
|
import com.sun.tools.javac.api.JavacTaskImpl;
|
||||||
import com.sun.tools.javac.api.JavacTool;
|
import com.sun.tools.javac.api.JavacTool;
|
||||||
|
import com.sun.tools.javac.main.Main;
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.javac.util.Context;
|
import com.sun.tools.javac.util.Context;
|
||||||
import com.sun.tools.javac.util.Dependencies;
|
import com.sun.tools.javac.util.Dependencies;
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
|
@ -80,7 +82,7 @@ public class CompilationService {
|
||||||
Dependencies.GraphDependencies.preRegister(context);
|
Dependencies.GraphDependencies.preRegister(context);
|
||||||
|
|
||||||
// Now setup the actual compilation
|
// Now setup the actual compilation
|
||||||
CompilationSubResult compilationResult = new CompilationSubResult(0);
|
CompilationSubResult compilationResult = new CompilationSubResult(Result.OK);
|
||||||
|
|
||||||
// First deal with explicit source files on cmdline and in at file
|
// First deal with explicit source files on cmdline and in at file
|
||||||
ListBuffer<JavaFileObject> explicitJFOs = new ListBuffer<>();
|
ListBuffer<JavaFileObject> explicitJFOs = new ListBuffer<>();
|
||||||
|
@ -97,7 +99,7 @@ public class CompilationService {
|
||||||
|
|
||||||
// Create a log to capture compiler output
|
// Create a log to capture compiler output
|
||||||
StringWriter stderrLog = new StringWriter();
|
StringWriter stderrLog = new StringWriter();
|
||||||
com.sun.tools.javac.main.Main.Result rc = com.sun.tools.javac.main.Main.Result.OK;
|
Result result;
|
||||||
PublicApiCollector pubApiCollector = new PublicApiCollector(context, explicitJFOs);
|
PublicApiCollector pubApiCollector = new PublicApiCollector(context, explicitJFOs);
|
||||||
PathAndPackageVerifier papVerifier = new PathAndPackageVerifier();
|
PathAndPackageVerifier papVerifier = new PathAndPackageVerifier();
|
||||||
NewDependencyCollector depsCollector = new NewDependencyCollector(context, explicitJFOs);
|
NewDependencyCollector depsCollector = new NewDependencyCollector(context, explicitJFOs);
|
||||||
|
@ -120,20 +122,23 @@ public class CompilationService {
|
||||||
task.addTaskListener(pubApiCollector);
|
task.addTaskListener(pubApiCollector);
|
||||||
task.addTaskListener(papVerifier);
|
task.addTaskListener(papVerifier);
|
||||||
logJavacInvocation(args);
|
logJavacInvocation(args);
|
||||||
rc = task.doCall();
|
result = task.doCall();
|
||||||
Log.debug("javac returned with code " + rc);
|
Log.debug("javac result: " + result);
|
||||||
sfm.flush();
|
sfm.flush();
|
||||||
|
} else {
|
||||||
|
result = Result.ERROR;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.error(Util.getStackTrace(e));
|
Log.error(Util.getStackTrace(e));
|
||||||
stderrLog.append(Util.getStackTrace(e));
|
stderrLog.append(Util.getStackTrace(e));
|
||||||
rc = com.sun.tools.javac.main.Main.Result.ERROR;
|
result = Result.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
compilationResult.packageArtifacts = sfm.getPackageArtifacts();
|
compilationResult.packageArtifacts = sfm.getPackageArtifacts();
|
||||||
|
|
||||||
if (papVerifier.errorsDiscovered())
|
if (papVerifier.errorsDiscovered()) {
|
||||||
rc = com.sun.tools.javac.main.Main.Result.ERROR;
|
result = Result.ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
compilationResult.packageDependencies = depsCollector.getDependencies(false);
|
compilationResult.packageDependencies = depsCollector.getDependencies(false);
|
||||||
compilationResult.packageCpDependencies = depsCollector.getDependencies(true);
|
compilationResult.packageCpDependencies = depsCollector.getDependencies(true);
|
||||||
|
@ -141,7 +146,7 @@ public class CompilationService {
|
||||||
compilationResult.packagePubapis = pubApiCollector.getPubApis(true);
|
compilationResult.packagePubapis = pubApiCollector.getPubApis(true);
|
||||||
compilationResult.dependencyPubapis = pubApiCollector.getPubApis(false);
|
compilationResult.dependencyPubapis = pubApiCollector.getPubApis(false);
|
||||||
compilationResult.stderr = stderrLog.toString();
|
compilationResult.stderr = stderrLog.toString();
|
||||||
compilationResult.returnCode = rc.exitCode;
|
compilationResult.result = result;
|
||||||
|
|
||||||
return compilationResult;
|
return compilationResult;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package com.sun.tools.sjavac.comp;
|
package com.sun.tools.sjavac.comp;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
import com.sun.tools.sjavac.server.Sjavac;
|
import com.sun.tools.sjavac.server.Sjavac;
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ public class PooledSjavac implements Sjavac {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compile(String[] args) {
|
public Result compile(String[] args) {
|
||||||
Log log = Log.get();
|
Log log = Log.get();
|
||||||
try {
|
try {
|
||||||
return pool.submit(() -> {
|
return pool.submit(() -> {
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.sun.tools.javac.file.JavacFileManager;
|
import com.sun.tools.javac.file.JavacFileManager;
|
||||||
import com.sun.tools.javac.main.Main;
|
import com.sun.tools.javac.main.Main;
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.javac.util.Context;
|
import com.sun.tools.javac.util.Context;
|
||||||
import com.sun.tools.sjavac.JavacState;
|
import com.sun.tools.sjavac.JavacState;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
|
@ -69,36 +70,36 @@ import javax.tools.JavaFileManager;
|
||||||
public class SjavacImpl implements Sjavac {
|
public class SjavacImpl implements Sjavac {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compile(String[] args) {
|
public Result compile(String[] args) {
|
||||||
Options options;
|
Options options;
|
||||||
try {
|
try {
|
||||||
options = Options.parseArgs(args);
|
options = Options.parseArgs(args);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Log.error(e.getMessage());
|
Log.error(e.getMessage());
|
||||||
return RC_FATAL;
|
return Result.CMDERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateOptions(options))
|
if (!validateOptions(options))
|
||||||
return RC_FATAL;
|
return Result.CMDERR;
|
||||||
|
|
||||||
if (srcDstOverlap(options.getSources(), options.getDestDir())) {
|
if (srcDstOverlap(options.getSources(), options.getDestDir())) {
|
||||||
return RC_FATAL;
|
return Result.CMDERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!createIfMissing(options.getDestDir()))
|
if (!createIfMissing(options.getDestDir()))
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
|
|
||||||
Path stateDir = options.getStateDir();
|
Path stateDir = options.getStateDir();
|
||||||
if (stateDir != null && !createIfMissing(options.getStateDir()))
|
if (stateDir != null && !createIfMissing(options.getStateDir()))
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
|
|
||||||
Path gensrc = options.getGenSrcDir();
|
Path gensrc = options.getGenSrcDir();
|
||||||
if (gensrc != null && !createIfMissing(gensrc))
|
if (gensrc != null && !createIfMissing(gensrc))
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
|
|
||||||
Path hdrdir = options.getHeaderDir();
|
Path hdrdir = options.getHeaderDir();
|
||||||
if (hdrdir != null && !createIfMissing(hdrdir))
|
if (hdrdir != null && !createIfMissing(hdrdir))
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
|
|
||||||
if (stateDir == null) {
|
if (stateDir == null) {
|
||||||
// Prepare context. Direct logging to our byte array stream.
|
// Prepare context. Direct logging to our byte array stream.
|
||||||
|
@ -113,7 +114,7 @@ public class SjavacImpl implements Sjavac {
|
||||||
.filter(arg -> !arg.startsWith(Option.SERVER.arg))
|
.filter(arg -> !arg.startsWith(Option.SERVER.arg))
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
// Compile
|
// Compile
|
||||||
Main.Result result = new Main("javac", printWriter).compile(passThroughArgs, context);
|
Result result = new Main("javac", printWriter).compile(passThroughArgs, context);
|
||||||
|
|
||||||
// Process compiler output (which is always errors)
|
// Process compiler output (which is always errors)
|
||||||
printWriter.flush();
|
printWriter.flush();
|
||||||
|
@ -128,7 +129,7 @@ public class SjavacImpl implements Sjavac {
|
||||||
throw new UncheckedIOException(es);
|
throw new UncheckedIOException(es);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.exitCode;
|
return result;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Load the prev build state database.
|
// Load the prev build state database.
|
||||||
|
@ -166,7 +167,7 @@ public class SjavacImpl implements Sjavac {
|
||||||
|
|
||||||
if (sources.isEmpty()) {
|
if (sources.isEmpty()) {
|
||||||
Log.error("Found nothing to compile!");
|
Log.error("Found nothing to compile!");
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,15 +293,15 @@ public class SjavacImpl implements Sjavac {
|
||||||
javac_state.removeSuperfluousArtifacts(recently_compiled);
|
javac_state.removeSuperfluousArtifacts(recently_compiled);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc[0] ? RC_OK : RC_FATAL;
|
return rc[0] ? Result.OK : Result.ERROR;
|
||||||
} catch (ProblemException e) {
|
} catch (ProblemException e) {
|
||||||
// For instance make file list mismatch.
|
// For instance make file list mismatch.
|
||||||
Log.error(e.getMessage());
|
Log.error(e.getMessage());
|
||||||
Log.debug(e);
|
Log.debug(e);
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.error(e);
|
Log.error(e);
|
||||||
return RC_FATAL;
|
return Result.ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -31,6 +31,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.pubapi.PubApi;
|
import com.sun.tools.sjavac.pubapi.PubApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,10 +45,7 @@ public class CompilationSubResult implements Serializable {
|
||||||
|
|
||||||
static final long serialVersionUID = 46739181113L;
|
static final long serialVersionUID = 46739181113L;
|
||||||
|
|
||||||
// Return code constants
|
public Result result;
|
||||||
public final static int ERROR_FATAL = -1;
|
|
||||||
|
|
||||||
public int returnCode;
|
|
||||||
public Map<String, Set<URI>> packageArtifacts = new HashMap<>();
|
public Map<String, Set<URI>> packageArtifacts = new HashMap<>();
|
||||||
public Map<String, Map<String, Set<String>>> packageDependencies = new HashMap<>();
|
public Map<String, Map<String, Set<String>>> packageDependencies = new HashMap<>();
|
||||||
public Map<String, Map<String, Set<String>>> packageCpDependencies = new HashMap<>();
|
public Map<String, Map<String, Set<String>>> packageCpDependencies = new HashMap<>();
|
||||||
|
@ -56,11 +54,11 @@ public class CompilationSubResult implements Serializable {
|
||||||
public String stdout = "";
|
public String stdout = "";
|
||||||
public String stderr = "";
|
public String stderr = "";
|
||||||
|
|
||||||
public CompilationSubResult(int returnCode) {
|
public CompilationSubResult(Result result) {
|
||||||
this.returnCode = returnCode;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReturnCode(int returnCode) {
|
public void setResult(Result result) {
|
||||||
this.returnCode = returnCode;
|
this.result = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,9 @@
|
||||||
|
|
||||||
package com.sun.tools.sjavac.server;
|
package com.sun.tools.sjavac.server;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
@ -66,7 +64,7 @@ public class IdleResetSjavac implements Sjavac {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compile(String[] args) {
|
public Result compile(String[] args) {
|
||||||
startCall();
|
startCall();
|
||||||
try {
|
try {
|
||||||
return delegate.compile(args);
|
return delegate.compile(args);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package com.sun.tools.sjavac.server;
|
package com.sun.tools.sjavac.server;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
import com.sun.tools.sjavac.Util;
|
import com.sun.tools.sjavac.Util;
|
||||||
|
|
||||||
|
@ -100,10 +101,10 @@ public class RequestHandler extends Thread {
|
||||||
checkInternalErrorLog();
|
checkInternalErrorLog();
|
||||||
|
|
||||||
// Perform compilation
|
// Perform compilation
|
||||||
int rc = sjavac.compile(args);
|
Main.Result rc = sjavac.compile(args);
|
||||||
|
|
||||||
// Send return code back to client
|
// Send return code back to client
|
||||||
out.println(LINE_TYPE_RC + ":" + rc);
|
out.println(LINE_TYPE_RC + ":" + rc.name());
|
||||||
|
|
||||||
// Check for internal errors again.
|
// Check for internal errors again.
|
||||||
checkInternalErrorLog();
|
checkInternalErrorLog();
|
||||||
|
|
|
@ -32,6 +32,8 @@ import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.Thread.UncaughtExceptionHandler;
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main;
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
import com.sun.tools.sjavac.Log.Level;
|
import com.sun.tools.sjavac.Log.Level;
|
||||||
import com.sun.tools.sjavac.server.log.LazyInitFileLog;
|
import com.sun.tools.sjavac.server.log.LazyInitFileLog;
|
||||||
|
@ -75,7 +77,7 @@ public class ServerMain {
|
||||||
// Any options other than --startserver?
|
// Any options other than --startserver?
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
Log.error("When spawning a background server, only a single --startserver argument is allowed.");
|
Log.error("When spawning a background server, only a single --startserver argument is allowed.");
|
||||||
return 1;
|
return Result.CMDERR.exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exitCode;
|
int exitCode;
|
||||||
|
@ -84,7 +86,7 @@ public class ServerMain {
|
||||||
exitCode = server.startServer();
|
exitCode = server.startServer();
|
||||||
} catch (IOException | InterruptedException ex) {
|
} catch (IOException | InterruptedException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
exitCode = -1;
|
exitCode = Result.ERROR.exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
package com.sun.tools.sjavac.server;
|
package com.sun.tools.sjavac.server;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,10 +40,6 @@ import java.io.Writer;
|
||||||
* deletion without notice.</b>
|
* deletion without notice.</b>
|
||||||
*/
|
*/
|
||||||
public interface Sjavac {
|
public interface Sjavac {
|
||||||
|
Result compile(String[] args);
|
||||||
final static int RC_FATAL = -1;
|
|
||||||
final static int RC_OK = 0;
|
|
||||||
|
|
||||||
int compile(String[] args);
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main;
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.sjavac.Log;
|
||||||
import com.sun.tools.sjavac.Util;
|
import com.sun.tools.sjavac.Util;
|
||||||
import com.sun.tools.sjavac.client.PortFileInaccessibleException;
|
import com.sun.tools.sjavac.client.PortFileInaccessibleException;
|
||||||
|
@ -167,7 +169,7 @@ public class SjavacServer implements Terminable {
|
||||||
if (portFile.containsPortInfo()) {
|
if (portFile.containsPortInfo()) {
|
||||||
Log.debug("Javac server not started because portfile exists!");
|
Log.debug("Javac server not started because portfile exists!");
|
||||||
portFile.unlock();
|
portFile.unlock();
|
||||||
return -1;
|
return Result.ERROR.exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// .-----------. .--------. .------.
|
// .-----------. .--------. .------.
|
||||||
|
@ -221,7 +223,7 @@ public class SjavacServer implements Terminable {
|
||||||
// Shut down
|
// Shut down
|
||||||
sjavac.shutdown();
|
sjavac.shutdown();
|
||||||
|
|
||||||
return 0;
|
return Result.OK.exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
* @run main Wrapper HiddenFiles
|
* @run main Wrapper HiddenFiles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.javac.util.Assert;
|
import com.sun.tools.javac.util.Assert;
|
||||||
import com.sun.tools.sjavac.server.Sjavac;
|
import com.sun.tools.sjavac.server.Sjavac;
|
||||||
|
|
||||||
|
@ -62,6 +63,6 @@ public class HiddenFiles extends SjavacBase {
|
||||||
"-d", BIN.toString(),
|
"-d", BIN.toString(),
|
||||||
"--state-dir=" + STATE_DIR);
|
"--state-dir=" + STATE_DIR);
|
||||||
|
|
||||||
Assert.check(rc == Sjavac.RC_FATAL, "Compilation succeeded unexpectedly.");
|
Assert.check(rc == Result.ERROR.exitCode, "Compilation succeeded unexpectedly.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@
|
||||||
* @build Wrapper
|
* @build Wrapper
|
||||||
* @run main Wrapper IdleShutdown
|
* @run main Wrapper IdleShutdown
|
||||||
*/
|
*/
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.server.IdleResetSjavac;
|
import com.sun.tools.sjavac.server.IdleResetSjavac;
|
||||||
import com.sun.tools.sjavac.server.Sjavac;
|
import com.sun.tools.sjavac.server.Sjavac;
|
||||||
import com.sun.tools.sjavac.server.Terminable;
|
import com.sun.tools.sjavac.server.Terminable;
|
||||||
|
@ -103,13 +103,13 @@ public class IdleShutdown {
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int compile(String[] args) {
|
public Result compile(String[] args) {
|
||||||
// Attempt to trigger idle timeout during a call by sleeping
|
// Attempt to trigger idle timeout during a call by sleeping
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TIMEOUT_MS + 1000);
|
Thread.sleep(TIMEOUT_MS + 1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
return 0;
|
return Result.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
* @run main Wrapper IncludeExcludePatterns
|
* @run main Wrapper IncludeExcludePatterns
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.javac.util.Assert;
|
import com.sun.tools.javac.util.Assert;
|
||||||
import com.sun.tools.sjavac.server.Sjavac;
|
import com.sun.tools.sjavac.server.Sjavac;
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ public class IncludeExcludePatterns extends SjavacBase {
|
||||||
int rc = compile((Object[]) args.split(" "));
|
int rc = compile((Object[]) args.split(" "));
|
||||||
|
|
||||||
// Compilation should always pass in these tests
|
// Compilation should always pass in these tests
|
||||||
Assert.check(rc == Sjavac.RC_OK, "Compilation failed unexpectedly.");
|
Assert.check(rc == Result.OK.exitCode, "Compilation failed unexpectedly.");
|
||||||
|
|
||||||
// The resulting .class files should correspond to the visible source files
|
// The resulting .class files should correspond to the visible source files
|
||||||
Set<Path> result = allFilesInDir(BIN);
|
Set<Path> result = allFilesInDir(BIN);
|
||||||
|
|
|
@ -30,12 +30,10 @@
|
||||||
* @build Wrapper
|
* @build Wrapper
|
||||||
* @run main Wrapper PooledExecution
|
* @run main Wrapper PooledExecution
|
||||||
*/
|
*/
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import com.sun.tools.sjavac.Log;
|
import com.sun.tools.javac.main.Main.Result;
|
||||||
import com.sun.tools.sjavac.comp.PooledSjavac;
|
import com.sun.tools.sjavac.comp.PooledSjavac;
|
||||||
import com.sun.tools.sjavac.server.Sjavac;
|
import com.sun.tools.sjavac.server.Sjavac;
|
||||||
|
|
||||||
|
@ -111,7 +109,7 @@ public class PooledExecution {
|
||||||
AtomicInteger activeRequests = new AtomicInteger(0);
|
AtomicInteger activeRequests = new AtomicInteger(0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compile(String[] args) {
|
public Result compile(String[] args) {
|
||||||
leftToStart.countDown();
|
leftToStart.countDown();
|
||||||
int numActiveRequests = activeRequests.incrementAndGet();
|
int numActiveRequests = activeRequests.incrementAndGet();
|
||||||
System.out.printf("Left to start: %2d / Currently active: %2d%n",
|
System.out.printf("Left to start: %2d / Currently active: %2d%n",
|
||||||
|
@ -125,7 +123,7 @@ public class PooledExecution {
|
||||||
}
|
}
|
||||||
activeRequests.decrementAndGet();
|
activeRequests.decrementAndGet();
|
||||||
System.out.println("Task completed");
|
System.out.println("Task completed");
|
||||||
return 0;
|
return Result.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue