Skip to content

Commit

Permalink
Merge pull request #190 from nebula-plugins/config-cache-compatibility
Browse files Browse the repository at this point in the history
Config cache compatibility
  • Loading branch information
rpalcolea committed Nov 16, 2023
2 parents d200096 + 60e860f commit f8376a0
Show file tree
Hide file tree
Showing 25 changed files with 287 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.gradle.api.publish.ivy.IvyModuleDescriptorDescription
import org.gradle.api.publish.ivy.IvyModuleDescriptorSpec
import org.gradle.api.publish.ivy.IvyPublication

@CompileDynamic
class IvyBasePublishPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
Expand Down Expand Up @@ -55,73 +56,62 @@ class IvyBasePublishPlugin implements Plugin<Project> {
*/

PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications(new Action<PublicationContainer>() {
project.afterEvaluate(new Action<Project>() {
@Override
void execute(PublicationContainer publications) {
publications.withType(IvyPublication) { IvyPublication publication ->
if (! project.state.executed) {
project.afterEvaluate(new Action<Project>() {
@Override
void execute(Project p) {
configureDescription(publication, project)
}
})
} else {
configureDescription(publication, project)
}

publication.descriptor(new Action<IvyModuleDescriptorSpec>() {
@Override
void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) {
ivyModuleDescriptorSpec.withXml(new Action<XmlProvider>() {
void execute(Project p) {
String status = p.status
String description = p.description ?: ''
publishing.publications(new Action<PublicationContainer>() {
@Override
void execute(PublicationContainer publications) {
publications.withType(IvyPublication) { IvyPublication publication ->
publication.descriptor.status = status
publication.descriptor.description(new Action<IvyModuleDescriptorDescription>() {
@Override
void execute(XmlProvider xml) {
configureXml(xml)
void execute(IvyModuleDescriptorDescription ivyModuleDescriptorDescription) {
ivyModuleDescriptorDescription.text.set(description)
}
})
}
})
}
}
})
}

@CompileDynamic
private void configureXml(XmlProvider xml) {
def root = xml.asNode()
def configurationsNode = root?.configurations
if(!configurationsNode) {
configurationsNode = root.appendNode('configurations')
}
else {
configurationsNode = configurationsNode[0]
}
publication.descriptor(new Action<IvyModuleDescriptorSpec>() {
@Override
void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) {
ivyModuleDescriptorSpec.withXml(new Action<XmlProvider>() {
@Override
void execute(XmlProvider xml) {
def root = xml.asNode()
def configurationsNode = root?.configurations
if (!configurationsNode) {
configurationsNode = root.appendNode('configurations')
} else {
configurationsNode = configurationsNode[0]
}

def minimalConfs = [
compile: [], default: ['runtime', 'master'], javadoc: [], master: [],
runtime: ['compile'], sources: [], test: ['runtime']
]
def minimalConfs = [
compile: [], default: ['runtime', 'master'], javadoc: [], master: [],
runtime: ['compile'], sources: [], test: ['runtime']
]

minimalConfs.each { minimal ->
def conf = configurationsNode.conf.find { it.@name == minimal.key }
if(!conf) {
conf = configurationsNode.appendNode('conf')
}
conf.@name = minimal.key
conf.@visibility = 'public'
minimalConfs.each { minimal ->
def conf = configurationsNode.conf.find { it.@name == minimal.key }
if (!conf) {
conf = configurationsNode.appendNode('conf')
}
conf.@name = minimal.key
conf.@visibility = 'public'

if(!minimal.value.empty)
conf.@extends = minimal.value.join(',')
}
}
if (!minimal.value.empty)
conf.@extends = minimal.value.join(',')
}
}
})
}
})
}
}
})

private void configureDescription(IvyPublication publication, Project p) {
publication.descriptor.status = p.status
publication.descriptor.description(new Action<IvyModuleDescriptorDescription>() {
@Override
void execute(IvyModuleDescriptorDescription ivyModuleDescriptorDescription) {
ivyModuleDescriptorDescription.text.set(p.description ?: '')
}
})

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*/
package nebula.plugin.publishing.ivy

import groovy.transform.Canonical
import groovy.transform.CompileDynamic
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.XmlProvider
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.publish.PublicationContainer
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.ivy.IvyModuleDescriptorSpec
import org.gradle.api.publish.ivy.IvyPublication

@CompileDynamic
class IvyCompileOnlyPlugin implements Plugin<Project> {

static enum DependenciesContent {
Expand All @@ -41,46 +42,57 @@ class IvyCompileOnlyPlugin implements Plugin<Project> {

PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
project.plugins.withType(JavaPlugin) { JavaPlugin javaBasePlugin ->

publishing.publications(new Action<PublicationContainer>() {
project.afterEvaluate(new Action<Project>() {
@Override
void execute(PublicationContainer publications) {
publications.withType(IvyPublication) { IvyPublication publication ->
publication.descriptor(new Action<IvyModuleDescriptorSpec>() {
@Override
void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) {
ivyModuleDescriptorSpec.withXml(new Action<XmlProvider>() {
void execute(Project p) {
def compileOnlyDependencies = project.configurations.compileOnly.incoming.dependencies.collect {
new Dependency(it.group, it.name, it.version)
}

publishing.publications(new Action<PublicationContainer>() {
@Override
void execute(PublicationContainer publications) {
publications.withType(IvyPublication) { IvyPublication publication ->
publication.descriptor(new Action<IvyModuleDescriptorSpec>() {
@Override
void execute(XmlProvider xml) {
configureXml(project, xml)
void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) {
ivyModuleDescriptorSpec.withXml(new Action<XmlProvider>() {
@Override
void execute(XmlProvider xml) {
def root = xml.asNode()
def dependencies = compileOnlyDependencies
if (dependencies.size() > 0) {
def confs = root.configurations ? root.configurations[0] : root.appendNode('configurations')
confs.appendNode('conf', [name: 'provided', visibility: 'public'])
def deps = root.dependencies ? root.dependencies[0] : root.appendNode('dependencies')
dependencies.each { dep ->
def newDep = deps.appendNode('dependency')
newDep.@org = dep.organisation
newDep.@name = dep.module
newDep.@rev = dep.version
newDep.@conf = 'provided'
}
deps.children().sort(true, {
DependenciesContent.valueOf(it.name()).ordinal()
})
}
}
})
}
})
}
})
}
}
})
}
})

}
}

@CompileDynamic
private void configureXml(Project project, XmlProvider xml) {
def root = xml.asNode()
def dependencies = project.configurations.compileOnly.dependencies
if (dependencies.size() > 0) {
def confs = root.configurations ? root.configurations[0] : root.appendNode('configurations')
confs.appendNode('conf', [name: 'provided', visibility: 'public'])
def deps = root.dependencies ? root.dependencies[0] : root.appendNode('dependencies')
dependencies.each { dep ->
def newDep = deps.appendNode('dependency')
newDep.@org = dep.group
newDep.@name = dep.name
newDep.@rev = dep.version
newDep.@conf = 'provided'
}
deps.children().sort(true, {
DependenciesContent.valueOf(it.name()).ordinal()
})
}
@Canonical
private static class Dependency {
String organisation
String module
String version
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gradle.api.publish.ivy.IvyPublication

import static nebula.plugin.publishing.ManifestElementNameGenerator.*

@CompileDynamic
class IvyManifestPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
Expand All @@ -38,7 +39,12 @@ class IvyManifestPlugin implements Plugin<Project> {
ivyModuleDescriptorSpec.withXml(new Action<XmlProvider>() {
@Override
void execute(XmlProvider xml) {
configureXml(infoBroker, xml)
def desc = xml.asNode()?.info[0].description[0]
desc.'@xmlns:nebula' = 'http://netflix.com/build'

infoBroker.buildManifest().each { key, value ->
desc.appendNode("nebula:${elementName(key)}", value)
}
}
})
}
Expand All @@ -48,16 +54,4 @@ class IvyManifestPlugin implements Plugin<Project> {
})
}
}

@CompileDynamic
private void configureXml(InfoBrokerPlugin infoBroker, XmlProvider xml) {
// the ivy info>description tag is the only one which can contain free
// text, including arbitrary xml
def desc = xml.asNode()?.info[0].description[0]
desc.'@xmlns:nebula' = 'http://netflix.com/build'

infoBroker.buildManifest().each { key, value ->
desc.appendNode("nebula:${elementName(key)}", value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ class IvyNebulaPublishPlugin implements Plugin<Project> {
project.ext.set(IVY_JAR, true)
}

project.publishing {
publications {
nebulaIvy(IvyPublication) {
if (! project.state.executed) {
//configuration when STABLE_PUBLISHING is enabled
project.afterEvaluate { p ->
configurePublication(it, p)
project.afterEvaluate { p ->
def component = getComponent(p)
project.publishing {
publications {
nebulaIvy(IvyPublication) { publication ->
if(component) {
publication.from component
}
} else {
configurePublication(it, project)
}
}
}
}
}

private void configurePublication(IvyPublication publication, Project p) {
if (p.ext.get(IVY_WAR)) {
publication.from p.components.web
} else if (p.ext.get(IVY_JAR)) {
publication.from p.components.java
private getComponent(Project p) {
if(p.ext.get(IVY_WAR)) {
return p.components.web
} else if(p.ext.get(IVY_JAR)) {
return p.components.java
} else {
return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.gradle.api.publish.ivy.IvyPublication
* Removes from descriptor dependencies that are invalid:
* 1) No revision available
*/
@CompileDynamic
class IvyRemoveInvalidDependenciesPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
Expand All @@ -45,7 +46,12 @@ class IvyRemoveInvalidDependenciesPlugin implements Plugin<Project> {
ivyModuleDescriptorSpec.withXml(new Action<XmlProvider>() {
@Override
void execute(XmlProvider xml) {
configureXml(xml)
xml.asNode().dependencies.dependency.findAll() { Node dep ->
String revision = dep.@rev
if(!revision) {
dep.parent().remove(dep)
}
}
}
})
}
Expand All @@ -54,14 +60,4 @@ class IvyRemoveInvalidDependenciesPlugin implements Plugin<Project> {
}
})
}

@CompileDynamic
private void configureXml(XmlProvider xml) {
xml.asNode().dependencies.dependency.findAll() { Node dep ->
String revision = dep.@rev
if(!revision) {
dep.parent().remove(dep)
}
}
}
}
Loading

0 comments on commit f8376a0

Please sign in to comment.