This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
/
Application.java
151 lines (137 loc) · 4.17 KB
/
Application.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package net.sourcewalker.svnnotify;
import java.util.List;
import net.sourcewalker.svnnotify.data.NullNotifier;
import net.sourcewalker.svnnotify.data.ShellProvider;
import net.sourcewalker.svnnotify.data.interfaces.IDatabase;
import net.sourcewalker.svnnotify.data.interfaces.INotifier;
import net.sourcewalker.svnnotify.data.interfaces.IObjectFactory;
import net.sourcewalker.svnnotify.data.interfaces.IProvider;
import net.sourcewalker.svnnotify.data.interfaces.IRepository;
import net.sourcewalker.svnnotify.data.interfaces.IRevision;
import net.sourcewalker.svnnotify.data.xmldb.XmlDatabase;
/**
* @author Xperimental
*
*/
public class Application implements Runnable {
/**
* Entry point for application start.
*
* @param args
* Command-line parameters.
*/
public static void main(String[] args) {
Application app = new Application(args);
app.run();
}
IDatabase database;
IObjectFactory objectFactory;
IProvider provider;
INotifier notifier;
ApplicationMode mode = ApplicationMode.NORMAL;
String repoName = null;
String repoUrl = null;
public Application(String[] args) {
database = new XmlDatabase("database.xml");
objectFactory = (IObjectFactory) database;
provider = new ShellProvider();
notifier = new NullNotifier();
parseArgs(args);
}
/**
* @param args
*/
private void parseArgs(String[] args) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.equalsIgnoreCase("--help")) {
mode = ApplicationMode.HELP;
return;
}
if (arg.equalsIgnoreCase("--create")) {
mode = ApplicationMode.CREATE_REPO;
continue;
}
if (arg.equalsIgnoreCase("--delete")) {
mode = ApplicationMode.DELETE_REPO;
continue;
}
if (arg.equalsIgnoreCase("--list")) {
mode = ApplicationMode.LIST_REPO;
return;
}
if (arg.equalsIgnoreCase("--name")) {
repoName = args[i + 1];
continue;
}
if (arg.equalsIgnoreCase("--url")) {
repoUrl = args[i + 1];
continue;
}
}
}
@Override
public void run() {
switch (mode) {
case NORMAL:
normalRun();
break;
case HELP:
showHelpScreen();
break;
case LIST_REPO:
listRepos();
break;
default:
System.out.println("Error: Application mode not defined!");
}
}
private void listRepos() {
System.out.println("Configured repositories:");
List<IRepository> repos = database.getRepositories();
for (IRepository repo: repos) {
System.out.println(repo.getName());
System.out.println(" URL: " + repo.getURL().toString());
System.out.println();
}
}
private void showHelpScreen() {
System.out.println("usage:");
System.out.println("\tsvn-notify");
System.out.println("\tsvn-notify --help");
System.out.println("\tsvn-notify --list");
System.out.println("\tsvn-notify --create --name <name> --url <url>");
System.out.println("\tsvn-notify --delete --name <name>\n");
System.out.println("Running svn-notify without parameters will check the" +
" repositories for new revisions and alert the user," +
" if there are any.\n");
System.out.println("Running svn-notify with the \"--help\" parameter" +
" will show this message.\n");
System.out.println("The parameter \"--list\" causes svn-notify to print" +
" out all the repositories it is configured to monitor.\n");
System.out.println("The parameters \"--create\" and \"--delete\" are" +
" used to create and delete repositories for monitoring.");
}
private void normalRun() {
System.out.println("Check for new revisions:");
for (IRepository repo : database.getRepositories()) {
System.out.println("Checking repository " + repo.getName());
List<IRevision> newRevisions = provider.getNewRevisions(
objectFactory, repo);
System.out.println("\tGot " + newRevisions.size()
+ " revisions from server.");
if (newRevisions.size() > 0) {
List<IRevision> notifyRevisions = repo
.updateRepository(newRevisions);
if (notifyRevisions.size() > 0) {
System.out.println("\t" + notifyRevisions.size()
+ " revisions left for notify!");
notifier.reportUpdates(repo, notifyRevisions);
} else
System.out.println("\tNo revisions to notify user about!");
System.out.println();
}
}
database.save();
}
}