Search in sources :

Example 6 with IOError

use of java.io.IOError in project bazel by bazelbuild.

the class BlazeJavacMain method setLocations.

private static void setLocations(JavacFileManager fileManager, BlazeJavacArguments arguments) {
    try {
        fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, arguments.classPath());
        fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, ImmutableList.of(arguments.classOutput()));
        fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, arguments.sourcePath());
        // TODO(cushon): require an explicit bootclasspath
        Iterable<Path> bootClassPath = arguments.bootClassPath();
        if (!Iterables.isEmpty(bootClassPath)) {
            fileManager.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
        }
        fileManager.setLocationFromPaths(StandardLocation.ANNOTATION_PROCESSOR_PATH, arguments.processorPath());
        if (arguments.sourceOutput() != null) {
            fileManager.setLocationFromPaths(StandardLocation.SOURCE_OUTPUT, ImmutableList.of(arguments.sourceOutput()));
        }
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : Path(java.nio.file.Path) IOError(java.io.IOError) IOException(java.io.IOException)

Example 7 with IOError

use of java.io.IOError in project error-prone by google.

the class CompilationTestHelper method doTest.

/**
   * Performs a compilation and checks that the diagnostics and result match the expectations.
   */
// TODO(eaftan): any way to ensure that this is actually called?
public void doTest() {
    Preconditions.checkState(!sources.isEmpty(), "No source files to compile");
    List<String> allArgs = buildArguments(args);
    Result result = compile(sources, allArgs.toArray(new String[allArgs.size()]));
    for (Diagnostic<? extends JavaFileObject> diagnostic : diagnosticHelper.getDiagnostics()) {
        if (diagnostic.getCode().contains("error.prone.crash")) {
            fail(diagnostic.getMessage(Locale.ENGLISH));
        }
    }
    if (expectNoDiagnostics) {
        List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticHelper.getDiagnostics();
        assertWithMessage(String.format("Expected no diagnostics produced, but found %d: %s", diagnostics.size(), diagnostics)).that(diagnostics.size()).isEqualTo(0);
    } else {
        for (JavaFileObject source : sources) {
            try {
                diagnosticHelper.assertHasDiagnosticOnAllMatchingLines(source, lookForCheckNameInDiagnostic);
            } catch (IOException e) {
                throw new IOError(e);
            }
        }
        assertTrue("Unused error keys: " + diagnosticHelper.getUnusedLookupKeys(), diagnosticHelper.getUnusedLookupKeys().isEmpty());
    }
    if (expectedResult.isPresent()) {
        assertWithMessage(String.format("Expected compilation result %s, but was %s", expectedResult.get(), result)).that(result).isEqualTo(expectedResult.get());
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) IOError(java.io.IOError) LookForCheckNameInDiagnostic(com.google.errorprone.DiagnosticTestHelper.LookForCheckNameInDiagnostic) Diagnostic(javax.tools.Diagnostic) IOException(java.io.IOException) Result(com.sun.tools.javac.main.Main.Result)

Example 8 with IOError

use of java.io.IOError in project error-prone by google.

the class ErrorProneJavaCompilerTest method doCompile.

private CompilationResult doCompile(List<String> fileNames, List<String> extraArgs, List<Class<? extends BugChecker>> customCheckers) {
    DiagnosticTestHelper diagnosticHelper = new DiagnosticTestHelper();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(outputStream, UTF_8), true);
    ErrorProneInMemoryFileManager fileManager = new ErrorProneInMemoryFileManager();
    List<String> args = Lists.newArrayList("-d", tempDir.getRoot().getAbsolutePath(), "-proc:none");
    args.addAll(extraArgs);
    JavaCompiler errorProneJavaCompiler = (customCheckers.isEmpty()) ? new ErrorProneJavaCompiler() : new ErrorProneJavaCompiler(ScannerSupplier.fromBugCheckerClasses(customCheckers));
    JavaCompiler.CompilationTask task = errorProneJavaCompiler.getTask(printWriter, fileManager, diagnosticHelper.collector, args, null, fileManager.forResources(getClass(), fileNames.toArray(new String[0])));
    try {
        fileManager.close();
    } catch (IOException e) {
        throw new IOError(e);
    }
    return new CompilationResult(task.call(), diagnosticHelper);
}
Also used : JavaCompiler(javax.tools.JavaCompiler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) IOError(java.io.IOError) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 9 with IOError

