-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from codefreak/feature/enumed
Add enumeration of available task templates
- Loading branch information
Showing
5 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: CI | ||
|
||
on: [push, pull_request, release] | ||
|
||
jobs: | ||
main: | ||
runs-on: ubuntu-20.04 | ||
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
# 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. | ||
|
||
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 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 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.codefreak.templates; | ||
|
||
import java.io.InputStream; | ||
|
||
public enum TaskTemplate { | ||
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, 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"; | ||
} | ||
|
||
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; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/org/codefreak/templates/TaskTemplateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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(); | ||
}); | ||
} | ||
} | ||
} |