|
| 1 | +/* |
| 2 | + * A Gradle plugin for the creation of Minecraft mods and MinecraftForge plugins. |
| 3 | + * Copyright (C) 2013 Minecraft Forge |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2.1 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 18 | + * USA |
| 19 | + */ |
| 20 | +package net.minecraftforge.gradle.user; |
| 21 | + |
| 22 | +import static net.minecraftforge.gradle.common.Constants.TASK_GENERATE_SRGS; |
| 23 | + |
| 24 | +import java.util.Collection; |
| 25 | +import java.util.List; |
| 26 | + |
| 27 | +import org.gradle.api.NamedDomainObjectFactory; |
| 28 | +import org.gradle.api.Task; |
| 29 | +import org.gradle.api.file.FileCollection; |
| 30 | +import org.gradle.api.tasks.bundling.Jar; |
| 31 | + |
| 32 | +import net.minecraftforge.gradle.util.GradleConfigurationException; |
| 33 | + |
| 34 | +public class ReobfTaskFactory implements NamedDomainObjectFactory<IReobfuscator> |
| 35 | +{ |
| 36 | + private final UserBasePlugin<?> plugin; |
| 37 | + |
| 38 | + public ReobfTaskFactory(UserBasePlugin<?> plugin) |
| 39 | + { |
| 40 | + this.plugin = plugin; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public IReobfuscator create(String jarName) |
| 45 | + { |
| 46 | + Task jar = plugin.project.getTasks().getByName(jarName); |
| 47 | + |
| 48 | + if (!(jar instanceof Jar)) |
| 49 | + { |
| 50 | + throw new GradleConfigurationException(jarName + " is not a jar task. Can only reobf jars!"); |
| 51 | + } |
| 52 | + String name = "reobf" + Character.toUpperCase(jarName.charAt(0)) + jarName.substring(1); |
| 53 | + TaskSingleReobf task = plugin.maybeMakeTask(name, TaskSingleReobf.class); |
| 54 | + |
| 55 | + task.setJar(((Jar) jar).getArchivePath()); |
| 56 | + |
| 57 | + task.dependsOn(TASK_GENERATE_SRGS, jar); |
| 58 | + task.mustRunAfter("test"); |
| 59 | + |
| 60 | + plugin.project.getTasks().getByName("build").dependsOn(task); |
| 61 | + plugin.project.getTasks().getByName("assemble").dependsOn(task); |
| 62 | + |
| 63 | + plugin.setupReobf(task); |
| 64 | + |
| 65 | + return new TaskWrapper(jarName, task); |
| 66 | + } |
| 67 | + |
| 68 | + class TaskWrapper implements IReobfuscator |
| 69 | + { |
| 70 | + private final String name; |
| 71 | + private final IReobfuscator reobf; |
| 72 | + |
| 73 | + public TaskWrapper(String name, IReobfuscator reobf) |
| 74 | + { |
| 75 | + this.name = name; |
| 76 | + this.reobf = reobf; |
| 77 | + } |
| 78 | + |
| 79 | + public String getName() |
| 80 | + { |
| 81 | + return name; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Returns the instance of {@link TaskSingleReobf} that this object |
| 86 | + * wraps. |
| 87 | + * |
| 88 | + * @return The task |
| 89 | + */ |
| 90 | + public IReobfuscator getTask() |
| 91 | + { |
| 92 | + return reobf; |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public boolean equals(Object obj) |
| 97 | + { |
| 98 | + if (obj instanceof TaskWrapper) |
| 99 | + { |
| 100 | + return name.equals(((TaskWrapper) obj).name); |
| 101 | + } |
| 102 | + return false; |
| 103 | + } |
| 104 | + |
| 105 | + public Object getMappings() |
| 106 | + { |
| 107 | + return reobf.getMappings(); |
| 108 | + } |
| 109 | + |
| 110 | + public void setMappings(Object srg) |
| 111 | + { |
| 112 | + reobf.setMappings(srg); |
| 113 | + } |
| 114 | + |
| 115 | + public void setClasspath(FileCollection classpath) |
| 116 | + { |
| 117 | + reobf.setClasspath(classpath); |
| 118 | + } |
| 119 | + |
| 120 | + public FileCollection getClasspath() |
| 121 | + { |
| 122 | + return reobf.getClasspath(); |
| 123 | + } |
| 124 | + |
| 125 | + public List<Object> getExtra() |
| 126 | + { |
| 127 | + return reobf.getExtra(); |
| 128 | + } |
| 129 | + |
| 130 | + public void setExtra(List<Object> extra) |
| 131 | + { |
| 132 | + reobf.setExtra(extra); |
| 133 | + } |
| 134 | + |
| 135 | + public void extra(Object... o) |
| 136 | + { |
| 137 | + reobf.extra(o); |
| 138 | + } |
| 139 | + |
| 140 | + public void extra(Collection<Object> o) |
| 141 | + { |
| 142 | + reobf.extra(o); |
| 143 | + } |
| 144 | + |
| 145 | + public void useSrgSrg() |
| 146 | + { |
| 147 | + reobf.useSrgSrg(); |
| 148 | + } |
| 149 | + |
| 150 | + public void useNotchSrg() |
| 151 | + { |
| 152 | + reobf.useNotchSrg(); |
| 153 | + } |
| 154 | + } |
| 155 | +} |
0 commit comments