<commit_before>package io.liveoak.container.tenancy.service;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Consumer;

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.liveoak.common.codec.json.JSONDecoder;
import io.liveoak.common.util.StringPropertyReplacer;
import io.liveoak.spi.util.ObjectMapperFactory;
import io.liveoak.container.service.MediaTypeMountService;
import io.liveoak.container.tenancy.ApplicationConfigurationManager;
import io.liveoak.container.tenancy.ApplicationContext;
import io.liveoak.container.tenancy.ApplicationResource;
import io.liveoak.container.tenancy.InternalApplication;
import io.liveoak.container.tenancy.InternalApplicationRegistry;
import io.liveoak.container.zero.extension.ZeroExtension;
import io.liveoak.container.zero.service.GitResourceInstallService;
import io.liveoak.spi.LiveOak;
import io.liveoak.spi.MediaType;
import io.liveoak.spi.ResourcePath;
import io.liveoak.spi.Services;
import io.liveoak.spi.client.Client;
import io.liveoak.spi.resource.MountPointResource;
import io.liveoak.spi.state.ResourceState;
import org.jboss.logging.Logger;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.service.ValueService;
import org.jboss.msc.value.ImmediateValue;
import org.jboss.msc.value.InjectedValue;

/**
 * @author <NAME>
 * @author <NAME>
 */
public class ApplicationService implements Service<InternalApplication> {

    public ApplicationService(String id, String name, File directory, Consumer<File> gitCommit) {
        this.id = id;
        this.name = name != null ? name : id;
        this.directory = directory;
        this.gitCommit = gitCommit;
    }

    @Override
    public void start(StartContext context) throws StartException {
        ServiceTarget target = context.getChildTarget();

        File appDir = this.directory;

        if (appDir == null) {
            appDir = new File(this.applicationsDirectoryInjector.getValue(), this.id);
        }

        if (!appDir.exists()) {
            log.debug("attempt to create: " + appDir);
            appDir.mkdirs();
        }

        if (!appDir.exists()) {
            log.error("FAILED TO CREATE: " + appDir);
        }

        log.debug(appDir + " .mkdirs: " + appDir.mkdirs() + " // " + appDir.exists());
        File applicationJson = new File(appDir, "application.json");

        String appName = this.name;
        Boolean appVisible = Boolean.TRUE;
        String appExample = null;
        String versionResourceId = null;
        ResourcePath htmlApp = null;
        ResourceState resourcesTree = null;

        List<String> configurationFiles = new ArrayList<>();

        Properties properties = new Properties();
        properties.setProperty("application.id", this.id);

        if (applicationJson.exists()) {
            JSONDecoder decoder = new JSONDecoder();
            try {
                ResourceState state = decoder.decode(applicationJson);
                Object value;
                if ((value = state.getProperty(LiveOak.NAME)) != null) {
                    appName = StringPropertyReplacer.replaceProperties((String) value, properties);
                    properties.put("application.name", appName);
                }
                if ((value = state.getProperty("html-app")) != null) {
                    htmlApp = new ResourcePath((String) value);
                    if (!htmlApp.head().name().equals(this.id)) {
                        htmlApp.prependSegment(this.id);
                    }
                }
                if ((value = state.getProperty("visible")) != null) {
                    appVisible = (Boolean) value;
                }
                if ((value = state.getProperty("example")) != null) {
                    appExample = (String) value;
                }
                if ((value = state.getProperty("version-resource-id")) != null) {
                    versionResourceId = (String) value;
                }
                if ((value = state.getProperty(LiveOak.RESOURCES)) != null) {<commit_msg>Remove unneeded statement from ApplicationService<commit_after>package io.liveoak.container.tenancy.service;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Consumer;

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.liveoak.common.codec.json.JSONDecoder;
import io.liveoak.common.util.StringPropertyReplacer;
import io.liveoak.spi.util.ObjectMapperFactory;
import io.liveoak.container.service.MediaTypeMountService;
import io.liveoak.container.tenancy.ApplicationConfigurationManager;
import io.liveoak.container.tenancy.ApplicationContext;
import io.liveoak.container.tenancy.ApplicationResource;
import io.liveoak.container.tenancy.InternalApplication;
import io.liveoak.container.tenancy.InternalApplicationRegistry;
import io.liveoak.container.zero.extension.ZeroExtension;
import io.liveoak.container.zero.service.GitResourceInstallService;
import io.liveoak.spi.LiveOak;
import io.liveoak.spi.MediaType;
import io.liveoak.spi.ResourcePath;
import io.liveoak.spi.Services;
import io.liveoak.spi.client.Client;
import io.liveoak.spi.resource.MountPointResource;
import io.liveoak.spi.state.ResourceState;
import org.jboss.logging.Logger;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.service.ValueService;
import org.jboss.msc.value.ImmediateValue;
import org.jboss.msc.value.InjectedValue;

/**
 * @author <NAME>
 * @author <NAME>
 */
public class ApplicationService implements Service<InternalApplication> {

    public ApplicationService(String id, String name, File directory, Consumer<File> gitCommit) {
        this.id = id;
        this.name = name != null ? name : id;
        this.directory = directory;
        this.gitCommit = gitCommit;
    }

    @Override
    public void start(StartContext context) throws StartException {
        ServiceTarget target = context.getChildTarget();

        File appDir = this.directory;

        if (appDir == null) {
            appDir = new File(this.applicationsDirectoryInjector.getValue(), this.id);
        }

        if (!appDir.exists()) {
            log.debug("attempt to create: " + appDir);
            appDir.mkdirs();
        }

        if (!appDir.exists()) {
            log.error("FAILED TO CREATE: " + appDir);
        }

        log.debug(appDir + " .mkdirs: " + appDir.mkdirs() + " // " + appDir.exists());
        File applicationJson = new File(appDir, "application.json");

        String appName = this.name;
        Boolean appVisible = Boolean.TRUE;
        String appExample = null;
        String versionResourceId = null;
        ResourcePath htmlApp = null;
        ResourceState resourcesTree = null;

        List<String> configurationFiles = new ArrayList<>();

        Properties properties = new Properties();
        properties.setProperty("application.id", this.id);

        if (applicationJson.exists()) {
            JSONDecoder decoder = new JSONDecoder();
            try {
                ResourceState state = decoder.decode(applicationJson);
                Object value;
                if ((value = state.getProperty(LiveOak.NAME)) != null) {
                    appName = StringPropertyReplacer.replaceProperties((String) value, properties);
                }
                if ((value = state.getProperty("html-app")) != null) {
                    htmlApp = new ResourcePath((String) value);
                    if (!htmlApp.head().name().equals(this.id)) {
                        htmlApp.prependSegment(this.id);
                    }
                }
                if ((value = state.getProperty("visible")) != null) {
                    appVisible = (Boolean) value;
                }
                if ((value = state.getProperty("example")) != null) {
                    appExample = (String) value;
                }
                if ((value = state.getProperty("version-resource-id")) != null) {
                    versionResourceId = (String) value;
                }
                if ((value = state.getProperty(LiveOak.RESOURCES)) != null) {
{'fraction_non_alphanumeric': 0.11321982431406571, 'fraction_numerical': 0.0, 'mean_word_length': 2.828144458281445, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6101754', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2523, 'n_words': 480}