This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 203038
Collapse All | Expand All

(-)a/cnd.remote/src/org/netbeans/modules/cnd/remote/mapper/RemoteMirrorPathProvider.java (-3 / +11 lines)
Lines 42-52 Link Here
42
42
43
package org.netbeans.modules.cnd.remote.mapper;
43
package org.netbeans.modules.cnd.remote.mapper;
44
44
45
import java.io.IOException;
46
import java.net.ConnectException;
45
import java.text.ParseException;
47
import java.text.ParseException;
46
import org.netbeans.modules.cnd.remote.support.RemoteUtil;
47
import org.netbeans.modules.cnd.spi.remote.setup.MirrorPathProvider;
48
import org.netbeans.modules.cnd.spi.remote.setup.MirrorPathProvider;
48
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
49
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
49
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
50
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
51
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
52
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
50
import org.netbeans.modules.nativeexecution.api.util.MacroExpanderFactory;
53
import org.netbeans.modules.nativeexecution.api.util.MacroExpanderFactory;
51
import org.netbeans.modules.nativeexecution.api.util.MacroExpanderFactory.MacroExpander;
54
import org.netbeans.modules.nativeexecution.api.util.MacroExpanderFactory.MacroExpander;
52
import org.netbeans.modules.remote.spi.FileSystemCacheProvider;
55
import org.netbeans.modules.remote.spi.FileSystemCacheProvider;
Lines 70-76 Link Here
70
    }
73
    }
71
74
72
    @Override
75
    @Override
73
    public String getRemoteMirror(ExecutionEnvironment executionEnvironment) {
76
    public String getRemoteMirror(ExecutionEnvironment executionEnvironment) throws ConnectException, IOException, ConnectionManager.CancellationException {
74
        String root;
77
        String root;
75
        root = System.getProperty("cnd.remote.sync.root." + executionEnvironment.getHost()); //NOI18N
78
        root = System.getProperty("cnd.remote.sync.root." + executionEnvironment.getHost()); //NOI18N
76
        if (root != null) {
79
        if (root != null) {
Lines 80-86 Link Here
80
        if (root != null) {
83
        if (root != null) {
81
            return root;
84
            return root;
82
        }
85
        }
83
        String home = RemoteUtil.getHomeDirectory(executionEnvironment);
86
        
87
        if (!HostInfoUtils.isHostInfoAvailable(executionEnvironment)) {
88
            throw new ConnectException("No HostInfo available for " + executionEnvironment);
89
        }
90
        String home = HostInfoUtils.getHostInfo(executionEnvironment).getUserDir();
91
        
84
        if (home == null) {
92
        if (home == null) {
85
            return null;
93
            return null;
86
        }
94
        }
(-)a/cnd.remote/src/org/netbeans/modules/cnd/remote/mapper/RemotePathMap.java (-4 / +15 lines)
Lines 49-54 Link Here
49
import java.io.FileReader;
49
import java.io.FileReader;
50
import java.io.FileWriter;
50
import java.io.FileWriter;
51
import java.io.IOException;
51
import java.io.IOException;
52
import java.net.ConnectException;
52
import java.util.ArrayList;
53
import java.util.ArrayList;
53
import java.util.Collections;
54
import java.util.Collections;
54
import java.util.HashMap;
55
import java.util.HashMap;
Lines 66-72 Link Here
66
import org.netbeans.modules.cnd.utils.CndUtils;
67
import org.netbeans.modules.cnd.utils.CndUtils;
67
import org.netbeans.modules.cnd.utils.cache.CndFileUtils;
68
import org.netbeans.modules.cnd.utils.cache.CndFileUtils;
68
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
69
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
70
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
69
import org.netbeans.modules.nativeexecution.api.util.WindowsSupport;
71
import org.netbeans.modules.nativeexecution.api.util.WindowsSupport;
72
import org.openide.util.Exceptions;
70
import org.openide.util.Lookup;
73
import org.openide.util.Lookup;
71
import org.openide.util.NbPreferences;
74
import org.openide.util.NbPreferences;
72
import org.openide.util.Utilities;
75
import org.openide.util.Utilities;
Lines 576-584 Link Here
576
579
577
        private void initRemoteBase(boolean addMapping) {
580
        private void initRemoteBase(boolean addMapping) {
578
            if (remoteBase == null) {
581
            if (remoteBase == null) {
579
                remoteBase = getRemoteSyncRoot(super.execEnv);
582
                try {
580
                if (addMapping && remoteBase != null) {
583
                    remoteBase = getRemoteSyncRoot(super.execEnv);
581
                    addMappingImpl("/", remoteBase); // NOI18N
584
                    if (addMapping && remoteBase != null) {
585
                        addMappingImpl("/", remoteBase); // NOI18N
586
                    }
587
                } catch (ConnectException ex) {
588
                    ex.printStackTrace();
589
                } catch (IOException ex) {
590
                    ex.printStackTrace();
591
                } catch (CancellationException ex) {
592
                    //don;t report CancellationException
582
                }
593
                }
583
            }
594
            }
584
        }
595
        }
Lines 594-600 Link Here
594
        }
605
        }
595
    }
606
    }
