Skip to content

Commit

Permalink
Move filament into the yarn repo. (#3296)
Browse files Browse the repository at this point in the history
This will make further developments a lot easier.
  • Loading branch information
modmuss50 authored Sep 19, 2022
1 parent 18a44f9 commit 1f98558
Show file tree
Hide file tree
Showing 36 changed files with 86,391 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[*.{gradle,mapping,unpick}]
indent_style = tab

[*.java]
indent_style = tab
ij_continuation_indent_size = 8
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.fabricmc.**
12 changes: 11 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
java: [17-jdk, 18-jdk]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container:
image: openjdk:${{ matrix.java }}
options: --user root
Expand All @@ -20,3 +20,13 @@ jobs:
with:
name: Artifacts
path: build/libs/

test-build-logic:
runs-on: ubuntu-22.04
container:
image: openjdk:18-jdk
options: --user root
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew :filament:build
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ concurrency: ci-${{ github.ref }}
jobs:
publish:
if: ${{ github.repository_owner == 'FabricMC' }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container:
image: openjdk:18-jdk
options: --user root
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
update:
if: ${{ github.event.label.name == 'update-base' }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: FabricMC/fabric-action-scripts@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
id 'de.undercouch.download' version '4.1.2'
id 'maven-publish'
id "com.diffplug.spotless" version "6.4.2"
id 'net.fabricmc.filament' version '0.3.0'
id 'net.fabricmc.filament'
}

def minecraft_version = "1.19.2"
Expand Down
56 changes: 56 additions & 0 deletions filament/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
plugins {
id 'java-library'
id 'java-gradle-plugin'
id 'checkstyle'
}

group = 'net.fabricmc'

def properties = new Properties()
file('../gradle.properties').newInputStream().withCloseable {
properties.load(it)
}

repositories {
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
mavenCentral()
}

dependencies {
implementation "org.ow2.asm:asm:${properties.asm_version}"
implementation "org.ow2.asm:asm-tree:${properties.asm_version}"
implementation "cuchaz:enigma:$properties.enigma_version"
implementation "net.fabricmc.unpick:unpick:$properties.unpick_version"
implementation "net.fabricmc.unpick:unpick-format-utils:$properties.unpick_version"
implementation "net.fabricmc:tiny-mappings-parser:$properties.tiny_mappings_parser_version"

testImplementation platform("org.junit:junit-bom:$properties.junit_version")
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation "org.assertj:assertj-core:$properties.assertj_version"
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
}

test {
useJUnitPlatform()
}

checkstyle {
configFile = file('checkstyle.xml')
toolVersion = '10.3.3'
}

gradlePlugin {
plugins {
filament {
id = 'net.fabricmc.filament'
implementationClass = 'net.fabricmc.filament.FilamentGradlePlugin'
}
}
}
164 changes: 164 additions & 0 deletions filament/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="fileExtensions" value="java"/>
<property name="localeLanguage" value="en"/>
<property name="localeCountry" value="US"/>

<module name="NewlineAtEndOfFile"/>

<!-- disallow trailing whitespace -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="trailing whitespace"/>
</module>

<!-- note: RegexpMultiline shows nicer messages than Regexp, but has to be outside TreeWalker -->
<!-- disallow multiple consecutive blank lines -->
<module name="RegexpMultiline">
<property name="format" value="\n[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="message" value="adjacent blank lines"/>
</module>

<!-- disallow blank after { -->
<module name="RegexpMultiline">
<property name="format" value="\{[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="message" value="blank line after '{'"/>
</module>

<!-- disallow blank before } -->
<module name="RegexpMultiline">
<property name="format" value="\n[\t ]*\r?\n[\t ]*\}"/>
<property name="message" value="blank line before '}'"/>
</module>

<!-- require blank before { in the same indentation level -->
<module name="RegexpMultiline">
<!-- the regex works as follows:
It matches (=fails) for \n<indentation><something>\n<same indentation><control statement>[...]{\n
while <something> is a single line comment, it'll look for a blank line one line earlier
if <something> is a space, indicating a formatting error or ' */', it'll ignore the instance
if <something> is a tab, indicating a continued line, it'll ignore the instance
<control statement> is 'if', 'do', 'while', 'for', 'try' or nothing (instance initializer block)
- first \n: with positive lookbehind (?<=\n) to move the error marker to a more reasonable place
- capture tabs for <indentation>, later referenced via \1
- remaining preceding line as a non-comment (doesn't start with '/', '//', ' ' or '\t') or multiple lines where all but the first are a single line comment with the same indentation
- new line
- <indentation> as captured earlier
- <control statement> as specified above
- { before the next new line -->
<property name="format" value="(?&lt;=\n)([\t]+)(?:[^/\r\n \t][^\r\n]*|/[^/\r\n][^\r\n]*|[^/\r\n][^\r\n]*(\r?\n\1//[^\r\n]*)+)\r?\n\1(|(if|do|while|for|try)[^\r\n]+)\{[\t ]*\r?\n"/>
<property name="message" value="missing blank line before block at same indentation level"/>
</module>

<!-- require blank after } in the same indentation level -->
<module name="RegexpMultiline">
<!-- \n<indentation>}\n<same indentation><whatever unless newline, '}' or starting with cas(e) or def(ault)> -->
<property name="format" value="(?&lt;=\n)([\t]+)\}\r?\n\1(?:[^\r\n\}cd]|c[^\r\na]|ca[^\r\ns]|d[^\r\ne]|de[^\r\nf])"/>
<property name="message" value="missing blank line after block at same indentation level"/>
</module>

<module name="TreeWalker">
<!-- Ensure all imports are ship shape -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<module name="ImportOrder">
<property name="groups" value="java,javax,*,net.minecraft,net.fabricmc"/>
<property name="ordered" value="false"/><!-- the plugin orders alphabetically without considering separators.. -->
<property name="separated" value="true"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>

<!-- Ensures braces are at the end of a line -->
<module name="LeftCurly"/>
<module name="RightCurly"/>

<!-- single line statements on one line, -->
<module name="NeedBraces">
<property name="tokens" value="LITERAL_IF,LITERAL_FOR,LITERAL_WHILE"/>
<property name="allowSingleLineStatement" value="true"/>
</module>
<module name="NeedBraces">
<property name="tokens" value="LITERAL_ELSE,LITERAL_DO"/>
<property name="allowSingleLineStatement" value="false"/>
</module>

<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
<property name="allowMultipleEmptyLines" value="false"/>
<!-- exclude METHOD_DEF and VARIABLE_DEF -->
<property name="tokens" value="PACKAGE_DEF,IMPORT,STATIC_IMPORT,CLASS_DEF,INTERFACE_DEF,ENUM_DEF,STATIC_INIT,INSTANCE_INIT,CTOR_DEF"/>
</module>

<module name="OperatorWrap"/>
<module name="SeparatorWrap">
<property name="tokens" value="DOT,ELLIPSIS,AT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="COMMA,SEMI"/>
<property name="option" value="eol"/>
</module>

<module name="Indentation">
<property name="basicOffset" value="8"/>
<property name="caseIndent" value="0"/>
<property name="throwsIndent" value="8"/>
<property name="arrayInitIndent" value="8"/>
<property name="lineWrappingIndentation" value="16"/>
</module>

<module name="ParenPad"/>
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceAfter">
<!-- allow ARRAY_INIT -->
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
</module>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<!-- Allow PLUS, MINUS, MUL, DIV as they may be more readable without spaces in some cases -->
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="GenericWhitespace"/>
<module name="CommentsIndentation"/>

<module name="ArrayTypeStyle"/>
<module name="DefaultComesLast">
<property name="skipIfLastAndSharedWithCase" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>

<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<module name="AnnotationLocation"/>
<module name="MissingOverride"/>

<!-- By default this allows catch blocks with only comments -->
<module name="EmptyCatchBlock"/>

<!-- Enforce tabs -->
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* ([^*]|\*[^ /])"/>
<property name="message" value="non-tab indentation"/>
</module>

<module name="OuterTypeFilename"/>

<!--<module name="InvalidJavadocPosition"/>-->
<module name="JavadocParagraph"/>
<module name="JavadocStyle"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param,@return,@throws,@deprecated"/>
</module>
</module>
</module>
1 change: 1 addition & 0 deletions filament/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'fabric-filament'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.fabricmc.filament;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

import net.fabricmc.filament.task.CombineUnpickDefinitionsTask;
import net.fabricmc.filament.task.GeneratePackageInfoMappingsTask;
import net.fabricmc.filament.task.JavadocLintTask;
import net.fabricmc.filament.task.RemapUnpickDefinitionsTask;

public final class FilamentGradlePlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getTasks().register("generatePackageInfoMappings", GeneratePackageInfoMappingsTask.class);
project.getTasks().register("javadocLint", JavadocLintTask.class);

var combineUnpickDefinitions = project.getTasks().register("combineUnpickDefinitions", CombineUnpickDefinitionsTask.class);
project.getTasks().register("remapUnpickDefinitionsIntermediary", RemapUnpickDefinitionsTask.class, task -> {
task.dependsOn(combineUnpickDefinitions);
task.getInput().set(combineUnpickDefinitions.flatMap(CombineUnpickDefinitionsTask::getOutput));
task.getSourceNamespace().set("named");
task.getTargetNamespace().set("intermediary");
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.fabricmc.filament.task;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import javax.inject.Inject;

import daomephsta.unpick.constantmappers.datadriven.parser.v2.UnpickV2Reader;
import daomephsta.unpick.constantmappers.datadriven.parser.v2.UnpickV2Writer;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.workers.WorkAction;
import org.gradle.workers.WorkParameters;
import org.gradle.workers.WorkQueue;
import org.gradle.workers.WorkerExecutor;

import net.fabricmc.filament.util.FileUtil;
import net.fabricmc.filament.util.UnpickUtil;

public abstract class CombineUnpickDefinitionsTask extends DefaultTask {
@InputDirectory
public abstract DirectoryProperty getInput();

@OutputFile
public abstract RegularFileProperty getOutput();

@Inject
protected abstract WorkerExecutor getWorkerExecutor();

@TaskAction
public void run() {
WorkQueue workQueue = getWorkerExecutor().noIsolation();
workQueue.submit(CombineAction.class, parameters -> {
parameters.getInput().set(getInput());
parameters.getOutput().set(getOutput());
});
}

public interface CombineParameters extends WorkParameters {
@InputDirectory
DirectoryProperty getInput();

@OutputFile
RegularFileProperty getOutput();
}

public abstract static class CombineAction implements WorkAction<CombineParameters> {
@Inject
public CombineAction() {
}

@Override
public void execute() {
try {
File output = getParameters().getOutput().getAsFile().get();
FileUtil.deleteIfExists(output);

UnpickV2Writer writer = new UnpickV2Writer();

// Sort inputs to get reproducible outputs (also for testing)
List<File> files = new ArrayList<>(getParameters().getInput().getAsFileTree().getFiles());
files.sort(Comparator.comparing(File::getName));

for (File file : files) {
if (!file.getName().endsWith(".unpick")) {
continue;
}

try (UnpickV2Reader reader = new UnpickV2Reader(new FileInputStream(file))) {
reader.accept(writer);
}
}

FileUtil.write(output, UnpickUtil.getLfOutput(writer));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
}
Loading

0 comments on commit 1f98558

Please sign in to comment.