001
014
015 package com.liferay.portal.module.framework.test;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.module.framework.ModuleFrameworkUtilAdapter;
021 import com.liferay.registry.Registry;
022 import com.liferay.registry.RegistryUtil;
023 import com.liferay.registry.ServiceReference;
024
025 import java.util.ArrayList;
026 import java.util.Collection;
027
028
031 public class ModuleFrameworkTestUtil {
032
033 public static <T> Collection<Long> getBundleIds(
034 Class<T> clazz, String filter)
035 throws Exception {
036
037 Registry registry = RegistryUtil.getRegistry();
038
039 Collection<Long> bundleIds = new ArrayList<>();
040
041 Collection<ServiceReference<T>>
042 serviceReferences = registry.getServiceReferences(clazz, filter);
043
044 for (ServiceReference<T> serviceReference : serviceReferences) {
045 Long bundleId = (Long)serviceReference.getProperty(
046 "service.bundleid");
047
048 bundleIds.add(bundleId);
049 }
050
051 return bundleIds;
052 }
053
054 public static void startBundles(Iterable<Long> bundleIds) {
055 for (long bundleId : bundleIds) {
056 try {
057 ModuleFrameworkUtilAdapter.startBundle(bundleId);
058 }
059 catch (Exception e) {
060 _log.error("Unable to start bundle " + bundleId, e);
061 }
062 }
063 }
064
065 public static void stopBundles(Iterable<Long> bundleIds)
066 throws PortalException {
067
068 for (long bundleId : bundleIds) {
069 ModuleFrameworkUtilAdapter.stopBundle(bundleId);
070 }
071 }
072
073 private static final Log _log = LogFactoryUtil.getLog(
074 ModuleFrameworkTestUtil.class);
075
076 }