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