Search in sources :

Example 6 with RegisteredResource

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

the class OsgiInstallerWebConsolePlugin method service.

@Override
public void service(final ServletRequest req, final ServletResponse res) throws IOException {
    final PrintWriter pw = res.getWriter();
    final InstallationState state = this.installer.getInstallationState();
    pw.print("<p class='statline ui-state-highlight'>Apache Sling OSGi Installer");
    if (state.getActiveResources().size() == 0 && state.getInstalledResources().size() == 0 && state.getUntransformedResources().size() == 0) {
        pw.print(" - no resources registered.");
    }
    pw.print("</p>");
    String rt = null;
    for (final ResourceGroup group : state.getActiveResources()) {
        final Resource toActivate = group.getResources().get(0);
        if (!toActivate.getType().equals(rt)) {
            if (rt != null) {
                pw.println("</tbody></table>");
            }
            pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
            pw.printf("<span style='float: left; margin-left: 1em;'>Active Resources - %s</span>", getType(toActivate));
            pw.println("</div>");
            pw.println("<table class='nicetable'><tbody>");
            pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL (Version)</th><th>State</th><th>Error</th></tr>");
            rt = toActivate.getType();
        }
        pw.printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", getEntityId(toActivate, group.getAlias()), getInfo(toActivate), getURL(toActivate), toActivate.getState(), getError(toActivate));
    }
    if (rt != null) {
        pw.println("</tbody></table>");
    }
    rt = null;
    for (final ResourceGroup group : state.getInstalledResources()) {
        final Collection<Resource> resources = group.getResources();
        if (resources.size() > 0) {
            final Iterator<Resource> iter = resources.iterator();
            final Resource first = iter.next();
            if (!first.getType().equals(rt)) {
                if (rt != null) {
                    pw.println("</tbody></table>");
                }
                pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
                pw.printf("<span style='float: left; margin-left: 1em;'>Processed Resources - %s</span>", getType(first));
                pw.println("</div>");
                pw.println("<table class='nicetable'><tbody>");
                pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL (Version)</th><th>State</th><th>Error</th></tr>");
                rt = first.getType();
            }
            pw.print("<tr><td>");
            pw.print(getEntityId(first, group.getAlias()));
            pw.print("</td><td>");
            pw.print(getInfo(first));
            pw.print("</td><td>");
            pw.print(getURL(first));
            pw.print("</td><td>");
            pw.print(getState(first));
            if (first.getState() == ResourceState.INSTALLED) {
                final long lastChange = first.getLastChange();
                if (lastChange > 0) {
                    pw.print("<br/>");
                    pw.print(formatDate(lastChange));
                }
            }
            pw.print("</td><td>");
            pw.print(getError(first));
            pw.print("</td></tr>");
            if (first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null) {
                pw.printf("<tr><td></td><td colspan='2'>%s</td><td></td><td></td></tr>", first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED));
            }
            if (first.getAttribute(TaskResource.ATTR_INSTALL_INFO) != null) {
                pw.printf("<tr><td></td><td colspan='2'>%s</td><td></td><td></td></tr>", first.getAttribute(TaskResource.ATTR_INSTALL_INFO));
            }
            while (iter.hasNext()) {
                final Resource resource = iter.next();
                pw.printf("<tr><td></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", getInfo(resource), getURL(resource), resource.getState(), getError(resource));
            }
        }
    }
    if (rt != null) {
        pw.println("</tbody></table>");
    }
    rt = null;
    for (final RegisteredResource registeredResource : state.getUntransformedResources()) {
        if (!registeredResource.getType().equals(rt)) {
            if (rt != null) {
                pw.println("</tbody></table>");
            }
            pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
            pw.printf("<span style='float: left; margin-left: 1em;'>Untransformed Resources - %s</span>", getType(registeredResource));
            pw.println("</div>");
            pw.println("<table class='nicetable'><tbody>");
            pw.printf("<tr><th>Digest/Priority</th><th>URL</th></tr>");
            rt = registeredResource.getType();
        }
        pw.printf("<tr><td>%s</td><td>%s</td></tr>", getInfo(registeredResource), registeredResource.getURL());
    }
    if (rt != null) {
        pw.println("</tbody></table>");
    }
}
Also used : InstallationState(org.apache.sling.installer.api.info.InstallationState) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) Resource(org.apache.sling.installer.api.info.Resource) InstallableResource(org.apache.sling.installer.api.InstallableResource) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup) PrintWriter(java.io.PrintWriter)

