package io.liveoak.container.zero;

import java.io.File;

import io.liveoak.container.tenancy.InternalApplication;
import io.liveoak.container.tenancy.InternalApplicationRegistry;
import io.liveoak.common.DefaultMountPointResource;
import io.liveoak.spi.RequestContext;
import io.liveoak.spi.resource.async.Responder;
import io.liveoak.spi.state.ResourceState;
import org.eclipse.jgit.api.Git;

/**
 * @author Bob McWhirter
 * @author Ken Finnigan
 */
public class ApplicationsResource extends DefaultMountPointResource {

    public ApplicationsResource(InternalApplicationRegistry applicationRegistry) {
        super("applications");
        this.applicationRegistry = applicationRegistry;
    }

    @Override
    public void createMember(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
        File dir = null;
        String dirPath = (String) state.getProperty("dir");
        if (dirPath != null) {
            dir = new File(dirPath);
            GitHelper.initRepo(dir);
        }

        InternalApplication app = this.applicationRegistry.createApplication(state.id(), (String) state.getProperty("name"), dir, installDir -> {
            try {
                Git gitRepo = GitHelper.initRepo(installDir);
                GitHelper.addAllAndCommit(gitRepo, ctx.securityContext().getUser(), "Initial creation of LiveOak application");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });

        responder.resourceCreated(app.resource());
    }

    private final InternalApplicationRegistry applicationRegistry;

}

@@ -386,16 +386,49 @@
 api.Git;
+%0Aimport org.jboss.logging.Logger;
 %0A%0A/**%0A *
@@ -1215,16 +1215,79 @@
   try %7B%0A
+                log.debug(%22Init git repo for: %22 + installDir);%0A
         
@@ -1704,10 +1704,94 @@
 istry;%0A%0A
+    private static final Logger log = Logger.getLogger(ApplicationsResource.class);%0A
 %7D%0A

Add some debug to git init for testing