596
607
597
    public static String getRemoteSyncRoot(ExecutionEnvironment executionEnvironment) {
608
    public static String getRemoteSyncRoot(ExecutionEnvironment executionEnvironment) throws ConnectException, IOException, CancellationException {
598
        for (MirrorPathProvider mpp : Lookup.getDefault().lookupAll(MirrorPathProvider.class)) {
609
        for (MirrorPathProvider mpp : Lookup.getDefault().lookupAll(MirrorPathProvider.class)) {
599
            String result = mpp.getRemoteMirror(executionEnvironment);
610
            String result = mpp.getRemoteMirror(executionEnvironment);
600
            if (result != null) {
611
            if (result != null) {
(-)a/cnd.remote/src/org/netbeans/modules/cnd/remote/support/RemoteUtil.java (-49 lines)
Lines 46-62 Link Here
46
import java.util.Map;
46
import java.util.Map;
47
import java.util.logging.Level;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
48
import java.util.logging.Logger;
49
import org.netbeans.modules.cnd.api.remote.HostInfoProvider;
50
import org.netbeans.modules.cnd.api.remote.ServerList;
49
import org.netbeans.modules.cnd.api.remote.ServerList;
51
import org.netbeans.modules.cnd.api.remote.ServerRecord;
50
import org.netbeans.modules.cnd.api.remote.ServerRecord;
52
import org.netbeans.modules.cnd.api.toolchain.CompilerSetManager;
51
import org.netbeans.modules.cnd.api.toolchain.CompilerSetManager;
53
import org.netbeans.modules.cnd.api.toolchain.ui.ToolsCacheManager;
52
import org.netbeans.modules.cnd.api.toolchain.ui.ToolsCacheManager;
54
import org.netbeans.modules.cnd.remote.server.RemoteServerRecord;
53
import org.netbeans.modules.cnd.remote.server.RemoteServerRecord;
55
import org.netbeans.modules.cnd.utils.CndUtils;
56
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
54
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
57
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
55
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
58
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils;
59
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils.ExitStatus;
60
56
61
/**
57
/**
62
 * Misc. utiliy finctions
58
 * Misc. utiliy finctions
Lines 64-70 Link Here
64
 */
60
 */
65
public class RemoteUtil {
61
public class RemoteUtil {
66
62
67
    private static final Map<ExecutionEnvironment, String> homeDirs = new LinkedHashMap<ExecutionEnvironment, String>();
68
    public static final Logger LOGGER = Logger.getLogger("cnd.remote.logger"); //NOI18N
63
    public static final Logger LOGGER = Logger.getLogger("cnd.remote.logger"); //NOI18N
69
64
70
    public static class PrefixedLogger {
65
    public static class PrefixedLogger {
Lines 86-135 Link Here
86
81
87
    private RemoteUtil() {}
82
    private RemoteUtil() {}
88
83
89
//    public static void log(String prefix, Level level, String format, Object... args) {
90
//        if (LOGGER.isLoggable(level)) {
91
//            String text = String.format(format, args);
92
//            LOGGER.log(level, String.format("%s: ", text));
93
//        }
94
//    }
95
96
    /** 
97
     * Returns home directory for the given host
98
     * NB: this is a LONG RUNNING method - never call from UI thread
99
     */
100
    public static String getHomeDirectory(ExecutionEnvironment execEnv) {
101
        CndUtils.assertNonUiThread();
102
        String dir = null;
103
        // it isn't worth doing smart synchronization here
104
        synchronized(homeDirs) {
105
            // we cache nulls as well
106
            if (homeDirs.containsKey(execEnv)) {
107
                return homeDirs.get(execEnv);
108
            }
109
        }
110
        try { // FIXUP: remove this try/catch as soon as in NPE in execution is fixed
111
            if (Boolean.getBoolean("cnd.emulate.null.home.dir")) { // to emulate returning null //NOI18N
112
                return null;
113
            }
114
            // NB: it's important that /bin/pwd is called since it always reports resolved path
115
            // while shell's pwd result depend on shell
116
            ExitStatus res = ProcessUtils.execute(execEnv, "sh", "-c", "cd; /bin/pwd"); // NOI18N
117
            if (res.isOK()) {
118
                String s = res.output;
119
                if (HostInfoProvider.fileExists(execEnv, s)) {
120
                    dir = s;
121
                }
122
            }
123
        } catch (Exception e) {
124
            e.printStackTrace();
125
        }
126
        synchronized(homeDirs) {
127
            // we cache nulls as well
128
            homeDirs.put(execEnv, dir);            
129
        }
130
        return dir;
131
    }
132
133
    /**
84
    /**
134
     * FIXUP: * Need this hack for Cloud stuff:
85
     * FIXUP: * Need this hack for Cloud stuff:
135
     * we have to distinguish "normal", i.e. CND environments
86
     * we have to distinguish "normal", i.e. CND environments
(-)a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/FtpSyncWorker.java (-1 / +13 lines)
Lines 47-52 Link Here
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.io.InterruptedIOException;
48
import java.io.InterruptedIOException;
49
import java.io.PrintWriter;
49
import java.io.PrintWriter;
50
import java.net.ConnectException;
50
import java.util.Map;
51
import java.util.Map;
51
import java.util.concurrent.ExecutionException;
52
import java.util.concurrent.ExecutionException;
52
import java.util.concurrent.Future;
53
import java.util.concurrent.Future;
Lines 64-70 Link Here
64
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
65
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
65
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
66
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
66
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport.UploadStatus;
67
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport.UploadStatus;
68
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
67
import org.openide.util.Cancellable;
69
import org.openide.util.Cancellable;
70
import org.openide.util.Exceptions;
68
import org.openide.util.NbBundle;
71
import org.openide.util.NbBundle;
69
72
70
/**
73
/**
Lines 254-260 Link Here
254
    @Override
257
    @Override
255
    public boolean startup(Map<String, String> env2add) {
258
    public boolean startup(Map<String, String> env2add) {
256
        // Later we'll allow user to specify where to copy project files to
259
        // Later we'll allow user to specify where to copy project files to
257
        String remoteRoot = RemotePathMap.getRemoteSyncRoot(executionEnvironment);
260
        String remoteRoot = null;
261
        try {
262
            remoteRoot = RemotePathMap.getRemoteSyncRoot(executionEnvironment);
263
        } catch (ConnectException ex) {
264
            ex.printStackTrace();
265
        } catch (IOException ex) {
266
            ex.printStackTrace();
267
        } catch (CancellationException ex) {
268
            // don't report CancellationException
269
        }
258
        if (remoteRoot == null) {
270
        if (remoteRoot == null) {
259
            if (err != null) {
271
            if (err != null) {
260
                err.printf("%s\n", NbBundle.getMessage(getClass(), "MSG_Cant_find_sync_root", ServerList.get(executionEnvironment).toString()));
272
                err.printf("%s\n", NbBundle.getMessage(getClass(), "MSG_Cant_find_sync_root", ServerList.get(executionEnvironment).toString()));
(-)a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/RfsLocalController.java (-1 / +14 lines)
Lines 51-56 Link Here
51
import java.io.InterruptedIOException;
51
import java.io.InterruptedIOException;
52
import java.io.OutputStreamWriter;
52
import java.io.OutputStreamWriter;
53
import java.io.PrintWriter;
53
import java.io.PrintWriter;
54
import java.net.ConnectException;
54
import java.util.ArrayList;
55
import java.util.ArrayList;
55
import java.util.Collection;
56
import java.util.Collection;
56
import java.util.Collections;
57
import java.util.Collections;
Lines 307-313 Link Here
307
    }
308
    }
308
309
309
    private boolean initNewFilesDiscovery() {
310
    private boolean initNewFilesDiscovery() {
310
        String remoteSyncRoot = RemotePathMap.getRemoteSyncRoot(execEnv);
311
        String remoteSyncRoot;
312
        try {
313
            remoteSyncRoot = RemotePathMap.getRemoteSyncRoot(execEnv);
314
        } catch (ConnectException ex) {
315
            ex.printStackTrace();
316
            return false;
317
        } catch (IOException ex) {
318
            ex.printStackTrace();
319
            return false;
320
        } catch (CancellationException ex) {
321
            // don't report CancellationException
322
            return false;
323
        }
311
        ExitStatus res = ProcessUtils.execute(execEnv, "mktemp", "-p", remoteSyncRoot); // NOI18N
324
        ExitStatus res = ProcessUtils.execute(execEnv, "mktemp", "-p", remoteSyncRoot); // NOI18N
312
        if (res.isOK()) {
325
        if (res.isOK()) {
313
           timeStampFile = res.output.trim();
326
           timeStampFile = res.output.trim();
(-)a/cnd.remote/src/org/netbeans/modules/cnd/remote/sync/ZipSyncWorker.java (-1 / +13 lines)
Lines 49-54 Link Here
49
import java.io.InputStreamReader;
49
import java.io.InputStreamReader;
50
import java.io.InterruptedIOException;
50
import java.io.InterruptedIOException;
51
import java.io.PrintWriter;
51
import java.io.PrintWriter;
52
import java.net.ConnectException;
52
import java.util.ArrayList;
53
import java.util.ArrayList;
53
import java.util.Collection;
54
import java.util.Collection;
54
import java.util.Map;
55
import java.util.Map;
Lines 68-73 Link Here
68
import org.netbeans.modules.nativeexecution.api.NativeProcessBuilder;
69
import org.netbeans.modules.nativeexecution.api.NativeProcessBuilder;
69
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
70
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
70
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport.UploadStatus;
71
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport.UploadStatus;
72
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
73
import org.openide.util.Exceptions;
71
import org.openide.util.NbBundle;
74
import org.openide.util.NbBundle;
72
75
73
/**
76
/**
Lines 325-331 Link Here
325
    @Override
328
    @Override
326
    public boolean startup(Map<String, String> env2add) {
329
    public boolean startup(Map<String, String> env2add) {
327
        // Later we'll allow user to specify where to copy project files to
330
        // Later we'll allow user to specify where to copy project files to
328
        String remoteRoot = RemotePathMap.getRemoteSyncRoot(executionEnvironment);
331
        String remoteRoot = null;
332
        try {
333
            remoteRoot = RemotePathMap.getRemoteSyncRoot(executionEnvironment);
334
        } catch (ConnectException ex) {
335
            ex.printStackTrace();
336
        } catch (IOException ex) {
337
            ex.printStackTrace();
338
        } catch (CancellationException ex) {
339
            // don't report CancellationException
340
        }
329
        if (remoteRoot == null) {
341
        if (remoteRoot == null) {
330
            if (err != null) {
342
            if (err != null) {
331
                err.printf("%s\n", NbBundle.getMessage(getClass(), "MSG_Cant_find_sync_root", ServerList.get(executionEnvironment).toString()));
343
                err.printf("%s\n", NbBundle.getMessage(getClass(), "MSG_Cant_find_sync_root", ServerList.get(executionEnvironment).toString()));
(-)a/cnd.remote/src/org/netbeans/modules/cnd/spi/remote/setup/MirrorPathProvider.java (-1 / +5 lines)
Lines 42-48 Link Here
42
42
43
package org.netbeans.modules.cnd.spi.remote.setup;
43
package org.netbeans.modules.cnd.spi.remote.setup;
44
44
45
import java.io.IOException;
46
import java.net.ConnectException;
45
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
47
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
48
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
46
49
47
/**
50
/**
48
 * Allows to redefine places where local->remote and remote->local mirrors are located
51
 * Allows to redefine places where local->remote and remote->local mirrors are located
Lines 58-64 Link Here
58
     * @return remote mirror absolute path
61
     * @return remote mirror absolute path
59
     * or null in the case this provider can not provide it for the given environment
62
     * or null in the case this provider can not provide it for the given environment
60
     */
63
     */
61
    String getRemoteMirror(ExecutionEnvironment executionEnvironment);
64
    String getRemoteMirror(ExecutionEnvironment executionEnvironment) 
65
            throws ConnectException, IOException, ConnectionManager.CancellationException;
62
66
63
    /**
67
    /**
64
     * Gets local mirror absolute path.
68
     * Gets local mirror absolute path.
(-)a/cnd.remote/src/org/netbeans/modules/remote/ui/AddToFavoritesAction.java (-2 / +13 lines)
Lines 44-49 Link Here
44
44
45
import java.awt.Frame;
45
import java.awt.Frame;
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.net.ConnectException;
47
import javax.swing.JMenu;
48
import javax.swing.JMenu;
48
import javax.swing.JMenuItem;
49
import javax.swing.JMenuItem;
49
import javax.swing.SwingUtilities;
50
import javax.swing.SwingUtilities;
Lines 153-158 Link Here
153
        }
154
        }
154
155
155
        protected abstract FileObject getRoot(ExecutionEnvironment env, FileSystem fs);
156
        protected abstract FileObject getRoot(ExecutionEnvironment env, FileSystem fs);
157
        /** can return null in the case of problems */
156
        protected abstract String getPath(ExecutionEnvironment env);
158
        protected abstract String getPath(ExecutionEnvironment env);
157
        
159
        
158
        @Override
160
        @Override
Lines 285-292 Link Here
285
        
287
        
286
        @Override
288
        @Override
287
        protected String getPath(ExecutionEnvironment env) {
289
        protected String getPath(ExecutionEnvironment env) {
288
            String remoteSyncRoot = RemotePathMap.getRemoteSyncRoot(env);
290
            try {
289
            return remoteSyncRoot;
291
                String remoteSyncRoot = RemotePathMap.getRemoteSyncRoot(env);
292
                return remoteSyncRoot;
293
            } catch (ConnectException ex) {
294
                ex.printStackTrace();
295
            } catch (IOException ex) {
296
                ex.printStackTrace();
297
            } catch (CancellationException ex) {
298
                // don't report CancellationException
299
            }
300
            return null;
290
        }
301
        }
291
    }
302
    }
292
    
303
    
(-)a/cnd.remote/src/org/netbeans/modules/remote/ui/FileSystemRootNode.java (-22 / +35 lines)
Lines 43-53 Link Here
43
package org.netbeans.modules.remote.ui;
43
package org.netbeans.modules.remote.ui;
44
44
45
import java.awt.Image;
45
import java.awt.Image;
46
import java.io.IOException;
47
import java.net.ConnectException;
46
import java.util.List;
48
import java.util.List;
47
import org.netbeans.modules.cnd.remote.mapper.RemotePathMap;
49
import org.netbeans.modules.cnd.remote.mapper.RemotePathMap;
48
import org.netbeans.modules.cnd.remote.support.RemoteUtil;
49
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
50
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
50
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
51
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
52
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
53
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
51
import org.netbeans.modules.remote.spi.FileSystemProvider;
54
import org.netbeans.modules.remote.spi.FileSystemProvider;
52
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileSystem;
56
import org.openide.filesystems.FileSystem;
Lines 55-60 Link Here
55
import org.openide.nodes.ChildFactory;
58
import org.openide.nodes.ChildFactory;
56
import org.openide.nodes.Children;
59
import org.openide.nodes.Children;
57
import org.openide.nodes.Node;
60
import org.openide.nodes.Node;
61
import org.openide.util.Exceptions;
58
import org.openide.util.ImageUtilities;
62
import org.openide.util.ImageUtilities;
59
import org.openide.util.NbBundle;
63
import org.openide.util.NbBundle;
60
import org.openide.util.lookup.Lookups;
64
import org.openide.util.lookup.Lookups;
Lines 131-159 Link Here
131
135
132
        @Override
136
        @Override
133
        protected Node createNodeForKey(Kind key) {
137
        protected Node createNodeForKey(Kind key) {
134
            FileObject fo;
138
            try {
135
            switch (key) {
139
                FileObject fo = null;            
136
                case DISCONNECTED:
140
                switch (key) {
141
                    case DISCONNECTED:
142
                        return new NotConnectedNode(env);
143
                    case HOME:
144
                        String homeDir = HostInfoUtils.getHostInfo(env).getUserDir();
145
                        fo = rootFileObject.getFileObject(homeDir);
146
                        break;
147
                    case MIRROR:
148
                        String mirror = RemotePathMap.getRemoteSyncRoot(env);
149
                        fo = rootFileObject.getFileObject(mirror);
150
                        break;
151
                    case ROOT:
152
                        fo = rootFileObject;
153
                        break;
154
                    default:
155
                        fo = rootFileObject;
156
                        break;
157
                }
158
                if (fo != null) {
159
                    return new FileSystemNode(env, fo);
160
                } else {
137
                    return new NotConnectedNode(env);
161
                    return new NotConnectedNode(env);
138
                case HOME:
162
                }
139
                    String homeDir = RemoteUtil.getHomeDirectory(env);
163
            } catch (ConnectException ex) {
140
                    fo = rootFileObject.getFileObject(homeDir);
164
                return new NotConnectedNode(env);
141
                    break;
165
            } catch (IOException ex) {
142
                case MIRROR:
166
                return new NotConnectedNode(env);
143
                    String mirror = RemotePathMap.getRemoteSyncRoot(env);
167
            } catch (ConnectionManager.CancellationException ex) {
144
                    fo = rootFileObject.getFileObject(mirror);
168
                return new NotConnectedNode(env);
145
                    break;
146
                case ROOT:
147
                    fo = rootFileObject;
148
                    break;
149
                default:
150
                    fo = rootFileObject;
151
                    break;
152
            }
169
            }
153
            if (fo != null) {
154
                return new FileSystemNode(env, fo);
155
            }
156
            return null; // TODO: error processing
157
        }
170
        }
158
    }
171
    }
159
}
172
}
(-)a/cnd.remote/src/org/netbeans/modules/remote/ui/OpenTerminalAction.java (-4 / +14 lines)
Lines 45-50 Link Here
45
import java.awt.Frame;
45
import java.awt.Frame;
46
import java.io.File;
46
import java.io.File;
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.net.ConnectException;
48
import javax.swing.*;
49
import javax.swing.*;
49
import org.netbeans.modules.cnd.api.remote.RemoteFileUtil;
50
import org.netbeans.modules.cnd.api.remote.RemoteFileUtil;
50
import org.netbeans.modules.cnd.remote.mapper.RemotePathMap;
51
import org.netbeans.modules.cnd.remote.mapper.RemotePathMap;
Lines 149-155 Link Here
149
            this.place = place;
150
            this.place = place;
150
            putProperty("noIconInMenu", Boolean.TRUE);// NOI18N
151
            putProperty("noIconInMenu", Boolean.TRUE);// NOI18N
151
        }
152
        }
152
153
        /** can return null in the case of issues */
153
        protected abstract String getPath(ExecutionEnvironment env);
154
        protected abstract String getPath(ExecutionEnvironment env);
154
155
155
        @Override
156
        @Override
Lines 263-273 Link Here
263
264
264
        @Override
265
        @Override
265
        protected String getPath(ExecutionEnvironment env) {
266
        protected String getPath(ExecutionEnvironment env) {
266
            String remoteSyncRoot = RemotePathMap.getRemoteSyncRoot(env);
267
            try {
267
            return remoteSyncRoot;
268
                String remoteSyncRoot = RemotePathMap.getRemoteSyncRoot(env);
269
                return remoteSyncRoot;
270
            } catch (ConnectException ex) {
271
                ex.printStackTrace();
272
            } catch (IOException ex) {
273
                ex.printStackTrace();
274
            } catch (CancellationException ex) {
275
                // don't report CancellationException
276
            }
277
            return null;
268
        }
278
        }
269
    }
279
    }
