Skip to content

Commit

Permalink
Merge pull request #1 from rhysdh540/master
Browse files Browse the repository at this point in the history
feature parity with architectury injectables
  • Loading branch information
wagyourtail authored Jun 6, 2024
2 parents 35d6c5c + 5fd0064 commit d27d836
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 355 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
.idea/
out/
!**/src/main/**/out/
!**/src/test/**/out/
Expand Down
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/checkstyle-idea.xml

This file was deleted.

24 changes: 0 additions & 24 deletions .idea/gradle.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/misc.xml

This file was deleted.

124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ val asmVersion: String by project.properties

dependencies {
implementation(gradleApi())
implementation("org.ow2.asm:asm:${asmVersion}")
implementation("org.ow2.asm:asm-tree:${asmVersion}")

testImplementation(kotlin("test"))
}
Expand Down Expand Up @@ -68,6 +68,10 @@ val annotationJar = tasks.register<Jar>("annotationJar") {
}
}

tasks.assemble {
dependsOn(annotationJar)
}

kotlin {
jvmToolchain(8)
}
Expand Down
10 changes: 5 additions & 5 deletions expect-platform-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ buildscript {
}
}
dependencies {
classpath "xyz.wagyourtail.unimined.expect-platform:expect-platform:1.0-SNAPSHOT"
classpath "org.ow2.asm:asm:9.7"
classpath "xyz.wagyourtail.unimined.expect-platform:expect-platform:1.0.0"
classpath "org.ow2.asm:asm-tree:9.7"
}
}

Expand Down Expand Up @@ -44,17 +44,17 @@ dependencies {
implementation(expectPlatform.annotationsDep)
}

tasks.create("aExpectPlatform", ExpectPlatformFiles) {
tasks.register("aExpectPlatform", ExpectPlatformFiles) {
platformName = "a"
inputCollection = sourceSets.main.output
}

tasks.create("bExpectPlatform", ExpectPlatformFiles) {
tasks.register("bExpectPlatform", ExpectPlatformFiles) {
platformName = "b"
inputCollection = sourceSets.main.output
}

tasks.create("cExpectPlatform", ExpectPlatformFiles) {
tasks.register("cExpectPlatform", ExpectPlatformFiles) {
platformName = "c"
inputCollection = sourceSets.main.output
}
Expand Down
17 changes: 17 additions & 0 deletions expect-platform-test/src/main/java/xyz/wagyourtail/ept/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package xyz.wagyourtail.ept;

import xyz.wagyourtail.unimined.expect.annotation.ExpectPlatform;
import xyz.wagyourtail.unimined.expect.annotation.PlatformOnly;
import xyz.wagyourtail.unimined.expect.Target;

public class Main {

public static void main(String[] args) {
System.out.println("current platform: " + Target.getCurrentTarget());

Target.getCurrentTarget();
Target.getCurrentTarget();

System.out.println(platformTest("test"));

try {
Main.class.getDeclaredMethod("platformOnlyTest");
System.out.println("platformOnlyTest exists");
} catch (NoSuchMethodException e) {
System.out.println("platformOnlyTest does not exist");
}
}

@ExpectPlatform(
Expand All @@ -18,4 +32,7 @@ public static String platformTest(String name) {
throw new AssertionError();
}

@PlatformOnly({"a", "b"})
public static void platformOnlyTest() {
}
}
13 changes: 13 additions & 0 deletions src/annotations/java/xyz/wagyourtail/unimined/expect/Target.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xyz.wagyourtail.unimined.expect;

public final class Target {
private Target() {
}

/**
* @return the currently targeted platform
*/
public static String getCurrentTarget() {
throw new AssertionError("failed to transform method");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotate public static methods to replace their contents with platform specific implementations.
*/
@Retention(java.lang.annotation.RetentionPolicy.CLASS)
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface ExpectPlatform {

Expand All @@ -25,4 +26,10 @@
String target();
}

// marker annotation for transformed methods
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
@interface Transformed {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package xyz.wagyourtail.unimined.expect.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotate a method to only be present on specified platforms.
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface PlatformOnly {
String[] value();

String FORGE = "forge";
String FABRIC = "fabric";
String QUIILT = "quilt";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package xyz.wagyourtail.unimined.expect
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.attributes.Attribute
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Internal
import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformTransform

abstract class ExpectPlatformExtension(val project: Project) {
@get:Internal
val version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.0-SNAPSHOT"

val annotationsDep = "xyz.wagyourtail.unimined:expect-platform:$version:annotations"
val version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.0.0-SNAPSHOT"

val annotationsDep = "xyz.wagyourtail.unimined.expect-platform:expect-platform:$version:annotations"

fun platform(platformName: String, configuration: Configuration) {
val expectPlatformAttribute = Attribute.of("expectPlatform.${configuration.name}", Boolean::class.javaObjectType)
Expand Down
Loading

0 comments on commit d27d836

Please sign in to comment.