📄 update.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: Update.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.database.hierarchy.Library;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.text.TextUtils;import com.sun.electric.tool.Job;import com.sun.electric.tool.io.input.LibraryFiles;import com.sun.electric.tool.io.output.DELIB;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowFrame;import javax.swing.JOptionPane;import java.io.*;import java.util.*;/** * User: gainsley * Date: Mar 13, 2006 */public class Update { public enum UpdateEnum {UPDATE("Update"), STATUS("Status"), ROLLBACK("Roll Back"), ROLLFORWARD("Roll Forward"); String name; UpdateEnum(String n) { name = n; } String getMessage() {return name;} }; // ------------------ Update/Status --------------------- /** * Update all libraries. * @param type the type of update to do */ public static void updateProject(UpdateEnum type) { List<Library> allLibs = new ArrayList<Library>(); for (Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (lib.isHidden()) continue; if (!lib.isFromDisk()) continue; if (lib.getName().equals("spiceparts")) continue; allLibs.add(lib); } update(allLibs, null, type, true, true); } /** * Update all open libraries. * @param type the type of update to do */ public static void updateOpenLibraries(UpdateEnum type) { List<Library> allLibs = new ArrayList<Library>(); for (Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (lib.isHidden()) continue; if (!lib.isFromDisk()) continue; if (lib.getName().equals("spiceparts")) continue; allLibs.add(lib); } update(allLibs, null, type, false, true); } /** * Update all Cells from a library. * @param lib * @param type the type of update to do */ public static void updateLibrary(Library lib, UpdateEnum type) { List<Library> libsToUpdate = new ArrayList<Library>(); libsToUpdate.add(lib); update(libsToUpdate, null, type, false, false); } /** * Update a Cell. * @param cell * @param type the type of update to do */ public static void updateCell(Cell cell, UpdateEnum type) { List<Cell> cellsToUpdate = new ArrayList<Cell>(); cellsToUpdate.add(cell); update(null, cellsToUpdate, type, false, false); } /** * Run Update/Status/Rollback on the libraries and cells * @param libs * @param cells * @param type * @param updateProject * @param checkEditors */ public static void update(List<Library> libs, List<Cell> cells, UpdateEnum type, boolean updateProject, boolean checkEditors) { 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 (type == UpdateEnum.STATUS) { // remove offending cells for (Cell cell : bad.cells) cells.remove(cell); } else 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 "+type.getMessage()+" Error", bad.libs, bad.cells); return; } // make sure the selecetd objecs are in cvs bad = CVSLibrary.getNotInCVS(libs, cells); // for STATUS, remove libraries not in cvs, and also set their state unknown if (type == UpdateEnum.STATUS) { for (Library lib : bad.libs) { libs.remove(lib); CVSLibrary.setState(lib, State.UNKNOWN); } for (Cell cell : bad.cells) { cells.remove(cell); CVSLibrary.setState(cell, State.UNKNOWN); } } else if (bad.libs.size() > 0 || bad.cells.size() > 0) { // if any of them not in cvs, issue error and abort CVS.showError("Error: the following Libraries or Cells are not in CVS", "CVS "+type.getMessage()+" 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); // for update or rollback, make sure they are also not modified if (type == UpdateEnum.UPDATE) { bad = CVSLibrary.getModified(libs, cells); if (bad.libs.size() > 0 || bad.cells.size() > 0) { String [] choices = new String [] { "Continue Anyway", "Cancel" }; int choice = CVS.askForChoice("Warning: Unsaved changes may be lost! For:", "CVS "+type.getMessage()+" Warning!", bad.libs, bad.cells, choices, choices[1]); if (choice == 1) return; } } // issue final warning for rollback if (type == UpdateEnum.ROLLBACK) { String [] choices = new String [] { "Continue Anyway", "Cancel" }; int choice = CVS.askForChoice("Warning: Saved and Unsaved changes will be lost! For:", "CVS "+type.getMessage()+" Warning!", good.libs, good.cells, choices, choices[1]); if (choice == 1) return; } (new UpdateJob(good.cells, good.libs, type, updateProject, checkEditors)).startJob(); } private static class UpdateJob extends Job { private List<Cell> cellsToUpdate; private List<Library> librariesToUpdate; private UpdateEnum type; private List<Library> libsToReload; private boolean updateProject; // update whole project private int exitVal; private boolean inJob; private boolean checkEditors; /** * Update cells and/or libraries. * @param cellsToUpdate * @param librariesToUpdate */ private UpdateJob(List<Cell> cellsToUpdate, List<Library> librariesToUpdate, UpdateEnum type, boolean updateProject, boolean checkEditors) { super("CVS Update Library, " + type.getMessage(), User.getUserTool(), ((type==UpdateEnum.STATUS)?Job.Type.EXAMINE:Job.Type.CHANGE), null, null, Job.Priority.USER); this.cellsToUpdate = cellsToUpdate; this.librariesToUpdate = librariesToUpdate; this.type = type; this.updateProject = updateProject; this.checkEditors = checkEditors; exitVal = -1; inJob = true; if (this.cellsToUpdate == null) this.cellsToUpdate = new ArrayList<Cell>(); if (this.librariesToUpdate == null) this.librariesToUpdate = new ArrayList<Library>(); } public boolean doIt() { String useDir = CVS.getUseDir(librariesToUpdate, cellsToUpdate); StringBuffer libs = CVS.getLibraryFiles(librariesToUpdate, useDir); StringBuffer cells = CVS.getCellFiles(cellsToUpdate, useDir); // disable lastModified for now, since users with older versions // of electric will not commit new lastModified file, // and then users of new electric will not get updated files // // Also, last modified won't work, because user can commit cell A, // then commit cell B, then rollback cell A. Electric can't tell // whether or not to also rollback lastModified file List<File> backupFiles = new ArrayList<File>(); if (type == UpdateEnum.ROLLFORWARD) { // build list of files to back up for (Library lib : librariesToUpdate) { File libFile = TextUtils.getFile(lib.getLibFile()); if (libFile == null) continue; if (CVS.isDELIB(lib)) { // add all cell files and header file for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { backupFiles.add(CVS.getCellFile(it.next())); } backupFiles.add(new File(libFile, DELIB.getHeaderFile())); } else { backupFiles.add(libFile); } } for (Cell cell : cellsToUpdate) { backupFiles.add(CVS.getCellFile(cell)); } // move all the files out of the way for (File f : backupFiles) { File newf = new File(f.getAbsolutePath()+".ecvstemp"); if (!f.exists()) continue; if (!f.renameTo(newf)) { System.out.println("Could not rename file "+f+" to "+newf); } else { System.out.println("Renamed "+f+" to "+newf); } } } String updateFiles = libs.toString() + " " + cells.toString(); if (updateFiles.trim().equals("") && !updateProject) { exitVal = 0; if (inJob) fieldVariableChanged("exitVal"); System.out.println("Nothing to "+type.getMessage()); return true; } if (updateProject && (type == UpdateEnum.UPDATE || type == UpdateEnum.STATUS)) updateFiles = ""; StatusResult result = update(updateFiles, useDir, type); commentStatusResult(result, type); exitVal = result.getExitVal(); if (type == UpdateEnum.ROLLFORWARD) { // even if update failed, restore user's files for (File f : backupFiles) { File newf = new File(f.getAbsolutePath()+".ecvstemp"); if (newf.exists()) if (!newf.renameTo(f)) { System.out.println("Error: unabled to rename "+newf+" to "+f); } else { System.out.println("Renamed "+newf+" to "+f); } } // reload status result = update(updateFiles, useDir, UpdateEnum.STATUS); commentStatusResult(result, type); } if (inJob) fieldVariableChanged("exitVal"); if (exitVal != 0 && exitVal != 1) { return true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -