001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.exec;
034:
035: import org.libresource.so6.core.StateMonitoring;
036: import org.libresource.so6.core.WsConnection;
037: import org.libresource.so6.core.client.WorkspaceListener;
038: import org.libresource.so6.core.engine.log.LogUtils;
039: import org.libresource.so6.core.engine.log.StandardOutputWriter;
040: import org.libresource.so6.core.engine.log.monitoring.XMLMonitoringThread;
041:
042: import java.util.logging.Logger;
043:
044: /**
045: * The <code>Commit</code> class is used to commit local changes
046: *
047: * @author Smack
048: * @version 1.0, 26/05/04
049: * @see org.libresource.so6.core.WsConnection
050: * @since JDK1.4
051: */
052: public class CommitXml {
053: private WsConnection ws;
054: private String comment;
055: private XMLMonitoringThread monitoringThread;
056:
057: /**
058: * Instantiate a commit process
059: *
060: * @param wsPath
061: * @param comment
062: * @throws Exception
063: */
064: public CommitXml(String wscPath, String comment) throws Exception {
065: this .ws = new WsConnection(wscPath);
066: this .comment = comment;
067:
068: // init output
069: LogUtils.removeAllHandlers(Logger.getLogger("ui.log"));
070: LogUtils.removeAllHandlers(StateMonitoring.getInstance()
071: .getXMLMonitoringLogger());
072: monitoringThread = new XMLMonitoringThread();
073:
074: StandardOutputWriter outWriter = new StandardOutputWriter(
075: monitoringThread.getTreeContext());
076: monitoringThread.attachMessageWriter(outWriter);
077: }
078:
079: /**
080: * Execute the commit process
081: *
082: * @throws Exception
083: */
084: public void execute() throws Exception {
085: monitoringThread.start();
086: ws.commit(comment);
087: monitoringThread.join();
088:
089: if (ws.getClient() instanceof WorkspaceListener) {
090: ((WorkspaceListener) ws.getClient())
091: .notifyQueue(ws.getNs());
092: }
093:
094: System.out.println("\n*** Report ***\n");
095: System.out.println(ws.getReport());
096: }
097:
098: /**
099: * Simulate the commit process
100: *
101: * @param outputDir
102: * @throws Exception
103: */
104: public void simulate(String outputDir) throws Exception {
105: ws.setSimulationMode(true, outputDir);
106:
107: //
108: monitoringThread.start();
109: ws.commit(comment);
110: monitoringThread.join();
111: }
112:
113: /**
114: * Instantiate and execute the commit process
115: *
116: * @param args
117: * <ul>
118: * <li>Path of the connection property file</li>
119: * <li>Comment for the commit</li>
120: * </ul>
121: * @throws Exception
122: */
123: public static void main(String[] args) throws Exception {
124: if (args.length < 1) {
125: System.err.println("Usage: wsPath (comment)");
126: System.err.println(" (1) wsPath: path of the file "
127: + WsConnection.SO6_WSC_FILE);
128: System.err.println(" (2) comment: commit comment");
129: } else {
130: String wsPath = args[0];
131: String comment = "No comment";
132:
133: if (args.length > 1) {
134: comment = "";
135:
136: for (int i = 1; i < args.length; i++)
137: comment += (args[i] + " ");
138: }
139:
140: CommitXml commit = new CommitXml(wsPath, comment);
141: commit.execute();
142:
143: //
144: System.out.println("\007");
145: System.exit(0);
146: }
147: }
148: }
|