Skip to content

Commit e450a0f

Browse files
author
Daniel Henrique Alves Lima
committed
Added option to disable sync once (new default)
1 parent 1b6c30b commit e450a0f

File tree

9 files changed

+115
-37
lines changed

9 files changed

+115
-37
lines changed

bundle/src/main/java/com/techdm/aem/vltsync/impl/InitialRegistrationImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public class InitialRegistrationImpl {
6060

6161
/* Default value for sync.once.expected.time property. */
6262
private static final long DEFAULT_SYNC_ONCE_EXPECTED_TIME = 3000;
63+
64+
/**
65+
* Value for empty sync-once. @see <a href=
66+
* "http://jackrabbit.apache.org/filevault/usage.html#a.vlt-sync-config.properties">.vlt-sync-config.properties()</a>.
67+
*/
68+
protected static final String SYNC_ONCE_DISABLED = "";
6369

6470
/**
6571
* Value for the "auto detecting" type. If the filesystem local path is
@@ -86,8 +92,9 @@ public class InitialRegistrationImpl {
8692
@Property(label = "Local Path", description = "Filesystem local path to be added as sync root.[Required]")
8793
protected static final String PROP_LOCAL_PATH = "local.path";
8894

89-
@Property(label = "Sync Once Type", value = SYNC_ONCE_AUTO, description = "Type of sync-once"
90-
+ " to perform.[Optional] [Default: Auto detect]", options = {
95+
@Property(label = "Sync Once Type", value = SYNC_ONCE_DISABLED, description = "Type of sync-once"
96+
+ " to perform.[Optional] [Default: ]", options = {
97+
@PropertyOption(name = SYNC_ONCE_DISABLED, value = ""),
9198
@PropertyOption(name = SYNC_ONCE_AUTO, value = "Auto detect"),
9299
@PropertyOption(name = SYNC_ONCE_FS2JCR, value = "Filesystem to JCR"),
93100
@PropertyOption(name = SYNC_ONCE_JCR2FS, value = "JCR to Filesystem") })
@@ -138,7 +145,7 @@ protected void activate(final Map<String, Object> props) throws ServiceException
138145
this.overwriteConfigFiles = PropertiesUtil.toBoolean(props.get(PROP_OVERWRITE_CONFIG_FILES),
139146
DEFAULT_OVERWRITE_CONFIG_FILES);
140147

141-
this.syncOnceType = PropertiesUtil.toString(props.get(PROP_SYNC_ONCE_TYPE), SYNC_ONCE_AUTO);
148+
this.syncOnceType = PropertiesUtil.toString(props.get(PROP_SYNC_ONCE_TYPE), SYNC_ONCE_DISABLED);
142149

143150
generateFiles();
144151

bundle/src/test/java/com/techdm/aem/vltsync/impl/InitialRegistrationImplTest.java

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,20 @@ public class InitialRegistrationImplTest {
6363
public void setUp() throws NoSuchFieldException, IOException {
6464
this.initialRegistration = new InitialRegistrationImpl();
6565
this.serviceSettings = mock(ServiceSettingsImpl.class);
66-
66+
6767
PrivateAccessor.setField(this.initialRegistration, "serviceSettings", this.serviceSettings);
68-
68+
6969
this.baseDir = File.createTempFile(getClass().getName(), "_tmp");
7070
this.baseDir.delete();
7171
this.baseDir.mkdir();
7272
this.baseDir.deleteOnExit();
7373
new File(this.baseDir, DEFAULT_FILTER_FN).delete();
7474

7575
this.generatedConfigFile = new File(this.baseDir, SYNC_CONFIG_FN);
76-
this.generatedFilterFile = new File(this.baseDir, SYNC_FILTER_FN);
76+
this.generatedFilterFile = new File(this.baseDir, SYNC_FILTER_FN);
7777

7878
this.props = new LinkedHashMap<String, Object>();
79+
this.props.put(InitialRegistrationImpl.PROP_SYNC_ONCE_TYPE, InitialRegistrationImpl.SYNC_ONCE_AUTO);
7980
this.props.put(InitialRegistrationImpl.PROP_LOCAL_PATH, this.baseDir.getAbsolutePath());
8081
this.props.put(InitialRegistrationImpl.PROP_FILTER_ROOTS,
8182
new String[] { "/content/my-app", "/etc/designs/my-app" });
@@ -109,6 +110,41 @@ public void testActivateEmptyDir() throws URISyntaxException {
109110
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
110111
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
111112
}
113+
114+
115+
@Test
116+
public void testActivateEmptyDirDisabled1() throws URISyntaxException {
117+
/* Prepare data. */
118+
this.baseDir.delete();
119+
assertEquals(false, this.baseDir.exists());
120+
this.props.remove(InitialRegistrationImpl.PROP_SYNC_ONCE_TYPE);
121+
122+
/* Invoke method. */
123+
this.initialRegistration.activate(this.props);
124+
125+
/* Check its results. */
126+
FileAssert.assertEquals(getResource("data3-config.properties"), this.generatedConfigFile);
127+
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
128+
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
129+
}
130+
131+
132+
@Test
133+
public void testActivateEmptyDirDisabled2() throws URISyntaxException {
134+
/* Prepare data. */
135+
this.baseDir.delete();
136+
assertEquals(false, this.baseDir.exists());
137+
this.props.put(InitialRegistrationImpl.PROP_SYNC_ONCE_TYPE, InitialRegistrationImpl.SYNC_ONCE_DISABLED);
138+
139+
/* Invoke method. */
140+
this.initialRegistration.activate(this.props);
141+
142+
/* Check its results. */
143+
FileAssert.assertEquals(getResource("data3-config.properties"), this.generatedConfigFile);
144+
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
145+
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
146+
}
147+
112148

