Giter Site home page Giter Site logo

minimallycorrect / mixin Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 0.0 495 KB

Applies Mixin-style monkey patches to .java source or compiled .class files. Lightweight

License: Other

Java 96.20% Groovy 3.80%
aspect-oriented-programming bytecode-manipulation java mixin

mixin's People

Contributors

dependabot[bot] avatar lunnova avatar renovate-bot avatar renovate[bot] avatar shipkit-org avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mixin's Issues

Try to use Artifact Transforms in the gradle plugin

Artifact transforms were added to gradle, and should be a clean way of applying our patches to dependencies. The current approach is fragile as it relies on internal API, and breaks transitive dependencies.

Unfortunately, there have been some issues implementing this.


Documentation

It's not clear what the possible values for built in gradle attributes are, or what to use. The examples use java and jar as values for artifactType. Where are those defined? jar is in ArtifactTypeDefinition but there's nothing for java.

https://github.com/gradle/gradle/blob/5bb0f7bf70c1311a07cf82677ed1b1660bfd8f87/subprojects/core-api/src/main/java/org/gradle/api/artifacts/type/ArtifactTypeDefinition.java#L30-L76

Source transformation?

Haven't been able to get transformation of sources working the same way as with jars. Using artifactType java or sources seems to result in nothing happening? The sources used when importing into IDEA don't get transformations applied.

if (useTransforms) {
registerTransform(project, ArtifactTypeDefinition.JAR_TYPE, applyMixinsMap);
registerTransform(project, ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, applyMixinsMap);
// TODO: this is intended to be for source jars but doesn't work?
registerTransform(project, "java", applyMixinsMap);

Looks like this is the same as gradle/gradle#11519 "DefauitArtifactResolutionQuery does not care for specified Transformers and ArtifactAttributes"

Per-dependency transformation

It doesn't seem to be possible to register a transformer for a specific set of dependencies, it gets ran on all of them. This means we need to pass a huge blob of parameters in registered once, and determine what to do per dependency. Extra work for gradle here as it's running the transform (and doing cache stuff) for every dep. Somewhat breaks caching, as if the input for any dep changes the cache is stale.

@Input
Map<String, ApplyMixins> getPerDependencyApplyMixins();

Once we've done that, it's hard to figure out what dependency the input file is from as only a File is provided. Raised gradle/gradle#11831 to ask about that.

// TODO this is awful but we don't get module data any other way? :C
private static String guessIdentifier(File input) {
for (int i = 0; i < 2; i++) {
val result = tryIdentifier(input, i);
if (result != null) {
return result;
}
}
return null;
}
private static String tryIdentifier(File input, int skips) {
File skipped = input;
for (int i = 0; i < skips; i++) {
skipped = skipped.getParentFile();
}
val version = skipped.getParentFile();
val name = version.getParentFile();
File groupFile = name.getParentFile();
if (!input.getName().startsWith(name.getName() + '-' + version.getName())) {
// name + version not as expected, fail
return null;
}
StringBuilder group = new StringBuilder(groupFile.getName());
// special case for mavenLocal()
if (!groupFile.getName().contains(".")) {
int tries = 7;
while (groupFile.exists()) {
groupFile = groupFile.getParentFile();
if (groupFile.getName().equals("repository") && groupFile.getParentFile().getName().equals(".m2")) {
break;
}
group.insert(0, groupFile.getName() + ".");
if (tries-- <= 0) {
return null;
}
}
}
return group.append(':').append(name.getName()).append(':').append(version.getName()).toString();
}

Transformer parameters can't reference task outputs or configs?

Only serializable values seem to work in the task parameters, so we have to do a horrible hack with static state and find the task again when running. This also means the dependency isn't being taken into account. Initially expected it would be, as for tasks you can do @InputFiles and a file dependency from another task's outputs will automatically depend on that task being ran first.

public interface Parameters extends TransformParameters {
@Input
Map<String, ApplyMixins> getPerDependencyApplyMixins();
void setPerDependencyApplyMixins(Map<String, ApplyMixins> value);
@Input
String getArtifactType();
void setArtifactType(String value);
}

@Classpath
@InputFiles
@NonNull
private transient FileCollection mixinSource;

if (mixinSource == null) {
logger.warn("mixinSource disappeared from ApplyMixins, trying to recreate it.");
mixinSource = HackyCurrentGradleSource.gradleWeakReference.get().getRootProject().findProject(mixinProjectPath).getTasks().getByPath("jar").getOutputs().getFiles();
}

Is there a better workaround than this static hack? Is pretty awful, so don't want to turn on using transformers at all as the generated dependency doesn't depend on that. Generated dep approach also has working dependency on the subproject task.

Raised gradle/gradle#11847

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • gradle/wrapper-validation-action v2.1.1@699bb18358f12c5b78b37bb0111d3a0e2276e0e2
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/cache v3.0.5@0865c47f36e68161719c5b124609996bb5c40129
  • actions/setup-java v4.2.1@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/cache v3.0.5@0865c47f36e68161719c5b124609996bb5c40129
  • actions/setup-java v4.2.1@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
.github/workflows/codeql-analysis.yml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • github/codeql-action v3.25.13@2d790406f505036ef40ecba973cc774a50395aac
  • github/codeql-action v3.25.13@2d790406f505036ef40ecba973cc774a50395aac
  • github/codeql-action v3.25.13@2d790406f505036ef40ecba973cc774a50395aac
gradle
gradle.properties
properties.gradle
settings.gradle.kts
build.gradle.kts
  • com.github.johnrengelman.shadow 7.1.2
  • org.shipkit.shipkit-auto-version 1.2.1
  • org.shipkit.shipkit-changelog 1.2.0
  • org.shipkit.shipkit-github-release 1.2.0
  • dev.minco.gradle.defaults-plugin 0.2.61
  • junit:junit 4.13.2
  • me.nallar.whocalled:WhoCalled 1.1
  • dev.minco:java-transformer 1.10.49
  • org.projectlombok:lombok 1.18.24
gradle/shipkit.gradle
gradle-plugin/groovy.gradle
  • io.github.classgraph:classgraph 4.8.149
gradle-plugin/build.gradle.kts
  • org.spockframework:spock-bom 2.1-groovy-3.0
  • junit:junit 4.13.2
  • org.projectlombok:lombok 1.18.24
  • org.jetbrains:annotations 23.0.0
  • org.ow2.asm:asm 9.3
gradle-plugin/test-template/settings.gradle
gradle-plugin/test-template/build.gradle
  • junit:junit 4.13.2
  • com.google.guava:guava 31.1-jre
  • com.google.guava:guava 31.1-jre
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.0.2

  • Check this box to trigger a request for Renovate to run again on this repository

First release task list

  • Implement source transformations in SourceEditor
  • Implement bytecode transformations in ByteCodeEditor
  • Implement annotation parsing from source, bytecode and loaded class
  • Implement running source/bytecodeeditor using the parsed annotaitons
  • Split parsing code to separate project nallar/JavaTransformer

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.