# HG changeset patch # User Vladimir Kvashin # Date 1322032373 -10800 # Node ID 0935b681c495eba80157c5174a7a6e37beb6b451 # Parent 6376617653fcd3d6a3ec9b7c2744dfb4bf9ee620 fixed #203038 - Exception: Should not be called from UI thread diff -r 6376617653fc -r 0935b681c495 cnd.remote/src/org/netbeans/modules/cnd/remote/mapper/RemoteMirrorPathProvider.java --- a/cnd.remote/src/org/netbeans/modules/cnd/remote/mapper/RemoteMirrorPathProvider.java Tue Nov 22 22:03:16 2011 +0100 +++ b/cnd.remote/src/org/netbeans/modules/cnd/remote/mapper/RemoteMirrorPathProvider.java Wed Nov 23 10:12:53 2011 +0300 @@ -42,11 +42,13 @@ package org.netbeans.modules.cnd.remote.mapper; +import java.io.IOException; import java.text.ParseException; -import org.netbeans.modules.cnd.remote.support.RemoteUtil; import org.netbeans.modules.cnd.spi.remote.setup.MirrorPathProvider; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory; +import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException; +import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils; import org.netbeans.modules.nativeexecution.api.util.MacroExpanderFactory; import org.netbeans.modules.nativeexecution.api.util.MacroExpanderFactory.MacroExpander; import org.netbeans.modules.remote.spi.FileSystemCacheProvider; @@ -80,10 +82,21 @@ if (root != null) { return root; } - String home = RemoteUtil.getHomeDirectory(executionEnvironment); - if (home == null) { + + if (!HostInfoUtils.isHostInfoAvailable(executionEnvironment)) { return null; } + String home; + try { + home = HostInfoUtils.getHostInfo(executionEnvironment).getUserDir(); + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } catch (CancellationException ex) { + // don't report CancellationException + return null; + } + final ExecutionEnvironment local = ExecutionEnvironmentFactory.getLocal(); MacroExpander expander = MacroExpanderFactory.getExpander(local); String localHostID = local.getHost(); diff -r 6376617653fc -r 0935b681c495 cnd.remote/src/org/netbeans/modules/cnd/remote/support/RemoteUtil.java --- a/cnd.remote/src/org/netbeans/modules/cnd/remote/support/RemoteUtil.java Tue Nov 22 22:03:16 2011 +0100 +++ b/cnd.remote/src/org/netbeans/modules/cnd/remote/support/RemoteUtil.java Wed Nov 23 10:12:53 2011 +0300 @@ -46,17 +46,13 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import org.netbeans.modules.cnd.api.remote.HostInfoProvider; import org.netbeans.modules.cnd.api.remote.ServerList; import org.netbeans.modules.cnd.api.remote.ServerRecord; import org.netbeans.modules.cnd.api.toolchain.CompilerSetManager; import org.netbeans.modules.cnd.api.toolchain.ui.ToolsCacheManager; import org.netbeans.modules.cnd.remote.server.RemoteServerRecord; -import org.netbeans.modules.cnd.utils.CndUtils; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory; -import org.netbeans.modules.nativeexecution.api.util.ProcessUtils; -import org.netbeans.modules.nativeexecution.api.util.ProcessUtils.ExitStatus; /** * Misc. utiliy finctions @@ -64,7 +60,6 @@ */ public class RemoteUtil { - private static final Map homeDirs = new LinkedHashMap(); public static final Logger LOGGER = Logger.getLogger("cnd.remote.logger"); //NOI18N public static class PrefixedLogger { @@ -86,50 +81,6 @@ private RemoteUtil() {} -// public static void log(String prefix, Level level, String format, Object... args) { -// if (LOGGER.isLoggable(level)) { -// String text = String.format(format, args); -// LOGGER.log(level, String.format("%s: ", text)); -// } -// } - - /** - * Returns home directory for the given host - * NB: this is a LONG RUNNING method - never call from UI thread - */ - public static String getHomeDirectory(ExecutionEnvironment execEnv) { - CndUtils.assertNonUiThread(); - String dir = null; - // it isn't worth doing smart synchronization here - synchronized(homeDirs) { - // we cache nulls as well - if (homeDirs.containsKey(execEnv)) { - return homeDirs.get(execEnv); - } - } - try { // FIXUP: remove this try/catch as soon as in NPE in execution is fixed - if (Boolean.getBoolean("cnd.emulate.null.home.dir")) { // to emulate returning null //NOI18N - return null; - } - // NB: it's important that /bin/pwd is called since it always reports resolved path - // while shell's pwd result depend on shell - ExitStatus res = ProcessUtils.execute(execEnv, "sh", "-c", "cd; /bin/pwd"); // NOI18N - if (res.isOK()) { - String s = res.output; - if (HostInfoProvider.fileExists(execEnv, s)) { - dir = s; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - synchronized(homeDirs) { - // we cache nulls as well - homeDirs.put(execEnv, dir); - } - return dir; - } - /** * FIXUP: * Need this hack for Cloud stuff: * we have to distinguish "normal", i.e. CND environments diff -r 6376617653fc -r 0935b681c495 cnd.remote/src/org/netbeans/modules/remote/ui/FileSystemRootNode.java --- a/cnd.remote/src/org/netbeans/modules/remote/ui/FileSystemRootNode.java Tue Nov 22 22:03:16 2011 +0100 +++ b/cnd.remote/src/org/netbeans/modules/remote/ui/FileSystemRootNode.java Wed Nov 23 10:12:53 2011 +0300 @@ -43,11 +43,13 @@ package org.netbeans.modules.remote.ui; import java.awt.Image; +import java.io.IOException; import java.util.List; import org.netbeans.modules.cnd.remote.mapper.RemotePathMap; -import org.netbeans.modules.cnd.remote.support.RemoteUtil; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; import org.netbeans.modules.nativeexecution.api.util.ConnectionManager; +import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException; +import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils; import org.netbeans.modules.remote.spi.FileSystemProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; @@ -55,6 +57,7 @@ import org.openide.nodes.ChildFactory; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.util.Exceptions; import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; import org.openide.util.lookup.Lookups; @@ -131,17 +134,25 @@ @Override protected Node createNodeForKey(Kind key) { - FileObject fo; + FileObject fo = null; switch (key) { case DISCONNECTED: return new NotConnectedNode(env); case HOME: - String homeDir = RemoteUtil.getHomeDirectory(env); - fo = rootFileObject.getFileObject(homeDir); + try { + String homeDir = HostInfoUtils.getHostInfo(env).getUserDir(); + fo = rootFileObject.getFileObject(homeDir); + } catch (IOException ex) { + ex.printStackTrace(); + } catch (CancellationException ex) { + // don't report CancellationException + } break; case MIRROR: String mirror = RemotePathMap.getRemoteSyncRoot(env); - fo = rootFileObject.getFileObject(mirror); + if (mirror!= null) { + fo = rootFileObject.getFileObject(mirror); + } break; case ROOT: fo = rootFileObject; @@ -153,7 +164,7 @@ if (fo != null) { return new FileSystemNode(env, fo); } - return null; // TODO: error processing + return null; // TODO: error processing } } } diff -r 6376617653fc -r 0935b681c495 cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/support/RemoteUtilTestCase.java --- a/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/support/RemoteUtilTestCase.java Tue Nov 22 22:03:16 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2008 Sun Microsystems, Inc. - */ -package org.netbeans.modules.cnd.remote.support; - -import org.netbeans.modules.cnd.remote.test.RemoteTestBase; -import junit.framework.Test; -import org.netbeans.modules.cnd.api.remote.HostInfoProvider; -import org.netbeans.modules.cnd.remote.test.RemoteDevelopmentTest; -import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; -import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory; -import org.netbeans.modules.nativeexecution.test.ForAllEnvironments; - -/** - * There hardly is a way to unit test remote operations. - * This is just an entry point for manual validation. - * - * @author Sergey Grinev - */ -public class RemoteUtilTestCase extends RemoteTestBase { - - public RemoteUtilTestCase(String testName, ExecutionEnvironment execEnv) { - super(testName, execEnv); - } - - @ForAllEnvironments - public void testGetHomeDirectory() throws Exception { - System.out.printf("Testng getHomeDirectory\n"); - ExecutionEnvironment execEnv = getTestExecutionEnvironment(); - long time1 = System.currentTimeMillis(); - String home = RemoteUtil.getHomeDirectory(execEnv); - time1 = System.currentTimeMillis() - time1; - System.out.printf("\tgetHomeDirectory: returned %s for %s; time is %d ms\n", home, execEnv, time1); - assertNotNull(home); - boolean exists = HostInfoProvider.fileExists(execEnv, home); - assertTrue(exists); - } - - @ForAllEnvironments - public void testGetHomeDirectoryCachingNotNull() throws Exception { - System.out.printf("Testng getHomeDirectory caching: returning not null\n"); - ExecutionEnvironment goodEnv = getTestExecutionEnvironment(); - long time1 = System.currentTimeMillis(); - String home = RemoteUtil.getHomeDirectory(goodEnv); - time1 = System.currentTimeMillis() - time1; - System.out.printf("Testng getHomeDirectory: returned %s for %s; time is %d ms\n", home, goodEnv, time1); - assertNotNull(home); - for (int i = 0; i < 10; i++) { - long time2 = System.currentTimeMillis(); - String t = RemoteUtil.getHomeDirectory(goodEnv); - time2 = System.currentTimeMillis() - time2; - System.out.printf("Good, pass %d; time is %d ms\n", i, time2); - assert(time2 < 100); - } - } - - @ForAllEnvironments - public void testGetHomeDirectoryCachingNull() throws Exception { - System.out.printf("Testng getHomeDirectory caching: returning null\n"); - ExecutionEnvironment badEnv = ExecutionEnvironmentFactory.createNew("inexistent/user", "inexistent/host"); - long time1 = System.currentTimeMillis(); - String home = RemoteUtil.getHomeDirectory(badEnv); - time1 = System.currentTimeMillis() - time1; - System.out.printf("Testng getHomeDirectory: returned %s for %s; time is %d ms\n", home, badEnv, time1); - assertNull(home); - for (int i = 0; i < 10; i++) { - long time2 = System.currentTimeMillis(); - String t = RemoteUtil.getHomeDirectory(badEnv); - time2 = System.currentTimeMillis() - time2; - System.out.printf("Bad, pass %d; time is %d ms\n", i, time2); - long max = 100; - assertTrue("getHomeDirectory time should be less than " + time2 + "; but it is" + max, time2 < max); - } - } - - public static Test suite() { - return new RemoteDevelopmentTest(RemoteUtilTestCase.class); - } - -} diff -r 6376617653fc -r 0935b681c495 cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/test/RemoteDevelopmentTest.java --- a/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/test/RemoteDevelopmentTest.java Tue Nov 22 22:03:16 2011 +0100 +++ b/cnd.remote/test/unit/src/org/netbeans/modules/cnd/remote/test/RemoteDevelopmentTest.java Wed Nov 23 10:12:53 2011 +0300 @@ -53,7 +53,6 @@ import org.netbeans.modules.cnd.remote.mapper.IncludeMappingsTestCase; import org.netbeans.modules.cnd.remote.mapper.MappingsTestCase; import org.netbeans.modules.cnd.remote.support.DownloadTestCase; -import org.netbeans.modules.cnd.remote.support.RemoteUtilTestCase; import org.netbeans.modules.cnd.remote.support.ServerListTestCase; import org.netbeans.modules.cnd.remote.support.TransportTestCase; import org.netbeans.modules.cnd.remote.support.UploadTestCase; @@ -84,7 +83,6 @@ RfsGnuRemoteBuildTestCase.class, RfsSunStudioRemoteBuildTestCase.class, DownloadTestCase.class, - RemoteUtilTestCase.class, ServerListTestCase.class, TransportTestCase.class, UploadTestCase.class,