Example 7 with RegisteredResource

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

the class PersistentResourceList method addOrUpdate.

/**
     * Add or update an installable resource.
     * @param input The installable resource
     */
public RegisteredResource addOrUpdate(final InternalResource input) {
    // first check untransformed resource if there are resources with the same url and digest
    for (final RegisteredResource rr : this.untransformedResources) {
        if (rr.getURL().equals(input.getURL()) && (rr.getDigest().equals(input.getDigest()))) {
            // if we found the resource we can return after updating
            ((RegisteredResourceImpl) rr).update(input);
            return rr;
        }
    }
    // installed resources are next
    for (final EntityResourceList group : this.data.values()) {
        for (final RegisteredResource rr : group.listResources()) {
            if (rr.getURL().equals(input.getURL()) && (rr.getDigest().equals(input.getDigest()))) {
                // if we found the resource we can return after updating
                ((RegisteredResourceImpl) rr).update(input);
                return rr;
            }
        }
    }
    try {
        final RegisteredResourceImpl registeredResource = RegisteredResourceImpl.create(input);
        this.checkInstallable(registeredResource);
        return registeredResource;
    } catch (final IOException ioe) {
        logger.warn("Ignoring resource. Error during processing of " + input.getURL(), ioe);
        return null;
    }
}
Also used : RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) IOException(java.io.IOException)

Example 8 with RegisteredResource

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

the class PersistentResourceList method remove.

/**
     * Remove a resource by url.
     * Check all resource groups and the list of untransformed resources.
     * @param url The url to remove
     */
public void remove(final String url) {
    // with the given url
    for (final EntityResourceList group : this.data.values()) {
        group.remove(url);
    }
    // iterate over untransformed resources and remove
    // the resource with that url
    final Iterator<RegisteredResource> i = this.untransformedResources.iterator();
    while (i.hasNext()) {
        final RegisteredResource rr = i.next();
        if (rr.getURL().equals(url)) {
            ((RegisteredResourceImpl) rr).cleanup();
            i.remove();
            break;
        }
    }
}
Also used : RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource)

Example 9 with RegisteredResource

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

the class RegisteredResourceComparatorTest method assertOrder.

private void assertOrder(final Set<RegisteredResource> toTest, final RegisteredResource[] inOrder) {
    assertEquals("Expected sizes to match", toTest.size(), inOrder.length);
    int i = 0;
    for (final RegisteredResource r : toTest) {
        final RegisteredResource ref = inOrder[i];
        assertSame("At index " + i + ", expected toTest and ref to match.", ref, r);
        i++;
    }
}
Also used : RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource)

Example 10 with RegisteredResource

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

the class EntityResourceList method writeObject.

/**
     * Serialize the object
     * - write version id
     * - serialize each entry in the resources list
     * @param out Object output stream
     * @throws IOException
     */
private void writeObject(final java.io.ObjectOutputStream out) throws IOException {
    out.writeInt(VERSION);
    out.writeInt(resources.size());
    for (final RegisteredResource rr : this.resources) {
        out.writeObject(rr);
    }
    out.writeObject(this.alias);
    out.writeObject(this.resourceId);
}
Also used : RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource)

Aggregations

RegisteredResource (org.apache.sling.installer.api.tasks.RegisteredResource)16 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)6 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)5 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 InstallableResource (org.apache.sling.installer.api.InstallableResource)3 InstallationState (org.apache.sling.installer.api.info.InstallationState)3 Resource (org.apache.sling.installer.api.info.Resource)3 ResourceGroup (org.apache.sling.installer.api.info.ResourceGroup)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 Attributes (java.util.jar.Attributes)2 JarFile (java.util.jar.JarFile)2 Manifest (java.util.jar.Manifest)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 ResourceTransformer (org.apache.sling.installer.api.tasks.ResourceTransformer)2