Skip to content

Commit

Permalink
Merge pull request #45 from codefreak/feature/enumed
Browse files Browse the repository at this point in the history
Add enumeration of available task templates
  • Loading branch information
erikhofer authored Aug 20, 2021
2 parents 73d2c13 + e81562b commit baca0c6
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 4 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
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/
7 changes: 7 additions & 0 deletions README.md
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.
27 changes: 23 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
plugins {
id "java"
// for local testing with "gradle install"
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"
}
}

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")
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/org/codefreak/templates/TaskTemplate.java
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 src/test/java/org/codefreak/templates/TaskTemplateTest.java
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();
});
}
}
}

0 comments on commit baca0c6

Please sign in to comment.