From 9c33675eced6e984157b6d6f4e692302a01779a3 Mon Sep 17 00:00:00 2001 From: Evgeny Naumenko Date: Mon, 2 Mar 2015 22:44:15 +0300 Subject: [PATCH] debug logging added --- .../com.github.jk1.tcdeps/LogFacade.groovy | 22 +++++++++++++ .../TeamCityDependenciesPlugin.groovy | 5 ++- .../processing/DepedencyPinner.groovy | 6 +++- .../processing/RepositoryBuilder.groovy | 33 +++++++++++++++---- 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/main/groovy/com.github.jk1.tcdeps/LogFacade.groovy diff --git a/src/main/groovy/com.github.jk1.tcdeps/LogFacade.groovy b/src/main/groovy/com.github.jk1.tcdeps/LogFacade.groovy new file mode 100644 index 0000000..ce4ecf6 --- /dev/null +++ b/src/main/groovy/com.github.jk1.tcdeps/LogFacade.groovy @@ -0,0 +1,22 @@ +package com.github.jk1.tcdeps + + +class LogFacade { + + private static final PREFIX = '[TCdeps]' + + // initialized from TeamCityDependenciesPlugin + static volatile logger; + + public static debug( message) { + logger.debug("$PREFIX $message") + } + + public static info(message) { + logger.info("$PREFIX $message") + } + + public static warn(message, exception) { + logger.warn("$PREFIX $message", exception) + } +} diff --git a/src/main/groovy/com.github.jk1.tcdeps/TeamCityDependenciesPlugin.groovy b/src/main/groovy/com.github.jk1.tcdeps/TeamCityDependenciesPlugin.groovy index 8b6894e..60cb5cc 100644 --- a/src/main/groovy/com.github.jk1.tcdeps/TeamCityDependenciesPlugin.groovy +++ b/src/main/groovy/com.github.jk1.tcdeps/TeamCityDependenciesPlugin.groovy @@ -13,6 +13,7 @@ class TeamCityDependenciesPlugin implements Plugin { @Override void apply(Project project) { + LogFacade.logger = project.logger processors = [new ChangingModuleVersionResolver(), new RepositoryBuilder(), new DepedencyPinner()] project.extensions.add("teamcityServer", new PluginConfiguration()) project.ext.tc = { Object notation -> @@ -30,6 +31,8 @@ class TeamCityDependenciesPlugin implements Plugin { private Object addDependency(DependencyDescriptor descriptor) { processors.each { it.addDependency(descriptor) } - return descriptor.toDependencyNotation() + def notation = descriptor.toDependencyNotation() + LogFacade.debug("Dependency generated: $notation") + return notation } } diff --git a/src/main/groovy/com.github.jk1.tcdeps/processing/DepedencyPinner.groovy b/src/main/groovy/com.github.jk1.tcdeps/processing/DepedencyPinner.groovy index e86fb53..c79ed00 100644 --- a/src/main/groovy/com.github.jk1.tcdeps/processing/DepedencyPinner.groovy +++ b/src/main/groovy/com.github.jk1.tcdeps/processing/DepedencyPinner.groovy @@ -1,5 +1,6 @@ package com.github.jk1.tcdeps.processing +import com.github.jk1.tcdeps.LogFacade import com.github.jk1.tcdeps.PluginConfiguration import org.gradle.api.GradleException @@ -22,12 +23,15 @@ class DepedencyPinner implements DependencyProcessor { dependencies.findAll { !it.version.changing }.collectAll { "$config.url/httpAuth/app/rest/builds/buildType:$it.buildTypeId,number:$it.version.version/pin" }.unique().each { pinBuild(it) } + } else { + LogFacade.debug("Dependency pinning is disabled") } } private def pinBuild(String url) { String response = "No response recorded. Rerun with --stacktrace to see an exception." try { + LogFacade.debug("Pinning the build: $url") HttpURLConnection connection = url.toURL().openConnection() connection.setDoOutput(true); connection.setRequestMethod("PUT"); @@ -40,7 +44,7 @@ class DepedencyPinner implements DependencyProcessor { if (config.stopBuildOnFail) { throw new GradleException(message, e) } else { - project.logger.warn(message, e) + LogFacade.warn(message, e) } } } diff --git a/src/main/groovy/com.github.jk1.tcdeps/processing/RepositoryBuilder.groovy b/src/main/groovy/com.github.jk1.tcdeps/processing/RepositoryBuilder.groovy index 9db697f..4f98628 100644 --- a/src/main/groovy/com.github.jk1.tcdeps/processing/RepositoryBuilder.groovy +++ b/src/main/groovy/com.github.jk1.tcdeps/processing/RepositoryBuilder.groovy @@ -1,5 +1,6 @@ package com.github.jk1.tcdeps.processing +import com.github.jk1.tcdeps.LogFacade import com.github.jk1.tcdeps.model.DependencyDescriptor import org.gradle.api.artifacts.repositories.IvyArtifactRepository @@ -10,24 +11,44 @@ import org.gradle.api.artifacts.repositories.IvyArtifactRepository class RepositoryBuilder implements DependencyProcessor { private final TC_DOWNLOAD_PATH = 'guestAuth/repository/download' + private IvyArtifactRepository lastAdded + private patterns = new ArrayList() + + RepositoryBuilder() { + // default pattern for artifacts without a path + patterns.add('[module]/[revision]/[artifact](.[ext])') + } @Override - def addDependency(DependencyDescriptor dependecy) { + def addDependency(DependencyDescriptor dependency) { project.repositories.remove(lastAdded) - dependencies.add(dependecy) - def patterns = dependencies - .findAll { it.artifactDescriptor.hasPath() } - .collectAll { "[module]/[revision]/${it.artifactDescriptor.path}[artifact](.[ext])" } + dependencies.add(dependency) + if (dependency.artifactDescriptor.hasPath()){ + patterns.add("[module]/[revision]/${dependency.artifactDescriptor.path}[artifact](.[ext])") + } lastAdded = project.repositories.ivy { url "${project.teamcityServer.url}/$TC_DOWNLOAD_PATH" layout "pattern", { ivy '[module]/[revision]/teamcity-ivy.xml' - artifact '[module]/[revision]/[artifact](.[ext])' patterns.each { pattern -> artifact pattern } } } } + + @Override + def process() { + LogFacade.debug('Ivy repository descriptor:') + LogFacade.debug('ivy {') + LogFacade.debug(" url ${lastAdded.url}") + LogFacade.debug(" layout 'pattern', {") + LogFacade.debug(" ivy '[module]/[revision]/teamcity-ivy.xml'") + patterns.each { + pattern -> LogFacade.debug(" artifact $pattern") + } + LogFacade.debug(' }') + LogFacade.debug('}') + } }