Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ivy: dependency graph output to console

  • Loading branch information...
commit b7e20fd8b587761e0ee5471fe6b4d1dab5b8bc71 1 parent 4cfc964
@graemerocher graemerocher authored
View
5 grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/resolve/DependencyManager.java
@@ -29,6 +29,11 @@
public interface DependencyManager {
/**
+ * Outputs the dependency graph to System.out
+ */
+ void produceReport();
+
+ /**
* Creates a copy of this dependency manager with repository configuration retained but dependencies omitted.
*
* @param buildSettings The BuildSettings
View
25 grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/resolve/IvyDependencyManager.groovy
@@ -31,7 +31,9 @@ import org.apache.ivy.core.settings.IvySettings
import org.apache.ivy.core.sort.SortEngine
import org.apache.ivy.plugins.repository.TransferListener
import org.codehaus.groovy.grails.plugins.VersionComparator
+import org.codehaus.groovy.grails.resolve.ivy.IvyGraphNode
import org.codehaus.groovy.grails.resolve.reporting.DependencyGraphRenderer
+import org.codehaus.groovy.grails.resolve.reporting.SimpleGraphRenderer
import java.util.concurrent.ConcurrentLinkedQueue
@@ -450,4 +452,27 @@ class IvyDependencyManager extends AbstractIvyDependencyManager implements Depen
Collection<Dependency> getAllDependencies(String scope) {
convertToGrailsDependencies(dependencyDescriptors.findAll { it.scope == scope })
}
+
+ @Override
+ @CompileStatic
+ void produceReport() {
+ // build scope
+ reportOnScope(BuildSettings.BUILD_SCOPE, BuildSettings.BUILD_SCOPE_DESC)
+ // provided scope
+ reportOnScope(BuildSettings.PROVIDED_SCOPE, BuildSettings.PROVIDED_SCOPE_DESC)
+ // compile scope
+ reportOnScope(BuildSettings.COMPILE_SCOPE, BuildSettings.COMPILE_SCOPE_DESC)
+ // runtime scope
+ reportOnScope(BuildSettings.RUNTIME_SCOPE, BuildSettings.RUNTIME_SCOPE_DESC)
+ // test scope
+ reportOnScope(BuildSettings.TEST_SCOPE, BuildSettings.TEST_SCOPE_DESC)
+ }
+
+ void reportOnScope(String scope, String desc) {
+ ResolveReport resolveReport = resolveDependencies(scope)
+
+ IvyGraphNode node = new IvyGraphNode(resolveReport)
+ def renderer = new SimpleGraphRenderer(scope, "$desc (total: ${resolveReport.artifacts.size()})")
+ renderer.render(node)
+ }
}
View
52 grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/resolve/ivy/IvyGraphNode.groovy
@@ -0,0 +1,52 @@
+/* Copyright 2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.codehaus.groovy.grails.resolve.ivy
+
+import groovy.transform.CompileStatic
+import org.apache.ivy.core.module.id.ModuleRevisionId
+import org.apache.ivy.core.report.ResolveReport
+import org.apache.ivy.core.resolve.IvyNode
+import org.codehaus.groovy.grails.resolve.Dependency
+import org.codehaus.groovy.grails.resolve.reporting.GraphNode
+
+/**
+ * Adapts an Ivy graph into a Grails one
+ *
+ * @author Graeme Rocher
+ * @since 2.3
+ */
+@CompileStatic
+class IvyGraphNode extends GraphNode{
+ IvyGraphNode(ResolveReport report) {
+ super(new Dependency("org.grails.internal", "root", "1.0")) // version numbers not relevant for root node / dummy object
+ createGraph(this, report.getDependencies(), report.getConfigurations())
+ }
+ void createGraph(GraphNode current, Collection<IvyNode> nodes, String[] confs) {
+ for(IvyNode node in nodes) {
+ if (node.isLoaded()) {
+
+ final ModuleRevisionId id = node.id
+ def graphNode = new GraphNode(new Dependency(id.organisation, id.name, id.revision))
+ current.children << graphNode
+
+ final Collection<IvyNode> dependencies = node.getDependencies(confs[0], confs)
+ if (dependencies) {
+ createGraph(graphNode, dependencies, confs)
+ }
+ }
+
+ }
+ }
+}
View
2  grails-plugin-hibernate/build.gradle
@@ -1,4 +1,4 @@
dependencies {
- compile project(":grails-hibernate"), project(":grails-plugin-datasource")
+ compile project(":grails-hibernate")
}
jar.appendix = 'plugin-hibernate'
View
4 scripts/DependencyReport.groovy
@@ -54,9 +54,7 @@ target(dependencyReport:"Produces a dependency report for the current Grails app
grailsConsole.addStatus "Dependency report output to [${targetDir}/index.html]"
}
- else {
- grailsSettings.dependencyManager.produceReport()
- }
+ grailsSettings.dependencyManager.produceReport()
}
setDefaultTarget(dependencyReport)
Please sign in to comment.
Something went wrong with that request. Please try again.