Skip to content

Commit

Permalink
debug logging added
Browse files Browse the repository at this point in the history
  • Loading branch information
jk1 committed Mar 2, 2015
1 parent 427e784 commit 9c33675
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/main/groovy/com.github.jk1.tcdeps/LogFacade.groovy
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TeamCityDependenciesPlugin implements Plugin<Project> {

@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 ->
Expand All @@ -30,6 +31,8 @@ class TeamCityDependenciesPlugin implements Plugin<Project> {

private Object addDependency(DependencyDescriptor descriptor) {
processors.each { it.addDependency(descriptor) }
return descriptor.toDependencyNotation()
def notation = descriptor.toDependencyNotation()
LogFacade.debug("Dependency generated: $notation")
return notation
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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");
Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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<String>()

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('}')
}
}

0 comments on commit 9c33675

Please sign in to comment.