Search in sources :

Example 1 with InstallTaskFactory

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

the class OsgiInstallerImpl method computeTasks.

/**
     * Compute OSGi tasks based on our resources, and add to supplied list of tasks.
     */
private SortedSet<InstallTask> computeTasks() {
    final SortedSet<InstallTask> tasks = new TreeSet<>();
    // Walk the list of entities, and create appropriate OSGi tasks for each group
    final List<InstallTaskFactory> services = this.factoryTracker.getSortedServices();
    if (services.size() > 0) {
        for (final String entityId : this.persistentList.getEntityIds()) {
            final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
            // Check the first resource in each group
            final TaskResource toActivate = group.getActiveResource();
            if (toActivate != null) {
                final InstallTask task = getTask(services, group);
                if (task != null) {
                    tasks.add(task);
                }
            }
        }
    }
    return tasks;
}
Also used : InstallTaskFactory(org.apache.sling.installer.api.tasks.InstallTaskFactory) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) TreeSet(java.util.TreeSet) InstallTask(org.apache.sling.installer.api.tasks.InstallTask)

Example 2 with InstallTaskFactory

use of org.apache.sling.installer.api.tasks.InstallTaskFactory 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

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