Skip to content

Commit 42372e5

Browse files
committed
Added PID file creation; Updated README; Done some code cleanup.
1 parent 57dea8f commit 42372e5

11 files changed

+170
-77
lines changed

README.md

+48-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ These dedicated folders are designed to keep the intermediate data files that
99
are in fact the patches or bundles of Git or other VCS system.
1010
This bridge is duplex - so that you can exchange data in both directions.
1111

12+
Contents
13+
--------
14+
15+
1. [The Short Explanation](#the-short-explanation)
16+
2. [How It Works In A Nutshell](#how-it-works-in-a-nutshell)
17+
1. [The Overall Diagram](#the-overall-diagram)
18+
3. [Build And Run](#build-and-run)
19+
1. [Prerequisites](#prerequisites)
20+
2. [Build](#build)
21+
3. [Run](#run)
22+
4. [Notices](#notices)
23+
4. [Usage](#usage)
24+
1. [Configuration file](#configuration-file)
25+
1. [EWS Settings](#ews-settings)
26+
2. [Test bridge on one node](#test-bridge-on-one-node)
27+
3. [Both sides use the same EWS server](#both-sides-use-the-same-ews-server)
28+
4. [Each side uses its own EWS server](#each-side-uses-its-own-ews-server)
29+
2. [Git Bundle Mode](#git-bundle-mode)
30+
1. [Case 1. Existing repo on Side 1 and new empty repo on Side 2
31+
](#case-1-existing-repo-on-side-1-and-new-empty-repo-on-side-2)
32+
2. [Case 2. Changes are committed on Side 1, need to be pushed to Side 2
33+
](#case-2-changes-are-committed-on-side-1-need-to-be-pushed-to-side-2)
34+
3. [Git Email Mode](#git-email-mode)
35+
1. [Get full patch set from the beginning](#get-full-patch-set-from-the-beginning)
36+
2. [Get partial patch set from tagged commit](#get-partial-patch-set-from-tagged-commit)
37+
3. [Restore the patch set](#restore-the-patch-set)
38+
4. [Post-Receive Script](#post-receive-script)
39+
5. [Tune Logging](#tune-logging)
40+
5. [References](#references)
41+
6. [TODO](#todo)
42+
1243
The Short Explanation
1344
---------------------
1445

@@ -24,7 +55,7 @@ initial conditions:
2455
non-detectable (encrypted) attachments.
2556
* Only files (not sub-folders) are synchronized between computers. That's
2657
by design limitation, b/c application's `inbox` and `outbox` purpose is to
27-
temporarily keep VCS (Git) patches or bundles that in fact is plain list, so
58+
temporarily keep VCS ([Git]) patches or bundles that in fact is plain list, so
2859
that any kind of file hierarchy support is business of VCS.
2960

3061
How It Works In A Nutshell
@@ -54,7 +85,7 @@ Both sides have symmetric settings and work in absolutely the same manner.
5485
So the main flow may look like that:
5586

5687
1. User of "Side 1" puts file or files into `outbox` folder (these files are
57-
intended to be the result of Git command - see the **"Usage"** section below
88+
intended to be the result of [Git] command - see the **"Usage"** section below
5889
for details).
5990
2. App on "Side 1" detects that new files are appeared in `outbox` and creates
6091
new Email message(s) where attaches these files (packed and/or encrypted if
@@ -64,7 +95,7 @@ So the main flow may look like that:
6495
4. App on "Side 2" detects that new email is available, so receives it and
6596
processes to obtain files from attachments and puts these files into `inbox`
6697
folder in its original representation (decrypted and/or unpacked).
67-
5. User of "Side 2" runs appropriate commands (e.g. Git) to apply new changes
98+
5. User of "Side 2" runs appropriate commands (e.g. [Git]) to apply new changes
6899
represented by these files, and cleans up the `inbox` folder.
69100

70101
The last point may be automated as well - see **"Post-Receive Script"** section
@@ -75,12 +106,18 @@ Build And Run
75106

76107
### Prerequisites ###
77108

78-
To build and run this application you need:
109+
To build this application you need:
79110

80-
* Java 7+;
81-
* Maven 3+;
111+
* JDK 7+;
112+
* [Maven](https://maven.apache.org/) 3+;
82113
* Internet connection.
83114

115+
To run:
116+
117+
* JRE/JDK 7+;
118+
* [Git];
119+
* If OS is Windows - [Cygwin] - optional but recommended.
120+
84121
### Build ###
85122

86123
This project is Maven-driven, so all what you need to do to build it is to run
@@ -89,19 +126,17 @@ the following command:
89126
$ mvn clean package
90127

91128
### Run ###
92-
129+
93130
If build is successful, you can run the resulting JAR file as standalone Java
94131
app like that:
95132

96-
$ java -jar target/email-bridge-X.X.X-standalone.jar
97-
98-
Where `X.X.X` is current version number.
133+
$ java -jar target/email-bridge-0.1.2-standalone.jar
99134

100135
The invocation w/o arguments will show an error that proper configuration file
101136
is required. Just in case - you can get the short help about supported command
102137
line arguments by specifying `-h` option:
103138

104-
$ java -jar target/email-bridge-X.X.X-standalone.jar -h
139+
$ java -jar target/email-bridge-0.1.2-standalone.jar -h
105140

106141
### Notices ###
107142

@@ -457,12 +492,14 @@ References
457492
3. [Prepare patches for e-mail submission][git-format-patch]
458493
4. [Apply a series of patches from a mailbox][git-am]
459494
5. [Cygwin Project][Cygwin]
495+
6. [Git VCS][Git]
460496

461497
[ews-java-api]: https://github.com/OfficeDev/ews-java-api
462498
[git-bundle]: http://git-scm.com/docs/git-bundle
463499
[git-format-patch]: http://git-scm.com/docs/git-format-patch
464500
[git-am]: http://git-scm.com/docs/git-am
465501
[Cygwin]: http://cygwin.org/
502+
[Git]: https://git-scm.com/downloads
466503

467504
TODO
468505
----

data/config-template.properties

+7
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,10 @@ email.recipients.to =
162162
# If file size is bigger, it will be split to several parts.
163163
# Default value is 5.
164164
#email.attach.max.size =
165+
166+
# Optional path to PID file.
167+
# If PID file is specified but cannot be created/rewritten then application stops with error.
168+
#pid.file =
169+
170+
# Whether to keep or not the PID file on application finish. Default value is "false".
171+
#pid.file.keep =

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.exchange.git</groupId>
88
<artifactId>email-bridge</artifactId>
9-
<version>0.1.1</version>
9+
<version>0.1.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>email-bridge</name>

src/main/java/org/mail/bridge/AbstractMonitor.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
/**
3434
* @author <a href="mailto:[email protected]">Maksym Dominichenko</a>
3535
*/
36+
@SuppressWarnings("UnusedReturnValue")
3637
public abstract class AbstractMonitor {
3738

3839
private final Map<Class<? extends Message<?>>, List<MonitorCallback<?>>> callbacks = new HashMap<>();
3940

40-
protected <T> AbstractMonitor addCallback(Class<? extends Message<T>> messageClass, MonitorCallback<T> callback) {
41+
<T> AbstractMonitor addCallback(Class<? extends Message<T>> messageClass, MonitorCallback<T> callback) {
4142
if (callback != null) {
4243
List<MonitorCallback<?>> callbackList = callbacks.get(messageClass);
4344
if (callbackList == null) {
@@ -50,7 +51,7 @@ protected <T> AbstractMonitor addCallback(Class<? extends Message<T>> messageCla
5051
}
5152

5253
@SuppressWarnings({"unchecked", "SuspiciousMethodCalls"})
53-
protected <T> void postMessage(Message<T> message) {
54+
<T> void postMessage(Message<T> message) {
5455
List callbackList = Utils.ensureEmpty(callbacks.get(message.getClass()));
5556
for (MonitorCallback<T> callback : (List<MonitorCallback<T>>) callbackList)
5657
callback.onMessage(message);

src/main/java/org/mail/bridge/Config.java

+51-32
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public class Config {
8282
private final String emailAttachExtEnc;
8383
private final int emailAttachMaxSize;
8484

85+
private final String pidFile;
86+
private final boolean pidFileKeep;
87+
8588
public Config(String propertiesFileName) throws IOException {
8689
Properties config = new Properties();
8790
config.load(new FileInputStream(propertiesFileName));
@@ -165,133 +168,145 @@ public Config(String propertiesFileName) throws IOException {
165168
emailAttachExtEnc = checkExt(s.isEmpty() ? ".enc" : s);
166169
s = config.getProperty("email.attach.max.size", "");
167170
emailAttachMaxSize = s.isEmpty() ? 5 : Integer.parseInt(s);
171+
172+
pidFile = config.getProperty("pid.file", "");
173+
s = config.getProperty("pid.file.keep", "");
174+
pidFileKeep = !s.isEmpty() && Boolean.parseBoolean(s);
168175
}
169176

170-
public String getEwsEmail() {
177+
String getEwsEmail() {
171178
return ewsEmail;
172179
}
173180

174-
public String getEwsDomain() {
181+
String getEwsDomain() {
175182
return ewsDomain;
176183
}
177184

178-
public String getEwsUsername() {
185+
String getEwsUsername() {
179186
return ewsUsername;
180187
}
181188

182-
public String getEwsPassword() {
189+
String getEwsPassword() {
183190
return ewsPassword;
184191
}
185192

186-
public String getEwsServer() {
193+
String getEwsServer() {
187194
return ewsServer;
188195
}
189196

190-
public int getEwsViewSize() {
197+
int getEwsViewSize() {
191198
return ewsViewSize;
192199
}
193200

194-
public int getEwsSubscriptionLifetime() {
201+
int getEwsSubscriptionLifetime() {
195202
return ewsSubscriptionLifetime;
196203
}
197204

198-
public String getProxyHost() {
205+
String getProxyHost() {
199206
return proxyHost;
200207
}
201208

202-
public int getProxyPort() {
209+
int getProxyPort() {
203210
return proxyPort;
204211
}
205212

206-
public String getProxyUsername() {
213+
String getProxyUsername() {
207214
return proxyUsername;
208215
}
209216

210-
public String getProxyPassword() {
217+
String getProxyPassword() {
211218
return proxyPassword;
212219
}
213220

214-
public String getProxyDomain() {
221+
String getProxyDomain() {
215222
return proxyDomain;
216223
}
217224

218-
public String getOutboxFolder() {
225+
String getOutboxFolder() {
219226
return outboxFolder;
220227
}
221228

222-
public boolean isOutboxCleanup() {
229+
boolean isOutboxCleanup() {
223230
return outboxCleanup;
224231
}
225232

226-
public String getOutboxFileRegexp() {
233+
String getOutboxFileRegexp() {
227234
return outboxFileRegexp;
228235
}
229236

230-
public String getInboxFolder() {
237+
String getInboxFolder() {
231238
return inboxFolder;
232239
}
233240

234-
public String getInboxScript() {
241+
String getInboxScript() {
235242
return inboxScript;
236243
}
237244

238-
public int getInboxScriptStopCode() {
245+
int getInboxScriptStopCode() {
239246
return inboxScriptStopCode;
240247
}
241248

242-
public boolean isEmailInboxCleanup() {
249+
boolean isEmailInboxCleanup() {
243250
return emailInboxCleanup;
244251
}
245252

246-
public String getEmailTagIncoming() {
253+
String getEmailTagIncoming() {
247254
return emailTagIncoming;
248255
}
249256

250-
public String getEmailTagOutgoing() {
257+
String getEmailTagOutgoing() {
251258
return emailTagOutgoing;
252259
}
253260

254-
public MessageFormat getEmailSubjectFormat() {
261+
MessageFormat getEmailSubjectFormat() {
255262
return emailSubjectFormat;
256263
}
257264

258-
public MessageFormat getEmailBodyFormat() {
265+
MessageFormat getEmailBodyFormat() {
259266
return emailBodyFormat;
260267
}
261268

262-
public String[] getEmailRecipientsTo() {
269+
String[] getEmailRecipientsTo() {
263270
return emailRecipientsTo;
264271
}
265272

266-
public String[] getEmailRecipientsCc() {
273+
String[] getEmailRecipientsCc() {
267274
return emailRecipientsCc;
268275
}
269276

270-
public String[] getEmailRecipientsBcc() {
277+
String[] getEmailRecipientsBcc() {
271278
return emailRecipientsBcc;
272279
}
273280

274-
public String getEmailAttachPassword() {
281+
String getEmailAttachPassword() {
275282
return emailAttachPassword;
276283
}
277284

278-
public boolean isEmailAttachGzip() {
285+
boolean isEmailAttachGzip() {
279286
return emailAttachGzip;
280287
}
281288

282-
public String getEmailAttachExtGzip() {
289+
String getEmailAttachExtGzip() {
283290
return emailAttachExtGzip;
284291
}
285292

286-
public String getEmailAttachExtEnc() {
293+
String getEmailAttachExtEnc() {
287294
return emailAttachExtEnc;
288295
}
289296

290-
public int getEmailAttachMaxSize() {
297+
int getEmailAttachMaxSize() {
291298
return emailAttachMaxSize;
292299
}
293300

294-
public Map<String, String> asEnvironmentMap() {
301+
String getPidFile() {
302+
return pidFile;
303+
}
304+
305+
boolean isPidFileKeep() {
306+
return pidFileKeep;
307+
}
308+
309+
Map<String, String> asEnvironmentMap() {
295310
Map<String, String> result = new HashMap<>();
296311
result.put("EWS_EMAIL", ewsEmail);
297312
result.put("EWS_DOMAIN", ewsDomain);
@@ -324,6 +339,8 @@ public Map<String, String> asEnvironmentMap() {
324339
result.put("EMAIL_ATTACH_EXT_GZIP", emailAttachExtGzip);
325340
result.put("EMAIL_ATTACH_EXT_ENC", emailAttachExtEnc);
326341
result.put("EMAIL_ATTACH_MAX_SIZE", "" + emailAttachMaxSize);
342+
result.put("PID_FILE", pidFile);
343+
result.put("PID_FILE_KEEP", "" + pidFileKeep);
327344
return result;
328345
}
329346

@@ -367,6 +384,8 @@ public String toString() {
367384
",\n\temailAttachExtGzip='" + emailAttachExtGzip + '\'' +
368385
",\n\temailAttachExtEnc='" + emailAttachExtEnc + '\'' +
369386
",\n\temailAttachMaxSize=" + emailAttachMaxSize +
387+
",\n\tpidFile='" + pidFile + '\'' +
388+
",\n\tpidFileKeep=" + pidFileKeep +
370389
'}';
371390
}
372391
}

0 commit comments

Comments
 (0)