Commit 371b1a5b authored by Ard Schrijvers's avatar Ard Schrijvers

CMS7-8836 besides some trivial refactoring of some methods and introducing a...

CMS7-8836 besides some trivial refactoring of some methods and introducing a WatchFilesUtils, now we make a distinction during startup whether autoreload is enabled or not: If not enabled, the normal repository bootstrapping and PostStartupTask will be executed to import webfiles. However, when auto reload is enabled, the import will always be done from the webfiles files system directory. The logic is as follows:
 
 1) During local development, the PostStartUpTask from bootstrap to import the web files from a jar is disabled by default (see (2)). Instead, during local development start up, webfiles are always imported into the repository from local filesystem, regardless whether you restart with an existing repository or a newly created one. This guarantees that local filesystem during development is always in sync with the repository webfiles. Even if the initialize item gets a reloadonstartup with new version configured, the PostStartUpTask from bootstrapping is disabled.
 2) When from the pom.xml <project.basedir>$
 {project.basedir}
 </project.basedir> is removed, the Web File Watch gets disabled, and the initialization is done via normal bootstrapping, thus including the PostStartUpTask. The reloadonstartup logic is then also applied. This is useful for testing a new deployment locally.
parent 0942d6a3
......@@ -5,6 +5,7 @@ src/main/java/org/onehippo/cms7/services/webfiles/WebFilesServiceModule.java -te
src/main/java/org/onehippo/cms7/services/webfiles/jcr/JcrBinaryImpl.java -text
src/main/java/org/onehippo/cms7/services/webfiles/jcr/WebFileBundleImpl.java -text
src/main/java/org/onehippo/cms7/services/webfiles/jcr/WebFileImpl.java -text
src/main/java/org/onehippo/cms7/services/webfiles/util/WatchFilesUtils.java -text
src/main/java/org/onehippo/cms7/services/webfiles/vault/AbstractWebFilesArchive.java -text
src/main/java/org/onehippo/cms7/services/webfiles/vault/FileNameComparatorUtils.java -text
src/main/java/org/onehippo/cms7/services/webfiles/watch/WebFilesWatcherJcrConfig.java -text
......
......@@ -35,6 +35,7 @@ import org.apache.jackrabbit.vault.fs.io.Importer;
import org.hippoecm.repository.util.JcrUtils;
import org.onehippo.cms7.event.HippoEvent;
import org.onehippo.cms7.services.HippoServiceRegistry;
import org.onehippo.cms7.services.autoreload.AutoReloadService;
import org.onehippo.cms7.services.eventbus.HippoEventBus;
import org.onehippo.cms7.services.webfiles.jcr.WebFileBundleImpl;
import org.onehippo.cms7.services.webfiles.vault.AbstractWebFilesArchive;
......@@ -91,15 +92,29 @@ public class WebFilesServiceImpl implements WebFilesService {
}
@Override
public void importJcrWebFileBundle(final Session session, final File directory) throws IOException, WebFileException {
public void importJcrWebFileBundle(final Session session, final File directory, boolean bootstrapPhase) throws IOException, WebFileException {
final AutoReloadService autoReload = HippoServiceRegistry.getService(AutoReloadService.class);
if (bootstrapPhase && autoReload != null && autoReload.isEnabled()) {
// (re)import files will be done directly from file system. In case of an existing local repository, existing
// web files will be replaced completely to sync possible local changes after restart
log.debug("Auto reload is enabled hence webfiles are (re-)imported directly from filesystem instead of via bootstrap.");
}
final WebFilesFileArchive archive = new WebFilesFileArchive(directory, importedFiles);
importJcrWebFileBundle(session, archive);
}
@Override
public void importJcrWebFileBundle(final Session session, final ZipFile zip) throws IOException, WebFileException {
final WebFilesZipArchive archive = new WebFilesZipArchive(zip, importedFiles);
importJcrWebFileBundle(session, archive);
public void importJcrWebFileBundle(final Session session, final ZipFile zip, boolean bootstrapPhase) throws IOException, WebFileException {
final AutoReloadService autoReload = HippoServiceRegistry.getService(AutoReloadService.class);
if (bootstrapPhase && autoReload != null && autoReload.isEnabled()) {
// (re)import files will be done directly from file system. In case of an existing local repository, existing
// web files will be replaced completely to sync possible local changes after restart
log.debug("Auto reload is enabled hence webfiles are (re-)imported directly from filesystem instead of via bootstrap.");
} else {
final WebFilesZipArchive archive = new WebFilesZipArchive(zip, importedFiles);
importJcrWebFileBundle(session, archive);
}
}
......
/*
* Copyright 2015 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.cms7.services.webfiles.util;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.onehippo.cms7.services.webfiles.watch.WebFilesWatcherConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WatchFilesUtils {
private static final Logger log = LoggerFactory.getLogger(WatchFilesUtils.class);
public static final String PROJECT_BASEDIR_PROPERTY = "project.basedir";
public static final String WEB_FILES_LOCATION_IN_MODULE = "src/main/resources";
public static Path getProjectBaseDir() {
final String projectBaseDir = System.getProperty(PROJECT_BASEDIR_PROPERTY);
if (projectBaseDir != null) {
final Path baseDir = FileSystems.getDefault().getPath(projectBaseDir);
if (Files.isDirectory(baseDir)) {
return baseDir;
} else {
log.warn("Watching web files is disabled: environment variable '{}' does not point to a directory", PROJECT_BASEDIR_PROPERTY);
}
} else {
log.info("Watching web files is disabled: environment variable '{}' not set", PROJECT_BASEDIR_PROPERTY);
}
return null;
}
public static List<Path> getWebFilesDirectories(final Path projectBaseDir,
final WebFilesWatcherConfig config) {
List<Path> webFilesDirectories = new ArrayList<>(config.getWatchedModules().size());
for (String watchedModule : config.getWatchedModules()) {
final Path webFilesModule = projectBaseDir.resolve(watchedModule);
final Path webFilesDirectory = webFilesModule.resolve(WEB_FILES_LOCATION_IN_MODULE);
if (Files.isDirectory(webFilesDirectory)) {
webFilesDirectories.add(webFilesDirectory);
} else {
log.warn("Cannot watch web files in module '{}': it does not contain directory '{}'",
watchedModule, WEB_FILES_LOCATION_IN_MODULE);
}
}
return webFilesDirectories;
}
}
......@@ -17,6 +17,7 @@ package org.onehippo.cms7.services.webfiles.watch;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
/**
* Observes registered directories for changes (created, modified en deleted files and directories)
......@@ -32,6 +33,12 @@ public interface FileSystemObserver {
*/
public void registerDirectory(Path directory, FileSystemListener listener) throws IOException;
/**
* @return the root {@link java.nio.file.Path} directories which are registered via
* {@link #registerDirectory(java.nio.file.Path, FileSystemListener)}
*/
public List<Path> getObservedRootDirectories();
/**
* Closes resources used by this observer.
*/
......
......@@ -19,7 +19,9 @@ import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.monitor.FileAlterationListener;
......@@ -65,6 +67,11 @@ class FileSystemPoller implements FileSystemObserver, FileAlterationListener {
monitor.addObserver(observer);
}
@Override
public List<Path> getObservedRootDirectories() {
return new ArrayList<>(listeners.keySet());
}
@Override
public void onStart(final FileAlterationObserver observer) {
final Path observedPath = observer.getDirectory().toPath();
......
......@@ -92,6 +92,11 @@ class FileSystemWatcher implements FileSystemObserver, Runnable {
}
}
@Override
public List<Path> getObservedRootDirectories() {
return new ArrayList<>(changesProcessors.keySet());
}
private void registerRecursively(final Path directory) throws IOException {
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
......
......@@ -45,7 +45,12 @@ class SubDirectoriesWatcher implements FileSystemListener {
private final SortedSet<Path> modifiedPaths;
private final Set<Path> deletedPaths;
SubDirectoriesWatcher(final Path directory, final FileSystemObserver fsObserver, final PathChangesListener listener) throws IOException {
public static void watch(final Path webFilesDirectory, final FileSystemObserver fsObserver, final PathChangesListener listener) throws IOException {
new SubDirectoriesWatcher(webFilesDirectory, fsObserver, listener);
}
private SubDirectoriesWatcher(final Path directory, final FileSystemObserver fsObserver, final PathChangesListener listener) throws IOException {
this.rootDirectory = directory;
this.listener = listener;
this.fsObserver = fsObserver;
......
......@@ -16,15 +16,21 @@
package org.onehippo.cms7.services.webfiles.watch;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jcr.AccessDeniedException;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.ReferentialIntegrityException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.version.VersionException;
import org.apache.commons.lang.StringUtils;
import org.onehippo.cms7.services.autoreload.AutoReloadService;
......@@ -32,6 +38,7 @@ import org.onehippo.cms7.services.eventbus.HippoEventBus;
import org.onehippo.cms7.services.webfiles.WebFileEvent;
import org.onehippo.cms7.services.webfiles.WebFileException;
import org.onehippo.cms7.services.webfiles.WebFilesService;
import org.onehippo.cms7.services.webfiles.util.WatchFilesUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -43,10 +50,7 @@ import org.slf4j.LoggerFactory;
*/
public class WebFilesWatcher implements SubDirectoriesWatcher.PathChangesListener {
public static final String PROJECT_BASEDIR_PROPERTY = "project.basedir";
public static final String WEB_FILES_LOCATION_IN_MODULE = "src/main/resources";
static Logger log = LoggerFactory.getLogger(WebFilesWatcher.class);
public static Logger log = LoggerFactory.getLogger(WebFilesWatcher.class);
private final WebFilesWatcherConfig config;
private WebFilesService service;
......@@ -66,23 +70,32 @@ public class WebFilesWatcher implements SubDirectoriesWatcher.PathChangesListene
if (fileSystemObserver == null && autoReload != null) {
autoReload.setEnabled(false);
} else if (autoReload != null){
log.info("Auto reload and Web Files watching enabled. Start with initial (re-)import");
for (Path webFilesRootDirectory : fileSystemObserver.getObservedRootDirectories()) {
try {
log.info("Importing directory '{}'", webFilesRootDirectory);
service.importJcrWebFileBundle(session, webFilesRootDirectory.toFile(), false);
session.save();
} catch (IOException | RepositoryException e) {
if (log.isDebugEnabled()) {
log.warn("Failed to import directory '{}'", webFilesRootDirectory, e);
} else {
log.warn("Failed to import directory '{}' : '{}'", webFilesRootDirectory, e.toString());
}
resetSilently(session);
}
}
}
}
private FileSystemObserver observeFileSystemIfNeeded() {
final List<String> watchedModules = config.getWatchedModules();
if (!watchedModules.isEmpty()) {
final String projectBaseDir = System.getProperty(PROJECT_BASEDIR_PROPERTY);
if (projectBaseDir != null) {
final Path baseDir = FileSystems.getDefault().getPath(projectBaseDir);
if (Files.isDirectory(baseDir)) {
return observeFileSystem(baseDir);
} else {
log.warn("Watching web files is disabled: environment variable '{}' does not point to a directory", PROJECT_BASEDIR_PROPERTY);
}
} else {
log.info("Watching web files is disabled: environment variable '{}' not set", PROJECT_BASEDIR_PROPERTY);
}
final Path projectBaseDir = WatchFilesUtils.getProjectBaseDir();
if (projectBaseDir == null) {
return null;
}
if (config.getWatchedModules().size() > 0) {
return observeFileSystem(projectBaseDir);
} else {
log.info("Watching web files is disabled: no web file modules configured to watch");
}
......@@ -97,14 +110,13 @@ public class WebFilesWatcher implements SubDirectoriesWatcher.PathChangesListene
log.error("Watching web files is disabled: cannot create file system observer", e);
return null;
}
for (String watchedModule : config.getWatchedModules()) {
List<Path> webFilesDirectories = WatchFilesUtils.getWebFilesDirectories(projectBaseDir, config);
for (Path webFilesDirectory : webFilesDirectories) {
try {
final SubDirectoriesWatcher watcherOrNull = createWatcherOrNull(projectBaseDir, watchedModule, fsObserver);
if (watcherOrNull != null) {
log.info("Watching web files in module '{}'", watchedModule);
}
SubDirectoriesWatcher.watch(webFilesDirectory, fsObserver, this);
} catch (Exception e) {
log.error("Failed to watch web files in module '{}'", watchedModule, e);
log.error("Failed to watch or import web files in module '{}'", webFilesDirectory, e);
}
}
return fsObserver;
......@@ -138,19 +150,6 @@ public class WebFilesWatcher implements SubDirectoriesWatcher.PathChangesListene
return matcher.matchesCurrentOs();
}
private SubDirectoriesWatcher createWatcherOrNull(final Path projectBaseDir, final String watchedModule, final FileSystemObserver fsObserver) throws Exception {
final Path webFilesModule = projectBaseDir.resolve(watchedModule);
final Path webFilesDirectory = webFilesModule.resolve(WEB_FILES_LOCATION_IN_MODULE);
if (Files.isDirectory(webFilesDirectory)) {
return new SubDirectoriesWatcher(webFilesDirectory, fsObserver, this);
} else {
log.warn("Cannot watch web files in module '{}': it does not contain directory '{}'",
watchedModule, WEB_FILES_LOCATION_IN_MODULE);
}
return null;
}
@Override
public void onStart() {
// nothing to do, but needed for thread synchronization in tests
......@@ -248,7 +247,7 @@ public class WebFilesWatcher implements SubDirectoriesWatcher.PathChangesListene
final Path bundleRootDir = watchedRootDir.resolve(bundleName);
if (reimportedBundleRoots.add(bundleRootDir)) {
log.info("Reimporting bundle '{}'", bundleName);
service.importJcrWebFileBundle(session, bundleRootDir.toFile());
service.importJcrWebFileBundle(session, bundleRootDir.toFile(), false);
}
}
session.save();
......
......@@ -208,7 +208,7 @@ public class WebFilesServiceImplIT extends RepositoryTestCase {
public void importBundleFromZip() throws RepositoryException, IOException {
File testBundleFile = FileUtils.toFile(getClass().getResource("/testbundle.zip"));
ZipFile testBundleZip = new ZipFile(testBundleFile);
service.importJcrWebFileBundle(session, testBundleZip);
service.importJcrWebFileBundle(session, testBundleZip, true);
assertTestBundle();
}
......@@ -216,7 +216,7 @@ public class WebFilesServiceImplIT extends RepositoryTestCase {
public void importEmptyBundleFromZip() throws IOException, RepositoryException {
File emptyBundleFile = FileUtils.toFile(getClass().getResource("/testbundle-empty.zip"));
ZipFile emptyBundleZip = new ZipFile(emptyBundleFile);
service.importJcrWebFileBundle(session, emptyBundleZip);
service.importJcrWebFileBundle(session, emptyBundleZip, true);
assertNotNull("testbundle should exist", service.getJcrWebFileBundle(session, "testbundle"));
}
......@@ -224,7 +224,7 @@ public class WebFilesServiceImplIT extends RepositoryTestCase {
public void importEmptyZip() throws IOException, RepositoryException {
File emptyZipFile = FileUtils.toFile(getClass().getResource("/empty.zip"));
ZipFile emptyZip = new ZipFile(emptyZipFile);
service.importJcrWebFileBundle(session, emptyZip);
service.importJcrWebFileBundle(session, emptyZip, true);
}
@Test
......@@ -233,7 +233,7 @@ public class WebFilesServiceImplIT extends RepositoryTestCase {
File testBundleFile = FileUtils.toFile(getClass().getResource("/testbundle-with-custom-dot-content-xml.zip"));
ZipFile testBundleZip = new ZipFile(testBundleFile);
service.importJcrWebFileBundle(session, testBundleZip);
service.importJcrWebFileBundle(session, testBundleZip, true);
assertTestBundle();
assertTrue("test folder defined in .content.xml exists", session.nodeExists("/webfiles/testbundle/test"));
......@@ -244,7 +244,7 @@ public class WebFilesServiceImplIT extends RepositoryTestCase {
public void importBundleFromZipWithEmptyDirectory() throws IOException, RepositoryException {
File testBundleFile = FileUtils.toFile(getClass().getResource("/testbundle-with-empty-dir.zip"));
ZipFile testBundleZip = new ZipFile(testBundleFile);
service.importJcrWebFileBundle(session, testBundleZip);
service.importJcrWebFileBundle(session, testBundleZip, true);
assertTestBundle();
final String emptyDirNodePath = WebFilesService.JCR_ROOT_PATH + "/testbundle/emptyDir";
......
......@@ -74,7 +74,7 @@ public abstract class AbstractSubDirectoriesWatcherWithFileSystemObserverIT exte
fileNameMatcher.includeFiles("*.js");
fileSystemObserver = createFileSystemObserver();
callbackTracker = new CallbackTracker();
new SubDirectoriesWatcher(webFilesDirectory.toPath(), fileSystemObserver, callbackTracker);
SubDirectoriesWatcher.watch(webFilesDirectory.toPath(), fileSystemObserver, callbackTracker);
}
protected abstract FileSystemObserver createFileSystemObserver() throws Exception;
......
......@@ -23,9 +23,12 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.onehippo.cms7.services.webfiles.util.WatchFilesUtils;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onehippo.cms7.services.webfiles.util.WatchFilesUtils.PROJECT_BASEDIR_PROPERTY;
import static org.onehippo.cms7.services.webfiles.util.WatchFilesUtils.WEB_FILES_LOCATION_IN_MODULE;
public class AbstractWatcherIT {
......@@ -47,7 +50,7 @@ public class AbstractWatcherIT {
public void setUp() throws Exception {
String webFilesDirectoryPath = tmpFolder.getRoot().getCanonicalPath()
+ File.separator + watchedModule
+ File.separator + WebFilesWatcher.WEB_FILES_LOCATION_IN_MODULE;
+ File.separator + WEB_FILES_LOCATION_IN_MODULE;
webFilesDirectory = new File(webFilesDirectoryPath);
FileUtils.forceMkdir(webFilesDirectory);
webFilesDirectory.deleteOnExit();
......@@ -55,7 +58,7 @@ public class AbstractWatcherIT {
watchModuleDir = webFilesDirectory.toPath().getParent().getParent().getParent();
projectBaseDir = watchModuleDir.getParent().getParent();
System.setProperty(WebFilesWatcher.PROJECT_BASEDIR_PROPERTY, projectBaseDir.toString());
System.setProperty(PROJECT_BASEDIR_PROPERTY, projectBaseDir.toString());
testBundleDir = new File(webFilesDirectory, "testbundle");
......@@ -81,7 +84,7 @@ public class AbstractWatcherIT {
@After
public void tearDown() throws InterruptedException {
System.clearProperty(WebFilesWatcher.PROJECT_BASEDIR_PROPERTY);
System.clearProperty(PROJECT_BASEDIR_PROPERTY);
}
}
......@@ -42,11 +42,13 @@ import org.onehippo.cms7.services.webfiles.WebFilesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
......@@ -158,6 +160,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void onPathsChanged_invoked_directly() throws IOException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq("css/style.css"), eq(styleCss));
expectLastCall();
......@@ -181,6 +185,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void onPathsChanged_invoked_directly_without_eventBus() throws IOException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq("css/style.css"), eq(styleCss));
expectLastCall();
......@@ -222,6 +228,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void creating_file_imports_file() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File cssDir = styleCss.getParentFile();
final File newCss = new File(cssDir, "new.css");
......@@ -242,6 +250,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void creating_directory_imports_directory() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File newDir = new File(testBundleDir, "newDir");
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq("newDir"), eq(newDir));
......@@ -261,6 +271,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void creating_excluded_directory_imports_nothing() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File newDir = new File(testBundleDir, ".svn");
replayWebFilesService();
......@@ -275,6 +287,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void touching_file_imports_file() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq("css/style.css"), eq(styleCss));
expectLastCall();
autoReload.broadcastPageReload();
......@@ -292,6 +306,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void creating_excluded_file_imports_nothing() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File stylePdf = new File(cssDir, "style.pdf");
replayWebFilesService();
......@@ -307,6 +323,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void removing_file_imports_parent_directory() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File cssDir = styleCss.getParentFile();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq(cssDir.getName()), eq(cssDir));
......@@ -326,6 +344,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void renaming_file_imports_parent_directory() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File cssDir = styleCss.getParentFile();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq(cssDir.getName()), eq(cssDir));
......@@ -346,6 +366,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void removing_subdirectory_imports_parent() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final File cssDir = styleCss.getParentFile();
final File cssSubDir = new File(cssDir, "cssSubDir");
assertTrue(cssSubDir.mkdir());
......@@ -367,6 +389,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test(timeout = TIMEOUT_MS)
public void removing_root_directory_imports_everything() throws IOException, InterruptedException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq(""), eq(testBundleDir));
expectLastCall();
autoReload.broadcastPageReload();
......@@ -396,11 +420,13 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void failing_import_logs_warning_resets_session_and_reimport_whole_bundle() throws IOException, InterruptedException, RepositoryException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
webFilesService.importJcrWebFiles(anyObject(Session.class), eq("testbundle"), eq("css"), eq(cssDir));
expectLastCall().andThrow(new WebFileException("Simulating failed import"));
session.refresh(eq(false));
expectLastCall();
webFilesService.importJcrWebFileBundle(anyObject(Session.class), eq(testBundleDir));
webFilesService.importJcrWebFileBundle(anyObject(Session.class), eq(testBundleDir), anyBoolean());
expectLastCall();
autoReload.broadcastPageReload();
expectLastCall();
......@@ -417,6 +443,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void windows_paths_are_converted_to_correct_jcr_paths() throws IOException, InterruptedException, RepositoryException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final Path windowsBundleRoot = new MockPath("C:\\Users\\John\\myhippoproject\\bootstrap\\webfiles\\src\\main\\resources", '\\');
final Path windowsStyleCss = new MockPath("C:\\Users\\John\\myhippoproject\\bootstrap\\webfiles\\src\\main\\resources\\bundle\\css\\style.css", '\\');
......@@ -435,6 +463,8 @@ public class WebFilesWatcherIT extends AbstractWatcherIT {
@Test
public void modification_after_watcher_shutdown_does_not_trigger_import() throws InterruptedException, IOException {
webFilesService.importJcrWebFileBundle(anyObject(Session.class), anyObject(File.class), anyBoolean());
expectLastCall();
final AtomicInteger counter = new AtomicInteger();
webFilesService.importJcrWebFiles(anyObject(Session.class), anyObject(String.class), anyObject(String.class), anyObject(File.class));
......
......@@ -28,7 +28,7 @@ public class WebFilesWatcherJavaConfig implements WebFilesWatcherConfig {
private final List<String> useWatchServiceOnOsNames;
private long watchDelayMillis;
WebFilesWatcherJavaConfig() {
public WebFilesWatcherJavaConfig() {
watchedModules = new ArrayList<>();
includedFiles = new ArrayList<>();
excludedDirs = new ArrayList<>();
......@@ -40,13 +40,13 @@ public class WebFilesWatcherJavaConfig implements WebFilesWatcherConfig {
watchedModules.add(module);
}
void includeFiles(final String... globPatterns) {
public void includeFiles(final String... globPatterns) {
for (String pattern : globPatterns) {
includedFiles.add(pattern);
}
}
void excludeDirs(final String... globPatterns) {
public void excludeDirs(final String... globPatterns) {
for (String pattern : globPatterns) {
excludedDirs.add(pattern);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment