mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-06 07:20:30 +00:00
Some minor build system improvements
- Correctly handle Git commands failing. We need an actual default value, not just null! - Use run/ and build/tmp/ for temporary test locations, not /test-files.
This commit is contained in:
parent
f4e542b4db
commit
8171578e80
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,7 +11,6 @@
|
||||
# Runtime directories
|
||||
/run
|
||||
/run-*
|
||||
/test-files
|
||||
|
||||
*.ipr
|
||||
*.iws
|
||||
|
@ -77,14 +77,14 @@ minecraft {
|
||||
}
|
||||
|
||||
val testClient by registering {
|
||||
workingDirectory(project.file("test-files/client"))
|
||||
workingDirectory(file("run/testClient"))
|
||||
parent(client.get())
|
||||
|
||||
mods.register("cctest") { source(sourceSets["testMod"]) }
|
||||
}
|
||||
|
||||
val testServer by registering {
|
||||
workingDirectory(project.file("test-files/server"))
|
||||
workingDirectory(file("run/testServer"))
|
||||
parent(server.get())
|
||||
|
||||
property("cctest.run", "true")
|
||||
@ -165,7 +165,7 @@ val luaJavadoc by tasks.registering(Javadoc::class) {
|
||||
group = JavaBasePlugin.DOCUMENTATION_GROUP
|
||||
|
||||
source(sourceSets.main.get().java)
|
||||
setDestinationDir(project.buildDir.resolve("docs/luaJavadoc"))
|
||||
setDestinationDir(buildDir.resolve("docs/luaJavadoc"))
|
||||
classpath = sourceSets.main.get().compileClasspath
|
||||
|
||||
options.docletpath = configurations["cctJavadoc"].files.toList()
|
||||
@ -296,6 +296,10 @@ val docWebsite by tasks.registering(Copy::class) {
|
||||
|
||||
// Check tasks
|
||||
|
||||
tasks.test {
|
||||
systemProperty("cct.test-files", buildDir.resolve("tmp/test-files").absolutePath)
|
||||
}
|
||||
|
||||
val lintLua by tasks.registering(IlluaminateExec::class) {
|
||||
group = JavaBasePlugin.VERIFICATION_GROUP
|
||||
description = "Lint Lua (and Lua docs) with illuaminate"
|
||||
@ -321,7 +325,7 @@ val setupRunGametest by tasks.registering(Copy::class) {
|
||||
include("eula.txt")
|
||||
include("server.properties")
|
||||
}
|
||||
into("test-files/server")
|
||||
into("run/testServer")
|
||||
}
|
||||
|
||||
val runGametest by tasks.registering(JavaExec::class) {
|
||||
@ -354,7 +358,7 @@ val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) {
|
||||
group = PublishingPlugin.PUBLISH_TASK_GROUP
|
||||
description = "Upload artifacts to CurseForge"
|
||||
|
||||
apiToken = project.findProperty("curseForgeApiKey") ?: ""
|
||||
apiToken = findProperty("curseForgeApiKey") ?: ""
|
||||
enabled = apiToken != ""
|
||||
|
||||
val mainFile = upload("282001", tasks.shadowJar)
|
||||
@ -368,7 +372,7 @@ val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) {
|
||||
tasks.publish { dependsOn(publishCurseForge) }
|
||||
|
||||
modrinth {
|
||||
token.set(project.findProperty("modrinthApiKey") as String? ?: "")
|
||||
token.set(findProperty("modrinthApiKey") as String? ?: "")
|
||||
projectId.set("gu7yAYhd")
|
||||
versionNumber.set("$mcVersion-$modVersion")
|
||||
versionName.set(modVersion)
|
||||
@ -377,13 +381,13 @@ modrinth {
|
||||
gameVersions.add(mcVersion)
|
||||
changelog.set("Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion).")
|
||||
|
||||
syncBodyFrom.set(project.provider { file("doc/mod-page.md").readText() })
|
||||
syncBodyFrom.set(provider { file("doc/mod-page.md").readText() })
|
||||
}
|
||||
|
||||
tasks.publish { dependsOn(tasks.modrinth) }
|
||||
|
||||
githubRelease {
|
||||
token(project.findProperty("githubApiKey") as String? ?: "")
|
||||
token(findProperty("githubApiKey") as String? ?: "")
|
||||
owner.set("cc-tweaked")
|
||||
repo.set("CC-Tweaked")
|
||||
targetCommitish.set(cct.gitBranch)
|
||||
@ -391,14 +395,12 @@ githubRelease {
|
||||
tagName.set("v$mcVersion-$modVersion")
|
||||
releaseName.set("[$mcVersion] $modVersion")
|
||||
body.set(
|
||||
project.provider(
|
||||
{
|
||||
"## " + file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md")
|
||||
.readLines()
|
||||
.takeWhile { it != "Type \"help changelog\" to see the full version history." }
|
||||
.joinToString("\n").trim()
|
||||
},
|
||||
),
|
||||
provider {
|
||||
"## " + file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md")
|
||||
.readLines()
|
||||
.takeWhile { it != "Type \"help changelog\" to see the full version history." }
|
||||
.joinToString("\n").trim()
|
||||
},
|
||||
)
|
||||
prerelease.set(!isStable)
|
||||
}
|
||||
|
@ -25,17 +25,17 @@ abstract class CCTweakedExtension(
|
||||
private val fs: FileSystemOperations,
|
||||
) {
|
||||
/** Get the hash of the latest git commit. */
|
||||
val gitHash: Provider<String> = gitProvider(project) {
|
||||
val gitHash: Provider<String> = gitProvider(project, "<no git hash>") {
|
||||
ProcessHelpers.captureOut("git", "-C", project.projectDir.absolutePath, "rev-parse", "HEAD")
|
||||
}
|
||||
|
||||
/** Get the current git branch. */
|
||||
val gitBranch: Provider<String> = gitProvider(project) {
|
||||
val gitBranch: Provider<String> = gitProvider(project, "<no git branch>") {
|
||||
ProcessHelpers.captureOut("git", "-C", project.projectDir.absolutePath, "rev-parse", "--abbrev-ref", "HEAD")
|
||||
}
|
||||
|
||||
/** Get a list of all contributors to the project. */
|
||||
val gitContributors: Provider<List<String>> = gitProvider(project) {
|
||||
val gitContributors: Provider<List<String>> = gitProvider(project, listOf()) {
|
||||
val authors: Set<String> = HashSet(
|
||||
ProcessHelpers.captureLines(
|
||||
"git", "-C", project.projectDir.absolutePath, "log",
|
||||
@ -110,13 +110,13 @@ abstract class CCTweakedExtension(
|
||||
"GitHub", "Daniel Ratcliffe", "Weblate",
|
||||
)
|
||||
|
||||
private fun <T> gitProvider(project: Project, supplier: () -> T): Provider<T> {
|
||||
private fun <T> gitProvider(project: Project, default: T, supplier: () -> T): Provider<T> {
|
||||
return project.provider {
|
||||
try {
|
||||
supplier()
|
||||
} catch (e: IOException) {
|
||||
project.logger.error("Cannot read Git Repository", e)
|
||||
null
|
||||
project.logger.error("Cannot read Git repository: ${e.message}")
|
||||
default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import dan200.computercraft.core.filesystem.FileSystemException;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral;
|
||||
import dan200.computercraft.support.TestFiles;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -31,13 +32,13 @@ import org.opentest4j.AssertionFailedError;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
@ -50,18 +51,18 @@ import static dan200.computercraft.api.lua.LuaValues.getType;
|
||||
|
||||
/**
|
||||
* Loads tests from {@code test-rom/spec} and executes them.
|
||||
*
|
||||
* <p>
|
||||
* This spins up a new computer and runs the {@code mcfly.lua} script. This will then load all files in the {@code spec}
|
||||
* directory and register them with {@code cct_test.start}.
|
||||
*
|
||||
* <p>
|
||||
* From the test names, we generate a tree of {@link DynamicNode}s which queue an event and wait for
|
||||
* {@code cct_test.submit} to be called. McFly pulls these events, executes the tests and then calls the submit method.
|
||||
*
|
||||
* <p>
|
||||
* Once all tests are done, we invoke {@code cct_test.finish} in order to mark everything as complete.
|
||||
*/
|
||||
public class ComputerTestDelegate
|
||||
{
|
||||
private static final File REPORT_PATH = new File( "test-files/luacov.report.out" );
|
||||
private static final Path REPORT_PATH = TestFiles.get( "luacov.report.out" );
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger( ComputerTestDelegate.class );
|
||||
|
||||
@ -96,10 +97,10 @@ public class ComputerTestDelegate
|
||||
{
|
||||
ComputerCraft.logComputerErrors = true;
|
||||
|
||||
if( REPORT_PATH.delete() ) ComputerCraft.log.info( "Deleted previous coverage report." );
|
||||
if( Files.deleteIfExists( REPORT_PATH ) ) ComputerCraft.log.info( "Deleted previous coverage report." );
|
||||
|
||||
Terminal term = new Terminal( 80, 100, true );
|
||||
IWritableMount mount = new FileMount( new File( "test-files/mount" ), 10_000_000 );
|
||||
IWritableMount mount = new FileMount( TestFiles.get( "mount" ).toFile(), 10_000_000 );
|
||||
|
||||
// Remove any existing files
|
||||
List<String> children = new ArrayList<>();
|
||||
@ -161,8 +162,8 @@ public class ComputerTestDelegate
|
||||
|
||||
if( finishedWith != null )
|
||||
{
|
||||
REPORT_PATH.getParentFile().mkdirs();
|
||||
try( BufferedWriter writer = Files.newBufferedWriter( REPORT_PATH.toPath() ) )
|
||||
Files.createDirectories( REPORT_PATH.getParent() );
|
||||
try( BufferedWriter writer = Files.newBufferedWriter( REPORT_PATH ) )
|
||||
{
|
||||
new LuaCoverage( finishedWith ).write( writer );
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.core.apis.ObjectWrapper;
|
||||
import dan200.computercraft.core.apis.handles.EncodedWritableHandle;
|
||||
import dan200.computercraft.support.TestFiles;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
@ -22,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class FileSystemTest
|
||||
{
|
||||
private static final File ROOT = new File( "test-files/filesystem" );
|
||||
private static final File ROOT = TestFiles.get( "filesystem" ).toFile();
|
||||
private static final long CAPACITY = 1000000;
|
||||
|
||||
private static FileSystem mkFs() throws FileSystemException
|
||||
|
@ -7,6 +7,7 @@ package dan200.computercraft.core.filesystem;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.support.TestFiles;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -27,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class JarMountTest
|
||||
{
|
||||
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
|
||||
private static final File ZIP_FILE = TestFiles.get( "jar-mount.zip" ).toFile();
|
||||
|
||||
private static final FileTime MODIFY_TIME = FileTime.from( Instant.EPOCH.plus( 2, ChronoUnit.DAYS ) );
|
||||
|
||||
|
31
src/test/java/dan200/computercraft/support/TestFiles.java
Normal file
31
src/test/java/dan200/computercraft/support/TestFiles.java
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.support;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Location for temporary test files.
|
||||
*/
|
||||
public final class TestFiles
|
||||
{
|
||||
private static final Path ROOT = Paths.get( System.getProperty( "cct.test-files", "build/tmp/testFiles" ) );
|
||||
|
||||
private TestFiles()
|
||||
{
|
||||
}
|
||||
|
||||
public static Path get()
|
||||
{
|
||||
return ROOT;
|
||||
}
|
||||
|
||||
public static Path get( String path )
|
||||
{
|
||||
return ROOT.resolve( path );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user