270
    
280
271
    private static final class AddOther extends AddPlace {
281
    private static final class AddOther extends AddPlace {
272
        private final Frame mainWindow;
282
        private final Frame mainWindow;
273
        
283
        
(-)a/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/fs/RemoteCodeModelTestCase.java (-1 / +1 lines)
Lines 87-93 Link Here
87
    }
87
    }
88
88
89
    @Override
89
    @Override
90
    protected void clearRemoteSyncRoot() {
90
    protected void clearRemoteSyncRoot() throws Exception {
91
        super.clearRemoteSyncRoot();
91
        super.clearRemoteSyncRoot();
92
        if (testReconnect) {
92
        if (testReconnect) {
93
            ConnectionManager.getInstance().disconnect(getTestExecutionEnvironment());
93
            ConnectionManager.getInstance().disconnect(getTestExecutionEnvironment());
(-)a/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/support/RemoteUtilTestCase.java (-118 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 * 
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 * 
38
 * Contributor(s):
39
 * 
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.cnd.remote.support;
43
44
import org.netbeans.modules.cnd.remote.test.RemoteTestBase;
45
import junit.framework.Test;
46
import org.netbeans.modules.cnd.api.remote.HostInfoProvider;
47
import org.netbeans.modules.cnd.remote.test.RemoteDevelopmentTest;
48
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
49
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
50
import org.netbeans.modules.nativeexecution.test.ForAllEnvironments;
51
52
/**
53
 * There hardly is a way to unit test remote operations.
54
 * This is just an entry point for manual validation.
55
 *
56
 * @author Sergey Grinev
57
 */
58
public class RemoteUtilTestCase extends RemoteTestBase {
59
60
    public RemoteUtilTestCase(String testName, ExecutionEnvironment execEnv) {
61
        super(testName, execEnv);
62
    }
63
64
    @ForAllEnvironments
65
    public void testGetHomeDirectory() throws Exception {
66
        System.out.printf("Testng getHomeDirectory\n");
67
        ExecutionEnvironment execEnv = getTestExecutionEnvironment();
68
        long time1 = System.currentTimeMillis();
69
        String home = RemoteUtil.getHomeDirectory(execEnv);
70
        time1 = System.currentTimeMillis() - time1;
71
        System.out.printf("\tgetHomeDirectory: returned %s for %s; time is %d ms\n", home, execEnv, time1);
72
        assertNotNull(home);
73
        boolean exists = HostInfoProvider.fileExists(execEnv, home);
74
        assertTrue(exists);
75
    }
76
77
    @ForAllEnvironments
78
    public void testGetHomeDirectoryCachingNotNull() throws Exception {
79
        System.out.printf("Testng getHomeDirectory caching: returning not null\n");
80
        ExecutionEnvironment goodEnv = getTestExecutionEnvironment();
81
        long time1 = System.currentTimeMillis();
82
        String home = RemoteUtil.getHomeDirectory(goodEnv);
83
        time1 = System.currentTimeMillis() - time1;
84
        System.out.printf("Testng getHomeDirectory: returned %s for %s; time is %d ms\n", home, goodEnv, time1);
85
        assertNotNull(home);
86
        for (int i = 0; i < 10; i++) {
87
            long time2 = System.currentTimeMillis();
88
            String t = RemoteUtil.getHomeDirectory(goodEnv);
89
            time2 = System.currentTimeMillis() - time2;
90
            System.out.printf("Good, pass %d; time is %d ms\n", i, time2);
91
            assert(time2 < 100);
92
        }
93
    }
94
95
    @ForAllEnvironments
96
    public void testGetHomeDirectoryCachingNull() throws Exception {
97
        System.out.printf("Testng getHomeDirectory caching: returning null\n");
98
        ExecutionEnvironment badEnv = ExecutionEnvironmentFactory.createNew("inexistent/user", "inexistent/host");
99
        long time1 = System.currentTimeMillis();
100
        String home = RemoteUtil.getHomeDirectory(badEnv);
101
        time1 = System.currentTimeMillis() - time1;
102
        System.out.printf("Testng getHomeDirectory: returned %s for %s; time is %d ms\n", home, badEnv, time1);
103
        assertNull(home);
104
        for (int i = 0; i < 10; i++) {
105
            long time2 = System.currentTimeMillis();
106
            String t = RemoteUtil.getHomeDirectory(badEnv);
107
            time2 = System.currentTimeMillis() - time2;
108
            System.out.printf("Bad, pass %d; time is %d ms\n", i, time2);
109
            long max = 100;
110
            assertTrue("getHomeDirectory time should be less than " + time2 + "; but it is" + max, time2 < max);
111
        }
112
    }
113
114
    public static Test suite() {
115
        return new RemoteDevelopmentTest(RemoteUtilTestCase.class);
116
    }
117
118
}
(-)a/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/test/RemoteDevelopmentTest.java (-2 lines)
Lines 53-59 Link Here
53
import org.netbeans.modules.cnd.remote.mapper.IncludeMappingsTestCase;
53
import org.netbeans.modules.cnd.remote.mapper.IncludeMappingsTestCase;
54
import org.netbeans.modules.cnd.remote.mapper.MappingsTestCase;
54
import org.netbeans.modules.cnd.remote.mapper.MappingsTestCase;
55
import org.netbeans.modules.cnd.remote.support.DownloadTestCase;
55
import org.netbeans.modules.cnd.remote.support.DownloadTestCase;
56
import org.netbeans.modules.cnd.remote.support.RemoteUtilTestCase;
57
import org.netbeans.modules.cnd.remote.support.ServerListTestCase;
56
import org.netbeans.modules.cnd.remote.support.ServerListTestCase;
58
import org.netbeans.modules.cnd.remote.support.TransportTestCase;
57
import org.netbeans.modules.cnd.remote.support.TransportTestCase;
59
import org.netbeans.modules.cnd.remote.support.UploadTestCase;
58
import org.netbeans.modules.cnd.remote.support.UploadTestCase;
Lines 84-90 Link Here
84
           RfsGnuRemoteBuildTestCase.class,
83
           RfsGnuRemoteBuildTestCase.class,
85
           RfsSunStudioRemoteBuildTestCase.class,
84
           RfsSunStudioRemoteBuildTestCase.class,
86
           DownloadTestCase.class,
85
           DownloadTestCase.class,
87
           RemoteUtilTestCase.class,
88
           ServerListTestCase.class,
86
           ServerListTestCase.class,
89
           TransportTestCase.class,
87
           TransportTestCase.class,
90
           UploadTestCase.class,
88
           UploadTestCase.class,
(-)a/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/test/RemoteTestBase.java (-1 / +3 lines)
Lines 44-49 Link Here
44
44
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.io.PrintWriter;
46
import java.io.PrintWriter;
47
import java.net.ConnectException;
47
import java.util.Arrays;
48
import java.util.Arrays;
48
import java.util.Collections;
49
import java.util.Collections;
49
import java.util.HashSet;
50
import java.util.HashSet;
Lines 71-76 Link Here
71
import org.netbeans.modules.cnd.remote.sync.ZipSyncFactory;
72
import org.netbeans.modules.cnd.remote.sync.ZipSyncFactory;
72
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
73
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
73
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
74
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
75
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
74
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils;
76
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils;
75
import org.netbeans.modules.nativeexecution.test.NativeExecutionTestSupport;
77
import org.netbeans.modules.nativeexecution.test.NativeExecutionTestSupport;
76
import org.netbeans.modules.nativeexecution.test.RcFile;
78
import org.netbeans.modules.nativeexecution.test.RcFile;
Lines 285-291 Link Here
285
        }
287
        }
286
    }
288
    }
287
289
288
    protected void clearRemoteSyncRoot() {
290
    protected void clearRemoteSyncRoot() throws Exception {
289
        String dirToRemove = RemotePathMap.getRemoteSyncRoot(getTestExecutionEnvironment());
291
        String dirToRemove = RemotePathMap.getRemoteSyncRoot(getTestExecutionEnvironment());
290
        boolean isOk = ProcessUtils.execute(getTestExecutionEnvironment(), "sh", "-c", "rm -rf " + dirToRemove + "/*").isOK();
292
        boolean isOk = ProcessUtils.execute(getTestExecutionEnvironment(), "sh", "-c", "rm -rf " + dirToRemove + "/*").isOK();
291
        assertTrue("Failed to remove " + dirToRemove, isOk);
293
        assertTrue("Failed to remove " + dirToRemove, isOk);

Return to bug 203038