package com.liferay.support.tools.gogo;

import com.liferay.portal.background.task.exception.NoSuchBackgroundTaskException;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManager;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;

import java.util.Arrays;
import java.util.List;

import org.apache.felix.service.command.Descriptor;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
 * Background Task Commands
 * 
 * @author Yasuyuki Takeo
 */
@Component(
	property = {
		"osgi.command.scope=df",
		"osgi.command.function=killbg" 
	},
	service = Object.class
)
public class BackgroundTaskCommand {
	
	@Descriptor("Kill background process(s)")
	public void killbg(String... backgroundTaskIds){

		if(0 == backgroundTaskIds.length) {
			System.out.println("Please input valid background ID");
			return;
		}
		
		List<String> ids = Arrays.asList(backgroundTaskIds);
		
		for(String id : ids) {
			if(!Validator.isNumber(id)) {
				System.out.println("Invalid background ID : " + id + " Skip...");
				continue;
			}
			
			try {
				
				_backgroundTaskManager.deleteBackgroundTask(Long.valueOf(id));
				
			} catch (NoSuchBackgroundTaskException e) {
				System.out.println("Background ID :" + id + " has been successfully deleted.");
			} catch (PortalException e) {
				
				System.out.println("Exception occured. Please see server console.");
				_log.error(e,e);
			}
		}
	}

	@Reference
	private BackgroundTaskManager _backgroundTaskManager;

	private static final Log _log =
		LogFactoryUtil.getLog(BackgroundTaskCommand.class);
}

@@ -109,32 +109,96 @@
 dTaskException;%0A
+import com.liferay.portal.kernel.backgroundtask.BackgroundTask;%0A
 import com.lifer
@@ -250,16 +250,20 @@
 kManager
+Util
 ;%0Aimport
@@ -622,65 +622,8 @@
 ent;
-%0Aimport org.osgi.service.component.annotations.Reference;
 %0A%0A/*
@@ -1277,15 +1277,30 @@
 %09%09%09%09
-%0A%09%09%09%09_b
+BackgroundTask bkt = B
 ackg
@@ -1319,15 +1319,16 @@
 ager
-.del
+Util.g
 et
-e
 Back
@@ -1357,16 +1357,101 @@
 f(id));%0A
+%09%09%09%09BackgroundTaskManagerUtil.cleanUpBackgroundTask(%0A%09%09%09%09%09bkt, bkt.getStatus());%09%09%09%09%0A
 %09%09%09%09%0A%09%09%09
@@ -1723,80 +1723,12 @@
 %09%09%7D%0A
+
 %09%7D%0A%0A
-%09@Reference%0A%09private BackgroundTaskManager _backgroundTaskManager;%0A%0A
 %09pri

Change the way to delete background tasks