Skip to content

Commit

Permalink
Only allow directories, jars and zips on the lcp.
Browse files Browse the repository at this point in the history
Closes: #144
  • Loading branch information
marchermans committed May 16, 2024
1 parent 660e8cc commit 1d0e313
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,57 @@ class RunTests extends BuilderBasedTestSpecification {
run.output.contains('runClient')
}

def "when referencing pom on run classpath, it should not list it on the LCP, but it should list its dependencies"() {
given:
def project = create("runs_support_poms", {
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'net.neoforged:neoforge:+'
}
runs {
client {
dependencies {
runtime 'org.graalvm.polyglot:python:23.1.2'
}
modSource project.sourceSets.main
}
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':writeMinecraftClasspathClient')
}

then:
run.task(':writeMinecraftClasspathClient').outcome == TaskOutcome.SUCCESS

def neoformDir = run.file(".gradle/configuration/neoForm")
def versionedNeoformDir = neoformDir.listFiles()[0]
def stepsDir = new File(versionedNeoformDir, "steps")
def stepDir = new File(stepsDir, "writeMinecraftClasspathClient")
def classpathFile = new File(stepDir, "classpath.txt")

classpathFile.exists()

classpathFile.text.contains("org.graalvm.polyglot/polyglot")
!classpathFile.text.contains(".pom")
}

def "userdev supports custom run dependencies"() {
given:
def project = create("run_with_custom_dependencies", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ public void run() throws Exception {
final File out = ensureFileWorkspaceReady(getOutput());
Files.write(
out.toPath(),
getInputFiles().getFiles().stream()
getInputFiles()
.getAsFileTree()
//Filter out valid classpath elements, this can put .pom files in the input files, so we need to remove those.
.matching(filter -> {
filter.include(fileTreeElement -> fileTreeElement.isDirectory() ||
fileTreeElement.getName().endsWith(".jar") ||
fileTreeElement.getName().endsWith(".zip"));
})
.getFiles().stream()
.map(File::getAbsolutePath)
.sorted()
.collect(Collectors.toCollection(LinkedHashSet::new)),
Expand Down

0 comments on commit 1d0e313

Please sign in to comment.