Search in sources :

Example 1 with Batcher

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) Logger(org.apache.sling.ide.log.Logger) Repository(org.apache.sling.ide.transport.Repository) CoreException(org.eclipse.core.runtime.CoreException) Batcher(org.apache.sling.ide.transport.Batcher) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Logger (org.apache.sling.ide.log.Logger)1 Batcher (org.apache.sling.ide.transport.Batcher)1 Repository (org.apache.sling.ide.transport.Repository)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)1 IModuleResourceDelta (org.eclipse.wst.server.core.model.IModuleResourceDelta)1