package de.pitkley.jenkins.plugins.dockerswarmslave;

import hudson.Extension;
import hudson.model.Build;
import hudson.model.Project;
import hudson.model.Run;
import hudson.model.listeners.RunListener;

@Extension
public class DockerSwarmSlaveRunListener extends RunListener<Run<?, ?>> {
    @Override
    public void onFinalized(Run<?, ?> run) {
        // Check that we have a build
        if (!Build.class.isAssignableFrom(run.getClass())) {
            return;
        }
        Build<?, ?> b = (Build) run;

        // Check that it is a project
        if (!Project.class.isAssignableFrom(b.getProject().getClass())) {
            return;
        }
        Project<?, ?> project = b.getProject();

        // Was our build-wrapper active?
        DockerSwarmSlaveBuildWrapper buildWrapper = DockerSwarmSlaveLabelAssignment.getDockerSwarmSlaveBuildWrapper(project);
        if (buildWrapper == null) {
            return;
        }

        // Do we have a matching DockerSwarmSlave?
        DockerSwarmSlave dockerSwarmSlave = DockerSwarmSlave.get(project);
        if (dockerSwarmSlave == null) {
            return;
        }

        // Clean everything up
        dockerSwarmSlave.cleanup();
    }
}

@@ -92,16 +92,24 @@
 n.model.
+Abstract
 Build;%0Ai
@@ -127,23 +127,83 @@
 n.model.
-Project
+AbstractProject;%0Aimport hudson.model.BuildableItemWithBuildWrappers
 ;%0Aimport
@@ -460,16 +460,24 @@
    if (!
+Abstract
 Build.cl
@@ -554,16 +554,24 @@
         
+Abstract
 Build%3C?,
@@ -579,16 +579,24 @@
 ?%3E b = (
+Abstract
 Build) r
@@ -651,16 +651,24 @@
    if (!
+Abstract
 Project.
@@ -758,16 +758,24 @@
         
+Abstract
 Project%3C
@@ -807,16 +807,137 @@
 ect();%0A%0A
+        if (!BuildableItemWithBuildWrappers.class.isAssignableFrom(project.getClass())) %7B%0A            return;%0A        %7D%0A%0A
         
@@ -1085,16 +1085,49 @@
 Wrapper(
+(BuildableItemWithBuildWrappers) 
 project)

Use abstract classes in the runlistener