support appending to existing <dependencies> keys in maven-publish hook; in came a buildscript uses .withXml, say
This commit is contained in:
		
							parent
							
								
									dc69315715
								
							
						
					
					
						commit
						253c2ed15e
					
				
					 2 changed files with 86 additions and 17 deletions
				
			
		|  | @ -26,34 +26,22 @@ package net.fabricmc.loom; | |||
| 
 | ||||
| import com.google.common.collect.ImmutableMap; | ||||
| import groovy.util.Node; | ||||
| import groovy.util.NodeList; | ||||
| import groovy.xml.QName; | ||||
| import net.fabricmc.loom.providers.MappingsProvider; | ||||
| import net.fabricmc.loom.providers.MinecraftProvider; | ||||
| import net.fabricmc.loom.providers.ModRemapperProvider; | ||||
| import net.fabricmc.loom.task.RemapJar; | ||||
| import net.fabricmc.loom.task.RemapSourcesJar; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import net.fabricmc.loom.util.LoomDependencyManager; | ||||
| import net.fabricmc.loom.util.NestedJars; | ||||
| import net.fabricmc.loom.util.SetupIntelijRunConfigs; | ||||
| import net.fabricmc.loom.util.*; | ||||
| import org.gradle.api.*; | ||||
| import org.gradle.api.artifacts.Configuration; | ||||
| import org.gradle.api.artifacts.Dependency; | ||||
| import org.gradle.api.artifacts.ModuleDependency; | ||||
| import org.gradle.api.artifacts.ProjectDependency; | ||||
| import org.gradle.api.artifacts.dsl.DependencyHandler; | ||||
| import org.gradle.api.artifacts.maven.Conf2ScopeMappingContainer; | ||||
| import org.gradle.api.artifacts.repositories.MavenArtifactRepository; | ||||
| import org.gradle.api.plugins.JavaPlugin; | ||||
| import org.gradle.api.plugins.JavaPluginConvention; | ||||
| import org.gradle.api.plugins.MavenPlugin; | ||||
| import org.gradle.api.plugins.MavenPluginConvention; | ||||
| import org.gradle.api.publish.Publication; | ||||
| import org.gradle.api.publish.PublishingExtension; | ||||
| import org.gradle.api.publish.maven.MavenPublication; | ||||
| import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven; | ||||
| import org.gradle.api.publish.maven.tasks.GenerateMavenPom; | ||||
| import org.gradle.api.tasks.SourceSet; | ||||
| import org.gradle.api.tasks.bundling.AbstractArchiveTask; | ||||
| import org.gradle.api.tasks.compile.JavaCompile; | ||||
|  | @ -63,10 +51,9 @@ import org.gradle.plugins.ide.idea.model.IdeaModel; | |||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.Collections; | ||||
| import java.util.HashSet; | ||||
| import java.util.Map; | ||||
| import java.util.Optional; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| public class AbstractPlugin implements Plugin<Project> { | ||||
|  | @ -313,9 +300,24 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 						if (publication instanceof MavenPublication) { | ||||
| 							((MavenPublication) publication).pom((pom) -> { | ||||
| 								pom.withXml((xml) -> { | ||||
| 									Node dependencies = xml.asNode().appendNode("dependencies"); | ||||
| 									Node dependencies = GroovyXmlUtil.getOrCreateNode(xml.asNode(), "dependencies"); | ||||
| 									Set<String> foundArtifacts = new HashSet<>(); | ||||
| 
 | ||||
| 									GroovyXmlUtil.childrenNodesStream(dependencies) | ||||
| 											.filter((n) -> "dependency".equals(n.name())) | ||||
| 											.forEach((n) -> { | ||||
| 												Optional<Node> groupId = GroovyXmlUtil.getNode(n, "groupId"); | ||||
| 												Optional<Node> artifactId = GroovyXmlUtil.getNode(n, "artifactId"); | ||||
| 												if (groupId.isPresent() && artifactId.isPresent()) { | ||||
| 													foundArtifacts.add(groupId.get().text() + ":" + artifactId.get().text()); | ||||
| 												} | ||||
| 											}); | ||||
| 
 | ||||
| 									for (Dependency dependency : compileModsConfig.getAllDependencies()) { | ||||
| 										if (foundArtifacts.contains(dependency.getGroup() + ":" + dependency.getName())) { | ||||
| 											continue; | ||||
| 										} | ||||
| 
 | ||||
| 										Node depNode = dependencies.appendNode("dependency"); | ||||
| 										depNode.appendNode("groupId", dependency.getGroup()); | ||||
| 										depNode.appendNode("artifactId", dependency.getName()); | ||||
|  |  | |||
							
								
								
									
										67
									
								
								src/main/java/net/fabricmc/loom/util/GroovyXmlUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/main/java/net/fabricmc/loom/util/GroovyXmlUtil.java
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,67 @@ | |||
| /* | ||||
|  * 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.util; | ||||
| 
 | ||||
| import groovy.util.Node; | ||||
| 
 | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
| import java.util.stream.Collectors; | ||||
| import java.util.stream.Stream; | ||||
| 
 | ||||
| public final class GroovyXmlUtil { | ||||
| 	private GroovyXmlUtil() { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public static Node getOrCreateNode(Node parent, String name) { | ||||
| 		for (Object object : parent.children()) { | ||||
| 			if (object instanceof Node && name.equals(((Node) object).name())) { | ||||
| 				return (Node) object; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return parent.appendNode(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public static Optional<Node> getNode(Node parent, String name) { | ||||
| 		for (Object object : parent.children()) { | ||||
| 			if (object instanceof Node && name.equals(((Node) object).name())) { | ||||
| 				return Optional.of((Node) object); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return Optional.empty(); | ||||
| 	} | ||||
| 
 | ||||
| 	public static Stream<Node> childrenNodesStream(Node node) { | ||||
| 		//noinspection unchecked | ||||
| 		return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node)); | ||||
| 	} | ||||
| 
 | ||||
| 	public static Iterable<Node> childrenNodes(Node node) { | ||||
| 		return childrenNodesStream(node).collect(Collectors.toList()); | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in a new issue