use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class BundleTaskCreatorTest method testSingleBundleNew.
@Test
public void testSingleBundleNew() throws IOException {
final TaskResource[] r = { new MockBundleResource(SN, "1.0") };
final MockBundleTaskCreator c = new MockBundleTaskCreator();
final SortedSet<InstallTask> s = getTasks(r, c);
assertEquals("Expected one task", 1, s.size());
assertTrue("Expected a BundleInstallTask", s.first() instanceof BundleInstallTask);
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class BundleTaskCreatorTest method getTasks.
private SortedSet<InstallTask> getTasks(TaskResource[] resources, BundleTaskCreator btc) throws IOException {
final SortedSet<TaskResource> sortedResources = new TreeSet<TaskResource>();
for (final TaskResource rr : resources) {
sortedResources.add(rr);
}
final SortedSet<InstallTask> tasks = new TreeSet<InstallTask>();
for (final TaskResource r : sortedResources) {
final EntityResourceList erl = new EntityResourceList(r.getEntityId(), new MockInstallationListener());
erl.addOrUpdate(((MockBundleResource) r).getRegisteredResourceImpl());
assertNotNull(erl.getActiveResource());
tasks.add(btc.createTask(erl));
}
return tasks;
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class UninstallModelTask method execute.
@Override
public void execute(final InstallationContext ctx) {
try {
final OsgiInstaller installer = this.getService(OsgiInstaller.class);
if (installer == null) {
ctx.log("Unable to get OSGi Installer service!");
} else {
final TaskResource resource = this.getResource();
ctx.log("Uninstalling {}", resource.getEntityId());
installer.registerResources("model-" + resource.getAttribute(ModelTransformer.ATTR_FEATURE_NAME), null);
final String path = (String) resource.getAttribute(ModelTransformer.ATTR_BASE_PATH);
if (path != null) {
final File dir = new File(path);
deleteDirectory(dir);
}
this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED);
ctx.log("Uninstalled {}", resource.getEntityId());
}
} finally {
this.cleanup();
}
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class InstallSubsystemTask method execute.
@Override
public void execute(final InstallationContext ctx) {
final TaskResource tr = this.getResource();
ctx.log("Installing new subsystem from {}", tr);
try {
final Subsystem sub = this.rootSubsystem.install(tr.getURL(), tr.getInputStream());
ctx.addTaskToCurrentCycle(new StartSubsystemTask(this.getResourceGroup(), sub));
ctx.log("Installed new subsystem {}", sub);
} catch (final IOException e) {
ctx.log("Unable to install subsystem {} : {}", tr, e);
ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.IGNORED));
}
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class SubsystemInstaller method checkResource.
/**
* Check that the required attributes are available.
* This is just a sanity check
*/
private SubsystemInfo checkResource(final TaskResourceGroup toActivate) {
final TaskResource rsrc = toActivate.getActiveResource();
SubsystemInfo result = null;
final String symbolicName = (String) rsrc.getAttribute(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME);
if (symbolicName == null) {
logger.error("Subsystem resource is missing symbolic name {}", rsrc);
} else {
final String version = (String) rsrc.getAttribute(SubsystemConstants.SUBSYSTEM_VERSION);
if (version == null) {
logger.error("Subsystem resource is missing version {}", rsrc);
} else {
// check the version for validity
boolean validVersion = true;
try {
new Version(version);
} catch (final IllegalArgumentException iae) {
logger.info("Rejecting subsystem {} from {} due to invalid version information: {}.", new Object[] { symbolicName, rsrc, version });
validVersion = false;
}
if (validVersion) {
result = new SubsystemInfo();
result.symbolicName = symbolicName;
result.version = version;
}
}
}
return result;
}
Aggregations