⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exectasktest.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            getFileString("redirector.err"));        assertPropertyEquals("redirector.err", expectedErr.trim());    }    public void testRedirector8() throws IOException {        executeTarget("redirector8");        if (getProject().getProperty("wc.can.run") == null) {            return;        }        assertEquals("unexpected output", "3", getFileString("redirector.out").trim());        assertEquals("property redirector.out", "3",            getProject().getProperty("redirector.out").trim());        assertNull("unexpected error output", getFileString("redirector.err"));        assertPropertyEquals("redirector.err", "");    }    public void testRedirector9() throws IOException {        testRedirector9Thru12("redirector9");    }    public void testRedirector10() throws IOException {        testRedirector9Thru12("redirector10");    }    public void testRedirector11() throws IOException {        testRedirector9Thru12("redirector11");    }    public void testRedirector12() throws IOException {        testRedirector9Thru12("redirector12");    }    private void testRedirector9Thru12(String target) throws IOException {        executeTarget(target);        if (getProject().getProperty("cat.can.run") == null) {            return;        }        String expectedOut = "blah after blah";        assertEquals("unexpected output",            expectedOut, getFileString("redirector.out").trim());        assertPropertyEquals("redirector.out", expectedOut.trim());        assertNull("unexpected error output", getFileString("redirector.err"));        assertPropertyEquals("redirector.err", "");    }    public void testRedirector13() {        executeTarget("redirector13");        if (getProject().getProperty("test.can.run") == null) {            return;        }        String antfile = getProject().getProperty("ant.file");        try {            //no point in setting a message            assertEquals(antfile + " OUTPUT???" + antfile + " ERROR!!!", getLog());        } catch (ComparisonFailure cf) {            assertEquals("unexpected log content",                antfile + " ERROR!!!" + antfile + " OUTPUT???", getLog());        }    }    public void testRedirector14() {        executeTarget("redirector14");        if (getProject().getProperty("cat.can.run") == null) {            return;        }        assertEquals("unexpected log output", "blah after blah", getLog());    }    public void testRedirector15() throws IOException {        executeTarget("redirector15");        if (getProject().getProperty("cat.can.run") == null) {            return;        }        assertTrue("error with transcoding",            FILE_UTILS.contentEquals(            getProject().resolveFile("expected/utf-8"),            getProject().resolveFile("redirector.out")));    }    public void testRedirector16() {        executeTarget("redirector16");    }    public void testRedirector17() {        executeTarget("redirector17");    }    public void testRedirector18() {        if (getProject().getProperty("test.can.run") == null) {            return;        }        expectLog("redirector18", getProject().getProperty("ant.file")            + " out" + getProject().getProperty("ant.file") + " err");    }    public void testspawn() {        project.executeTarget("init");        if (project.getProperty("test.can.run") == null) {            return;        }        myBuild = new MonitoredBuild(new File(System.getProperty("root"), BUILD_FILE), "spawn");        logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir(), false, false);        // this is guaranteed by FileUtils#createTempFile        assertTrue("log file not existing", !logFile.exists());        // make the spawned process run 4 seconds        myBuild.setTimeToWait(TIME_TO_WAIT);        myBuild.setLogFile(logFile.getAbsolutePath());        myBuild.addBuildListener(new MonitoredBuildListener());        myBuild.start();        GregorianCalendar startwait = new GregorianCalendar();        // this loop runs parallel to the build        while (!buildFinished) {            try {                Thread.sleep(10);            } catch (InterruptedException e) {                System.out.println("my sleep was interrupted");            }            GregorianCalendar now = new GregorianCalendar();            // security            if (now.getTime().getTime() - startwait.getTime().getTime() > MAX_BUILD_TIME) {                System.out.println("aborting wait, too long " + (now.getTime().getTime() - startwait.getTime().getTime()) + "milliseconds");                break;            }        }        // now wait until the spawned process is finished        try {            Thread.sleep((TIME_TO_WAIT) * 1000 + SECURITY_MARGIN);        } catch (InterruptedException e) {            System.out.println("my sleep was interrupted");        }        // time of the build in milli seconds        long elapsed = myBuild.getTimeElapsed();        assertTrue("we waited more than the process lasted", TIME_TO_WAIT * 1000                + SECURITY_MARGIN > elapsed);        logFile = new File(logFile.getAbsolutePath());        assertTrue("log file found after spawn", logFile.exists());    }    public void testExecUnknownOS() {        executeTarget("testExecUnknownOS");    }    public void testExecOSFamily() {        executeTarget("testExecOSFamily");    }    public void testExecInconsistentSettings() {        executeTarget("testExecInconsistentSettings");    }        private static class MonitoredBuild implements Runnable {        private Thread worker;        private File myBuildFile = null;        private String target = null;        private Project project = null;        private int timeToWait = 0;        private String logFile = null;        private GregorianCalendar timeStarted = null;        private GregorianCalendar timeFinished = null;        public void setLogFile(String logFile) {            this.logFile = logFile;            project.setProperty("logFile", logFile);        }        public void setTimeToWait(int timeToWait) {            this.timeToWait = timeToWait;            project.setProperty("timeToWait", Long.toString(timeToWait));        }        public void addBuildListener(BuildListener bl) {            project.addBuildListener(bl);        }        public MonitoredBuild(File buildFile, String target) {            myBuildFile = buildFile;            this.target = target;            project=new Project();            project = new Project();            project.init();            project.setUserProperty( "ant.file" , myBuildFile.getAbsolutePath() );            ProjectHelper.configureProject(project, myBuildFile);        }        /**         *         * @return time in millis of the build         */        public long getTimeElapsed() {            return timeFinished.getTime().getTime() - timeStarted.getTime().getTime();        }        public void start() {            worker = new Thread(this, myBuildFile.toString() + "/" + target);            worker.start();        }        public void run() {            startProject();        }        private void startProject() {            timeStarted = new GregorianCalendar();            project.executeTarget(target);            timeFinished = new GregorianCalendar();        }    }    private class MonitoredBuildListener implements BuildListener {        public void buildStarted(BuildEvent event) {        }        public void buildFinished(BuildEvent event) {        }        public void targetStarted(BuildEvent event) {        }        public void targetFinished(BuildEvent event) {            if (event.getTarget().getName().equals("spawn")) {                buildFinished = true;            }        }        public void taskStarted(BuildEvent event) {        }        public void taskFinished(BuildEvent event) {        }        public void messageLogged(BuildEvent event) {        }    }    //borrowed from TokenFilterTest    private String getFileString(String filename) throws IOException {        String result = null;        FileReader reader = null;        try {            reader = new FileReader(getProject().resolveFile(filename));            result = FileUtils.readFully(reader);        } catch (IOException eyeOhEx) {        } finally {            FileUtils.close(reader);        }        return result;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -