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

📄 cvs.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: CVSMenu.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.hierarchy.View;import com.sun.electric.database.text.Pref;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.variable.VarContext;import com.sun.electric.database.Snapshot;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.Exec;import com.sun.electric.tool.user.dialogs.ModalCommandDialog;import com.sun.electric.tool.user.dialogs.OpenFile;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.user.ui.WindowFrame;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.io.output.DELIB;import com.sun.electric.tool.Job;import com.sun.electric.tool.Listener;import javax.swing.*;import java.io.*;import java.util.List;import java.util.ArrayList;import java.util.Iterator;import java.net.URL;/** * The CVS Module */public class CVS extends Listener {    private static CVS tool = new CVS();    private CVS() {        super("CVS");    }    public void init() {        setOn();    }    public static CVS getCVSTool() { return tool; }    /**      * Handles database changes of a Job.      * @param oldSnapshot database snapshot before Job.      * @param newSnapshot database snapshot after Job and constraint propagation.      * @param undoRedo true if Job was Undo/Redo job.      */     public void endBatch(Snapshot oldSnapshot, Snapshot newSnapshot, boolean undoRedo)     {         if (!CVS.isEnabled()) return;         if (newSnapshot.tool == tool) return;         Edit.endBatch(oldSnapshot, newSnapshot, undoRedo);     }    public static void checkoutFromRepository() {        // get list of modules in repository        ByteArrayOutputStream out = new ByteArrayOutputStream();        runModalCVSCommand("-n checkout -c", "Getting modules in repository...", User.getWorkingDirectory(), out);        // this must come after the runModal command        LineNumberReader result = new LineNumberReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));        List<String> modules = new ArrayList<String>();        for (;;) {            String line = null;            try {                line = result.readLine();            } catch (IOException e) {                System.out.println(e.getMessage());                return;            }            if (line == null) break;            line = line.trim();            if (line.equals("")) continue;            String[] parts = line.split("\\s");            modules.add(parts[0]);        }        if (modules.size() == 0) {            System.out.println("No modules in CVS!");            return;        }        Object ret = JOptionPane.showInputDialog(TopLevel.getCurrentJFrame(), "Choose Module to Checkout",                "Checkout Module...", JOptionPane.QUESTION_MESSAGE, null, modules.toArray(), modules.toArray()[0]);        if (ret == null) {            // user cancelled            return;        }        String module = (String)ret;        // choose directory to checkout to        String directory = OpenFile.chooseDirectory("Choose directory in which to checkout module "+module);        if (directory == null) {            // user cancelled            return;        }        // checkout module to current working directory        String cmd = "checkout "+module;        runModalCVSCommand(cmd, "Checking out '"+module+"' to "+directory, directory, System.out);        System.out.println("Checked out '"+module+"' to '"+directory+"'");    }    // ------------------------------------------------------------------------    /**     * This will run a CVS command in-thread; i.e. the current thread will     * block until the CVS command completes.     * @param cmd the command to run     * @param comment the message to display on the dialog     * @param workingDir the directory in which to run the CVS command     * (null for current working directory). I recommend you specify     * this as the current library dir.     * @param out where the result of the command gets printed. May be     * a ByteArrayOutputStream for storing it, or just System.out for     * printing it.     * @return the exit value     */    public static int runCVSCommand(String cmd, String comment, String workingDir, OutputStream out) {        String specifyRepository = "";        if (!getRepository().equals("")) specifyRepository = " -d"+getRepository();        String run = getCVSProgram() + specifyRepository +" "+cmd;        System.out.println(comment+": "+run);        Exec e = new Exec(run, null, new File(workingDir), out, out);        e.run();        return e.getExitVal();    }    /**     * Run this command if you have quotes ("") in your command that delimit a single     * argument. Normally exec breaks up the string command by whitespace, ignoring     * quotes. This command will preprocess the command to ensure it thinks of the     * string in quotes as one argument.     * @param cmd the command to run     * @param comment the message to display on the dialog     * @param workingDir the directory in which to run the CVS command     * (null for current working directory). I recommend you specify     * this as the current library dir.     * @param out where the result of the command gets printed. May be     * a ByteArrayOutputStream for storing it, or just System.out for     * printing it.     * @return the exit value     */    static int runCVSCommandWithQuotes(String cmd, String comment, String workingDir, OutputStream out) {        String specifyRepository = "";        if (!getRepository().equals("")) specifyRepository = " -d "+getRepository();        cmd = getCVSProgram() + specifyRepository + " " + cmd;        // break command into separate arguments        List<String> execparts = new ArrayList<String>();        String [] quoteParts = cmd.split("\"");        for (int i=0; i<quoteParts.length; i++) {            if (i % 2 == 0) {                // evens are not enclosed in quotes                String [] parts = quoteParts[i].trim().split("\\s+");                for (int j=0; j<parts.length; j++)                    execparts.add(parts[j]);            } else {                // odds are enclosed in quotes                execparts.add(quoteParts[i]);            }        }        String [] exec = new String[execparts.size()];        for (int i=0; i<exec.length; i++) {            exec[i] = execparts.get(i);            // debug            //System.out.println(i+": "+exec[i]);        }        System.out.println(comment+": "+cmd);        Exec e = new Exec(exec, null, new File(workingDir), out, out);        e.run();        return e.getExitVal();    }    /**     * This will run a CVS command in a separate Thread and block the GUI until the command     * completes, or until the user hits 'cancel', which will try to     * terminate the external command.  This method returns after     * the cvs command has completed.     * @param cmd the command to run     * @param comment the message to display on the dialog     * @param workingDir the directory in which to run the CVS command     * (null for current working directory). I recommend you specify     * this as the current library dir.     * @param out where the result of the command gets printed. May be     * a ByteArrayOutputStream for storing it, or just System.out for     * printing it.     */    public static void runModalCVSCommand(String cmd, String comment, String workingDir, OutputStream out) {        String run = getCVSProgram() + " -d"+getRepository()+" "+cmd;        Exec e = new Exec(run, null, new File(workingDir), out, out);        // add a listener to get rid of the modal dialog when the command finishes        String message = "Running: "+run;        JFrame frame = TopLevel.getCurrentJFrame();        ModalCommandDialog dialog = new ModalCommandDialog(frame, true, e, message, comment);        dialog.setVisible(true);    }    // -------------------------- Utility Commands --------------------------    public static void testModal() {        runModalCVSCommand("-n history -c -a", "testing command", User.getWorkingDirectory(), System.out);    }    /**     * Get the file for the given Cell, assuming the library is in DELIB format.     * @param cell the Cell being examined.     * @return the File for the Cell.  If its library is not in DELIB format, returns null.     */    public static File getCellFile(Cell cell) {        if (isDELIB(cell.getLibrary())) {            String relativeFile = DELIB.getCellFile(cell);            URL libFile = cell.getLibrary().getLibFile();            File file = TextUtils.getFile(libFile);            if (file == null) return null;            return new File(file, relativeFile);        }        return null;    }    public static boolean isDELIB(Library lib) {        URL libFile = lib.getLibFile();        if (libFile == null) return false;        FileType type = OpenFile.getOpenFileType(libFile.getFile(), FileType.JELIB);        return (type == FileType.DELIB);    }    /**     * Returns true if this file has is being maintained from a     * CVS respository, returns false otherwise.     */    public static boolean isFileInCVS(File fd) {        return isFileInCVS(fd, false, false);    }    /**     * Returns true if this file has is being maintained from a     * CVS respository, returns false otherwise.     */    public static boolean isFileInCVS(File fd, boolean assertScheduledForAdd, boolean assertScheduledForRemove) {        // get directory file is in        if (fd == null) 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;        // make sure file is mentioned in Entries file        String filename = fd.getName();        boolean found = false;        FileReader fr = null;        try {            fr = new FileReader(entries);            LineNumberReader reader = new LineNumberReader(fr);            for (;;) {                String line = reader.readLine();                if (line == null) break;                if (line.equals("")) continue;                String parts[] = line.split("/");                if (parts.length >= 2 && parts[1].equals(filename)) {                    // see if scheduled for add                    if (assertScheduledForAdd) {                        if (parts.length >= 3 && parts[2].equals("0")) {                            found = true;                            break;                        } else {                            break;                        }                    }                    if (assertScheduledForRemove) {                        if (parts.length >= 3 && parts[2].startsWith("-")) {                            found = true;                            break;                        } else {                            break;                        }                    }                    found = true;                    break;                }            }            fr.close();        } catch (IOException e) {        }        return found;    }    /**     * This checks the CVS Entries file to see if the library is in cvs (jelib/elib),     * or if the library dir + header file is in cvs (delib).     * @param lib     * @return true if the library is in cvs, false otherwise.     */    public static boolean isInCVS(Library lib) {        URL fileURL = lib.getLibFile();        if (fileURL == null) return false; // new library not saved yet        File libfile = TextUtils.getFile(fileURL);        if (libfile == null) return false;                String libfilestr = libfile.getPath();        File libFile = new File(libfilestr);        if (isDELIB(lib)) {            // check both lib dir and header file            File header = new File(libFile, DELIB.getHeaderFile());            if (!isFileInCVS(libFile) || !isFileInCVS(header)) return false;        } else {            if (!isFileInCVS(libFile)) return false;        }        return true;    }

⌨️ 快捷键说明

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