Skip to content

Commit e79d64f

Browse files
author
Erwin Mueller
committed
Add a new parameters to add/remove pattern to/from the exludes list. Changed the output of list to a nice table.
1 parent b70b4ec commit e79d64f

File tree

9 files changed

+324
-46
lines changed

9 files changed

+324
-46
lines changed

syncman-cli/src/main/java/org/deventm/syncman/cli/CliController.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.deventm.syncman.cli;
22

3-
import java.io.File;
4-
import java.util.ArrayList;
53
import java.util.logging.Level;
64
import java.util.logging.Logger;
75

6+
import org.deventm.syncman.database.Database;
87
import org.deventm.syncman.database.DatabaseException;
98
import org.deventm.syncman.database.Device;
109
import org.deventm.syncman.database.Path;
11-
import org.deventm.syncman.database.XMLDatabase;
1210
import org.deventm.syncman.output.CliOutput;
1311
import org.deventm.syncman.process.ProcessController;
1412
import org.deventm.synman.params.ParamsParser;
@@ -25,13 +23,11 @@ public class CliController {
2523
*/
2624
private static final String LOG_PATH_NOT_EXISTS_SKIPPING = "Path '%s' do not exists, skipping.";
2725

28-
private static final String HOME = System.getProperty("user.home");
29-
3026
private static final String LOG_DEVICE_NOT_EXISTS_SKIPPING = "Device '%s' do not exists, skipping.";
3127

3228
private final Logger log = Logger.getLogger(CliController.class.getName());
3329

34-
private final XMLDatabase database;
30+
private final Database database;
3531

3632
private final ParamsParser parser;
3733

@@ -41,7 +37,7 @@ public class CliController {
4137
* @param database
4238
* @param parser
4339
*/
44-
public CliController(XMLDatabase database, ParamsParser parser,
40+
public CliController(Database database, ParamsParser parser,
4541
CliOutput output) {
4642
this.database = database;
4743
this.parser = parser;
@@ -62,6 +58,8 @@ public void run() throws CliException {
6258
private void run0() throws DatabaseException {
6359
addPaths();
6460
removePaths();
61+
addExcludes();
62+
removeExcludes();
6563
if (parser.isList()) {
6664
output.listPaths(database.getDevices());
6765
}
@@ -70,13 +68,39 @@ private void run0() throws DatabaseException {
7068
}
7169
}
7270

71+
/**
72+
*
73+
*/
74+
private void addExcludes() {
75+
for (String devicestr : parser.getDevices()) {
76+
Device device = database.getDevice(devicestr);
77+
for (String exstr : parser.getAddExcludes()) {
78+
database.addExclude(device, exstr);
79+
output.outputAddEx(device, exstr);
80+
}
81+
}
82+
}
83+
84+
/**
85+
*
86+
*/
87+
private void removeExcludes() {
88+
for (String devicestr : parser.getDevices()) {
89+
Device device = database.getDevice(devicestr);
90+
for (String exstr : parser.getRemoveExcludes()) {
91+
database.removeExclude(device, exstr);
92+
output.outputRemoveEx(device, exstr);
93+
}
94+
}
95+
}
96+
7397
/**
7498
* @throws DatabaseException
7599
*
76100
*/
77101
private void startSync() throws DatabaseException {
78102
for (String devicestr : parser.getDevices()) {
79-
devicestr = devicestr.replaceFirst("^~", HOME);
103+
devicestr = new Device(devicestr).getDevice().getAbsolutePath();
80104
Device device = database.getDevice(devicestr);
81105
if (device == null) {
82106
continue;
@@ -93,12 +117,9 @@ private void startSync() throws DatabaseException {
93117
*/
94118
private void removePaths() throws DatabaseException {
95119
for (String devicestr : parser.getDevices()) {
96-
devicestr = devicestr.replaceFirst("^~", HOME);
97-
Device device = new Device(new ArrayList<Path>(), new File(
98-
devicestr));
120+
Device device = new Device(devicestr);
99121
for (String pathstr : parser.getRemoves()) {
100-
pathstr = pathstr.replaceFirst("^~", HOME);
101-
Path path = new Path(new File(pathstr));
122+
Path path = new Path(pathstr);
102123
output.outputRemove(device, path);
103124
database.removePath(device, path);
104125
}
@@ -111,9 +132,7 @@ private void removePaths() throws DatabaseException {
111132
*/
112133
private void addPaths() throws DatabaseException {
113134
for (String devicestr : parser.getDevices()) {
114-
devicestr = devicestr.replaceFirst("^~", HOME);
115-
Device device = new Device(new ArrayList<Path>(), new File(
116-
devicestr));
135+
Device device = new Device(devicestr);
117136
if (!device.exists()) {
118137
if (log.isLoggable(Level.WARNING))
119138
log.warning(LOG_DEVICE_NOT_EXISTS_SKIPPING.replace("%s",
@@ -123,8 +142,7 @@ private void addPaths() throws DatabaseException {
123142
}
124143

125144
for (String pathstr : parser.getAdds()) {
126-
pathstr = pathstr.replaceFirst("^~", HOME);
127-
Path path = new Path(new File(pathstr));
145+
Path path = new Path(pathstr);
128146

129147
if (!path.exists()) {
130148
if (log.isLoggable(Level.WARNING))

syncman-database/src/main/java/org/deventm/syncman/database/Database.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ public abstract void removePath(Device device, Path path)
2525

2626
public abstract Device getDevice(String devicestr);
2727

28+
/**
29+
* @param device
30+
* @param exstr
31+
*/
32+
public abstract void addExclude(Device device, String exstr);
33+
34+
/**
35+
* @param device
36+
* @param exstr
37+
*/
38+
public abstract void removeExclude(Device device, String exstr);
2839
}
Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.deventm.syncman.database;
22

33
import java.io.File;
4+
import java.util.ArrayList;
45
import java.util.List;
56

67
/**
@@ -10,13 +11,41 @@
1011
*/
1112
public class Device {
1213

14+
private static final String HOME = System.getProperty("user.home");
15+
1316
final File device;
1417

18+
final List<String> excludes;
19+
1520
final List<Path> paths;
1621

17-
public Device(List<Path> paths, File device) {
22+
public Device(List<Path> paths, File device, List<String> excludes) {
1823
this.paths = paths;
1924
this.device = device;
25+
this.excludes = excludes;
26+
}
27+
28+
public Device(List<Path> paths, String devicestr, List<String> excludes) {
29+
devicestr = devicestr.replaceFirst("^~", HOME);
30+
device = new File(devicestr);
31+
this.paths = paths;
32+
this.excludes = excludes;
33+
}
34+
35+
/**
36+
* @param devicestr
37+
*
38+
*/
39+
public Device(String devicestr) {
40+
this(new ArrayList<Path>(), devicestr, new ArrayList<String>());
41+
}
42+
43+
/**
44+
* @param path
45+
* @return
46+
*/
47+
public boolean contains(Path path) {
48+
return paths.contains(path);
2049
}
2150

2251
@Override
@@ -28,13 +57,27 @@ public boolean equals(Object obj) {
2857
return false;
2958
}
3059

60+
/**
61+
* @return
62+
*/
63+
public boolean exists() {
64+
return device.exists();
65+
}
66+
3167
/**
3268
* @return the device
3369
*/
3470
public File getDevice() {
3571
return device;
3672
}
3773

74+
/**
75+
* @return the excludes
76+
*/
77+
public List<String> getExcludes() {
78+
return excludes;
79+
}
80+
3881
/**
3982
* @return the paths
4083
*/
@@ -51,19 +94,4 @@ public int hashCode() {
5194
public String toString() {
5295
return device.getAbsolutePath();
5396
}
54-
55-
/**
56-
* @return
57-
*/
58-
public boolean exists() {
59-
return device.exists();
60-
}
61-
62-
/**
63-
* @param path
64-
* @return
65-
*/
66-
public boolean contains(Path path) {
67-
return paths.contains(path);
68-
}
6997
}

syncman-database/src/main/java/org/deventm/syncman/database/Path.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ public class Path {
1111

1212
final File path;
1313

14+
private static final String HOME = System.getProperty("user.home");
15+
16+
public Path(String pathstr) {
17+
pathstr = pathstr.replaceFirst("^~", HOME);
18+
path = new File(pathstr);
19+
}
20+
1421
public Path(File path) {
1522
this.path = path;
1623
}

syncman-filedatabase/src/main/java/org/deventm/syncman/database/XMLDatabase.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.io.FileOutputStream;
77
import java.io.IOException;
88
import java.io.OutputStream;
9-
import java.util.ArrayList;
109
import java.util.Collection;
1110
import java.util.HashMap;
1211
import java.util.Map;
@@ -136,8 +135,30 @@ private Map<Device, Device> loadData0(File database)
136135
* @return
137136
*/
138137
public Device getDevice(String devicestr) {
139-
Device dev = new Device(new ArrayList<Path>(), new File(devicestr));
138+
Device dev = new Device(devicestr);
140139
return devices.get(dev);
141140
}
142141

142+
@Override
143+
public void addExclude(Device device, String exstr) {
144+
Device dev = devices.get(device);
145+
if (dev == null) {
146+
return;
147+
}
148+
149+
if (!dev.excludes.contains(exstr)) {
150+
dev.excludes.add(exstr);
151+
}
152+
}
153+
154+
@Override
155+
public void removeExclude(Device device, String exstr) {
156+
Device dev = devices.get(device);
157+
if (dev == null) {
158+
return;
159+
}
160+
161+
dev.excludes.remove(exstr);
162+
}
163+
143164
}

0 commit comments

Comments
 (0)