List of usage examples for java.lang System setIn
public static void setIn(InputStream in)
From source file:org.gradle.integtests.fixtures.executer.InProcessGradleExecuter.java
private BuildResult doRun(OutputStream outputStream, OutputStream errorStream, BuildListenerImpl listener) { // Capture the current state of things that we will change during execution InputStream originalStdIn = System.in; Properties originalSysProperties = new Properties(); originalSysProperties.putAll(System.getProperties()); File originalUserDir = new File(originalSysProperties.getProperty("user.dir")).getAbsoluteFile(); Map<String, String> originalEnv = new HashMap<String, String>(System.getenv()); GradleInvocation invocation = buildInvocation(); Set<String> changedEnvVars = new HashSet<String>(invocation.environmentVars.keySet()); try {/*from w ww .j a v a 2 s. com*/ return executeBuild(invocation, outputStream, errorStream, listener); } finally { // Restore the environment System.setProperties(originalSysProperties); resetTempDirLocation(); processEnvironment.maybeSetProcessDir(originalUserDir); for (String envVar : changedEnvVars) { String oldValue = originalEnv.get(envVar); if (oldValue != null) { processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue); } else { processEnvironment.maybeRemoveEnvironmentVariable(envVar); } } System.setProperty("user.dir", originalSysProperties.getProperty("user.dir")); System.setIn(originalStdIn); } }
From source file:org.gradle.integtests.fixtures.executer.InProcessGradleExecuter.java
private BuildResult executeBuild(GradleInvocation invocation, OutputStream outputStream, OutputStream errorStream, BuildListenerImpl listener) { // Augment the environment for the execution System.setIn(connectStdIn()); processEnvironment.maybeSetProcessDir(getWorkingDir()); for (Map.Entry<String, String> entry : invocation.environmentVars.entrySet()) { processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue()); }/*from w w w . ja va2 s .com*/ Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties(); System.getProperties().putAll(implicitJvmSystemProperties); resetTempDirLocation(); // TODO: Fix tests that rely on this being set before we process arguments like this... StartParameterInternal startParameter = new StartParameterInternal(); startParameter.setCurrentDir(getWorkingDir()); // TODO: Reuse more of CommandlineActionFactory CommandLineParser parser = new CommandLineParser(); BuildLayoutFactory buildLayoutFactory = new BuildLayoutFactory(); ParametersConverter parametersConverter = new ParametersConverter(buildLayoutFactory); parametersConverter.configure(parser); final Parameters parameters = new Parameters(startParameter); parametersConverter.convert(parser.parse(getAllArgs()), parameters); BuildActionExecuter<BuildActionParameters> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class); ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class); listenerManager.addListener(listener); try { // TODO: Reuse more of BuildActionsFactory BuildAction action = new ExecuteBuildAction(startParameter); BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter); BuildRequestContext buildRequestContext = createBuildRequestContext(); LoggingManagerInternal loggingManager = createLoggingManager(startParameter, outputStream, errorStream); loggingManager.start(); try { startMeasurement(); try { actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES); } finally { stopMeasurement(); } } finally { loggingManager.stop(); } return new BuildResult(null, null); } catch (ReportedException e) { return new BuildResult(null, e.getCause()); } finally { listenerManager.removeListener(listener); } }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishStdInAutoDetect() throws Exception { String test = "This is an test."; System.setIn(new ByteArrayInputStream(test.getBytes())); String[] args = { "-adl" }; Main.main(args);/* ww w .jav a2 s . c o m*/ String stdout = new String(this.out.toByteArray()); String stderr = new String(this.err.toByteArray()); assertTrue(stderr.indexOf("Working on STDIN...") == 0); assertTrue(stderr.contains("Using English for")); assertTrue(stdout.contains("1.) Line 1, column 9, Rule ID: EN_A_VS_AN")); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testStdInWithExternalFalseFriends() throws Exception { String test = "Lska!\n"; System.setIn(new ByteArrayInputStream(test.getBytes())); String[] args = { "-l", "sk", "--falsefriends", getExternalFalseFriends(), "-m", "pl", "-" }; Main.main(args);//ww w. j av a2 s . c om String stdout = new String(this.out.toByteArray()); String stderr = new String(this.err.toByteArray()); assertTrue(stderr.contains("Expected text language: Slovak")); assertTrue(stderr.contains("Working on STDIN...")); assertTrue(stdout.contains("Rule ID: LASKA")); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishStdIn1() throws Exception { String test = "This is an test."; System.setIn(new ByteArrayInputStream(test.getBytes())); String[] args = { "-l", "en" }; Main.main(args);/* w w w . j ava2 s. c o m*/ String stdout = new String(this.out.toByteArray()); String stderr = new String(this.err.toByteArray()); assertTrue(stderr.indexOf("Expected text language: English") == 0); assertTrue(stdout.contains("1.) Line 1, column 9, Rule ID: EN_A_VS_AN")); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishStdIn2() throws Exception { String test = "This is an test."; System.setIn(new ByteArrayInputStream(test.getBytes())); String[] args = { "-l", "en", "-" }; Main.main(args);//w ww . j a v a 2s . c om String stdout = new String(this.out.toByteArray()); String stderr = new String(this.err.toByteArray()); assertTrue(stderr.indexOf("Expected text language: English") == 0); assertTrue(stdout.contains("1.) Line 1, column 9, Rule ID: EN_A_VS_AN")); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishStdIn3() throws Exception { String test = "This is an test."; System.setIn(new ByteArrayInputStream(test.getBytes())); String[] args = { "-l", "en", "-a", "-" }; Main.main(args);/*from w ww . j a va 2 s.c o m*/ String output = new String(this.out.toByteArray()); assertEquals("This is a test.", output); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishStdIn4() throws Exception { System.setIn(new FileInputStream(enTestFile)); String[] args = { "-l", "en", "--api", "-" }; Main.main(args);// w w w. j av a2s .c o m String output = new String(this.out.toByteArray()); assertTrue("Got: " + output, output.contains("<error fromy=\"4\" fromx=\"5\" toy=\"4\" " + "tox=\"10\" ruleId=\"ENGLISH_WORD_REPEAT_RULE\" msg=\"Possible typo: you repeated a word\" shortmsg=\"Word repetition\" " + "replacements=\"is\" context=\".... This is a test of of language tool. This is is a test of language tool. \"" + " contextoffset=\"48\" offset=\"60\" errorlength=\"5\" category=\"Miscellaneous\" categoryid=\"MISC\" locqualityissuetype=\"duplication\"/>")); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishStdInJsonOutput() throws Exception { System.setIn(new FileInputStream(enTestFile)); String[] args = { "-l", "en", "--json", "-" }; Main.main(args);//from w ww . j a va 2s . c o m String output = new String(this.out.toByteArray()); assertTrue("Got: " + output, output.contains("\"matches\":[{\"message\":\"Use \\\"a\\\" instead of 'an'")); assertTrue("Got: " + output, output.contains("\"shortMessage\":\"Wrong article\"")); assertTrue("Got: " + output, output.contains("\"replacements\":[{\"value\":\"a\"}]")); assertTrue("Got: " + output, output.contains("\"offset\":8")); assertTrue("Got: " + output, output.contains("\"length\":2")); assertTrue("Got: " + output, output .contains("\"context\":{\"text\":\"This is an test. This is a test of of language tool. ...\"")); assertTrue("Got: " + output, output.contains("\"id\":\"EN_A_VS_AN\"")); assertTrue("Got: " + output, output.contains("\"description\":\"Use of")); assertTrue("Got: " + output, output.contains("\"issueType\":\"misspelling\"")); assertTrue("Got: " + output, output.contains("\"category\":{\"id\":\"MISC\",\"name\":\"Miscellaneous\"}")); assertTrue("Got: " + output, output.contains("\"message\":\"Possible typo: you repeated a word\"")); assertTrue("Got: " + output, output.contains("\"sentence\":\"This is an test.\"")); assertTrue("Doesn't display Time", !output.contains("Time: ")); assertTrue("Json start check", output.startsWith("{\"software\":{\"name\":\"LanguageTool\",\"version\":")); assertTrue("Json end check", output.endsWith("}]}")); }
From source file:org.languagetool.commandline.MainTest.java
@Test public void testEnglishLineMode() throws Exception { String test = "This is what I mean\nand you know it."; System.setIn(new ByteArrayInputStream(test.getBytes())); String[] args = { "-l", "en", "-a", "-b", "-" }; Main.main(args);//from w w w. jav a 2 s . c om String output = new String(this.out.toByteArray()); assertEquals("This is what I mean\nAnd you know it.", output); }