Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.7 refactors #178

Merged
merged 16 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ dependencies {
transitive = false
}

implementation ('net.fabricmc:lorenz-tiny:1.0.0+build.1') {
transitive = false
}

// decompilers
implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+')
implementation ('org.jetbrains:intellij-fernflower:1.1.0.11')
Expand Down
24 changes: 3 additions & 21 deletions src/main/java/net/fabricmc/loom/AbstractPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.scala.ScalaCompile;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.model.IdeaModel;

import net.fabricmc.loom.providers.LaunchProvider;
Expand Down Expand Up @@ -100,8 +99,6 @@ public void apply(Project target) {

Configuration minecraftNamedConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_NAMED);
minecraftNamedConfig.setTransitive(false); // The launchers do not recurse dependencies
Configuration minecraftIntermediaryConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_INTERMEDIARY);
minecraftIntermediaryConfig.setTransitive(false);
Configuration minecraftDependenciesConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_DEPENDENCIES);
minecraftDependenciesConfig.setTransitive(false);
Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT);
Expand Down Expand Up @@ -135,7 +132,6 @@ public void apply(Project target) {
}

extendsFrom(Constants.MINECRAFT_NAMED, Constants.MINECRAFT_DEPENDENCIES);
extendsFrom(Constants.MINECRAFT_INTERMEDIARY, Constants.MINECRAFT_DEPENDENCIES);

extendsFrom("compile", Constants.MAPPINGS_FINAL);

Expand Down Expand Up @@ -224,9 +220,6 @@ protected void configureIDEs() {
ideaModel.getModule().setDownloadJavadoc(true);
ideaModel.getModule().setDownloadSources(true);
ideaModel.getModule().setInheritOutputDirs(true);

// ECLIPSE
EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
}

/**
Expand All @@ -236,7 +229,6 @@ protected void configureCompile() {
JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java");

SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet test = javaModule.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
Expand All @@ -249,11 +241,6 @@ protected void configureCompile() {
project.afterEvaluate(project1 -> {
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);

project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
flatDirectoryArtifactRepository.dir(extension.getUserCache());
flatDirectoryArtifactRepository.setName("UserCacheFiles");
});

project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
flatDirectoryArtifactRepository.dir(extension.getRootProjectBuildCache());
flatDirectoryArtifactRepository.setName("UserLocalCacheFiles");
Expand All @@ -269,11 +256,6 @@ protected void configureCompile() {
mavenArtifactRepository.setUrl("https://maven.fabricmc.net/");
});

/* project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("SpongePowered");
mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven");
}); */

