use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class ServiceImplTest method testLoadWithoutRanges.
@Test
public void testLoadWithoutRanges() throws IOException, GitAPIException {
BundleContext bundleContext = createMock(BundleContext.class);
ComponentContext componentContext = createMock(ComponentContext.class);
Bundle sysBundle = createMock(Bundle.class);
BundleContext sysBundleContext = createMock(BundleContext.class);
Bundle bundle = createMock(Bundle.class);
Bundle bundle2 = createMock(Bundle.class);
FrameworkWiring wiring = createMock(FrameworkWiring.class);
GitPatchRepository repository = createMock(GitPatchRepository.class);
//
// Create a new service, download a patch
//
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle).anyTimes();
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext).anyTimes();
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.data")).andReturn(karaf.getCanonicalPath() + "/data").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
PatchManagement pm = new GitPatchManagementServiceImpl(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
ServiceImpl service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test1.patch"));
assertEquals(2, pd.getBundles().size());
assertTrue(pd.getRequirements().isEmpty());
}
use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class Activator method start.
@Override
@SuppressWarnings("unchecked")
public void start(final BundleContext context) throws Exception {
bundle = context.getBundle();
systemContext = context.getBundle(0).getBundleContext();
logServiceTracker = new ServiceTracker(context, "org.osgi.service.log.LogService", null);
logServiceTracker.open();
patchManagementService = new GitPatchManagementServiceImpl(context);
final int targetStartLevel = Integer.parseInt(System.getProperty("org.osgi.framework.startlevel.beginning"));
sl = context.getBundle(0).adapt(FrameworkStartLevel.class);
activatedAt = sl.getStartLevel();
if (!patchManagementService.isEnabled()) {
log(LogService.LOG_INFO, "\nPatch management is disabled");
return;
}
switch(activatedAt) {
case PATCH_MANAGEMENT_START_LEVEL:
// this bundle is configured in etc/startup.properties, we can handle registered tasks
// like updating critical bundles
startupVersion = context.getBundle().getVersion();
// we're started before fileinstall, so we can remove this bundle if it is available in deploy/
patchManagementService.cleanupDeployDir();
break;
default:
// this bundle was activated from deploy/ directory or osgi:install. But this doesn't mean there's no
// patch-management bundle configured in etc/startup.properties
// the point is that when etc/startup.properties already has this bundle, there should be no such bundle in deploy/
// TODO (there may be newer version however)
deployVersion = context.getBundle().getVersion();
break;
}
patchManagementService.start();
patchManagementRegistration = systemContext.registerService(PatchManagement.class, PatchManagement.class.cast(patchManagementService), null);
backupServiceRegistration = systemContext.registerService(BackupService.class, new FileBackupService(systemContext), null);
if (startupVersion != null) {
// we should be at start level 2. let's check if there are any rollup paatches being installed or
// rolled back - we've got some work to do at this early stage of Karaf
patchManagementService.checkPendingPatches();
}
if (sl.getStartLevel() == targetStartLevel) {
// dropped to deploy/ when framework was already at target start-level
patchManagementService.ensurePatchManagementInitialized();
} else {
// let's wait for last start level
startLevelNotificationFrameworkListener = new StartLevelNotificationFrameworkListener(targetStartLevel);
systemContext.addFrameworkListener(startLevelNotificationFrameworkListener);
}
}
Aggregations