📄 addremove.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: AddRemove.java * * Copyright (c) 2003 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) 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 for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.cvspm;import com.sun.electric.tool.Job;import com.sun.electric.tool.io.output.DELIB;import com.sun.electric.tool.user.User;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.variable.ElectricObject;import java.util.List;import java.util.Iterator;import java.util.ArrayList;import java.util.HashMap;import java.io.*;import java.net.URL;/** * User: gainsley * Date: Mar 22, 2006 */public class AddRemove { public static void add(Library lib) { List<Library> libs = new ArrayList<Library>(); libs.add(lib); addremove(libs, null, true, false); } public static void add(Cell cell) { List<Cell> cells = new ArrayList<Cell>(); cells.add(cell); addremove(null, cells, true, false); } public static void remove(Library lib) { List<Library> libs = new ArrayList<Library>(); libs.add(lib); addremove(libs, null, false, false); } public static void remove(Cell cell) { List<Cell> cells = new ArrayList<Cell>(); cells.add(cell); addremove(null, cells, false, false); } /** * Add or Remove libs and cells from CVS. * @param libs * @param cells * @param add true to add to cvs, false to remove from cvs * @param undo true to undo add/remove (boolean add ignored in this case). */ public static void addremove(List<Library> libs, List<Cell> cells, boolean add, boolean undo) { if (libs == null) libs = new ArrayList<Library>(); if (cells == null) cells = new ArrayList<Cell>(); // make sure cells are part of a DELIB CVSLibrary.LibsCells bad = CVSLibrary.notFromDELIB(cells); if (bad.cells.size() > 0) { CVS.showError("Error: the following Cells are not part of a DELIB library and cannot be acted upon individually", "CVS Add/Remove Error", bad.libs, bad.cells); return; } bad = CVSLibrary.getModified(libs, cells); if (bad.libs.size() > 0 || bad.cells.size() > 0) { CVS.showError("Error: the following Libraries or Cells must be saved first", "CVS "+(add?"Add":"Remove")+" Error", bad.libs, bad.cells); return; } // delib cells must have library added first List<Library> assertLibsInCVS = new ArrayList<Library>(); for (Cell cell : cells) { Library lib = cell.getLibrary(); if (libs.contains(lib) || assertLibsInCVS.contains(lib)) continue; assertLibsInCVS.add(lib); } bad = CVSLibrary.getNotInCVS(assertLibsInCVS, null); if (bad.libs.size() > 0) { CVS.showError("Error: cannot add DELIB cells if cell's DELIB library is not in cvs", "CVS "+(add?"Add":"Remove")+" Error", bad.libs, bad.cells); return; } // optimize a little, remove cells from cells list if cell's lib in libs list CVSLibrary.LibsCells good = CVSLibrary.consolidate(libs, cells); if (!undo) { // when job generates files to add/remove, it will do the check to see if they are in // cvs or not. Don't do it here because we may specify lib to add unadded cells./* if (add) { good = CVSLibrary.getNotInCVS(libs, cells); } else { good = CVSLibrary.getInCVS(libs, cells); }*/ // issue final warning for Remove if (!add) { StringBuffer list = new StringBuffer("Warning! CVS Remove will delete disk files for these Libraries and Cells!!!"); for (Library lib : good.libs) list.append("\n "+lib.getName()); for (Cell cell : good.cells) list.append("\n "+cell.libDescribe()); if (!Job.getUserInterface().confirmMessage(list.toString())) return; } (new AddRemoveJob(good.libs, good.cells, add)).startJob(); } else { (new UndoAddRemoveJob(good.libs, good.cells)).startJob(); } } public static class AddRemoveJob extends Job { private List<Library> libs; private List<Cell> cells; private boolean add; private int exitVal; private HashMap<String,Integer> addedCellDirs; private AddRemoveJob(List<Library> libs, List<Cell> cells, boolean add) { super("CVS Add/Remove", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER); this.libs = libs; this.cells = cells; this.add = add; exitVal = -1; if (this.libs == null) this.libs = new ArrayList<Library>(); if (this.cells == null) this.cells = new ArrayList<Cell>(); addedCellDirs = new HashMap<String,Integer>(); } public boolean doIt() { String useDir = CVS.getUseDir(libs, cells); List<Library> stateChangeLibs = new ArrayList<Library>(); List<Cell> stateChangeCells = new ArrayList<Cell>(); // mark files as added/removed for (Library lib : libs) { if (CVS.isDELIB(lib)) { for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell cell = it.next(); if (add) { if (!CVS.isFileInCVS(CVS.getCellFile(cell))) stateChangeCells.add(cell); } else { if (CVS.isFileInCVS(CVS.getCellFile(cell))) stateChangeCells.add(cell); } } } else { // jelib or elib file if (add) { // if lib.getLibFile() is null -> library hasn't been saved URL fileURL = lib.getLibFile(); if (fileURL == null) { System.out.println("Library not on disk yet. Save it before applying this command"); exitVal = 0; return true; } if (!CVS.isFileInCVS(new File(fileURL.getPath()))) stateChangeLibs.add(lib); } else { if (!CVS.isFileInCVS(new File(lib.getLibFile().getPath()))) stateChangeLibs.add(lib); } } } for (Cell cell : cells) { if (add) { if (!CVS.isFileInCVS(CVS.getCellFile(cell))) stateChangeCells.add(cell); } else { if (CVS.isFileInCVS(CVS.getCellFile(cell))) stateChangeCells.add(cell); } } // unfortunately add/remove are not recursive, so we have // to specify directories as well as files to add/remove StringBuffer buf = new StringBuffer(); for (Library lib : libs) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -