Search in sources :

Example 6 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class Installer method initialSet.

/**
     * @see org.apache.sling.installer.provider.file.impl.FileChangesListener#initialSet(java.util.List)
     */
public void initialSet(final List<File> files) {
    logger.debug("Initial set for {}", this.scheme);
    final List<InstallableResource> resources = new ArrayList<InstallableResource>();
    for (final File f : files) {
        logger.debug("Initial file {}", f);
        final InstallableResource resource = this.createResource(f);
        if (resource != null) {
            resources.add(resource);
        }
    }
    this.installer.registerResources(this.scheme, resources.toArray(new InstallableResource[resources.size()]));
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) ArrayList(java.util.ArrayList) File(java.io.File)

Example 7 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class ConfigNodeConverter method convertNode.

/** Convert n to an InstallableData, or return null
	 * 	if we don't know how to convert it.
	 */
public InstallableResource convertNode(final Node n, final int priority) throws RepositoryException {
    InstallableResource result = null;
    // We only consider CONFIG_NODE_TYPE nodes
    if (n.isNodeType(CONFIG_NODE_TYPE)) {
        final Dictionary<String, Object> dict = load(n);
        result = new InstallableResource(n.getPath(), null, dict, computeDigest(dict), null, priority);
        log.debug("Converted node {} to {}", n.getPath(), result);
    } else {
        log.debug("Node is not a {} node, ignored:{}", CONFIG_NODE_TYPE, n.getPath());
    }
    return result;
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource)

Example 8 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class MockOsgiInstaller method updateResources.

/**
     * @see org.apache.sling.installer.api.OsgiInstaller#updateResources(java.lang.String, org.apache.sling.installer.api.InstallableResource[], java.lang.String[])
     */
public void updateResources(final String scheme, final InstallableResource[] resources, final String[] ids) {
    if (resources != null) {
        for (final InstallableResource d : resources) {
            urls.add(scheme + ':' + d.getId());
            recordCall("add", scheme, d);
        }
    }
    if (ids != null) {
        for (final String id : ids) {
            urls.remove(scheme + ':' + id);
            synchronized (this) {
                recordedCalls.add("remove:" + scheme + ':' + id + ":100");
            }
        }
    }
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource)

Example 9 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class InstallModelTask method transform.

private Result transform(final String name, final String modelText, final int featureIndex, final TaskResource rsrc, final File baseDir) {
    Model model = null;
    try (final Reader reader = new StringReader(modelText)) {
        model = ModelUtility.getEffectiveModel(ModelReader.read(reader, name));
    } catch (final IOException ioe) {
        logger.warn("Unable to read model file for feature " + name, ioe);
    }
    if (model == null) {
        return null;
    }
    int index = 0;
    final Iterator<Feature> iter = model.getFeatures().iterator();
    while (iter.hasNext()) {
        iter.next();
        if (index != featureIndex) {
            iter.remove();
        }
        index++;
    }
    if (baseDir != null) {
        final List<Artifact> artifacts = new ArrayList<>();
        final Feature feature = model.getFeatures().get(0);
        for (final RunMode rm : feature.getRunModes()) {
            for (final ArtifactGroup group : rm.getArtifactGroups()) {
                for (final Artifact a : group) {
                    artifacts.add(a);
                }
            }
        }
        // extract artifacts
        final byte[] buffer = new byte[1024 * 1024 * 256];
        try (final InputStream is = rsrc.getInputStream()) {
            ModelArchiveReader.read(is, new ModelArchiveReader.ArtifactConsumer() {

                @Override
                public void consume(final Artifact artifact, final InputStream is) throws IOException {
                    if (artifacts.contains(artifact)) {
                        final File artifactFile = new File(baseDir, artifact.getRepositoryPath().replace('/', File.separatorChar));
                        if (!artifactFile.exists()) {
                            artifactFile.getParentFile().mkdirs();
                            try (final OutputStream os = new FileOutputStream(artifactFile)) {
                                int l = 0;
                                while ((l = is.read(buffer)) > 0) {
                                    os.write(buffer, 0, l);
                                }
                            }
                        }
                    }
                }
            });
        } catch (final IOException ioe) {
            logger.warn("Unable to extract artifacts from model " + name, ioe);
            return null;
        }
    }
    final List<ArtifactDescription> files = new ArrayList<>();
    Map<Traceable, String> errors = collectArtifacts(model, files, baseDir);
    if (errors == null) {
        final Result result = new Result();
        for (final ArtifactDescription desc : files) {
            if (desc.artifactFile != null) {
                try {
                    final InputStream is = new FileInputStream(desc.artifactFile);
                    final String digest = String.valueOf(desc.artifactFile.lastModified());
                    // handle start level
                    final Dictionary<String, Object> dict = new Hashtable<String, Object>();
                    if (desc.startLevel > 0) {
                        dict.put(InstallableResource.BUNDLE_START_LEVEL, desc.startLevel);
                    }
                    dict.put(InstallableResource.RESOURCE_URI_HINT, desc.artifactFile.toURI().toString());
                    result.resources.add(new InstallableResource("/" + desc.artifactFile.getName(), is, dict, digest, InstallableResource.TYPE_FILE, null));
                } catch (final IOException ioe) {
                    logger.warn("Unable to read artifact " + desc.artifactFile, ioe);
                    return null;
                }
            } else if (desc.cfg != null) {
                final String id = (desc.cfg.getFactoryPid() != null ? desc.cfg.getFactoryPid() + "-" + desc.cfg.getPid() : desc.cfg.getPid());
                result.resources.add(new InstallableResource("/" + id + ".config", null, desc.cfg.getProperties(), null, InstallableResource.TYPE_CONFIG, null));
            } else if (desc.section != null) {
                result.repoinit = desc.section.getContents();
            }
        }
        return result;
    }
    logger.warn("Errors during parsing model file {} : {}", name, errors.values());
    return null;
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ModelArchiveReader(org.apache.sling.provisioning.model.io.ModelArchiveReader) Reader(java.io.Reader) StringReader(java.io.StringReader) ModelReader(org.apache.sling.provisioning.model.io.ModelReader) Feature(org.apache.sling.provisioning.model.Feature) StringReader(java.io.StringReader) Traceable(org.apache.sling.provisioning.model.Traceable) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) IOException(java.io.IOException) Artifact(org.apache.sling.provisioning.model.Artifact) FileInputStream(java.io.FileInputStream) ModelArchiveReader(org.apache.sling.provisioning.model.io.ModelArchiveReader) RunMode(org.apache.sling.provisioning.model.RunMode) FileOutputStream(java.io.FileOutputStream) Model(org.apache.sling.provisioning.model.Model) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup) File(java.io.File)

Example 10 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project sling by apache.

the class BundleInstallStressTest method install.

private void install(List<File> bundles) throws IOException {
    final List<InstallableResource> toInstall = new LinkedList<InstallableResource>();
    for (File f : bundles) {
        toInstall.add(getInstallableResource(f, f.getAbsolutePath() + f.lastModified())[0]);
    }
    installer.registerResources(URL_SCHEME, toInstall.toArray(new InstallableResource[toInstall.size()]));
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

InstallableResource (org.apache.sling.installer.api.InstallableResource)47 Hashtable (java.util.Hashtable)23 Test (org.junit.Test)21 File (java.io.File)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)7 Configuration (org.osgi.service.cm.Configuration)6 FileInputStream (java.io.FileInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)3 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)3 FileOutputStream (java.io.FileOutputStream)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 Node (javax.jcr.Node)2 OsgiInstaller (org.apache.sling.installer.api.OsgiInstaller)2 ModelArchiveReader (org.apache.sling.provisioning.model.io.ModelArchiveReader)2