Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Oct 25, 2024
2 parents a7cd603 + 0f656d3 commit 4b9d180
Show file tree
Hide file tree
Showing 302 changed files with 10,801 additions and 3,057 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: gradle
path: gradle-plugin/build/libs
path: gradle-plugin/build/libs

- uses: actions/upload-artifact@v4
with:
name: test-downgrade
path: testing/downgrade/build/libs

7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea/**/*.xml
!.idea/codeStyles/*.xml
*.iws
*.iml
*.ipr
Expand Down
28 changes: 28 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
## JvmDowngrader

Copyright (C) 2024 William Gray <[email protected]>

This program is provided under 2 licenses:

* [The GNU Lesser General Public License version 2.1](license/LGPLv2.1.md)
* [A Commercial License and Support Agreement](license/Commercial.md)
* [A Commercial And Support License Agreement](license/COMMERCIAL.md)

If you are a non-commercial user, it is recommended to use the LGPLv2.1 license, as it is more permissive and allows you to use the software for free.
If you are a commercial user, or need support with your use of the product, the commercial license is available for purchase by contacting me at the email address above.
If you are a non-commercial user, it is recommended to use the LGPLv2.1 license, as it is more permissive and allows you
to use the software for free.
If you are a commercial user, or need support with your use of the product, a commercial and support license is
available for purchase by contacting me at the email address above.

If you are a non-commercial user, or your usecase is covered by the LGPLv2.1 license,
If you are a non-commercial user, or your usecase is covered by the LGPLv2.1 license,
I would appreciate it if you would consider donating to support the project, but it is in no way required.

If you are a commercial user looking to validate this software for your usecase,
you are welcome to use the software on a single build of your software for evaluation purposes,
but you must purchase a license before using it in a production environment.
If you are in need of more evaluation options, or have any questions, please contact me at the email address above.

### LGPLv2.1 License Concerns

Some people think that shading would mean they're bound by the stricter GPL license due to the inclusion of jvmdowngrader's java class files. I don't belive this to be the case.
Some people think that shading would mean they're bound by the stricter GPL license due to the inclusion of
jvmdowngrader's java class files. I don't believe this to be the case.

For the purpose of Licensing, the produced jar from this task, or the downgrading task, should be considered a "Combined Work",
For the purpose of Licensing, the produced jar from this task, or the downgrading task, should be considered a "Combined
Work",
as it contains the original code from the input jar and the shaded code from jvmdowngrader's api.

And this does, usually, mean that you shouldn't need to use the *exact* same license.
Expand Down
72 changes: 61 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ Downgrades modern java bytecode to older versions. at either compile or runtime.

This is currently capable of downgrading from Java 22 to Java 8. Java 7 may come in the future.

Currently attempting to downgrade to Java 7 will produce valid class files, but some of the API stubs are broken, and many common ones dont exist.
Currently attempting to downgrade to Java 7 will produce valid class files, but some of the API stubs are broken, and
many common ones dont exist.

### After downgrading you must either shade, or add the api jar to the classpath at runtime.

**It is recommended to use the shade task/cli as documented below, as it will only include necessary methods in your jar.**
**It is recommended to use the shade task/cli as documented below, as it will only include necessary methods in your
jar.**

alternatively, you can add the api jar in its entirety to the classpath when running the jar.

The api jar can be found at `xyz.wagyourtail.jvmdowngrader:jvmdowngrader-java-api:0.9.0:downgraded-8`
there is also a `downgraded-11` jar there.
there is also a `downgraded-11` jar there.

alternatively, to produce other versions you can generate one yourself using the cli:
`java -jar JvmDowngrader-all.jar -c 53 debug downgradeApi ./java-api-9.jar`
Expand Down Expand Up @@ -52,20 +54,29 @@ in `build.gradle`:
```gradle
// add the plugin
plugins {
id 'xyz.wagyourtail.jvmdowngrader' version '1.0.0'
id 'xyz.wagyourtail.jvmdowngrader' version '$jvmdgVersion'
}
// optionally you can change some globals, here are their default values:
jvmdg.downgradeTo = JavaVersion.VERSION_1_8
jvmdg.apiJar = [this.getClass().getResourceAsStream("jvmdg/java-api-${version}.jar").writeToFile("build/jvmdg/java-api-${version}.jar")]
jvmdg.quiet = false
jvmdg.debug = false
jvmdg.logLevel = "INFO"
jvmdg.ignoreWarningsIn = [].toSet()
jvmdg.debugSkipStubs = [].toSet()
jvmdg.debugDumpClasses = false
jvmdg.shadePath = {
it.substringBefore(".").substringBeforeLast("-").replace(Regex("[.;\\[/]"), "-")
}
jvmdg.shadeInlining = true
jvmdg.multiReleaseOriginal = false
jvmdg.multiReleaseVersions = [].toSet()
```

You can see more of what these values mean
by [checking the docs on the flags classes](gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/flags)

This will create a default downgrade task for `jar` (or `shadowJar` if present) called `downgradeJar` that will
downgrade the output to java 8 by default.
as well as a `shadeDowngradedApi` to then insert the required classes for not having a runtime dependency on the api
Expand All @@ -83,10 +94,11 @@ shadeDowngradedApi {
}
```

The tasks have all the same flags as the extension, so you can change them separately,
The tasks have all the same flags as the extension, so you can change them separately,
their default value is to use the global one from the extension.

If you are merging multiple downgraded jars, please merge from the downgradeJar tasks, and then shade on the resulting mono-jar.
If you are merging multiple downgraded jars, please merge from the downgradeJar tasks, and then shade on the resulting
mono-jar.
otherwise some API stubs may be missing, due to how shade only includes what is used.

Optionally, you can also depend on the shadeDowngradedApi task when running build.
Expand All @@ -95,7 +107,7 @@ Optionally, you can also depend on the shadeDowngradedApi task when running buil
assemble.dependsOn shadeDowngradedApi
```

you can create a custom task by doing:
### Custom Tasks

```gradle
task customDowngrade(type: xyz.wagyourtail.jvmdg.gradle.task.DowngradeJar) {
Expand All @@ -111,7 +123,7 @@ task customShadeDowngradedApi(type: xyz.wagyourtail.jvmdg.gradle.task.ShadeJar)
}
```

you can also downgrade/shade a `FileCollection`:
### Downgrade FileCollection

```gradle
task downgradeFileCollection(type: xyz.wagyourtail.jvmdg.gradle.task.files.DowngradeFiles) {
Expand All @@ -135,22 +147,60 @@ shadeFileCollection.outputCollection
Make sure the task is configured before trying to use the outputCollection,
it's computed from the `toDowngrade` files.

you can downgrade a configuration:
### Downgrade Configuration

To depend on more modern jars on a lower java version you can downgrade the configuration.

```gradle
configurations {
downgrade
implementation.extendsFrom downgrade
}
jvmdg.dg(configurations.downgrade)
jvmdg.dg(configurations.downgrade) {
downgradeTo = JavaVersion.VERSION_1_8 // default
}
dependencies {
downgrade "newer.java:version:1.0"
}
```

#### Downgrading for shading/jij'ing dependencies

This is the expected usage of these functions.

`jvmdg.dg` has optional parameter, `shade: Boolean`, turn this to false if you plan on shadow'ing this configuration and
running `shadeDowngradedApi`, as otherwise there may be duplicate jvmdg-api classes.
ie. `jvmdg.dg(configurations.downgrade, false)`

you may have to include whatever configuration you're downgrading in ShadowJar yourself.
I do not automatically make the configuration shadowed into your output.

#### Including newer dependencies on lower java version building

This is not recommended due to the following but is still possible.
It is recommended to just shade dependencies into your project and downgrade the combined output.
The dependencies may not be correctly represented in the pom with this method.

There may be issues with gradle metadata breaking because of how early gradle checks the java version,
you can disable this by setting `mavenPom` and `artifact` in the `metadataSources` function on repositories
to explicitly disable gradle metadata.

for example:

```gradle
repositories {
mavenCentral {
metadataSources {
mavenPom()
artifact()
}
}
}
```

## "Compile" Time Downgrading

### Zip/Path Downgrading
Expand Down Expand Up @@ -207,7 +257,7 @@ You can also create your own downgrading classloader, for more complicated envir
DowngradingClassLoader loader = new DowngradingClassLoader(ClassDowngrader.getCurrentVersionDowngrader(), parent);
// adding jars
loader.addDelegate(new URL[] { new File("jarname.jar").toURI().toURL() });
loader.addDelegate(new URL[]{new File("jarname.jar").toURI().toURL()});
```

### inspired by
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ val mainVersion = project.properties["mainVersion"] as String
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(mainVersion.toInt()))
vendor.set(JvmVendorSpec.AZUL)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package xyz.wagyourtail.gradle.coverage
import org.gradle.api.JavaVersion
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.internal.ConventionTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService

@CacheableTask
abstract class CoverageRunTask : JavaExec() {
abstract class CoverageRunTask: JavaExec() {

@get:InputFile
@get:PathSensitive(PathSensitivity.NONE)
Expand Down Expand Up @@ -53,5 +51,4 @@ abstract class CoverageRunTask : JavaExec() {
super.exec()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.nio.file.StandardOpenOption
import java.util.zip.ZipFile
import kotlin.io.path.*

abstract class GenerateCtSymTask : ConventionTask() {
abstract class GenerateCtSymTask: ConventionTask() {

@get:Optional
@get:OutputFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.FilterReader
import java.io.Reader
import java.nio.charset.StandardCharsets

class PackageRelocateReader(input: Reader) : FilterReader(input) {
class PackageRelocateReader(input: Reader): FilterReader(input) {

var remapper: PackageRelocator by MustSet()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xyz.wagyourtail.gradle.shadow

import org.objectweb.asm.commons.Remapper

class PackageRelocator(val map: Map<String, String>) : Remapper() {
class PackageRelocator(val map: Map<String, String>): Remapper() {

override fun map(internalName: String): String {
for ((from, to) in map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.gradle.api.tasks.TaskAction
import org.gradle.jvm.tasks.Jar
import java.nio.charset.StandardCharsets

abstract class ShadowJar : Jar() {
abstract class ShadowJar: Jar() {

@get:Internal
abstract val shadowContents: ListProperty<FileCollection>
Expand Down
Loading

0 comments on commit 4b9d180

Please sign in to comment.