Skip to content

Commit

Permalink
Fix sources publishing (#1098)
Browse files Browse the repository at this point in the history
* Fix sources publishing

* Revert "Fix sources publishing"

This reverts commit a3fec65.

* A better fix
  • Loading branch information
modmuss50 authored Apr 15, 2024
1 parent 1b1168d commit 7010ad6
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,45 +120,50 @@ public void run() {

private void trySetupSourceRemapping() {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
final String sourcesJarTaskName = SourceSetHelper.getMainSourceSet(getProject()).getSourcesJarTaskName();

TaskProvider<RemapSourcesJarTask> remapSourcesTask = getTasks().register(REMAP_SOURCES_JAR_TASK_NAME, RemapSourcesJarTask.class, task -> {
task.setDescription("Remaps the default sources jar to intermediary mappings.");
task.setGroup(Constants.TaskGroup.FABRIC);
task.getIncludesClientOnlyClasses().set(getProject().provider(extension::areEnvironmentSourceSetsSplit));
});

getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(remapSourcesTask));

GradleUtils.afterSuccessfulEvaluation(getProject(), () -> {
final String sourcesJarTaskName = SourceSetHelper.getMainSourceSet(getProject()).getSourcesJarTaskName();
final Task sourcesTask = getTasks().findByName(sourcesJarTaskName);

boolean canRemap = true;

if (sourcesTask == null) {
getProject().getLogger().info("{} task was not found, not remapping sources", sourcesJarTaskName);
task.setEnabled(false);
return;
canRemap = false;
}

if (!(sourcesTask instanceof Jar sourcesJarTask)) {
if (canRemap && !(sourcesTask instanceof Jar)) {
getProject().getLogger().info("{} task is not a Jar task, not remapping sources", sourcesJarTaskName);
task.setEnabled(false);
return;
canRemap = false;
}

sourcesJarTask.getArchiveClassifier().convention("dev-sources");
sourcesJarTask.getDestinationDirectory().set(getProject().getLayout().getBuildDirectory().map(directory -> directory.dir("devlibs")));
task.getArchiveClassifier().convention("sources");
boolean finalCanRemap = canRemap;

task.dependsOn(sourcesJarTask);
task.getInputFile().convention(sourcesJarTask.getArchiveFile());
task.getIncludesClientOnlyClasses().set(getProject().provider(extension::areEnvironmentSourceSetsSplit));
});
remapSourcesTask.configure(task -> {
if (!finalCanRemap) {
task.setEnabled(false);
return;
}

getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(remapSourcesTask));
final Jar sourcesJarTask = (Jar) sourcesTask;

if (GradleUtils.getBooleanProperty(getProject(), "fabric.loom.disableRemappedVariants")) {
return;
}
sourcesJarTask.getArchiveClassifier().convention("dev-sources");
sourcesJarTask.getDestinationDirectory().set(getProject().getLayout().getBuildDirectory().map(directory -> directory.dir("devlibs")));
task.getArchiveClassifier().convention("sources");

GradleUtils.afterSuccessfulEvaluation(getProject(), () -> {
final Task sourcesTask = getTasks().findByName(sourcesJarTaskName);
task.dependsOn(sourcesJarTask);
task.getInputFile().convention(sourcesJarTask.getArchiveFile());
});

if (!(sourcesTask instanceof Jar sourcesJarTask)) {
if (GradleUtils.getBooleanProperty(getProject(), "fabric.loom.disableRemappedVariants")) {
return;
}

Expand Down

0 comments on commit 7010ad6

Please sign in to comment.