Cleanup (formatting)

GitOrigin-RevId: e1e96311643845409808cedc302e6c9e9f574898
This commit is contained in:
Roman Shevchenko
2019-12-27 23:32:53 +00:00
committed by intellij-monorepo-bot
parent 002e7f8004
commit 3004946398
3 changed files with 36 additions and 44 deletions
@@ -19,6 +19,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem;
@@ -39,8 +40,6 @@ import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
import static com.intellij.openapi.util.text.StringUtil.defaultIfEmpty;
/**
* This helpful action opens a file or directory in a system file manager.
*
@@ -246,37 +245,37 @@ public class RevealFileAction extends DumbAwareAction {
SystemInfo.isMac ? "Finder" :
SystemInfo.isWindows ? "Explorer" :
readDesktopEntryKey("Name").orElse("File Manager");
}
private static Optional<String> readDesktopEntryKey(String key) {
if (SystemInfo.hasXdgMime()) {
String appName = ExecUtil.execAndReadLine(new GeneralCommandLine("xdg-mime", "query", "default", "inode/directory"));
if (appName != null && appName.endsWith(".desktop")) {
return Stream.of(getXdgDataDirectories().split(":"))
.map(dir -> new File(dir, "applications/" + appName))
.filter(File::exists)
.findFirst()
.map(file -> readDesktopEntryKey(file, key));
private static Optional<String> readDesktopEntryKey(String key) {
if (SystemInfo.hasXdgMime()) {
String appName = ExecUtil.execAndReadLine(new GeneralCommandLine("xdg-mime", "query", "default", "inode/directory"));
if (appName != null && appName.endsWith(".desktop")) {
return Stream.of(getXdgDataDirectories().split(":"))
.map(dir -> new File(dir, "applications/" + appName))
.filter(File::exists)
.findFirst()
.map(file -> readDesktopEntryKey(file, key));
}
}
return Optional.empty();
}
return Optional.empty();
}
private static String getXdgDataDirectories() {
String dataHome = System.getenv("XDG_DATA_HOME");
String dataDirs = System.getenv("XDG_DATA_DIRS");
return defaultIfEmpty(dataHome, SystemProperties.getUserHome() + "/.local/share") + ':' + defaultIfEmpty(dataDirs, "/usr/local/share:/usr/share");
}
private static String readDesktopEntryKey(File file, String key) {
LOG.debug("looking for '" + key + "' in " + file);
String prefix = key + '=';
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
return reader.lines().filter(l -> l.startsWith(prefix)).map(l -> l.substring(prefix.length())).findFirst().orElse(null);
private static String getXdgDataDirectories() {
return StringUtil.defaultIfEmpty(System.getenv("XDG_DATA_HOME"), SystemProperties.getUserHome() + "/.local/share") + ':' +
StringUtil.defaultIfEmpty(System.getenv("XDG_DATA_DIRS"), "/usr/local/share:/usr/share");
}
catch (IOException | UncheckedIOException e) {
LOG.info("Cannot read: " + file, e);
return null;
private static String readDesktopEntryKey(File file, String key) {
LOG.debug("looking for '" + key + "' in " + file);
String prefix = key + '=';
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
return reader.lines().filter(l -> l.startsWith(prefix)).map(l -> l.substring(prefix.length())).findFirst().orElse(null);
}
catch (IOException | UncheckedIOException e) {
LOG.info("Cannot read: " + file, e);
return null;
}
}
}
}
@@ -14,14 +14,13 @@ import java.util.List;
public class ProcessOutput {
private final StringBuilder myStdoutBuilder = new StringBuilder();
private final StringBuilder myStderrBuilder = new StringBuilder();
@Nullable private Integer myExitCode;
private @Nullable Integer myExitCode;
private boolean myTimeout;
private boolean myCancelled;
public ProcessOutput() {
}
public ProcessOutput() { }
public ProcessOutput(final int exitCode) {
public ProcessOutput(int exitCode) {
myExitCode = exitCode;
}
@@ -63,18 +62,14 @@ public class ProcessOutput {
return splitLines(getStderr(), excludeEmptyLines);
}
@NotNull
private static List<String> splitLines(String s, boolean excludeEmptyLines) {
String converted = StringUtil.convertLineSeparators(s);
return StringUtil.split(converted, "\n", true, excludeEmptyLines);
}
/**
* If exit code is nonzero or the process timed out, logs stderr and exit code and returns false,
* else just returns true.
*
* @param logger where to put error information
* @return true iff exit code is zero
* If exit code is nonzero or the process timed out, logs exit code and process output (if any) and returns {@code false},
* otherwise just returns {@code true}.
*/
public boolean checkSuccess(@NotNull Logger logger) {
int ec = getExitCode();
@@ -103,8 +98,7 @@ public class ProcessOutput {
}
/**
* @return false if exit code wasn't set,
* for example, when our CapturingProcessHandler.runProcess() is interrupted)
* Returns {@code false} if exit code wasn't set (e.g. when {@code CapturingProcessHandler.runProcess()} execution was interrupted).
*/
public boolean isExitCodeSet() {
return myExitCode != null;
@@ -125,4 +119,4 @@ public class ProcessOutput {
public boolean isCancelled() {
return myCancelled;
}
}
}
@@ -89,8 +89,7 @@ class BrowserLauncherImpl : BrowserLauncherAppless() {
showError(ExecUtil.readFirstLine(process.errorStream, null), browser, project, null, launchTask)
}
}
catch (ignored: InterruptedException) {
}
catch (ignored: InterruptedException) { }
}
// 10 seconds is enough to start
JobScheduler.getScheduler().schedule({ future.cancel(true) }, 10, TimeUnit.SECONDS)