Search in sources :

Example 21 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class AbstractSlingContextImplTest method testRunModes.

@Test
public void testRunModes() {
    SlingSettingsService slingSettings = context.getService(SlingSettingsService.class);
    assertEquals(SlingContextImpl.DEFAULT_RUN_MODES, slingSettings.getRunModes());
    context.runMode("mode1", "mode2");
    Set<String> newRunModes = slingSettings.getRunModes();
    assertEquals(2, newRunModes.size());
    assertTrue(newRunModes.contains("mode1"));
    assertTrue(newRunModes.contains("mode2"));
}
Also used : SlingSettingsService(org.apache.sling.settings.SlingSettingsService) Test(org.junit.Test)

Example 22 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class ServicesListener method notifyChange.

public synchronized void notifyChange() {
    final boolean shouldRun = this.installer.hasConfigurations();
    if ((shouldRun && !running) || (!shouldRun && running)) {
        final OsgiInstaller installer = (OsgiInstaller) this.installerListener.getService();
        final SlingSettingsService settings = (SlingSettingsService) this.settingsListener.getService();
        if (installer != null && settings != null && !running) {
            logger.debug("Starting scanner");
            this.startScanner(installer, settings);
        } else if (running && (installer == null || settings == null)) {
            logger.debug("Stopping scanner");
            this.stopScanner();
        }
    }
}
Also used : OsgiInstaller(org.apache.sling.installer.api.OsgiInstaller) SlingSettingsService(org.apache.sling.settings.SlingSettingsService)

Example 23 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService 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());
}
Also used : RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) SlingSettingsService(org.apache.sling.settings.SlingSettingsService) URL(java.net.URL) ZipInputStream(java.util.zip.ZipInputStream) TransformationResult(org.apache.sling.installer.api.tasks.TransformationResult) DeleteOnCloseFileInputStream(org.apache.sling.installer.factories.subsystems.base.impl.SubsystemBaseTransformer.DeleteOnCloseFileInputStream) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService 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());
}
Also used : RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) SlingSettingsService(org.apache.sling.settings.SlingSettingsService) URL(java.net.URL) ZipInputStream(java.util.zip.ZipInputStream) TransformationResult(org.apache.sling.installer.api.tasks.TransformationResult) DeleteOnCloseFileInputStream(org.apache.sling.installer.factories.subsystems.base.impl.SubsystemBaseTransformer.DeleteOnCloseFileInputStream) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SlingSettingsService (org.apache.sling.settings.SlingSettingsService)24 Test (org.junit.Test)7 URL (java.net.URL)3 HashSet (java.util.HashSet)3 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 OsgiInstaller (org.apache.sling.installer.api.OsgiInstaller)2 RegisteredResource (org.apache.sling.installer.api.tasks.RegisteredResource)2 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)2 DeleteOnCloseFileInputStream (org.apache.sling.installer.factories.subsystems.base.impl.SubsystemBaseTransformer.DeleteOnCloseFileInputStream)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 Set (java.util.Set)1 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)1 ResourceChange (org.apache.sling.api.resource.observation.ResourceChange)1 DiscoveryService (org.apache.sling.discovery.DiscoveryService)1 LaunchpadContentProvider (org.apache.sling.launchpad.api.LaunchpadContentProvider)1