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.engine.log.LogUtils;
038: import org.libresource.so6.core.engine.log.StandardOutputWriter;
039: import org.libresource.so6.core.engine.log.monitoring.XMLMonitoringThread;
040:
041: import java.io.FileReader;
042: import java.io.LineNumberReader;
043:
044: import java.util.Vector;
045: import java.util.logging.Logger;
046:
047: /**
048: * The <code>PartialCommit</code> class is used to commit parts of local
049: * changes
050: * <p>
051: * Parameters of that command
052: * <ul>
053: * <li>wscPath : Path of the connection property file (.so6/1/so6.properties)
054: * </li>
055: * <li>comment : The comment for the commit. (Don't forget to put " around the
056: * comment)</li>
057: * <li>filterFile : The path of the file where we specify the files that we
058: * want to commit</li>
059: * </ul>
060: *
061: * <p>
062: * Filter file content exemple :
063: *
064: * <pre>
065: *
066: * src
067: * src/org
068: * src/org/libresource
069: * src/org/libresource/so6
070: * src/org/libresource/so6/Workspace.java
071: * src/org/libresource/so6/WsConnection.java
072: *
073: * </pre>
074: *
075: * @author Smack
076: * @version 1.0, 26/05/04
077: * @see org.libresource.so6.core.exec.Main
078: * @since JDK1.4
079: */
080: public class PartialCommit {
081: private WsConnection ws;
082: private String comment;
083: private XMLMonitoringThread monitoringThread;
084:
085: /**
086: * Instantiate a partial commit process
087: *
088: * @param wscPath :
089: * Path of the connection property file (.so6/1/so6.properties)
090: * @param comment :
091: * The comment for the commit. (Don't forget to put " around the
092: * comment)
093: * @param filterPath :
094: * The path of the file where we specify the files that we want
095: * to commit
096: *
097: * @throws Exception
098: */
099: public PartialCommit(String wscPath, String comment,
100: String filterPath) throws Exception {
101: this .ws = new WsConnection(wscPath);
102: this .comment = comment;
103:
104: // load filter
105: Vector filter = new Vector();
106: LineNumberReader lineReader = new LineNumberReader(
107: new FileReader(filterPath));
108: String line;
109:
110: while ((line = lineReader.readLine()) != null) {
111: filter.add(line);
112: }
113:
114: lineReader.close();
115: ws.setFilter(filter);
116:
117: // init output
118: LogUtils.removeAllHandlers(Logger.getLogger("ui.log"));
119: LogUtils.removeAllHandlers(StateMonitoring.getInstance()
120: .getXMLMonitoringLogger());
121: monitoringThread = new XMLMonitoringThread();
122:
123: StandardOutputWriter outWriter = new StandardOutputWriter(
124: monitoringThread.getTreeContext());
125: monitoringThread.attachMessageWriter(outWriter);
126: }
127:
128: /**
129: * Execute the partial commit process
130: *
131: * @throws Exception
132: */
133: public void execute() throws Exception {
134: monitoringThread.start();
135: ws.commit(comment);
136:
137: //monitoringThread.join();
138: }
139:
140: /**
141: * Simulate the partial commit process and build the patch file in the
142: * specified directory
143: *
144: * @param outputDir :
145: * output directory path
146: *
147: * @throws Exception
148: */
149: public void simulate(String outputDir) throws Exception {
150: ws.setSimulationMode(true, outputDir);
151:
152: //
153: monitoringThread.start();
154: ws.commit(comment);
155:
156: //monitoringThread.join();
157: }
158:
159: /**
160: * The <code>PartialCommit</code> class is used to commit parts of local
161: * changes
162: * <p>
163: * Parameters of that command
164: * <ul>
165: * <li>wscPath : Path of the connection property file
166: * (.so6/1/so6.properties)</li>
167: * <li>comment : The comment for the commit. (Don't forget to put " around
168: * the comment)</li>
169: * <li>filterFile : The path of the file where we specify the files that we
170: * want to commit</li>
171: * </ul>
172: *
173: * <p>
174: * Filter file content exemple :
175: *
176: * <pre>
177: *
178: * src
179: * src/org
180: * src/org/libresource
181: * src/org/libresource/so6
182: * src/org/libresource/so6/Workspace.java
183: * src/org/libresource/so6/WsConnection.java
184: *
185: * </pre>
186: *
187: * @param args
188: * @throws Exception
189: */
190: public static void main(String[] args) throws Exception {
191: if (args.length != 3) {
192: System.err.println("Usage: wscPath (comment)");
193: System.err.println(" (1) wscPath: path of the file "
194: + WsConnection.SO6_WSC_FILE);
195: System.err.println(" (2) comment: commit comment");
196: System.err.println(" (3) file: filter file name");
197: } else {
198: String wsPath = args[0];
199: String comment = args[1];
200: String filterFileName = args[2];
201: PartialCommit commit = new PartialCommit(wsPath, comment,
202: filterFileName);
203: commit.execute();
204:
205: //
206: System.out.println("\007");
207: System.exit(0);
208: }
209: }
210: }
|