<commit_before>package langs

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
)

// JavaMavenLangHelper provides a set of helper methods for the build lifecycle of Java Maven projects
type JavaMavenLangHelper struct {
	BaseHelper
}


// Entrypoint returns the Java runtime Docker entrypoint that will be executed when the function is run
func (lh *JavaMavenLangHelper) Entrypoint() string {
	return fmt.Sprintf("java -jar /function/target/function.jar com.example.faas.ExampleFunction::itsOn")
}

// HasPreBuild returns whether the Java runtime has a pre-build step
func (lh *JavaMavenLangHelper) HasPreBuild() bool {
	return true
}

// PreBuild runs "mvn clean package" in the root of the project and by default expects a jar at `target/function.jar` as the
// output.  We mount `$HOME/.m2` in order to get maven the proxy config specified in .m2/settings.xml, but it has the nice
// side effect of making the users .m2/repository available.  Any new deps downloaded will be owned by root :(
func (lh *JavaMavenLangHelper) PreBuild() error {
	wd, err := os.Getwd()
	if err != nil {
		return err
	}

	if !exists(filepath.Join(wd, "pom.xml")) {
		return fmt.Errorf("Could not find pom.xml - are you sure this is a maven project?")
	}

	cmd := exec.Command(
		"docker", "run",
		"--rm",
		"-v", wd+":/java", "-w", "/java",
		"-v", os.Getenv("HOME")+"/.m2:/.m2",
		"maven:3.5-jdk-8-alpine",
		"/bin/sh", "-c", "mvn -gs /.m2/settings.xml clean package",
	)

	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	if err := cmd.Run(); err != nil {
		return dockerBuildError(err)
	}
	return nil
}

// AfterBuild should remove the (root-owned) target dir.
func (lh *JavaMavenLangHelper) AfterBuild() error {
	return nil
}<commit_msg>Build project/func on host machine for java-maven<commit_after>package langs

import "fmt"

// JavaMavenLangHelper provides a set of helper methods for the build lifecycle of Java Maven projects
type JavaMavenLangHelper struct {
	BaseHelper
}

// Entrypoint returns the Java runtime Docker entrypoint that will be executed when the function is run
func (lh *JavaMavenLangHelper) Entrypoint() string {
	// TODO need mechanism to determine the java user function dynamically
	userFunction := "com.example.faas.ExampleFunction::itsOn"
	return fmt.Sprintf("java -jar /function/target/function.jar %s", userFunction)
}

func (lh *JavaMavenLangHelper) HasLocalBuildCmd() bool {
	return true
}

func (lh *JavaMavenLangHelper) LocalBuildCmd() []string {
	return []string{
		"mvn clean package",
	}
}

func (lh *JavaMavenLangHelper) HasPreBuild() bool { return false }

func (lh *JavaMavenLangHelper) PreBuild() error { return nil }

func (lh *JavaMavenLangHelper) AfterBuild() error { return nil }
{'fraction_non_alphanumeric': 0.1150866838804869, 'fraction_numerical': 0.0033198081888601992, 'mean_word_length': 4.2153846153846155, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3911641', 'n_tokens_mistral': 908, 'n_tokens_neox': 870, 'n_words': 308}