changeset: 153907:3b9a2e982457 tag: tip user: Vladimir Voskresensky date: Thu Nov 19 20:42:21 2009 +0300 summary: fixed IZ#177016: Can't build a project with localized path with smart secure copy diff --git a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/FileData.java b/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/FileData.java --- a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/FileData.java +++ b/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/FileData.java @@ -81,6 +81,12 @@ this.state = mode; this.timestamp = timestamp; } + + @Override + public String toString() { + return state.toString() + timestamp; + } + } public FileData(File privProjectStorageDir, ExecutionEnvironment executionEnvironment) { diff --git a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsLocalController.java b/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsLocalController.java --- a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsLocalController.java +++ b/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsLocalController.java @@ -4,10 +4,6 @@ import java.io.File; import java.io.FileFilter; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; @@ -28,7 +24,7 @@ class RfsLocalController implements Runnable { private final BufferedReader requestReader; - private final PrintStream responseStream; + private final PrintWriter responseStream; private final String remoteDir; private final File[] files; private final ExecutionEnvironment execEnv; @@ -42,14 +38,14 @@ } public RfsLocalController(ExecutionEnvironment executionEnvironment, File[] files, String remoteDir, - InputStream requestStream, OutputStream responseStream, PrintWriter err, + BufferedReader requestStreamReader, PrintWriter responseStreamWriter, PrintWriter err, FileData fileData) { super(); this.execEnv = executionEnvironment; this.files = files; this.remoteDir = remoteDir; - this.requestReader = new BufferedReader(new InputStreamReader(requestStream)); - this.responseStream = new PrintStream(responseStream); + this.requestReader = requestStreamReader; + this.responseStream = responseStreamWriter; this.err = err; this.fileData = fileData; } @@ -202,10 +198,8 @@ /** * Feeds remote controller with the list of files and their lengths - * @param rcOutputStream */ - void feedFiles(OutputStream rcOutputStream, SharabilityFilter filter) { - PrintWriter writer = new PrintWriter(rcOutputStream); + void feedFiles(SharabilityFilter filter) { List filesToFeed = new ArrayList(512); Set externalDirs = new HashSet(); RemotePathMap mapper = RemotePathMap.getPathMap(execEnv); @@ -245,17 +239,17 @@ } }); for (FileGatheringInfo info : filesToFeed) { - sendFileInitRequest(writer, info.file, info.relPath); + sendFileInitRequest(info.file, info.relPath); } - writer.printf("\n"); // NOI18N - writer.flush(); + responseStream.printf("\n"); // NOI18N + responseStream.flush(); fileData.store(); } - private void sendFileInitRequest(PrintWriter writer, File file, String relPath) { + private void sendFileInitRequest(File file, String relPath) { if (file.isDirectory()) { - writer.printf("D %s\n", relPath); //NOI18N - writer.flush(); //TODO: remove? + responseStream.printf("D %s\n", relPath); //NOI18N + responseStream.flush(); //TODO: remove? } else { FileData.FileInfo info = fileData.getFileInfo(file); FileState newState; @@ -280,8 +274,8 @@ } CndUtils.assertTrue(newState == FileState.INITIAL || newState == FileState.COPIED || newState == FileState.TOUCHED, "State shouldn't be " + newState); //NOI18N - writer.printf("%c %d %s\n", newState.id, file.length(), relPath); // NOI18N - writer.flush(); //TODO: remove? + responseStream.printf("%c %d %s\n", newState.id, file.length(), relPath); // NOI18N + responseStream.flush(); //TODO: remove? fileData.setState(file, newState); } } diff --git a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsSyncWorker.java b/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsSyncWorker.java --- a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsSyncWorker.java +++ b/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsSyncWorker.java @@ -46,7 +46,9 @@ import java.io.InputStreamReader; import java.io.InterruptedIOException; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.util.Map; import java.util.MissingResourceException; @@ -138,6 +140,33 @@ } } + private final static String remoteCharSet = System.getProperty("cnd.remote.charset"); // NOI18N + + private BufferedReader getReader(final InputStream is) { + final String charSet = remoteCharSet == null ? "UTF-8" : remoteCharSet; // NOI18N + // set charset + if (java.nio.charset.Charset.isSupported(charSet)) { + try { + return new BufferedReader(new InputStreamReader(is, charSet)); + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } + } + return new BufferedReader(new InputStreamReader(is)); + } + + private PrintWriter getWriter(final OutputStream os) { + final String charSet = remoteCharSet == null ? "UTF-8" : remoteCharSet; // NOI18N + // set charset + if (java.nio.charset.Charset.isSupported(charSet)) { + try { + return new PrintWriter(new OutputStreamWriter(os, charSet)); + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } + } + return new PrintWriter(os); + } private void startupImpl(Map env2add) throws IOException, InterruptedException, ExecutionException, RemoteException { String remoteControllerPath; @@ -162,14 +191,16 @@ final InputStream rcInputStream = remoteControllerProcess.getInputStream(); final OutputStream rcOutputStream = remoteControllerProcess.getOutputStream(); + final BufferedReader rcInputStreamReader = getReader(rcInputStream); + final PrintWriter rcOutputStreamWriter = getWriter(rcOutputStream); localController = new RfsLocalController( - executionEnvironment, files, remoteDir, rcInputStream, - rcOutputStream, err, new FileData(privProjectStorageDir, executionEnvironment)); + executionEnvironment, files, remoteDir, rcInputStreamReader, + rcOutputStreamWriter, err, new FileData(privProjectStorageDir, executionEnvironment)); - localController.feedFiles(rcOutputStream, new SharabilityFilter()); + localController.feedFiles(new SharabilityFilter()); // read port - String line = new BufferedReader(new InputStreamReader(rcInputStream)).readLine(); + String line = rcInputStreamReader.readLine(); String port; if (line != null && line.startsWith("PORT ")) { // NOI18N port = line.substring(5); diff --git a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/RemoteNativeProcess.java b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/RemoteNativeProcess.java --- a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/RemoteNativeProcess.java +++ b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/RemoteNativeProcess.java @@ -4,6 +4,7 @@ */ package org.netbeans.modules.nativeexecution; +import java.io.UnsupportedEncodingException; import org.netbeans.modules.nativeexecution.api.util.ConnectionManager; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSchException; @@ -20,6 +21,7 @@ import org.netbeans.modules.nativeexecution.support.Logger; import org.netbeans.modules.nativeexecution.api.util.MacroMap; import org.netbeans.modules.nativeexecution.api.util.UnbufferSupport; +import org.openide.util.Exceptions; public final class RemoteNativeProcess extends AbstractNativeProcess { @@ -72,7 +74,7 @@ final String workingDirectory = info.getWorkingDirectory(true); if (workingDirectory != null) { - streams.in.write(("cd \"" + workingDirectory + "\"\n").getBytes()); // NOI18N + streams.in.write(EnvWriter.getBytesWithRemoteCharset("cd \"" + workingDirectory + "\"\n")); // NOI18N streams.in.flush(); } @@ -84,7 +86,7 @@ streams.in.write("trap 'ITS_TIME_TO_START=1' CONT\n".getBytes()); // NOI18N streams.in.write("while [ -z \"$ITS_TIME_TO_START\" ]; do sleep 1; done\n".getBytes()); // NOI18N } - streams.in.write(("exec " + commandLine + "\n").getBytes()); // NOI18N + streams.in.write(EnvWriter.getBytesWithRemoteCharset("exec " + commandLine + "\n")); // NOI18N streams.in.flush(); readPID(streams.out); diff --git a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvReader.java b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvReader.java --- a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvReader.java +++ b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvReader.java @@ -41,9 +41,11 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Callable; +import org.openide.util.Exceptions; public final class EnvReader implements Callable> { @@ -52,10 +54,23 @@ public EnvReader(final InputStream is) { this.is = is; } + + private BufferedReader getReader(final InputStream is) { + final String charSet = EnvWriter.getCharSet(); // NOI18N + // set charset + if (java.nio.charset.Charset.isSupported(charSet)) { + try { + return new BufferedReader(new InputStreamReader(is, charSet)); + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } + } + return new BufferedReader(new InputStreamReader(is)); + } public Map call() throws Exception { Map result = new HashMap(); - BufferedReader br = new BufferedReader(new InputStreamReader(is)); + BufferedReader br = getReader(is); String s = null; StringBuilder buffer = new StringBuilder(); diff --git a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvWriter.java b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvWriter.java --- a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvWriter.java +++ b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/EnvWriter.java @@ -41,8 +41,10 @@ import org.netbeans.modules.nativeexecution.api.util.MacroMap; import java.io.IOException; import java.io.OutputStream; +import java.io.UnsupportedEncodingException; import java.util.Map.Entry; import java.util.regex.Pattern; +import org.openide.util.Exceptions; /** * @@ -54,6 +56,23 @@ public EnvWriter(OutputStream os) { this.os = os; + } + + private final static String remoteCharSet = System.getProperty("cnd.remote.charset"); // NOI18N + /*package*/static String getCharSet() { + return remoteCharSet == null ? "UTF-8" : remoteCharSet; // NOI18N + } + + public static byte[] getBytesWithRemoteCharset(String str) { + final String charSet = getCharSet(); + if (java.nio.charset.Charset.isSupported(charSet)) { + try { + return str.getBytes(charSet); + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } + } + return str.getBytes(); } public void write(final MacroMap env) throws IOException { @@ -73,7 +92,7 @@ value = entry.getValue(); if (value != null) { - os.write((name + "=\"" + value + "\" && export " + name + "\n").getBytes()); // NOI18N + os.write(getBytesWithRemoteCharset(name + "=\"" + value + "\" && export " + name + "\n")); // NOI18N os.flush(); } }