-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
408 additions
and
257 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
61 changes: 61 additions & 0 deletions
61
deployment/src/main/java/io/quarkiverse/antora/deployment/LinuxIDUtil.java
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,61 @@ | ||
package io.quarkiverse.antora.deployment; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
final class LinuxIDUtil { | ||
|
||
private LinuxIDUtil() { | ||
} | ||
|
||
static String getLinuxID(String option) { | ||
Process process; | ||
|
||
try { | ||
StringBuilder responseBuilder = new StringBuilder(); | ||
String line; | ||
|
||
ProcessBuilder idPB = new ProcessBuilder().command("id", option); | ||
idPB.redirectError(new File("/dev/null")); | ||
idPB.redirectInput(new File("/dev/null")); | ||
|
||
process = idPB.start(); | ||
try (InputStream inputStream = process.getInputStream()) { | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { | ||
while ((line = reader.readLine()) != null) { | ||
responseBuilder.append(line); | ||
} | ||
safeWaitFor(process); | ||
return responseBuilder.toString(); | ||
} | ||
} catch (Throwable t) { | ||
safeWaitFor(process); | ||
throw t; | ||
} | ||
} catch (IOException e) { //from process.start() | ||
//swallow and return null id | ||
return null; | ||
} | ||
} | ||
|
||
private static void safeWaitFor(Process process) { | ||
boolean intr = false; | ||
try { | ||
for (;;) | ||
try { | ||
process.waitFor(); | ||
return; | ||
} catch (InterruptedException ex) { | ||
intr = true; | ||
} | ||
} finally { | ||
if (intr) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.