use of java.io.IOError in project karaf by apache.
the class DeployMojo method deployWithSsh.
protected void deployWithSsh(List<String> locations) throws MojoExecutionException {
SshClient client = null;
try {
final Console console = System.console();
client = SshClient.setUpDefaultClient();
setupAgent(user, keyFile, client);
client.setUserInteraction(new UserInteraction() {
@Override
public void welcome(ClientSession s, String banner, String lang) {
console.printf(banner);
}
@Override
public String[] interactive(ClientSession s, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
String[] answers = new String[prompt.length];
try {
for (int i = 0; i < prompt.length; i++) {
if (console != null) {
if (echo[i]) {
answers[i] = console.readLine(prompt[i] + " ");
} else {
answers[i] = new String(console.readPassword(prompt[i] + " "));
}
}
}
} catch (IOError e) {
}
return answers;
}
@Override
public boolean isInteractionAllowed(ClientSession session) {
return true;
}
@Override
public void serverVersionInfo(ClientSession session, List<String> lines) {
}
@Override
public String getUpdatedPassword(ClientSession session, String prompt, String lang) {
return null;
}
});
client.start();
if (console != null) {
console.printf("Logging in as %s\n", user);
}
ClientSession session = connect(client);
if (password != null) {
session.addPasswordIdentity(password);
}
session.auth().verify();
StringWriter writer = new StringWriter();
PrintWriter print = new PrintWriter(writer, true);
for (String location : locations) {
print.println("bundle:install -s " + location);
}
final ClientChannel channel = session.createChannel("exec", writer.toString().concat(NEW_LINE));
channel.setIn(new ByteArrayInputStream(new byte[0]));
final ByteArrayOutputStream sout = new ByteArrayOutputStream();
final ByteArrayOutputStream serr = new ByteArrayOutputStream();
channel.setOut(AnsiConsole.wrapOutputStream(sout));
channel.setErr(AnsiConsole.wrapOutputStream(serr));
channel.open();
channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0);
sout.writeTo(System.out);
serr.writeTo(System.err);
// Expects issue KARAF-2623 is fixed
final boolean isError = (channel.getExitStatus() != null && channel.getExitStatus().intValue() != 0);
if (isError) {
final String errorMarker = Ansi.ansi().fg(Color.RED).toString();
final int fromIndex = sout.toString().indexOf(errorMarker) + errorMarker.length();
final int toIndex = sout.toString().lastIndexOf(Ansi.ansi().fg(Color.DEFAULT).toString());
throw new MojoExecutionException(NEW_LINE + sout.toString().substring(fromIndex, toIndex));
}
} catch (MojoExecutionException e) {
throw e;
} catch (Throwable t) {
t.printStackTrace();
throw new MojoExecutionException(t, t.getMessage(), t.toString());
} finally {
try {
client.stop();
} catch (Throwable t) {
throw new MojoExecutionException(t, t.getMessage(), t.toString());
}
}
}
use of java.io.IOError in project embulk by embulk.
the class MavenArtifactFinder method create.
public static MavenArtifactFinder create(final Path localMavenRepositoryPath) throws MavenRepositoryNotFoundException {
final Path absolutePath;
try {
absolutePath = localMavenRepositoryPath.normalize().toAbsolutePath();
} catch (IOError ex) {
throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex);
} catch (SecurityException ex) {
throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex);
}
if (!Files.exists(absolutePath)) {
throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, absolutePath, new NoSuchFileException(absolutePath.toString()));
}
if (!Files.isDirectory(absolutePath)) {
throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, absolutePath, new NotDirectoryException(absolutePath.toString()));
}
final RepositorySystem repositorySystem = createRepositorySystem();
return new MavenArtifactFinder(localMavenRepositoryPath, absolutePath, repositorySystem, createRepositorySystemSession(repositorySystem, absolutePath));
}
use of java.io.IOError in project JavaApps by stephenbaiuoft.
the class MergeSortWiki method sort.
// only takes input and prints
public void sort(String input) {
Scanner in = new Scanner(input);
int t = in.nextInt();
for (int a0 = 0; a0 < t; a0++) {
int n = in.nextInt();
int[] arr = new int[n];
for (int arr_i = 0; arr_i < n; arr_i++) {
try {
arr[arr_i] = in.nextInt();
} catch (IOError ie) {
System.out.println("arr_i is" + arr_i);
ie.printStackTrace();
;
} finally {
// System.out.println("arr_i is"+ arr_i);
}
}
// localTemp = Arrays.copyOf(arr, arr.length);
mergeSort(arr, 0, arr.length - 1);
if (verifySorted(arr)) {
System.out.println(Arrays.toString(arr));
System.out.println("num of swap is: " + countSwap);
} else {
System.out.println("ary is not sorted!!!");
}
}
}
use of java.io.IOError in project error-prone by google.
the class BaseErrorProneCompiler method run.
public Result run(String[] argv) {
try {
argv = CommandLine.parse(argv);
} catch (IOException e) {
throw new IOError(e);
}
List<String> javacOpts = new ArrayList<>();
List<String> sources = new ArrayList<>();
for (String arg : argv) {
// TODO(cushon): is there a better way to categorize javacopts?
if (!arg.startsWith("-") && arg.endsWith(".java")) {
sources.add(arg);
} else {
javacOpts.add(arg);
}
}
StandardJavaFileManager fileManager = new MaskedFileManager();
return run(javacOpts.toArray(new String[0]), fileManager, ImmutableList.copyOf(fileManager.getJavaFileObjectsFromStrings(sources)), /* processors= */
null);
}
use of java.io.IOError in project error-prone by google.
the class ErrorProneInMemoryFileManager method forResource.
/**
* Loads a resource of the provided class into a {@link JavaFileObject}.
*/
public JavaFileObject forResource(Class<?> clazz, String fileName) {
Path path = fileSystem.getPath("/", clazz.getPackage().getName().replace('.', '/'), fileName);
try (InputStream is = findResource(clazz, fileName)) {
Files.createDirectories(path.getParent());
Files.copy(is, path);
} catch (IOException e) {
throw new IOError(e);
}
return Iterables.getOnlyElement(getJavaFileObjects(path));
}
Aggregations