forked from KronicDeth/intellij-elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "convert sdk code to kotlin, and fix edt errors (KronicDeth#3631…
…)" This reverts commit dcfbf1a.
- Loading branch information
1 parent
7161299
commit 5a553e0
Showing
21 changed files
with
1,170 additions
and
1,024 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.elixir_lang.sdk; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.intellij.execution.ExecutionException; | ||
import com.intellij.execution.configurations.GeneralCommandLine; | ||
import com.intellij.execution.process.CapturingProcessHandler; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.util.Function; | ||
import com.intellij.util.PlatformUtils; | ||
import com.intellij.util.containers.ContainerUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by zyuyou on 2015/5/27. | ||
* | ||
*/ | ||
public class ProcessOutput { | ||
/* | ||
* CONSTANTS | ||
*/ | ||
|
||
private static final Logger LOGGER = Logger.getInstance(ProcessOutput.class); | ||
public static final int STANDARD_TIMEOUT = 10 * 1000; | ||
|
||
@Nullable | ||
public static <T> T transformStdoutLine(@NotNull com.intellij.execution.process.ProcessOutput output, @NotNull Function<String, T> lineTransformer) { | ||
List<String> lines; | ||
|
||
if (output.getExitCode() != 0 || output.isTimeout() || output.isCancelled()) { | ||
lines = ContainerUtil.emptyList(); | ||
} else { | ||
lines = output.getStdoutLines(); | ||
} | ||
|
||
T transformed = null; | ||
|
||
for (String line : lines) { | ||
transformed = lineTransformer.fun(line); | ||
|
||
if (transformed != null) { | ||
break; | ||
} | ||
} | ||
|
||
return transformed; | ||
} | ||
|
||
@Nullable | ||
public static <T> T transformStdoutLine(@NotNull Function<String, T> lineTransformer, | ||
int timeout, | ||
@NotNull String workDir, | ||
@NotNull String exePath, | ||
@NotNull String... arguments) { | ||
T transformed = null; | ||
|
||
try { | ||
com.intellij.execution.process.ProcessOutput output = getProcessOutput(timeout, workDir, exePath, arguments); | ||
|
||
transformed = transformStdoutLine(output, lineTransformer); | ||
} catch (ExecutionException executionException) { | ||
LOGGER.warn(executionException); | ||
} | ||
|
||
return transformed; | ||
} | ||
|
||
@NotNull | ||
public static com.intellij.execution.process.ProcessOutput getProcessOutput(int timeout, | ||
@Nullable String workDir, | ||
@NotNull String exePath, | ||
@NotNull String... arguments) throws ExecutionException{ | ||
if(workDir == null || !new File(workDir).isDirectory() || !new File(exePath).canExecute()){ | ||
return new com.intellij.execution.process.ProcessOutput(); | ||
} | ||
|
||
GeneralCommandLine cmd = new GeneralCommandLine().withCharset(Charsets.UTF_8); | ||
cmd.withWorkDirectory(workDir); | ||
cmd.setExePath(exePath); | ||
cmd.addParameters(arguments); | ||
|
||
return execute(cmd, timeout); | ||
} | ||
|
||
@NotNull | ||
public static com.intellij.execution.process.ProcessOutput execute(@NotNull GeneralCommandLine cmd) throws ExecutionException { | ||
return execute(cmd, STANDARD_TIMEOUT); | ||
} | ||
|
||
@NotNull | ||
public static com.intellij.execution.process.ProcessOutput execute(@NotNull GeneralCommandLine cmd, int timeout) throws ExecutionException { | ||
CapturingProcessHandler processHandler = new CapturingProcessHandler(cmd); | ||
return timeout < 0 ? processHandler.runProcess() : processHandler.runProcess(timeout); | ||
} | ||
|
||
public static boolean isSmallIde(){ | ||
return !(PlatformUtils.isIntelliJ() || PlatformUtils.getPlatformPrefix().equals("AndroidStudio")); | ||
} | ||
} |
Oops, something went wrong.