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;
}
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));
}
Aggregations