use of org.apache.sling.installer.api.tasks.RegisteredResource in project sling by apache.
the class RegisteredResourceComparatorTest method assertOrder.
private void assertOrder(RegisteredResource[] inOrder) {
final SortedSet<RegisteredResource> toTest = new TreeSet<RegisteredResource>();
for (int i = inOrder.length - 1; i >= 0; i--) {
toTest.add(inOrder[i]);
}
assertOrder(toTest, inOrder);
toTest.clear();
for (RegisteredResource r : inOrder) {
toTest.add(r);
}
assertOrder(toTest, inOrder);
}
use of org.apache.sling.installer.api.tasks.RegisteredResource in project sling by apache.
the class SubsystemBaseTransformerTest method testTransformNoRunMode.
@Test
public void testTransformNoRunMode() throws Exception {
SlingSettingsService slingSettings = Mockito.mock(SlingSettingsService.class);
SubsystemBaseTransformer sbt = new SubsystemBaseTransformer(slingSettings);
URL testArchive = getClass().getResource("/test1.subsystem-base");
RegisteredResource resource = new TestRegisteredResource(testArchive);
TransformationResult[] tra = sbt.transform(resource);
assertEquals(1, tra.length);
TransformationResult tr = tra[0];
assertEquals("esa", tr.getResourceType());
assertEquals("test1", tr.getId());
DeleteOnCloseFileInputStream dcis = (DeleteOnCloseFileInputStream) tr.getInputStream();
assertTrue("The file backing the stream should exist", dcis.file.exists());
Set<String> foundBundles = new HashSet<>();
try (ZipInputStream zis = new ZipInputStream(dcis);
JarFile jf = new JarFile(testArchive.getFile())) {
ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null) {
foundBundles.add(ze.getName());
switch(ze.getName()) {
case "OSGI-INF/SUBSYSTEM.MF":
Manifest mf = new Manifest(zis);
Attributes attrs = mf.getMainAttributes();
assertEquals("test1", attrs.getValue("Subsystem-SymbolicName"));
assertEquals("osgi.subsystem.composite", attrs.getValue("Subsystem-Type"));
assertEquals("(c) 2015 yeah!", attrs.getValue("Subsystem-Copyright"));
assertEquals("Extra subsystem headers can go here including very long ones " + "that would span multiple lines in a manifest", attrs.getValue("Subsystem-Description"));
assertEquals("org.apache.sling.commons.osgi;version=2.3.0;type=osgi.bundle;start-order:=0," + "org.apache.sling.commons.json;version=2.0.12;type=osgi.bundle;start-order:=10," + "org.apache.sling.commons.mime;version=2.1.8;type=osgi.bundle;start-order:=10", attrs.getValue("Subsystem-Content"));
break;
case "org.apache.sling.commons.osgi-2.3.0.jar":
ZipEntry oze = jf.getEntry("Potential_Bundles/0/org.apache.sling.commons.osgi-2.3.0.jar");
assertArtifactsEqual(oze.getName(), jf.getInputStream(oze), zis);
break;
case "org.apache.sling.commons.json-2.0.12.jar":
ZipEntry jze = jf.getEntry("Potential_Bundles/10/org.apache.sling.commons.json-2.0.12.jar");
assertArtifactsEqual(jze.getName(), jf.getInputStream(jze), zis);
break;
case "org.apache.sling.commons.mime-2.1.8.jar":
ZipEntry mze = jf.getEntry("Potential_Bundles/10/org.apache.sling.commons.mime-2.1.8.jar");
assertArtifactsEqual(mze.getName(), jf.getInputStream(mze), zis);
break;
}
}
}
assertEquals(new HashSet<>(Arrays.asList("OSGI-INF/SUBSYSTEM.MF", "org.apache.sling.commons.osgi-2.3.0.jar", "org.apache.sling.commons.json-2.0.12.jar", "org.apache.sling.commons.mime-2.1.8.jar")), foundBundles);
assertFalse("After closing the stream the temp file should have been deleted.", dcis.file.exists());
}
use of org.apache.sling.installer.api.tasks.RegisteredResource in project sling by apache.
the class SubsystemBaseTransformerTest method testOtherRunMode.
@Test
public void testOtherRunMode() throws Exception {
SlingSettingsService slingSettings = Mockito.mock(SlingSettingsService.class);
Mockito.when(slingSettings.getRunModes()).thenReturn(new HashSet<String>(Arrays.asList("bar", "tar")));
SubsystemBaseTransformer sbt = new SubsystemBaseTransformer(slingSettings);
URL testArchive = getClass().getResource("/test1.subsystem-base");
RegisteredResource resource = new TestRegisteredResource(testArchive);
TransformationResult[] tra = sbt.transform(resource);
assertEquals(1, tra.length);
TransformationResult tr = tra[0];
assertEquals("esa", tr.getResourceType());
assertEquals("test1", tr.getId());
DeleteOnCloseFileInputStream dcis = (DeleteOnCloseFileInputStream) tr.getInputStream();
assertTrue("The file backing the stream should exist", dcis.file.exists());
Set<String> foundBundles = new HashSet<>();
try (ZipInputStream zis = new ZipInputStream(dcis);
JarFile jf = new JarFile(testArchive.getFile())) {
ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null) {
foundBundles.add(ze.getName());
switch(ze.getName()) {
case "OSGI-INF/SUBSYSTEM.MF":
Manifest mf = new Manifest(zis);
Attributes attrs = mf.getMainAttributes();
assertEquals("test1", attrs.getValue("Subsystem-SymbolicName"));
assertEquals("osgi.subsystem.composite", attrs.getValue("Subsystem-Type"));
assertEquals("(c) 2015 yeah!", attrs.getValue("Subsystem-Copyright"));
assertEquals("Extra subsystem headers can go here including very long ones " + "that would span multiple lines in a manifest", attrs.getValue("Subsystem-Description"));
assertEquals("org.apache.sling.commons.osgi;version=2.3.0;type=osgi.bundle;start-order:=0," + "org.apache.sling.commons.json;version=2.0.12;type=osgi.bundle;start-order:=10," + "org.apache.sling.commons.mime;version=2.1.8;type=osgi.bundle;start-order:=10," + "org.apache.sling.commons.threads;version=3.2.0;type=osgi.bundle;start-order:=20," + "org.apache.sling.commons.contentdetection;version=1.0.2;type=osgi.bundle;start-order:=100", attrs.getValue("Subsystem-Content"));
break;
case "org.apache.sling.commons.osgi-2.3.0.jar":
ZipEntry oze = jf.getEntry("Potential_Bundles/0/org.apache.sling.commons.osgi-2.3.0.jar");
assertArtifactsEqual(oze.getName(), jf.getInputStream(oze), zis);
break;
case "org.apache.sling.commons.json-2.0.12.jar":
ZipEntry jze = jf.getEntry("Potential_Bundles/10/org.apache.sling.commons.json-2.0.12.jar");
assertArtifactsEqual(jze.getName(), jf.getInputStream(jze), zis);
break;
case "org.apache.sling.commons.mime-2.1.8.jar":
ZipEntry mze = jf.getEntry("Potential_Bundles/10/org.apache.sling.commons.mime-2.1.8.jar");
assertArtifactsEqual(mze.getName(), jf.getInputStream(mze), zis);
break;
case "org.apache.sling.commons.threads-3.2.0.jar":
ZipEntry tze = jf.getEntry("Potential_Bundles/20/org.apache.sling.commons.threads-3.2.0.jar");
assertArtifactsEqual(tze.getName(), jf.getInputStream(tze), zis);
break;
case "org.apache.sling.commons.contentdetection-1.0.2.jar":
ZipEntry cze = jf.getEntry("Potential_Bundles/100/org.apache.sling.commons.contentdetection-1.0.2.jar");
assertArtifactsEqual(cze.getName(), jf.getInputStream(cze), zis);
break;
}
}
}
assertEquals(new HashSet<>(Arrays.asList("OSGI-INF/SUBSYSTEM.MF", "org.apache.sling.commons.osgi-2.3.0.jar", "org.apache.sling.commons.json-2.0.12.jar", "org.apache.sling.commons.mime-2.1.8.jar", "org.apache.sling.commons.threads-3.2.0.jar", "org.apache.sling.commons.contentdetection-1.0.2.jar")), foundBundles);
assertFalse("After closing the stream the temp file should have been deleted.", dcis.file.exists());
}
use of org.apache.sling.installer.api.tasks.RegisteredResource in project sling by apache.
the class UpdateHandlerTest method setUp.
@Before
public void setUp() {
setupInstaller();
serviceRegistrations.clear();
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_RANKING, 1000);
serviceRegistrations.add(this.bundleContext.registerService(ResourceTransformer.class, new ResourceTransformer() {
public TransformationResult[] transform(final RegisteredResource resource) {
final int lastDot = resource.getURL().lastIndexOf('.');
final int lastSlash = resource.getURL().lastIndexOf('/');
if (resource.getURL().substring(lastDot + 1).equals(TYPE)) {
final String id = resource.getURL().substring(lastSlash + 1, lastDot);
final TransformationResult tr = new TransformationResult();
tr.setId(id);
tr.setResourceType(TYPE);
return new TransformationResult[] { tr };
}
return null;
}
}, props));
serviceRegistrations.add(this.bundleContext.registerService(InstallTaskFactory.class, new InstallTaskFactory() {
public InstallTask createTask(final TaskResourceGroup toActivate) {
final TaskResource tr = toActivate.getActiveResource();
if (tr != null && tr.getEntityId().startsWith(TYPE)) {
if (tr.getState() == ResourceState.INSTALL) {
installed.put(tr.getEntityId(), tr.getDictionary());
return new ChangeStateTask(toActivate, ResourceState.INSTALLED);
} else {
installed.remove(tr.getEntityId());
return new ChangeStateTask(toActivate, ResourceState.UNINSTALLED);
}
}
return null;
}
}, props));
}
use of org.apache.sling.installer.api.tasks.RegisteredResource in project sling by apache.
the class OsgiInstallerWebConsolePlugin method printConfiguration.
/**
* Method for the configuration printer.
*/
public void printConfiguration(final PrintWriter pw, final String mode) {
if (!"zip".equals(mode) && !"txt".equals(mode)) {
return;
}
pw.println("Apache Sling OSGi Installer");
pw.println("===========================");
final InstallationState state = this.installer.getInstallationState();
pw.println("Active Resources");
pw.println("----------------");
String rt = null;
for (final ResourceGroup group : state.getActiveResources()) {
final Resource toActivate = group.getResources().get(0);
if (!toActivate.getType().equals(rt)) {
pw.printf("%s:%n", getType(toActivate));
rt = toActivate.getType();
}
pw.printf("- %s: %s, %s, %s%n", getEntityId(toActivate, group.getAlias()), getInfo(toActivate), getURL(toActivate), toActivate.getState());
}
pw.println();
pw.println("Processed Resources");
pw.println("-------------------");
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)) {
pw.printf("%s:%n", getType(first));
rt = first.getType();
}
pw.printf("* %s: %s, %s, %s%n", getEntityId(first, group.getAlias()), getInfo(first), getURL(first), getState(first));
if (first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null) {
pw.printf(" : %s", first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED));
}
if (first.getAttribute(TaskResource.ATTR_INSTALL_INFO) != null) {
pw.printf(" : %s", first.getAttribute(TaskResource.ATTR_INSTALL_INFO));
}
while (iter.hasNext()) {
final Resource resource = iter.next();
pw.printf(" - %s, %s, %s%n", getInfo(resource), getURL(resource), resource.getState());
}
}
}
pw.println();
pw.println("Untransformed Resources");
pw.println("-----------------------");
rt = null;
for (final RegisteredResource registeredResource : state.getUntransformedResources()) {
if (!registeredResource.getType().equals(rt)) {
pw.printf("%s:%n", getType(registeredResource));
rt = registeredResource.getType();
}
pw.printf("- %s, %s%n", getInfo(registeredResource), registeredResource.getURL());
}
}
Aggregations