From d8198004d3aac8b38b054638e57950c79a2aaa82 Mon Sep 17 00:00:00 2001 From: Henning Kasch Date: Fri, 20 Aug 2021 11:43:52 +0200 Subject: [PATCH 1/6] Add enum class with list of templates --- build.gradle | 24 ++++++++-- .../org/codefreak/templates/TaskTemplate.java | 33 ++++++++++++++ .../codefreak/templates/TaskTemplateTest.java | 45 +++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/codefreak/templates/TaskTemplate.java create mode 100644 src/test/java/org/codefreak/templates/TaskTemplateTest.java diff --git a/build.gradle b/build.gradle index ce70b9c..d05a9a3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,31 @@ plugins { id "java" + id "maven" +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' } group = 'com.github.codefreak' -jar { +test { + useJUnitPlatform() + testLogging { + events "failed" + exceptionFormat "full" + } +} + +processResources { dependsOn 'createArchives' - from(fileTree("$buildDir/archives")) { - into "org/codefreak/templates" + from(fileTree("$buildDir/archives")) { + into "org/codefreak/templates" } } diff --git a/src/main/java/org/codefreak/templates/TaskTemplate.java b/src/main/java/org/codefreak/templates/TaskTemplate.java new file mode 100644 index 0000000..a66bc59 --- /dev/null +++ b/src/main/java/org/codefreak/templates/TaskTemplate.java @@ -0,0 +1,33 @@ +package org.codefreak.templates; + +import java.io.InputStream; + +public enum TaskTemplate { + CPP("C++"), + CSHARP("C# (.Net)"), + JAVA("Java"), + JAVASCRIPT("JavaScript (Node)"), + PYTHON("Python"); + + private final String title; + + TaskTemplate(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public String getArchiveFileBaseName() { + return name().toLowerCase() + ".tar"; + } + + public InputStream getArchiveStream() throws IllegalStateException { + InputStream archiveStream = this.getClass().getResourceAsStream(getArchiveFileBaseName()); + if (archiveStream == null) { + throw new IllegalStateException("Could not read template archive from " + getArchiveFileBaseName()); + } + return archiveStream; + } +} diff --git a/src/test/java/org/codefreak/templates/TaskTemplateTest.java b/src/test/java/org/codefreak/templates/TaskTemplateTest.java new file mode 100644 index 0000000..4bd4e29 --- /dev/null +++ b/src/test/java/org/codefreak/templates/TaskTemplateTest.java @@ -0,0 +1,45 @@ +package org.codefreak.templates; + +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TaskTemplateTest { + private final File templateRootDir = Paths.get(System.getProperty("user.dir")).resolve("templates").toFile(); + + @Test + public void testAllTemplateDirsHaveEnumDefined() { + for (File dir : Objects.requireNonNull(templateRootDir.listFiles())) { + String dirName = dir.getName(); + String expectedEnumName = dirName.toUpperCase(); + assertDoesNotThrow(() -> { + TaskTemplate.valueOf(expectedEnumName); + }, "There is no enum in TaskTemplate defined for template directory " + dirName + " (expected enum name is " + expectedEnumName + ")"); + } + } + + @Test + public void testAllEnumsHaveTemplatesDefined() { + List dirNames = Arrays.asList(templateRootDir.list()); + for (TaskTemplate definedTemplate : TaskTemplate.values()) { + String expectedDirName = definedTemplate.name().toLowerCase(); + assertTrue(dirNames.contains(expectedDirName), "There is a template " + definedTemplate.name() + " defined but not matching template dir exists (expected template directory name is " + expectedDirName + ")."); + } + } + + @Test + public void testAllArchiveStreamsHaveBeenBuilt() { + for (TaskTemplate definedTemplate : TaskTemplate.values()) { + assertDoesNotThrow(() -> { + definedTemplate.getArchiveStream().close(); + }); + } + } +} From ec1eac3f3cfa358f5b801825c09e1835ba400664 Mon Sep 17 00:00:00 2001 From: Henning Kasch Date: Fri, 20 Aug 2021 11:50:38 +0200 Subject: [PATCH 2/6] Add short contribution guide to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 051fe4f..7e9084b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ These are the task templates for [Code FREAK](https://github.com/codefreak/codef Contribution is welcome. **Please open issues in the [main repository](https://github.com/codefreak/codefreak).** +## Contribute a new template +Please create a new directory inside `/templates` with the name corresponding to the programming language name. +The content of the directory should equal to an unpacked task that can be imported into Code FREAK. +After you created the directory please add your template with a human-readable title to the [`org.codefreak.templates.TaskTemplate`](src/main/java/org/codefreak/templates/TaskTemplate.java) enum. +Please follow [GitHub's official Pull Request guide](https://docs.github.com/en/github/collaborating-with-pull-requests/getting-started/about-collaborative-development-models) on how to contribute your changes to this repository. + ## Development After changing something in this repository, you have to create a new tag in the [releases](https://github.com/codefreak/templates/releases) section. The templates are automatically packaged into a jar by JitPack. You then have to adjust the `com.github.codefreak:templates` dependency version in the [build.gradle](https://github.com/codefreak/codefreak/blob/master/build.gradle) of the main repository accordingly. From 1ce663471c8be66620d8391f1725ab932c42dea5 Mon Sep 17 00:00:00 2001 From: Henning Kasch Date: Fri, 20 Aug 2021 12:04:14 +0200 Subject: [PATCH 3/6] Add description to each task template --- README.md | 2 +- build.gradle | 3 ++- .../org/codefreak/templates/TaskTemplate.java | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7e9084b..095b3cb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Contribution is welcome. **Please open issues in the [main repository](https://g ## Contribute a new template Please create a new directory inside `/templates` with the name corresponding to the programming language name. The content of the directory should equal to an unpacked task that can be imported into Code FREAK. -After you created the directory please add your template with a human-readable title to the [`org.codefreak.templates.TaskTemplate`](src/main/java/org/codefreak/templates/TaskTemplate.java) enum. +After you created the directory please add your template with a human-readable title and a small description to the [`org.codefreak.templates.TaskTemplate`](src/main/java/org/codefreak/templates/TaskTemplate.java) enum. Please follow [GitHub's official Pull Request guide](https://docs.github.com/en/github/collaborating-with-pull-requests/getting-started/about-collaborative-development-models) on how to contribute your changes to this repository. ## Development diff --git a/build.gradle b/build.gradle index d05a9a3..b6c1a07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id "java" + // for local testing with "gradle install" id "maven" } @@ -33,7 +34,7 @@ task createArchives(type: Tar) { file('templates').eachDir { sub -> dependsOn tasks.create("${name}_${sub.name}", Tar) { from sub - archiveName = "${sub.name}.tar" + archiveFileName = "${sub.name}.tar" destinationDirectory = file("$buildDir/archives") } } diff --git a/src/main/java/org/codefreak/templates/TaskTemplate.java b/src/main/java/org/codefreak/templates/TaskTemplate.java index a66bc59..434a7fa 100644 --- a/src/main/java/org/codefreak/templates/TaskTemplate.java +++ b/src/main/java/org/codefreak/templates/TaskTemplate.java @@ -3,22 +3,28 @@ import java.io.InputStream; public enum TaskTemplate { - CPP("C++"), - CSHARP("C# (.Net)"), - JAVA("Java"), - JAVASCRIPT("JavaScript (Node)"), - PYTHON("Python"); + CPP("C++", "Google Test (gtest), cpplint"), + CSHARP("C#", ".NET, NUnit, dotnet-format"), + JAVA("Java", "JUnit, Checkstyle"), + JAVASCRIPT("JavaScript (Node)", "Jest, ESLint"), + PYTHON("Python", "Pytest, Pylint"); private final String title; + private final String description; - TaskTemplate(String title) { + TaskTemplate(String title, String description) { this.title = title; + this.description = description; } public String getTitle() { return title; } + public String getDescription() { + return description; + } + public String getArchiveFileBaseName() { return name().toLowerCase() + ".tar"; } From 291529adcc46b20ff4eb8a6b59d0a5758852573b Mon Sep 17 00:00:00 2001 From: Henning Kasch Date: Fri, 20 Aug 2021 12:55:57 +0200 Subject: [PATCH 4/6] Add GitHub action workflow --- .github/workflows/main.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..2389788 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: CI + +on: [push, pull_request, release] + +jobs: + main: + runs-on: ubuntu-20.04 + env: + # webpack build needs a lot of memory + NODE_OPTIONS: --max_old_space_size=4096 + + steps: + - uses: actions/checkout@v2 + + - name: Cache gradle dependencies + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Run unit tests + run: | + ./gradlew check + + - name: Prepare cache + run: | + rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + rm -fr $HOME/.gradle/caches/*/plugin-resolution/ From e410aded740b9e1717af1ecb5f0aaba90e5ec2aa Mon Sep 17 00:00:00 2001 From: Henning Kasch Date: Fri, 20 Aug 2021 12:57:20 +0200 Subject: [PATCH 5/6] Add README badge for CI --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 095b3cb..7815ad5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Task Templates +[![CI](https://github.com/codefreak/templates/actions/workflows/main.yml/badge.svg)](https://github.com/codefreak/templates/actions/workflows/main.yml) [![](https://jitpack.io/v/codefreak/templates.svg)](https://jitpack.io/#codefreak/templates) These are the task templates for [Code FREAK](https://github.com/codefreak/codefreak). They are available in the user interface under **Task Pool** → **Create Task**. You can also take a look at the code here to get started with task definition files. From e81562b5ce59b27892701298d859c3bf65e81f14 Mon Sep 17 00:00:00 2001 From: Henning Kasch Date: Fri, 20 Aug 2021 18:20:48 +0200 Subject: [PATCH 6/6] Remove node env flag --- .github/workflows/main.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2389788..f5b506b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,10 +5,6 @@ on: [push, pull_request, release] jobs: main: runs-on: ubuntu-20.04 - env: - # webpack build needs a lot of memory - NODE_OPTIONS: --max_old_space_size=4096 - steps: - uses: actions/checkout@v2