113149
@Test
114150
public void testActivateTrimPathProperty() throws URISyntaxException {
@@ -141,6 +177,23 @@ public void testActivateDirWithIgnorableContent() throws URISyntaxException, IOE
141177
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
142178
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
143179
}
180+
181+
182+
@Test
183+
public void testActivateDirWithIgnorableContentDisabled() throws URISyntaxException, IOException {
184+
/* Prepare data. */
185+
assertEquals(0, this.baseDir.list().length);
186+
createTempFiles(".vlt-sync.log");
187+
this.props.remove(InitialRegistrationImpl.PROP_SYNC_ONCE_TYPE);
188+
189+
/* Invoke method. */
190+
this.initialRegistration.activate(this.props);
191+
192+
/* Check its results. */
193+
FileAssert.assertEquals(getResource("data3-config.properties"), this.generatedConfigFile);
194+
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
195+
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
196+
}
144197

145198
@Test
146199
public void testActivateDirWithIgnorableContentOverwrite() throws URISyntaxException, IOException {
@@ -173,6 +226,22 @@ public void testActivateDirWithContents() throws IOException, URISyntaxException
173226
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
174227
}
175228

229+
230+
@Test
231+
public void testActivateDirWithContentsDisabled() throws IOException, URISyntaxException {
232+
/* Prepare data. */
233+
assertEquals(0, this.baseDir.list().length);
234+
createTempFiles("readme.txt", "LICENSE");
235+
this.props.remove(InitialRegistrationImpl.PROP_SYNC_ONCE_TYPE);
236+
237+
/* Invoke method. */
238+
this.initialRegistration.activate(this.props);
239+
240+
/* Check its results. */
241+
FileAssert.assertEquals(getResource("data3-config.properties"), this.generatedConfigFile);
242+
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
243+
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
244+
}
176245

177246
@Test
178247
public void testActivateDirWithContentsJcr2Fs() throws IOException, URISyntaxException {
@@ -236,6 +305,24 @@ public void testActivatePropertyFileExistsOverwrite() throws IOException, URISyn
236305
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
237306
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
238307
}
308+
309+
310+
@Test
311+
public void testActivatePropertyFileExistsOverwriteDisabled() throws IOException, URISyntaxException {
312+
/* Prepare data. */
313+
assertEquals(0, this.baseDir.list().length);
314+
createTempFiles(SYNC_CONFIG_FN);
315+
this.props.remove(InitialRegistrationImpl.PROP_SYNC_ONCE_TYPE);
316+
this.props.put(InitialRegistrationImpl.PROP_OVERWRITE_CONFIG_FILES, true);
317+
318+
/* Invoke method. */
319+
this.initialRegistration.activate(this.props);
320+
321+
/* Check its results. */
322+
FileAssert.assertEquals(getResource("data3-config.properties"), this.generatedConfigFile);
323+
FileAssert.assertEquals(getResource("data1-filter.xml"), this.generatedFilterFile);
324+
verify(this.serviceSettings, times(1)).addSyncRoot(this.baseDir, 3000l);
325+
}
239326

240327
@Test
241328
public void testActivatePropertyFileExistsDirWithContentsOverwrite() throws IOException, URISyntaxException {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<workspaceFilter version="1.0">
33
<filter root="/apps/techdm-vltsync-sample"/>
4-
<filter root="/content/techdm-vltsync-sample"/>
4+
<filter root="/content/techdm-vltsync-sample"/>
5+
<filter root="/etc/clientlibs/techdm-vltsync-sample"/>
56
</workspaceFilter>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
33
xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="sling:OsgiConfig"
4-
local.path="/tmp/vltsync-test/source"
4+
local.path="/tmp/vltsync-test/source/server"
55
filter.roots="[/apps/techdm-vltsync-sample]"
6+
sync.once.type="AUTO"
67
overwrite.config.files="true"
78
/>

sample-content/src/main/content/jcr_root/apps/techdm-vltsync-sample/config.author/com.techdm.aem.vltsync.impl.InitialRegistrationImpl-sample2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="sling:OsgiConfig"
44
local.path="/tmp/vltsync-test/data"
55
filter.roots="[/content/techdm-vltsync-sample]"
6+
sync.once.type="AUTO"
67
overwrite.config.files="true"
78
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
3+
xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="sling:OsgiConfig"
4+
local.path="/tmp/vltsync-test/source/client"
5+
filter.roots="[/etc/clientlibs/techdm-vltsync-sample]"
6+
overwrite.config.files="true"
7+
/>

sample-content/src/main/content/jcr_root/content/.content.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="sling:Folder"/>

sample-content/src/main/content/jcr_root/etc/clientlibs/techdm-vltsync-sample/CHANGEME.css

Whitespace-only changes.

0 commit comments

Comments
 (0)