package org.jboss.pnc;

import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.jboss.pnc.core.builder.BuildCoordinator;
import org.jboss.pnc.core.exception.CoreException;
import org.jboss.pnc.model.BuildConfiguration;
import org.jboss.pnc.model.Environment;
import org.jboss.pnc.model.User;
import org.jboss.weld.environment.se.events.ContainerInitialized;

public class LocalBuildRunner {

    @Inject
    private BuildCoordinator buildCoordinator;

    public void main(@Observes ContainerInitialized event){
        Environment env = Environment.Builder.defaultEnvironment().build();
        BuildConfiguration buildConfiguration = BuildConfiguration.Builder.newBuilder().id(0).scmRepoURL("git@github.com:release-engineering/pom-manipulation-ext.git")
                .buildScript("mvn install").name("MYBUILDCONFIG").environment(env).build();
        User user = User.Builder.newBuilder().id(1).build();
        try {
            buildCoordinator.build(buildConfiguration, user);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
}
@@ -21,48 +21,8 @@
 c;%0A%0A
-import javax.enterprise.event.Observes;%0A
 impo
@@ -310,35 +310,64 @@
 .se.
-events.ContainerInitialized
+Weld;%0Aimport org.jboss.weld.environment.se.WeldContainer
 ;%0A%0Ap
@@ -418,16 +418,8 @@
     
-private 
 Buil
@@ -449,17 +449,16 @@
 inator;%0A
-%0A
     publ
@@ -469,51 +469,39 @@
 oid 
-main(@Observes ContainerInitialized event)%7B
+run()%7B%0A%0A        int result = 0;
 %0A   
@@ -824,16 +824,72 @@
 nt(env).
+scmRevision(%2222855c9404319a30195b8ba7e637ddfb3f5dcaaf%22).
 build();
@@ -942,32 +942,34 @@
 .id(1).build();%0A
+%0A%0A
         try %7B%0A  
@@ -1080,25 +1080,787 @@
     
-e.printStackTrace
+result = 1;%0A        %7D%0A%0A        while(!buildCoordinator.getBuildTasks().isEmpty())%7B%0A            try %7B%0A                Thread.sleep(5000);%0A            %7D catch (InterruptedException e) %7B%0A                result = 1;%0A            %7D%0A        %7D%0A        System.exit(result);%0A%0A    %7D%0A%0A    public static void main(String%5B%5D args)%7B%0A%0A        Weld weld = new Weld();%0A        WeldContainer weldContainer = weld.initialize();%0A        weldContainer.instance().select(LocalBuildRunner.class).get().run();%0A%0A        Runtime.getRuntime().addShutdownHook(new ShutdownHook(weld));%0A    %7D%0A%0A    static class ShutdownHook extends Thread %7B%0A        private final Weld weld;%0A%0A%0A        ShutdownHook(final Weld weld) %7B%0A            this.weld = weld;%0A        %7D%0A%0A%0A        public void run() %7B%0A            weld.shutdown
 ();%0A
@@ -1876,8 +1876,9 @@
 %0A    %7D%0A%7D
+%0A

Add shutdownhook for weld.