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

📄 update.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // reload libs if needed            libsToReload = new ArrayList<Library>();            if (type != UpdateEnum.STATUS && type != UpdateEnum.ROLLFORWARD) {                for (Cell cell : result.getCells(State.UPDATE)) {                    Library lib = cell.getLibrary();                    if (!libsToReload.contains(lib))                        libsToReload.add(lib);                }                for (int i = 0; i < libsToReload.size(); i++) {                    Library lib = libsToReload.get(i);                    String libName = lib.getName();                    LibraryFiles.reloadLibrary(lib);                    libsToReload.set(i, Library.findLibrary(libName));                }            }/*            if (type == UpdateEnum.ROLLBACK) {                // turn off edit for rolled back cells                for (Cell cell : result.getCells(State.UPDATE)) {                    CVSLibrary.setEditing(cell, false);                }            }*/            // update states            updateStates(result, type);            System.out.println(type.getMessage()+" complete.");            if (inJob) fieldVariableChanged("libsToReload");            return true;        }        public void terminateOK() {            if (exitVal != 0 && exitVal != 1) {                Job.getUserInterface().showErrorMessage("CVS "+type.getMessage()+                        " Failed (exit status "+exitVal+")!  Please see messages window","CVS "+type.getMessage()+" Failed!");                return;            }            WindowFrame.wantToRedoLibraryTree();            CVS.fixStaleCellReferences(libsToReload);            if (checkEditors) {                Edit.editConsistencyCheck(librariesToUpdate, cellsToUpdate);            }        }    }    static void statusNoJob(List<Library> libs, List<Cell> cells, boolean updateProject) {        UpdateJob job = new UpdateJob(cells, libs, UpdateEnum.STATUS, updateProject, false);        job.inJob = false;        job.doIt();    }    /**     * Update the given file in the given directory.     * @param file the name of the file.     * @param dir the directory.     * @return parsed output from running CVS.     */    protected static StatusResult update(String file, String dir, UpdateEnum type) {        String command = "-q update -d -P ";        String message = "Running CVS Update";        if (type == UpdateEnum.STATUS) {            command = "-nq update -d -P ";            message = "Running CVS Status";        }        if (type == UpdateEnum.ROLLBACK) {            command = "-q update -C -P ";            message = "Rollback from CVS";        }        ByteArrayOutputStream out = new ByteArrayOutputStream();        int exitVal = CVS.runCVSCommand(command+file, message,                    dir, out);        LineNumberReader result = new LineNumberReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));        return parseOutput(result, exitVal);    }    private static void updateStates(StatusResult result, UpdateEnum type) {        for (Cell cell : result.getCells(State.ADDED)) {            CVSLibrary.setState(cell, State.ADDED);        }        for (Cell cell : result.getCells(State.REMOVED)) {            CVSLibrary.setState(cell, State.REMOVED);        }        for (Cell cell : result.getCells(State.MODIFIED)) {            CVSLibrary.setState(cell, State.MODIFIED);        }        for (Cell cell : result.getCells(State.CONFLICT)) {            CVSLibrary.setState(cell, State.CONFLICT);        }        for (Cell cell : result.getCells(State.UPDATE)) {            if (type == UpdateEnum.STATUS)                CVSLibrary.setState(cell, State.UPDATE);            else                CVSLibrary.setState(cell, State.NONE);        }        for (Cell cell : result.getCells(State.UNKNOWN)) {            CVSLibrary.setState(cell, State.UNKNOWN);        }    }    // -------------------- Rollback ----------------------------    public static void rollback(Cell cell) {        int ret = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(),                "WARNING! Disk file for Cell "+cell.libDescribe()+" will revert to latest CVS version!\n"+                "All uncommited changes will be lost!!!  Continue anyway?", "Rollback Cell", JOptionPane.YES_NO_OPTION,                JOptionPane.WARNING_MESSAGE);        if (ret == JOptionPane.NO_OPTION) return;        updateCell(cell, UpdateEnum.ROLLBACK);    }    public static void rollback(Library lib) {        int ret = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(),                "WARNING! Disk file(s) for Library"+lib.getName()+" will revert to latest CVS version!\n"+                "All uncommited changes will be lost!!!  Continue anyway?", "Rollback Library", JOptionPane.YES_NO_OPTION,                JOptionPane.WARNING_MESSAGE);        if (ret == JOptionPane.NO_OPTION) return;        updateLibrary(lib, UpdateEnum.ROLLBACK);    }    // ---------------------- Output Parsing -------------------------    /**     * Parse the output of an 'cvs -nq update' command, which     * checks the status of the given files.     * Returns true if all files are up-to-date, false otherwise     * @param reader     * @return     */    private static StatusResult parseOutput(LineNumberReader reader, int exitVal) {        StatusResult result = new StatusResult(exitVal);        for (;;) {            String line;            try {                line = reader.readLine();            } catch (IOException e) {                System.out.println(e.getMessage());                return result;            }            if (line == null) break;            if (line.equals("")) continue;            String parts[] = line.split("\\s+");            if (parts.length != 2) continue;            State state = State.getState(parts[0]);            if (state == null) continue;            if (state == State.PATCHED) state = State.UPDATE;            // find Cell for filename            String filename = parts[1];            File file = new File(filename);            if (filename.toLowerCase().endsWith(".jelib")) {                // jelib library file, set state of all cells                String endfile = file.getName();                Library lib = Library.findLibrary(endfile.substring(0, endfile.length()-6));                if (lib == null) continue;                CVSLibrary.setState(lib, state);            }            Cell cell = CVS.getCellFromPath(filename);            if (cell != null) {                result.addCell(state, cell);                continue;            }            Library lib = CVS.getLibraryFromHeader(filename);            if (lib != null) {                result.addLibraryHeaderFile(state, lib);                continue;            }            // default action            result.addUnknownFile(state, filename);        }        return result;    }    /**     * Parse the output of an 'cvs -nq update' command, which     * checks the status of the given files.     * Returns true if all files are up-to-date, false otherwise     */    public static void commentStatusResult(StatusResult result, UpdateEnum type) {        boolean allFilesUpToDate = true;        for (Cell cell : result.getCells(State.ADDED)) {            System.out.println("Added\t"+cell.libDescribe());            allFilesUpToDate = false;        }        for (Cell cell : result.getCells(State.REMOVED)) {            System.out.println("Removed\t"+cell.libDescribe());            allFilesUpToDate = false;        }        for (Cell cell : result.getCells(State.MODIFIED)) {            System.out.println("Modified\t"+cell.libDescribe());            allFilesUpToDate = false;        }        for (String file : result.getUnknownFiles(State.MODIFIED)) {            System.out.println("Modified\t"+file);            allFilesUpToDate = false;        }        for (Cell cell : result.getCells(State.CONFLICT)) {            System.out.println("Conflicts\t"+cell.libDescribe());            allFilesUpToDate = false;        }        for (String file : result.getUnknownFiles(State.CONFLICT)) {            System.out.println("Conflicts\t"+file);            allFilesUpToDate = false;        }        for (Cell cell : result.getCells(State.UPDATE)) {            if (type == UpdateEnum.STATUS)                System.out.println("NeedsUpdate\t"+cell.libDescribe());            if (type == UpdateEnum.UPDATE)                System.out.println("Updated\t"+cell.libDescribe());            allFilesUpToDate = false;        }        for (String file : result.getUnknownFiles(State.UPDATE)) {            if (type == UpdateEnum.STATUS)                System.out.println("NeedsUpdate\t"+file);            if (type == UpdateEnum.UPDATE)                System.out.println("Updated\t"+file);            allFilesUpToDate = false;        }        if (type == UpdateEnum.STATUS) {            if (allFilesUpToDate) System.out.println("All files up-to-date");            else System.out.println("All other files up-to-date");        }    }    public static class StatusResult {        private Map<State,List<Cell>> cells;        private Map<State,List<String>> unknownFiles;        private Map<State,List<Library>> headerFiles;        private int exitVal;        private StatusResult(int exitVal) {            cells = new HashMap<State,List<Cell>>();            headerFiles = new HashMap<State,List<Library>>();            unknownFiles = new HashMap<State,List<String>>();            this.exitVal = exitVal;        }        private void addCell(State state, Cell cell) {            List<Cell> statecells = cells.get(state);            if (statecells == null) {                statecells = new ArrayList<Cell>();                cells.put(state, statecells);            }            statecells.add(cell);        }        public List<Cell> getCells(State state) {            List<Cell> statecells = cells.get(state);            if (statecells == null)                statecells = new ArrayList<Cell>();            return statecells;        }        public void addLibraryHeaderFile(State state, Library lib) {            List<Library> statelibs = headerFiles.get(state);            if (statelibs == null) {                statelibs = new ArrayList<Library>();                headerFiles.put(state, statelibs);            }            statelibs.add(lib);        }        public List<Library> getLibraryHeaderFiles(State state) {            List<Library> statelibs = headerFiles.get(state);            if (statelibs == null)                statelibs = new ArrayList<Library>();            return statelibs;        }        public void addUnknownFile(State state, String file) {            List<String> list = unknownFiles.get(state);            if (list == null) {                list = new ArrayList<String>();                unknownFiles.put(state, list);            }            list.add(file);        }        public List<String> getUnknownFiles(State state) {            List<String> list = unknownFiles.get(state);            if (list == null)                list = new ArrayList<String>();            return list;        }        public int getExitVal() { return exitVal; }    }}

⌨️ 快捷键说明

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