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: import org.libresource.so6.core.exec.tools.CheckWscParameters;
042:
043: import java.io.BufferedReader;
044: import java.io.InputStreamReader;
045:
046: import java.util.Properties;
047: import java.util.logging.Logger;
048:
049: /**
050: * The <code>Commit</code> class is used to commit local changes
051: *
052: * @author Smack
053: * @version 1.0, 26/05/04
054: * @see org.libresource.so6.core.WsConnection
055: * @since JDK1.4
056: */
057: public class Commit {
058: private WsConnection ws;
059: private String comment;
060: private XMLMonitoringThread monitoringThread;
061:
062: /**
063: * Instantiate a commit process
064: *
065: * @param wsPath
066: * @param comment
067: * @throws Exception
068: */
069: public Commit(String wscPath, String comment) throws Exception {
070: this .ws = new WsConnection(wscPath);
071: this .comment = comment;
072:
073: if (this .ws.getProperty("so6.clienti.name").equals(
074: "org.libresource.so6.core.client.ClientIServletImpl")) {
075: CheckWscParameters checkWscParameters = new CheckWscParameters(
076: wscPath);
077: Properties newProps = checkWscParameters.editProperties();
078: this .ws.updateProp(newProps);
079: }
080:
081: // init output
082: LogUtils.removeAllHandlers(Logger.getLogger("ui.log"));
083: LogUtils.removeAllHandlers(StateMonitoring.getInstance()
084: .getXMLMonitoringLogger());
085: monitoringThread = new XMLMonitoringThread();
086:
087: StandardOutputWriter outWriter = new StandardOutputWriter(
088: monitoringThread.getTreeContext());
089: monitoringThread.attachMessageWriter(outWriter);
090: }
091:
092: public String readProperty(String property) throws Exception {
093: BufferedReader br = new BufferedReader(new InputStreamReader(
094: System.in));
095: System.out.print(property + " : ");
096:
097: return br.readLine();
098: }
099:
100: /**
101: * Execute the commit process
102: *
103: * @throws Exception
104: */
105: public void execute() throws Exception {
106: ws.commit(comment);
107:
108: if (ws.getClient() instanceof WorkspaceListener) {
109: ((WorkspaceListener) ws.getClient())
110: .notifyQueue(ws.getNs());
111: }
112:
113: System.out.println("\n*** Report ***\n");
114: System.out.println(ws.getReport());
115: }
116:
117: /**
118: * Simulate the commit process
119: *
120: * @param outputDir
121: * @throws Exception
122: */
123: public void simulate(String outputDir) throws Exception {
124: ws.setSimulationMode(true, outputDir);
125:
126: //
127: ws.commit(comment);
128: }
129:
130: /**
131: * Instantiate and execute the commit process
132: *
133: * @param args
134: * <ul>
135: * <li>Path of the connection property file</li>
136: * <li>Comment for the commit</li>
137: * </ul>
138: * @throws Exception
139: */
140: public static void main(String[] args) throws Exception {
141: if (args.length < 1) {
142: System.err.println("Usage: wsPath (comment)");
143: System.err.println(" (1) wsPath: path of the file "
144: + WsConnection.SO6_WSC_FILE);
145: System.err.println(" (2) comment: commit comment");
146: } else {
147: String wsPath = args[0];
148: String comment = "No comment";
149:
150: if (args.length > 1) {
151: comment = "";
152:
153: for (int i = 1; i < args.length; i++)
154: comment += (args[i] + " ");
155: }
156:
157: Commit commit = new Commit(wsPath, comment);
158: commit.execute();
159:
160: //
161: System.out.println("\007");
162: System.exit(0);
163: }
164: }
165: }
|