Skip to content

Commit

Permalink
Pull Changelog into its own plugin, if you want to use it without the…
Browse files Browse the repository at this point in the history
… rest of the utils.

Use recommended method of sharing task outputs between sub-projects.
https://docs.gradle.org/current/samples/sample_cross_project_output_sharing.html
  • Loading branch information
LexManos committed Nov 21, 2023
1 parent 859240d commit a952ffe
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 333 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ gradlePlugin {
id = 'net.minecraftforge.gradleutils'
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
}
changelog {
id = 'net.minecraftforge.changelog'
implementationClass = 'net.minecraftforge.gradleutils.changelog.ChangelogPlugin'
}
}
}

changelog {
fromTag '1.0'
fromBase()
publishAll = false
}

Expand Down
4 changes: 4 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ gradlePlugin {
id = 'net.minecraftforge.gradleutils'
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
}
changelog {
id = 'net.minecraftforge.changelog'
implementationClass = 'net.minecraftforge.gradleutils.changelog.ChangelogPlugin'
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,10 @@ class GradleUtils {
* @param projectDir THe project directory.
* @return
*/
static String buildProjectUrl(final File projectDir) {
Git git = Git.open(projectDir) //Create a git workspace.

static String buildProjectUrl(Git git) {
List<RemoteConfig> remotes = git.remoteList().call() //Get all remotes.
if (remotes.isEmpty())
throw new IllegalStateException("No remotes found in " + projectDir)
throw new IllegalStateException("No remotes found in " + git.repository.directory)

//Get the origin remote.
final originRemote = remotes.find { remote -> remote.name == 'origin' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
package net.minecraftforge.gradleutils

import groovy.transform.CompileStatic
import net.minecraftforge.gradleutils.changelog.ChangelogPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project

@CompileStatic
class GradleUtilsPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
GradleUtilsExtension extension = project.extensions.create("gradleutils", GradleUtilsExtension, project)
ChangelogGenerationExtension changelogGenerationExtension = project.extensions.create("changelog", ChangelogGenerationExtension, project)

project.plugins.apply(ChangelogPlugin)
project.extensions.create("gradleutils", GradleUtilsExtension, project)
//Setup the teamcity project task.
GradleUtils.setupCITasks(project)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.gradleutils.changelog

import groovy.transform.PackageScope
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.TaskProvider

import javax.inject.Inject

class ChangelogExtension {
public static final String NAME = "changelog"

@PackageScope final Project project
@PackageScope TaskProvider<GenerateChangelog> task

boolean publishAll = true
Directory gitRoot

@Inject
ChangelogExtension(Project project) {
this.project = project
}

void fromBase() {
from(null)
}

void from(String marker) {
task = ChangelogUtils.setupChangelogTask(this.project)
task.configure {
start = marker
}

project.afterEvaluate {
if (gitRoot != null) {
task.configure {
gitDirectory = gitRoot
}
}

if (publishAll)
ChangelogUtils.setupChangelogGenerationOnAllPublishTasks(project)
}
}

void publish(MavenPublication publication) {
ChangelogUtils.setupChangelogGenerationForPublishing(project, publication)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.gradleutils.changelog

import groovy.transform.CompileStatic
import net.minecraftforge.gradleutils.GradleUtils
import net.minecraftforge.gradleutils.GradleUtilsExtension
import net.minecraftforge.gradleutils.changelog.ChangelogExtension
import org.gradle.api.Plugin
import org.gradle.api.Project

@CompileStatic
class ChangelogPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.extensions.create(ChangelogExtension.NAME, ChangelogExtension, project)
}
}
Loading

0 comments on commit a952ffe

Please sign in to comment.