use of java.io.IOError in project azure-iot-sdk-java by Azure.

the class DeviceClient method setOption_SetSASTokenExpiryTime.

private void setOption_SetSASTokenExpiryTime(Object value) {
    logger.LogInfo("Setting SASTokenExpiryTime as %s seconds, method name is %s ", value, logger.getMethodName());
    if (value != null) {
        //**Codes_SRS_DEVICECLIENT_25_022: [**"SetSASTokenExpiryTime" should have value type long**.]**
        long validTimeInSeconds;
        if (value instanceof Long) {
            validTimeInSeconds = (long) value;
        } else {
            throw new IllegalArgumentException("value is not long = " + value);
        }
        boolean restart = false;
        if (this.deviceIO.isOpen()) {
            try {
                /* Codes_SRS_DEVICECLIENT_25_024: [**"SetSASTokenExpiryTime" shall restart the transport
                     *                                  1. If the device currently uses device key and
                     *                                  2. If transport is already open
                     *                                 after updating expiry time
                    */
                if (this.config.getDeviceKey() != null) {
                    restart = true;
                    this.deviceIO.close();
                }
            } catch (IOException e) {
                throw new IOError(e);
            }
        }
        this.config.setTokenValidSecs(validTimeInSeconds);
        if (restart) {
            try {
                this.deviceIO.open();
            } catch (IOException e) {
                throw new IOError(e);
            }
        }
    } else {
        throw new IllegalArgumentException("value should be in secs");
    }
}
Also used : IOError(java.io.IOError) IOException(java.io.IOException)

Example 10 with IOError

use of java.io.IOError in project karaf by apache.

the class Main method main.

