Search in sources :

Example 1 with TaskResourceGroup

use of org.apache.sling.installer.api.tasks.TaskResourceGroup in project sling by apache.

the class UpdateHandlerTest method setUp.

@Before
public void setUp() {
    setupInstaller();
    serviceRegistrations.clear();
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(Constants.SERVICE_RANKING, 1000);
    serviceRegistrations.add(this.bundleContext.registerService(ResourceTransformer.class, new ResourceTransformer() {

        public TransformationResult[] transform(final RegisteredResource resource) {
            final int lastDot = resource.getURL().lastIndexOf('.');
            final int lastSlash = resource.getURL().lastIndexOf('/');
            if (resource.getURL().substring(lastDot + 1).equals(TYPE)) {
                final String id = resource.getURL().substring(lastSlash + 1, lastDot);
                final TransformationResult tr = new TransformationResult();
                tr.setId(id);
                tr.setResourceType(TYPE);
                return new TransformationResult[] { tr };
            }
            return null;
        }
    }, props));
    serviceRegistrations.add(this.bundleContext.registerService(InstallTaskFactory.class, new InstallTaskFactory() {

        public InstallTask createTask(final TaskResourceGroup toActivate) {
            final TaskResource tr = toActivate.getActiveResource();
            if (tr != null && tr.getEntityId().startsWith(TYPE)) {
                if (tr.getState() == ResourceState.INSTALL) {
                    installed.put(tr.getEntityId(), tr.getDictionary());
                    return new ChangeStateTask(toActivate, ResourceState.INSTALLED);
                } else {
                    installed.remove(tr.getEntityId());
                    return new ChangeStateTask(toActivate, ResourceState.UNINSTALLED);
                }
            }
            return null;
        }
    }, props));
}
Also used : InstallTaskFactory(org.apache.sling.installer.api.tasks.InstallTaskFactory) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Hashtable(java.util.Hashtable) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) TaskResourceGroup(org.apache.sling.installer.api.tasks.TaskResourceGroup) ChangeStateTask(org.apache.sling.installer.api.tasks.ChangeStateTask) ResourceTransformer(org.apache.sling.installer.api.tasks.ResourceTransformer) TransformationResult(org.apache.sling.installer.api.tasks.TransformationResult) Before(org.junit.Before)

Aggregations

Hashtable (java.util.Hashtable)1 ChangeStateTask (org.apache.sling.installer.api.tasks.ChangeStateTask)1 InstallTaskFactory (org.apache.sling.installer.api.tasks.InstallTaskFactory)1 RegisteredResource (org.apache.sling.installer.api.tasks.RegisteredResource)1 ResourceTransformer (org.apache.sling.installer.api.tasks.ResourceTransformer)1 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)1 TaskResourceGroup (org.apache.sling.installer.api.tasks.TaskResourceGroup)1 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)1 Before (org.junit.Before)1