project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("Mojang");
mavenArtifactRepository.setUrl("https://libraries.minecraft.net/");
Expand All @@ -285,9 +267,9 @@ protected void configureCompile() {
LoomDependencyManager dependencyManager = new LoomDependencyManager();
extension.setDependencyManager(dependencyManager);

dependencyManager.addProvider(new MinecraftProvider());
dependencyManager.addProvider(new MappingsProvider());
dependencyManager.addProvider(new LaunchProvider());
dependencyManager.addProvider(new MinecraftProvider(getProject()));
dependencyManager.addProvider(new MappingsProvider(getProject()));
dependencyManager.addProvider(new LaunchProvider(getProject()));

dependencyManager.handleDependencies(project1);

Expand Down
23 changes: 22 additions & 1 deletion src/main/java/net/fabricmc/loom/LoomGradleExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.plugins.BasePluginConvention;

import net.fabricmc.loom.processors.JarProcessorManager;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider;
import net.fabricmc.loom.providers.MinecraftProvider;
Expand All @@ -58,12 +59,14 @@ public class LoomGradleExtension {
public boolean autoGenIDERuns = true;
public boolean extractJars = false;
public String customManifest = null;
public File accessWidener = null;

private List<Path> unmappedModsBuilt = new ArrayList<>();

//Not to be set in the build.gradle
private Project project;
private LoomDependencyManager dependencyManager;
private JarProcessorManager jarProcessorManager;
private JsonObject installerJson;
private MappingSet[] srcMappingCache = new MappingSet[2];
private Mercury[] srcMercuryCache = new Mercury[2];
Expand Down Expand Up @@ -116,6 +119,16 @@ public File getRootProjectPersistentCache() {
return projectCache;
}

public File getProjectPersistentCache() {
File projectCache = new File(project.file(".gradle"), "loom-cache");

if (!projectCache.exists()) {
projectCache.mkdirs();
}

return projectCache;
}

public File getRootProjectBuildCache() {
File projectCache = new File(project.getRootProject().getBuildDir(), "loom-cache");

Expand Down Expand Up @@ -167,7 +180,7 @@ public File getNativesJarStore() {
}

public File getNativesDirectory() {
File natives = new File(getUserCache(), "natives/" + getMinecraftProvider().minecraftVersion);
File natives = new File(getUserCache(), "natives/" + getMinecraftProvider().getMinecraftVersion());

if (!natives.exists()) {
natives.mkdirs();
Expand Down Expand Up @@ -283,6 +296,14 @@ public void setDependencyManager(LoomDependencyManager dependencyManager) {
this.dependencyManager = dependencyManager;
}

public JarProcessorManager getJarProcessorManager() {
return jarProcessorManager;
}

public void setJarProcessorManager(JarProcessorManager jarProcessorManager) {
this.jarProcessorManager = jarProcessorManager;
}

public String getRefmapName() {
if (refmapName == null || refmapName.isEmpty()) {
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import net.fabricmc.loom.task.fernflower.FernFlowerTask;

public class LoomGradlePlugin extends AbstractPlugin {
private static File getMappedByproduct(Project project, String suffix) {
public static File getMappedByproduct(Project project, String suffix) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MappingsProvider mappingsProvider = extension.getMappingsProvider();
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
Expand Down Expand Up @@ -108,7 +108,7 @@ public void apply(Project target) {

Project project = this.getProject();
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().libraryProvider;
MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().getLibraryProvider();
MappingsProvider mappingsProvider = extension.getMappingsProvider();
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
File linemappedJar = getMappedByproduct(project, "-linemapped.jar");
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/net/fabricmc/loom/processors/JarProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.fabricmc.loom.processors;

import java.io.File;

import org.gradle.api.Project;

public interface JarProcessor {
void setup(Project project);

void process(File file);

boolean isInvalid(File file);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.fabricmc.loom.processors;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.gradle.api.Project;

import net.fabricmc.loom.LoomGradleExtension;

public class JarProcessorManager {
private final Project project;
private final LoomGradleExtension extension;

private final List<JarProcessor> jarProcessors;

public JarProcessorManager(Project project) {
this.project = project;
this.extension = project.getExtensions().getByType(LoomGradleExtension.class);
jarProcessors = setupProcessors();
}

//TODO possibly expand via an API?
private List<JarProcessor> setupProcessors() {
List<JarProcessor> jarProcessors = new ArrayList<>();

jarProcessors.forEach(jarProcessor -> jarProcessor.setup(project));
return Collections.unmodifiableList(jarProcessors);
}

public boolean active() {
return !jarProcessors.isEmpty();
}

public boolean isInvalid(File file) {
if (!file.exists()) {
return true;
}

return jarProcessors.stream().anyMatch(jarProcessor -> jarProcessor.isInvalid(file));
}

public void process(File file) {
for (JarProcessor jarProcessor : jarProcessors) {
jarProcessor.process(file);
}
}

public <T extends JarProcessor> T getByType(Class<T> tClass) {
//noinspection unchecked
return (T) jarProcessors.stream().filter(jarProcessor -> jarProcessor.getClass().equals(tClass)).findFirst().orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.fabricmc.loom.processors;

import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;

import org.apache.commons.io.FileUtils;
import org.gradle.api.Project;

import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.util.Constants;

public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public static final String PROJECT_MAPPED_CLASSIFIER = "projectmapped";

private File projectMappedJar;

private final JarProcessorManager jarProcessorManager;

public MinecraftProcessedProvider(Project project, JarProcessorManager jarProcessorManager) {
super(project);
this.jarProcessorManager = jarProcessorManager;
}

@Override
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
if (jarProcessorManager.isInvalid(projectMappedJar)) {
getProject().getLogger().lifecycle(":processing mapped jar");
invalidateJars();

try {
FileUtils.copyFile(super.getMappedJar(), projectMappedJar);
} catch (IOException e) {
throw new RuntimeException("Failed to copy source jar", e);
}

jarProcessorManager.process(projectMappedJar);
}

getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER)));

getProject().getDependencies().add(Constants.MINECRAFT_NAMED,
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER)));
}

private void invalidateJars() {
File dir = getJarDirectory(getExtension().getUserCache(), PROJECT_MAPPED_CLASSIFIER);

if (dir.exists()) {
getProject().getLogger().warn("Invalidating project jars");

try {
FileUtils.cleanDirectory(dir);
} catch (IOException e) {
throw new RuntimeException("Failed to invalidate jars, try stopping gradle daemon or closing the game", e);
}
}
}

@Override
public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
super.initFiles(minecraftProvider, mappingsProvider);

projectMappedJar = new File(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER), "minecraft-" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER) + ".jar");
}

@Override
public File getMappedJar() {
return projectMappedJar;
}
}
Loading