📄 addremove.java
字号:
generate(buf, lib, useDir); } for (Cell cell : cells) { generate(buf, cell, useDir); } String addRemoveFiles = buf.toString(); if (addRemoveFiles.trim().equals("")) { System.out.println("Nothing to "+(add ? "Add" : "Remove")); exitVal = 0; return true; } String command = add ? "add" : "remove -f"; String message = "Running CVS " + (add ? "Add" : "Remove"); exitVal = CVS.runCVSCommand("-q "+command+" "+addRemoveFiles, message, useDir, System.out); fieldVariableChanged("exitVal"); if (exitVal != 0) return true; System.out.println("CVS "+command+" complete"); for (Cell cell : stateChangeCells) { if (add) CVSLibrary.setState(cell, State.ADDED); else CVSLibrary.setState(cell, State.REMOVED); } for (Library lib : stateChangeLibs) { if (add) CVSLibrary.setState(lib, State.ADDED); else CVSLibrary.setState(lib, State.REMOVED); } return true; } private void generate(StringBuffer buf, Library lib, String useDir) { // see if library file is in CVS File libraryFile = TextUtils.getFile(lib.getLibFile()); if (libraryFile == null) return; String libfile = libraryFile.getPath(); add(buf, libfile, useDir); if (CVS.isDELIB(lib)) { // see if cell directories are in CVS for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { generate(buf, it.next(), useDir); } // add header file File headerFile = new File(libfile, DELIB.getHeaderFile()); add(buf, headerFile.getPath(), useDir); } } private void generate(StringBuffer buf, Cell cell, String useDir) { if (!CVS.isDELIB(cell.getLibrary())) return; File libraryFile = TextUtils.getFile(cell.getLibrary().getLibFile()); if (libraryFile == null) return; String libfile = libraryFile.getPath(); // get cell directory if not already added before File celldirFile = new File(libfile, DELIB.getCellSubDir(cell.getId())); String celldir = celldirFile.getPath(); if (!addedCellDirs.containsKey(celldir) && !libfile.equals(celldir)) { if (celldirFile.exists()) add(buf, celldir, useDir); addedCellDirs.put(celldir, null); } // check cell files File cellFile = new File(libfile, DELIB.getCellFile(cell)); add(buf, cellFile.getPath(), useDir); // check that header is added or in cvs, or library is going to be added if (add) { File headerFile = new File(libfile, DELIB.getHeaderFile()); if (!libs.contains(cell.getLibrary()) && !CVS.isFileInCVS(headerFile)) { add(buf, headerFile.getPath(), useDir); } } } private void add(StringBuffer buf, String file, String useDir) { File FD = new File(file); if ((add && !CVS.isFileInCVS(FD, false, false)) || (!add && CVS.isFileInCVS(FD, false, false))) { if (file.startsWith(useDir)) { file = file.substring(useDir.length()+1, file.length()); } buf.append(file+" "); } } public void terminateOK() { if (exitVal != 0) { Job.getUserInterface().showErrorMessage("CVS "+(add?"Add":"Remove")+ " Failed! Please see messages window (exit status "+exitVal+")","CVS "+(add?"Add":"Remove")+" Failed!"); } } } public static class UndoAddRemoveJob extends Job { private List<Library> libs; private List<Cell> cells; HashMap<File,ElectricObject> filesToUndo; private UndoAddRemoveJob(List<Library> libs, List<Cell> cells) { super("CVS Undo Add/Remove", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER); this.libs = libs; this.cells = cells; if (this.libs == null) this.libs = new ArrayList<Library>(); if (this.cells == null) this.cells = new ArrayList<Cell>(); } public boolean doIt() {// StringBuffer buf = new StringBuffer(); for (Library lib : libs) { undo(lib); } for (Cell cell : cells) { undo(cell); } System.out.println("Undo CVS Add/Remove complete"); return true; } private void undo(Library lib) { // see if library file is in CVS File libraryFile = TextUtils.getFile(lib.getLibFile()); if (libraryFile == null) return; String libfile = libraryFile.getPath(); if (!CVS.isDELIB(lib)) { if (undo(new File(libfile))) { State state = CVSLibrary.getState(lib); if (state == State.ADDED) CVSLibrary.setState(lib, State.UNKNOWN); if (state == State.REMOVED) CVSLibrary.setState(lib, State.NONE); } } else { for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { undo(it.next()); } // undo header file File headerFile = new File(libfile, DELIB.getHeaderFile()); undo(headerFile); } } private void undo(Cell cell) { if (!CVS.isDELIB(cell.getLibrary())) return; File libraryFile = TextUtils.getFile(cell.getLibrary().getLibFile()); if (libraryFile == null) return; String libfile = libraryFile.getPath(); // get cell directory if not already added before // check cell files File cellFile = new File(libfile, DELIB.getCellFile(cell)); if (undo(cellFile)) { State state = CVSLibrary.getState(cell); if (state == State.ADDED) CVSLibrary.setState(cell, State.UNKNOWN); if (state == State.REMOVED) CVSLibrary.setState(cell, State.NONE); } } /** * Return true if succeeded, false otherwise * @param FD * @return */ private boolean undo(File FD) { if (FD.isDirectory()) return false; File parent = FD.getParentFile(); File CVSDIR = new File(parent, "CVS"); if (!CVSDIR.exists()) return false; File entries = new File(CVSDIR, "Entries"); if (!entries.exists()) return false; File entriestemp = new File(CVSDIR, "Entries.temp"); String filename = FD.getName(); boolean success = false; try { LineNumberReader reader = new LineNumberReader(new FileReader(entries)); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(entriestemp, false))); for (;;) { String line = reader.readLine(); if (line == null) break; if (line.equals("")) continue; String parts[] = line.split("/"); boolean skip = false; if (parts.length >= 2 && parts[1].equals(filename)) { // make sure it is scheduled for add/remove if (parts.length >= 3 && parts[2].equals("0")) { // scheduled for add, remove entry skip = true; success = true; } if (parts.length >= 3 && parts[2].startsWith("-")) { // schedule to remove, remove entry line = line.replaceAll("/"+parts[2]+"/", "/"+parts[2].substring(1)+"/"); success = true; } } if (!skip) pw.println(line); } reader.close(); pw.close(); // replace original with modified if (!entriestemp.renameTo(entries)) { System.out.println("Unable to move "+entriestemp+" to "+entries+", cannot undo add/remove of "+filename); return false; } } catch (IOException e) { } return success; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -