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