Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NETBEANS-2832] Added input reading to Gradle projects. #1461

Merged
merged 1 commit into from Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -48,6 +48,7 @@ class NetBeansRunSinglePlugin implements Plugin<Project> {
def runSingle = project.tasks.create(RUN_SINGLE_TASK, JavaExec) {
main = project.getProperty(RUN_SINGLE_MAIN)
classpath = project.sourceSets.main.runtimeClasspath
standardInput = System.in

if (project.hasProperty(RUN_SINGLE_ARGS)) {
args = project.getProperty(RUN_SINGLE_ARGS).tokenize(' ')
Expand Down
Expand Up @@ -29,7 +29,9 @@
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Collection;
import java.util.logging.Level;
Expand All @@ -55,6 +57,7 @@
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.util.Pair;
import org.openide.util.io.ReaderInputStream;
import org.openide.windows.IOColorPrint;
import org.openide.windows.IOColors;
import org.openide.windows.InputOutput;
Expand All @@ -69,6 +72,7 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
private static final Logger LOGGER = Logger.getLogger(GradleDaemonExecutor.class.getName());

private final ProgressHandle handle;
private InputStream inStream;
private OutputStream outStream;
private OutputStream errStream;
private boolean cancelling;
Expand Down Expand Up @@ -152,6 +156,12 @@ public void run() {

outStream = new EscapeProcessingOutputStream(new GradlePlainEscapeProcessor(io, config, false));
errStream = new EscapeProcessingOutputStream(new GradlePlainEscapeProcessor(io, config, true));
try {
inStream = new ReaderInputStream(io.getIn(), "UTF-8"); //NOI18N
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the JVM running the daemon configured to used UTF-8 as default encoding? I know that the java ecosystem is moving to UTF-8 as the default encoding, but is this a safe assumption here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the daemon runs specifically set with UTF-8 encoding. However the IDE might run in a different one and that's the encoding we are reading from.
I'd let this as it is to see how it work for the users before start to over-engineer the thing. We might have a problem with EOL as well, as IDE uses always LF, however the platform might use CRLF on the Gradle side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the IDE should not be the problem. The input comes directly from Swing, so it is (module bugs) clean, then it is passed through a UTF-8 writer, that converts the string to a byte sequence. So if the target is clean, this should be stable (yeah famous last words). I would also let it stay as is.

buildLauncher.setStandardInput(inStream);
} catch (IOException ex) {
// Unlikely but worst case we do not have the input set.
}
buildLauncher.setStandardOutput(outStream);
buildLauncher.setStandardError(errStream);
buildLauncher.addProgressListener((ProgressEvent pe) -> {
Expand Down Expand Up @@ -182,7 +192,7 @@ public void run() {
if (pconn != null) {
pconn.close();
}
closeOutErr();
closeInOutErr();
checkForExternalModifications();
handle.finish();
markFreeTab();
Expand Down Expand Up @@ -247,7 +257,8 @@ && new GradleFiles(gbp.getProjectDir(), true).hasWrapper()
}
}

private synchronized void closeOutErr() {
private synchronized void closeInOutErr() {
if (inStream != null) try {inStream.close();} catch (IOException ex) {}
if (outStream != null) try {outStream.close();} catch (IOException ex) {}
if (errStream != null) try {errStream.close();} catch (IOException ex) {}
}
Expand All @@ -267,7 +278,7 @@ public boolean cancel() {
handle.switchToIndeterminate();
handle.setDisplayName(Bundle.LBL_ABORTING_BUILD());
// Closing out and err streams to prevent ambigous output NETBEANS-2038
closeOutErr();
closeInOutErr();
cancelling = true;
cancelTokenSource.cancel();
}
Expand Down