use of org.apache.sling.ide.transport.Batcher in project sling by apache.
the class SlingLaunchpadBehaviour method publishContentModule.
private void publishContentModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException, SerializationException, IOException {
Logger logger = Activator.getDefault().getPluginLogger();
Repository repository = ServerUtil.getConnectedRepository(getServer(), monitor);
if (repository == null) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to find a repository for server " + getServer()));
}
Batcher batcher = Activator.getDefault().getBatcherFactory().createBatcher();
// TODO it would be more efficient to have a module -> filter mapping
// it would be simpler to implement this in SlingContentModuleAdapter, but
// the behaviour for resources being filtered out is deletion, and that
// would be an incorrect ( or at least suprising ) behaviour at development time
List<IModuleResource> addedOrUpdatedResources = new ArrayList<>();
IModuleResource[] allResources = getResources(module);
Set<IPath> handledPaths = new HashSet<>();
switch(deltaKind) {
case ServerBehaviourDelegate.CHANGED:
for (IModuleResourceDelta resourceDelta : getPublishedResourceDelta(module)) {
StringBuilder deltaTrace = new StringBuilder();
deltaTrace.append("- processing delta kind ");
switch(resourceDelta.getKind()) {
case IModuleResourceDelta.ADDED:
deltaTrace.append("ADDED ");
break;
case IModuleResourceDelta.CHANGED:
deltaTrace.append("CHANGED ");
break;
case IModuleResourceDelta.NO_CHANGE:
deltaTrace.append("NO_CHANGE ");
break;
case IModuleResourceDelta.REMOVED:
deltaTrace.append("REMOVED ");
break;
default:
deltaTrace.append("UNKNOWN - ").append(resourceDelta.getKind());
}
deltaTrace.append("for resource ").append(resourceDelta.getModuleResource());
logger.trace(deltaTrace.toString());
switch(resourceDelta.getKind()) {
case IModuleResourceDelta.ADDED:
case IModuleResourceDelta.CHANGED:
case // TODO is this needed?
IModuleResourceDelta.NO_CHANGE:
Command<?> command = addFileCommand(repository, resourceDelta.getModuleResource());
if (command != null) {
ensureParentIsPublished(resourceDelta.getModuleResource(), repository, allResources, handledPaths, batcher);
addedOrUpdatedResources.add(resourceDelta.getModuleResource());
}
enqueue(batcher, command);
break;
case IModuleResourceDelta.REMOVED:
enqueue(batcher, removeFileCommand(repository, resourceDelta.getModuleResource()));
break;
}
}
break;
case ServerBehaviourDelegate.ADDED:
case // TODO is this correct ?
ServerBehaviourDelegate.NO_CHANGE:
for (IModuleResource resource : getResources(module)) {
Command<?> command = addFileCommand(repository, resource);
enqueue(batcher, command);
if (command != null) {
addedOrUpdatedResources.add(resource);
}
}
break;
case ServerBehaviourDelegate.REMOVED:
for (IModuleResource resource : getResources(module)) {
enqueue(batcher, removeFileCommand(repository, resource));
}
break;
}
// reorder the child nodes at the end, when all create/update/deletes have been processed
for (IModuleResource resource : addedOrUpdatedResources) {
enqueue(batcher, reorderChildNodesCommand(repository, resource));
}
execute(batcher);
// set state to published
super.publishModule(kind, deltaKind, module, monitor);
setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
// setServerPublishState(IServer.PUBLISH_STATE_NONE);
}
Aggregations