mergeclassliststask.java.svn-base

来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 125 行

SVN-BASE
125
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.ant;import java.io.File;import java.io.PrintStream;import java.io.BufferedReader;import java.io.FileReader;import java.io.FileOutputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Hashtable;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Task;/** * Merges multiple test class lists into one. * @see com.sun.tck.ant.GenClassListTask */public class MergeClassListsTask extends Task {    private Hashtable table = new Hashtable();    private String srcFiles;    private String dest;    // The method executing the task    public void execute() throws BuildException {        String[] src = srcFiles.split("\\s");        for (int i = 0; i < src.length; i++) {            parse(new File(src[i]));        }        dumpTable(new File(dest));    }    public void setSourceFiles(String srcFiles) {        this.srcFiles = srcFiles;    }    public void setDestFile(String dest) {        this.dest = dest;    }    public void parse(File f) throws BuildException {        BufferedReader lstIn;        String line;        try {            lstIn = new BufferedReader(new FileReader(f));        } catch (FileNotFoundException e) {            throw new BuildException(e.getMessage());        }        try {            while ((line = lstIn.readLine()) != null) {                //skip comments and empty lines                if (line.matches("^\\s*$")) continue;                if (line.matches("^\\s*#.*")) continue;                //split the line: "url class1[, class2[, class3[...]]]"                //into url and classes                int sep = line.indexOf(' ');                String url = line.substring(0, sep);                String classes = line.substring(sep, line.length()).trim();                                //add pair url -> classes into hash                if (table.containsKey(url)) {                    //merge classes if needed                    classes += ", " + table.get(url);                }                table.put(url, classes);            }                lstIn.close();        } catch (IOException e) {            throw new BuildException(e.getMessage());        }    }    public void dumpTable(File f) throws BuildException {        PrintStream lstOut = null;        try {            lstOut = new PrintStream(new FileOutputStream(f));        } catch (FileNotFoundException e) {            throw new BuildException(e.getMessage());        }        String[] sortedKeys = (String[]) table.keySet().toArray(new String[1]);        java.util.Arrays.sort(sortedKeys);        for (int i = 0; i < sortedKeys.length; i++) {            String url = sortedKeys[i];            lstOut.println(url + " " + table.get(url));        }        lstOut.close();    }}

⌨️ 快捷键说明

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