/******************************* Copyright notice ******************************* Copyright (C)2002 by Andrei Loskutov <loskutov@gmx.de>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ package adiag.connection.p4api; import java.io.IOException; import java.util.Vector; import adiag.Const; import adiag.connection.Connector; import adiag.connection.LineReader; import adiag.gui.App; import com.perforce.api.Env; import com.perforce.api.FileEntry; import com.perforce.api.P4Process; /** * The connection to Perforce-Prozess through P4 API, only as * "technology preview", not ready for real work * @author Andrei Loskutov */ public class P4ApiConnector extends Connector { /** Perforce API Process instance */ private P4Process proc; /** * Constructor * @param app current GUI, for error feedback etc */ public P4ApiConnector(App app) throws Exception { super(app); } /** * Close opened process, but P4 API have one big bug: instead of process * closing, System.err will be closed!!! * @throws IOException currently will be not thrown */ public void close() throws IOException { //if(proc!=null){ // bug in P4Prozess: this close System.err !!!!!!! //proc.close(); //} } /** * read native P4 Log * @param apath initial paths for requested files/directories * @throws Exception if something goes wrong */ protected void readP4Out(String [] paths) throws Exception { if(paths == null || paths.length ==0){ return; } String[] cmd = new String[4 + paths.length]; cmd[0] = "p4"; cmd[1] = "filelog"; cmd[2] = "-l"; cmd[3] = "-i"; System.arraycopy(paths, 0, cmd, 4, paths.length); try { if(proc == null){ proc = new P4Process(new P4Env()); } proc.exec(cmd); } catch (Exception ex) { ex.printStackTrace(); //throw new Exception("Fehler in Connector.getP4Data:\n" + ex.getMessage()); } String apath = paths[0]; if(apath == null){ return; } if(apath.endsWith("/...")){ // directory received, also we get only first file from apath = proc.readLine(); if(apath == null){ return; } } LineReader in = new P4ProcessLineReader(proc); parseP4FileLog(apath, in); } /** * to test the filelog - API * @param args the file paths */ public static void main(String[] args) { P4ApiConnector c = null; try { c = new P4ApiConnector((App) null); } catch(Exception e) { } P4Env env = c.new P4Env(); //FileEntry fe = new FileEntry(env, args[0]); // not ready implemented: Vector v = FileEntry.getFileLog(env, args[0]); System.out.println("filelog has " +v.size() +" entries"); for (int i = 0; i < v.size(); i++){ FileEntry f = (FileEntry)v.get(i); System.out.println(f.toXML()); } } /** Wrapper for the Env from P4 * @author Andy the Great */ class P4Env extends Env{ public P4Env() { } /** * * @return String */ public String getClient() { // not null, for Prozess.exec() return app == null? "" : app.getPropsSetter().getProperty(Const.PROPERTY_P4_CLIENT); } /** * */ public void setClient(String client) { // not null, for Prozess.exec() //if(app != null) app.getPropsSetter().setProperty(Const.PROPERTY_P4_CLIENT, (client == null? "" : client)); } /** * * @return String[] */ protected String[] getEnvp() { // Workaround return null; } /** * * @return String */ public String getPassword() { // not null, for Prozess.exec() return app == null? "" : app.getPropsSetter().getProperty(Const.PROPERTY_P4_PASSWD); } /** * */ public void setPassword(String passwd) { // nicht null, damit Prozess.exec() es verarbeiten kann //if(app != null) app.getPropsSetter().setProperty(Const.PROPERTY_P4_PASSWD, (passwd == null? "" : passwd)); } /** * * @return String */ public String getPort() { // not null, for Prozess.exec() return app == null? "" : app.getPropsSetter().getProperty(Const.PROPERTY_P4_PORT); } /** * */ public void setPort(String port) { // not null, for Prozess.exec() //if(app != null) app.getPropsSetter().setProperty(Const.PROPERTY_P4_PORT, (port == null? "" : port)); } /** * * @return String */ public String getUser() { // not null, for Prozess.exec() return app == null? "" : app.getPropsSetter().getProperty(Const.PROPERTY_P4_USER); } /** * */ public void setUser(String user) { // not null, for Prozess.exec() //if(app != null) app.getPropsSetter().setProperty(Const.PROPERTY_P4_USER, (user == null? "" : user)); } } } /** * Wrapper for the P4Process * @author Andy the Great */ class P4ProcessLineReader implements LineReader { private P4Process process; /** * Constructor */ public P4ProcessLineReader(P4Process process) { super(); this.process = process; this.process.setRawMode(false); } /** (non-Javadoc) * @see LineReader#readLine() */ public String readLine() throws IOException { return this.process.readLine(); } /** (non-Javadoc) * @see LineReader#close() */ public void close() throws IOException { this.process.close(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 2735 | andrei_loskutov | sources are now included to binary distribution at http://andrei.gmxhome.de/perforce/index.html | ||
#4 | 2554 | andrei_loskutov |
#25.12.2002 23:29 Revision 1.3.0.4 beta 1) Some small refactoring 2) First integration with P4eclipse: properties etc, thanks Boris Pr�ssmann 5) Better integration to Eclipse: use Eclipse internal compare tool for diff. 6) Fix some minor bugs. #14.12.2002 23:15 Revision 1.3.0.3 beta 1) Fix endless loop bug if p4 path was not set. 2) Fix never getting focus bug after error message shown 3) Fix painting bug on JDK 1.4.1 (must be verified!!!) 4) Some small refactoring 5) Fix error handling. 6) Fix some minor bugs. |
||
#3 | 2552 | andrei_loskutov | 1.3.0.4 changes | ||
#2 | 2460 | andrei_loskutov |
1) Change configuration: always reed properties 2) Change password store to hex format/password field 3) Create standalone/not standalone state for new branchview eclipse wrapper 4) Refactor all main classes to remove cyclic package dependency 5) Add workaround to fix new JDK 1.4.1 Swing bugs on JScrollPane/JViewPort 6) Add dispose methods to panel/connector 7) Minor internal GUI fixes/refactorings |
||
#1 | 2222 | andrei_loskutov |
#13.10.2002 22:16 Revision 1.2.1 1) Documentation task is finished... Yes!!! 2) New feature: copy P4 depot path 3) Some small fixes to menu shortkeys belongs ctrl + c and ctrl + d 4) Clipboard fix because of JDK 1.2 - 1.3 bug 5) Smallest refactoring on some methods. 6) Html help updated |