public static void main(String[] args) throws Exception {
    ClientConfig config = new ClientConfig(args);
    SimpleLogger.setLevel(config.getLevel());
    if (config.getFile() != null) {
        StringBuilder sb = new StringBuilder();
        sb.setLength(0);
        try (Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(config.getFile())))) {
            for (int c = reader.read(); c >= 0; c = reader.read()) {
                sb.append((char) c);
            }
        }
        config.setCommand(sb.toString());
    } else if (config.isBatch()) {
        StringBuilder sb = new StringBuilder();
        sb.setLength(0);
        Reader reader = new BufferedReader(new InputStreamReader(System.in));
        for (int c = reader.read(); c >= 0; c = reader.read()) {
            sb.append((char) c);
        }
        config.setCommand(sb.toString());
    }
    try (SshClient client = ClientBuilder.builder().build()) {
        FilePasswordProvider passwordProvider = null;
        final Console console = System.console();
        if (console != null) {
            passwordProvider = resourceKey -> {
                char[] pwd = console.readPassword("Enter password for " + resourceKey + ": ");
                return new String(pwd);
            };
            client.setFilePasswordProvider(passwordProvider);
            client.setUserInteraction(new UserInteraction() {

                @Override
                public void welcome(ClientSession s, String banner, String lang) {
                    System.out.println(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 (echo[i]) {
                                answers[i] = console.readLine(prompt[i] + " ");
                            } else {
                                answers[i] = new String(console.readPassword(prompt[i] + " "));
                            }
                            if (answers[i] == null) {
                                return null;
                            }
                        }
                        return answers;
                    } catch (IOError e) {
                        return null;
                    }
                }

                @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;
                }
            });
        }
        setupAgent(config.getUser(), config.getKeyFile(), client, passwordProvider);
        client.getProperties().put(FactoryManager.IDLE_TIMEOUT, String.valueOf(config.getIdleTimeout()));
        // TODO: remove the line below when SSHD-732 is fixed
        client.setKeyPairProvider(new FileKeyPairProvider());
        client.start();
        if (console != null) {
            console.printf("Logging in as %s\n", config.getUser());
        }
        ClientSession session = connectWithRetries(client, config);
        if (config.getPassword() != null) {
            session.addPasswordIdentity(config.getPassword());
        }
        session.auth().verify();
        int exitStatus = 0;
        try (Terminal terminal = TerminalBuilder.terminal()) {
            Attributes attributes = terminal.enterRawMode();
            try {
                ClientChannel channel;
                if (config.getCommand().length() > 0) {
                    ChannelExec exec = session.createExecChannel(config.getCommand() + "\n");
                    channel = exec;
                    channel.setIn(new ByteArrayInputStream(new byte[0]));
                    exec.setAgentForwarding(true);
                } else {
                    ChannelShell shell = session.createShellChannel();
                    channel = shell;
                    channel.setIn(new NoCloseInputStream(terminal.input()));
                    Map<PtyMode, Integer> modes = new HashMap<>();
                    // Control chars
                    modes.put(PtyMode.VINTR, attributes.getControlChar(ControlChar.VINTR));
                    modes.put(PtyMode.VQUIT, attributes.getControlChar(ControlChar.VQUIT));
                    modes.put(PtyMode.VERASE, attributes.getControlChar(ControlChar.VERASE));
                    modes.put(PtyMode.VKILL, attributes.getControlChar(ControlChar.VKILL));
                    modes.put(PtyMode.VEOF, attributes.getControlChar(ControlChar.VEOF));
                    modes.put(PtyMode.VEOL, attributes.getControlChar(ControlChar.VEOL));
                    modes.put(PtyMode.VEOL2, attributes.getControlChar(ControlChar.VEOL2));
                    modes.put(PtyMode.VSTART, attributes.getControlChar(ControlChar.VSTART));
                    modes.put(PtyMode.VSTOP, attributes.getControlChar(ControlChar.VSTOP));
                    modes.put(PtyMode.VSUSP, attributes.getControlChar(ControlChar.VSUSP));
                    modes.put(PtyMode.VDSUSP, attributes.getControlChar(ControlChar.VDSUSP));
                    modes.put(PtyMode.VREPRINT, attributes.getControlChar(ControlChar.VREPRINT));
                    modes.put(PtyMode.VWERASE, attributes.getControlChar(ControlChar.VWERASE));
                    modes.put(PtyMode.VLNEXT, attributes.getControlChar(ControlChar.VLNEXT));
                    modes.put(PtyMode.VSTATUS, attributes.getControlChar(ControlChar.VSTATUS));
                    modes.put(PtyMode.VDISCARD, attributes.getControlChar(ControlChar.VDISCARD));
                    // Input flags
                    modes.put(PtyMode.IGNPAR, getFlag(attributes, InputFlag.IGNPAR));
                    modes.put(PtyMode.PARMRK, getFlag(attributes, InputFlag.PARMRK));
                    modes.put(PtyMode.INPCK, getFlag(attributes, InputFlag.INPCK));
                    modes.put(PtyMode.ISTRIP, getFlag(attributes, InputFlag.ISTRIP));
                    modes.put(PtyMode.INLCR, getFlag(attributes, InputFlag.INLCR));
                    modes.put(PtyMode.IGNCR, getFlag(attributes, InputFlag.IGNCR));
                    modes.put(PtyMode.ICRNL, getFlag(attributes, InputFlag.ICRNL));
                    modes.put(PtyMode.IXON, getFlag(attributes, InputFlag.IXON));
                    modes.put(PtyMode.IXANY, getFlag(attributes, InputFlag.IXANY));
                    modes.put(PtyMode.IXOFF, getFlag(attributes, InputFlag.IXOFF));
                    // Local flags
                    modes.put(PtyMode.ISIG, getFlag(attributes, LocalFlag.ISIG));
                    modes.put(PtyMode.ICANON, getFlag(attributes, LocalFlag.ICANON));
                    modes.put(PtyMode.ECHO, getFlag(attributes, LocalFlag.ECHO));
                    modes.put(PtyMode.ECHOE, getFlag(attributes, LocalFlag.ECHOE));
                    modes.put(PtyMode.ECHOK, getFlag(attributes, LocalFlag.ECHOK));
                    modes.put(PtyMode.ECHONL, getFlag(attributes, LocalFlag.ECHONL));
                    modes.put(PtyMode.NOFLSH, getFlag(attributes, LocalFlag.NOFLSH));
                    modes.put(PtyMode.TOSTOP, getFlag(attributes, LocalFlag.TOSTOP));
                    modes.put(PtyMode.IEXTEN, getFlag(attributes, LocalFlag.IEXTEN));
                    // Output flags
                    modes.put(PtyMode.OPOST, getFlag(attributes, OutputFlag.OPOST));
                    modes.put(PtyMode.ONLCR, getFlag(attributes, OutputFlag.ONLCR));
                    modes.put(PtyMode.OCRNL, getFlag(attributes, OutputFlag.OCRNL));
                    modes.put(PtyMode.ONOCR, getFlag(attributes, OutputFlag.ONOCR));
                    modes.put(PtyMode.ONLRET, getFlag(attributes, OutputFlag.ONLRET));
                    shell.setPtyModes(modes);
                    shell.setPtyColumns(terminal.getWidth());
                    shell.setPtyLines(terminal.getHeight());
                    shell.setAgentForwarding(true);
                    String ctype = System.getenv("LC_CTYPE");
                    if (ctype == null) {
                        ctype = Locale.getDefault().toString() + "." + System.getProperty("input.encoding", Charset.defaultCharset().name());
                    }
                    shell.setEnv("LC_CTYPE", ctype);
                }
                channel.setOut(terminal.output());
                channel.setErr(terminal.output());
                channel.open().verify();
                if (channel instanceof PtyCapableChannelSession) {
                    registerSignalHandler(terminal, (PtyCapableChannelSession) channel);
                }
                channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0);
                if (channel.getExitStatus() != null) {
                    exitStatus = channel.getExitStatus();
                }
            } finally {
                terminal.setAttributes(attributes);
            }
        }
        System.exit(exitStatus);
    } catch (Throwable t) {
        if (config.getLevel() > SimpleLogger.WARN) {
            t.printStackTrace();
        } else {
            System.err.println(t.getMessage());
        }
        System.exit(1);
    }
}
Also used : SshClient(org.apache.sshd.client.SshClient) HashMap(java.util.HashMap) Attributes(org.jline.terminal.Attributes) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ChannelShell(org.apache.sshd.client.channel.ChannelShell) ClientSession(org.apache.sshd.client.session.ClientSession) Console(java.io.Console) PtyCapableChannelSession(org.apache.sshd.client.channel.PtyCapableChannelSession) InputStreamReader(java.io.InputStreamReader) PtyMode(org.apache.sshd.common.channel.PtyMode) Terminal(org.jline.terminal.Terminal) FileInputStream(java.io.FileInputStream) ChannelExec(org.apache.sshd.client.channel.ChannelExec) ClientChannel(org.apache.sshd.client.channel.ClientChannel) FileKeyPairProvider(org.apache.sshd.common.keyprovider.FileKeyPairProvider) NoCloseInputStream(org.apache.sshd.common.util.io.NoCloseInputStream) IOError(java.io.IOError) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) UserInteraction(org.apache.sshd.client.auth.keyboard.UserInteraction) FilePasswordProvider(org.apache.sshd.common.config.keys.FilePasswordProvider)

Aggregations

IOError (java.io.IOError)49 IOException (java.io.IOException)42 File (java.io.File)8 DataInputStream (java.io.DataInputStream)5 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Console (java.io.Console)4 IPartitioner (org.apache.cassandra.dht.IPartitioner)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 SshClient (org.apache.sshd.client.SshClient)3 UserInteraction (org.apache.sshd.client.auth.keyboard.UserInteraction)3 ClientChannel (org.apache.sshd.client.channel.ClientChannel)3 ClientSession (org.apache.sshd.client.session.ClientSession)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 PrintWriter (java.io.PrintWriter)2