neoforged / GradleUtils

Gradle buildscript utility library for NeoForged projects
GNU Lesser General Public License v2.1
1 stars 5 forks source link

Refactor API and unify versioning in extension #9

Closed sciwhiz12 closed 9 months ago

sciwhiz12 commented 10 months ago

This PR massively refactors the public API of GradleUtils, both by removing certain parts and overhauling others.

The main drive of this API is to enhance the API of GradleUtils so it is future-proof and robust. This is achieved through two main goals:

  1. Any class which isn't necessary for the user to interact with is hidden as package-private. Notably, this includes both GradleUtils and ChangelogUtils, as their methods are exposed through their respective extensions.

    However, because the tasks need access to certain methods in the main package, which is not possible ordinarily because of the new package-private access of their owning classes, an internal accessor class exists to allow that access. Note that the internal accessor class, public it may be, is not included in the public API of GradleUtils, and is therefore subject to change or removal at any time.

  2. The versioning side of GradleUtils is majorly refactored, both its internals and public-facing API.

    Instead of different methods on the extension, each of which having their own specialities and being independently callable, we now unify the configuration to a single space in the extension, and collapse all those version-getting methods into a single method, getVersion() (which can simply be referenced as version in Groovy).

    The newly exposed configuration is flexible enough to replace all previously accessible methods, as well as exposing new settings for more configurability. In particular, this is key for the tag-based implementation of NeoForge's new versioning scheme (to be implemented in the release for MC 1.20.2).

    For example, the following demonstrates the equivalents for the previous 6 methods exposed on the extension:

    // Without any configuration, this is a replacement for `getTagOffsetVersion`
    gradleutils.version {
     // replacement for `get[Filtered]MCTagOffsetBranchVersion`
     minecraftVersion('1.20.1') // minecraft version prefix and suffix-exempted branch names
     tags {
       // replacement for `getFiltered[MC]TagOffset[Branch]Version`
       includePrefix('v') // filter on tag prefix
       // includeFilter('[0-9]') // can also filter based on tag alone
     }
     branches {
       // replacement for `get[Filtered][MC]TagOffsetBranchVersion
       suffixBranch = false // suffix branch to version
     }
    }
    
    // Assign project version
    version = ngu.version

This PR is currently a work-in-progress. Tasks remaining before becoming ready for merge: