Search in sources :

Example 21 with TaskResource

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);
}
Also used : TaskResource(org.apache.sling.installer.api.tasks.TaskResource) MockBundleResource(org.apache.sling.installer.core.impl.MockBundleResource) InstallTask(org.apache.sling.installer.api.tasks.InstallTask) Test(org.junit.Test)

Example 22 with TaskResource

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;
}
Also used : TaskResource(org.apache.sling.installer.api.tasks.TaskResource) TreeSet(java.util.TreeSet) InstallTask(org.apache.sling.installer.api.tasks.InstallTask) EntityResourceList(org.apache.sling.installer.core.impl.EntityResourceList)

Example 23 with TaskResource

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();
    }
}
Also used : TaskResource(org.apache.sling.installer.api.tasks.TaskResource) File(java.io.File) OsgiInstaller(org.apache.sling.installer.api.OsgiInstaller)

Example 24 with TaskResource

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));
    }
}
Also used : TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Subsystem(org.osgi.service.subsystem.Subsystem) ChangeStateTask(org.apache.sling.installer.api.tasks.ChangeStateTask) IOException(java.io.IOException)

Example 25 with TaskResource

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;
}
Also used : TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Version(org.osgi.framework.Version)

Aggregations

TaskResource (org.apache.sling.installer.api.tasks.TaskResource)28 ChangeStateTask (org.apache.sling.installer.api.tasks.ChangeStateTask)9 InstallTask (org.apache.sling.installer.api.tasks.InstallTask)6 IOException (java.io.IOException)5 Version (org.osgi.framework.Version)5 InstallableResource (org.apache.sling.installer.api.InstallableResource)4 RegisteredResource (org.apache.sling.installer.api.tasks.RegisteredResource)4 Subsystem (org.osgi.service.subsystem.Subsystem)4 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 OsgiInstaller (org.apache.sling.installer.api.OsgiInstaller)2 UpdateHandler (org.apache.sling.installer.api.UpdateHandler)2 InstallTaskFactory (org.apache.sling.installer.api.tasks.InstallTaskFactory)2 TaskResourceGroup (org.apache.sling.installer.api.tasks.TaskResourceGroup)2 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)2