<commit_before>package brooklyn.entity.java

import java.util.List

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import brooklyn.entity.Entity
import brooklyn.entity.basic.SoftwareProcessEntity
import brooklyn.entity.basic.UsesJava
import brooklyn.entity.basic.lifecycle.JavaStartStopSshDriver
import brooklyn.event.basic.BasicConfigKey
import brooklyn.location.basic.SshMachineLocation
import brooklyn.util.flags.SetFromFlag


public class VanillaJavaApp extends SoftwareProcessEntity implements UsesJava {

    // FIXME classpath values: need these to be downloaded and installed?
    
    private static final Logger log = LoggerFactory.getLogger(VanillaJavaApp.class)
    
    @SetFromFlag("args")
    public static final BasicConfigKey<String> ARGS = [ List, "vanillaJavaApp.args", "Arguments for launching the java app", [] ]
    
    @SetFromFlag
    String main

    @SetFromFlag
    List<String> classpath = []

    @SetFromFlag
    List<String> args = []

    public VanillaJavaApp(Map props=[:], Entity owner=null) {
        super(props, owner)
    }

    @Override
    protected void connectSensors() {
        super.connectSensors();
    }
    
    public VanillaJavaAppSshDriver newDriver(SshMachineLocation loc) {
        new VanillaJavaAppSshDriver(this, loc)
    }
}

public class VanillaJavaAppSshDriver extends JavaStartStopSshDriver {

    public VanillaJavaAppSshDriver(VanillaJavaApp entity, SshMachineLocation machine) {
        super(entity, machine)
    }

    public VanillaJavaApp getEntity() { super.getEntity() }

    protected String getLogFileLocation() {
        return "$runDir/console"
    }
    
    @Override
    public void install() {
        // TODO install classpath entries?
        
        newScript(INSTALLING).
            failOnNonZeroResultCode()
            .execute();
    }

    @Override
    public void customize() {
        // no-op
    }
    
    @Override
    public void launch() {
        // TODO Use JAVA_OPTIONS config, once that is fixed to support more than sys properties
        // TODO quote args?
        String classpath = entity.classpath.join(";")
        String clazz = entity.main
        String args = entity.getConfig(VanillaJavaApp.ARGS).join(" ")
        
        newScript(LAUNCHING, usePidFile:true).
            body.append(
                "java \$JAVA_OPTS -cp \"$classpath\" $clazz $args "+
                    " >> $runDir/console 2>&1 </dev/null &",
            ).execute();
    }
    
    @Override<commit_msg>VanillaJavaApp: implements UsesJava; classpath separator is ":"; and tidy<commit_after>package brooklyn.entity.java

import java.util.List

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import brooklyn.entity.Entity
import brooklyn.entity.basic.SoftwareProcessEntity
import brooklyn.entity.basic.UsesJava
import brooklyn.entity.basic.UsesJmx
import brooklyn.entity.basic.lifecycle.JavaStartStopSshDriver
import brooklyn.event.basic.BasicConfigKey
import brooklyn.location.basic.SshMachineLocation
import brooklyn.util.flags.SetFromFlag


public class VanillaJavaApp extends SoftwareProcessEntity implements UsesJava, UsesJmx {

    // FIXME classpath values: need these to be downloaded and installed?
    
    private static final Logger log = LoggerFactory.getLogger(VanillaJavaApp.class)
    
    @SetFromFlag("args")
    public static final BasicConfigKey<String> ARGS = [ List, "vanillaJavaApp.args", "Arguments for launching the java app", [] ]
    
    @SetFromFlag
    String main

    @SetFromFlag
    List<String> classpath = []

    public VanillaJavaApp(Map props=[:], Entity owner=null) {
        super(props, owner)
    }

    @Override
    protected void connectSensors() {
        super.connectSensors();
    }
    
    public VanillaJavaAppSshDriver newDriver(SshMachineLocation loc) {
        new VanillaJavaAppSshDriver(this, loc)
    }
}

public class VanillaJavaAppSshDriver extends JavaStartStopSshDriver {

    public VanillaJavaAppSshDriver(VanillaJavaApp entity, SshMachineLocation machine) {
        super(entity, machine)
    }

    public VanillaJavaApp getEntity() { super.getEntity() }

    protected String getLogFileLocation() {
        return "$runDir/console"
    }
    
    @Override
    public void install() {
        // TODO install classpath entries?
        
        newScript(INSTALLING).
            failOnNonZeroResultCode()
            .execute();
    }

    @Override
    public void customize() {
        // no-op
    }
    
    @Override
    public void launch() {
        // TODO Use JAVA_OPTIONS config, once that is fixed to support more than sys properties
        // TODO quote args?
        String classpath = entity.classpath.join(":")
        String clazz = entity.main
        String args = entity.getConfig(VanillaJavaApp.ARGS).join(" ")
        
        newScript(LAUNCHING, usePidFile:true).
            body.append(
                "java \$JAVA_OPTS -cp \"$classpath\" $clazz $args "+
                    " >> $runDir/console 2>&1 </dev/null &",
            ).execute();
    }
    
    @Override
{'fraction_non_alphanumeric': 0.08916946143223516, 'fraction_numerical': 0.001578220556322746, 'mean_word_length': 2.803450862715679, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6539911', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1443, 'n_words': 342}