Permalink
Browse files

Build with Gradle

Convert the build system from Gradle to Maven. This has had the side-effect of
forcing some code changes to be made:

Some test code has been changed to cope with Gradle's use of <project>/build
(on the command line) and <project>/bin (in Eclipse) for build output, as
opposed to Maven's use of <project>/target

The move to Gradle has also moved code coverage from Clover to Jacoco as, in
a Gradle environment, Jacoco's Sonar integration is better. There are some
differences between the coverage numbers reported by Jacoco and Clover. As
a result, some code has been reworked to improve its test coverage.
  • Loading branch information...
1 parent 92f2487 commit b1d41ff476121ff5eba1ae9a680e627d69c199a3 @wilkinsona wilkinsona committed Oct 22, 2012
Showing with 592 additions and 1,427 deletions.
  1. +4 −2 .gitignore
  2. +5 −0 analyze/build.gradle
  3. +1 −1 .../test/java/org/springframework/migrationanalyzer/analyze/fs/support/DirectoryFileSystemTests.java
  4. BIN ...t/resources/classpath-scanner/classes/org/springframework/migrationanalyzer/TargetInterface.class
  5. BIN ...es/classpath-scanner/classes/org/springframework/migrationanalyzer/internal/AbstractExample.class
  6. BIN .../resources/classpath-scanner/classes/org/springframework/migrationanalyzer/internal/Example.class
  7. BIN ...sources/classpath-scanner/classes/org/springframework/migrationanalyzer/internal/SubExample.class
  8. BIN ...lasspath-scanner/classes/org/springframework/migrationanalyzer/internal/SubInterfaceExample.class
  9. BIN ...classpath-scanner/classes/org/springframework/migrationanalyzer/internal/SubTargetInterface.class
  10. BIN analyze/src/test/resources/classpath-scanner/classpath-scanner.jar
  11. +133 −0 build.gradle
  12. +7 −0 command-line/build.gradle
  13. +23 −2 ...ne/src/main/java/org/springframework/migrationanalyzer/commandline/AbstractMigrationAnalysis.java
  14. +3 −24 command-line/src/main/java/org/springframework/migrationanalyzer/commandline/MigrationAnalysis.java
  15. +14 −22 ...c/test/java/org/springframework/migrationanalyzer/commandline/AbstraktMigrationAnalysisTests.java
  16. +10 −0 contributions/build.gradle
  17. +1 −4 ...rg/springframework/migrationanalyzer/contributions/apiusage/ApiUsageDetectingAsmVisitorTests.java
  18. +3 −5 ...pringframework/migrationanalyzer/contributions/bytecode/DelegatingByteCodeEntryAnalyzerTests.java
  19. +1 −3 ...nalyzer/contributions/transactions/ProgrammaticDataSourceTransactionDemarcationDetectorTests.java
  20. +2 −6 ...rationanalyzer/contributions/transactions/ProgrammaticJtaTransactionDemarcationDetectorTests.java
  21. +13 −0 gradle.properties
  22. BIN gradle/wrapper/gradle-wrapper.jar
  23. +6 −0 gradle/wrapper/gradle-wrapper.properties
  24. +164 −0 gradlew
  25. +90 −0 gradlew.bat
  26. +0 −86 packaging/pom.xml
  27. +0 −65 packaging/src/main/assembly/assembly.xml
  28. +4 −0 render/build.gradle
  29. +2 −2 ...c/test/java/org/springframework/migrationanalyzer/render/support/html/FileWriterFactoryTests.java
  30. +8 −0 settings.gradle
  31. 0 {packaging → }/src/main/resources/bin/migration-analysis.bat
  32. 0 {packaging → }/src/main/resources/bin/migration-analysis.sh
  33. 0 {packaging → }/src/main/resources/config/logback.xml
  34. +8 −0 test-apps/classpath-scanner/build.gradle
  35. +0 −52 test-apps/classpath-scanner/pom.xml
  36. 0 test-apps/classpath-scanner/src/main/java/.gitignore
  37. +0 −25 ...classpath-scanner/src/main/java/org/springframework/migrationanalyzer/internal/HiddenExample.java
  38. 0 test-apps/classpath-scanner/src/main/resources/.gitignore
  39. 0 test-apps/classpath-scanner/src/test/java/.gitignore
  40. 0 test-apps/classpath-scanner/src/test/resources/.gitignore
  41. +41 −0 user-guide/build.gradle
  42. +0 −72 user-guide/pom.xml
  43. +0 −35 user-guide/src/docbkx/resources/css/highlight.css
  44. +0 −96 user-guide/src/docbkx/resources/css/html.css
  45. BIN user-guide/src/docbkx/resources/images/admons/blank.png
  46. BIN user-guide/src/docbkx/resources/images/admons/caution.gif
  47. BIN user-guide/src/docbkx/resources/images/admons/caution.png
  48. BIN user-guide/src/docbkx/resources/images/admons/caution.tif
  49. BIN user-guide/src/docbkx/resources/images/admons/draft.png
  50. BIN user-guide/src/docbkx/resources/images/admons/home.gif
  51. BIN user-guide/src/docbkx/resources/images/admons/home.png
  52. BIN user-guide/src/docbkx/resources/images/admons/important.gif
  53. BIN user-guide/src/docbkx/resources/images/admons/important.png
  54. BIN user-guide/src/docbkx/resources/images/admons/important.tif
  55. BIN user-guide/src/docbkx/resources/images/admons/next.gif
  56. BIN user-guide/src/docbkx/resources/images/admons/next.png
  57. BIN user-guide/src/docbkx/resources/images/admons/note.gif
  58. BIN user-guide/src/docbkx/resources/images/admons/note.png
  59. BIN user-guide/src/docbkx/resources/images/admons/note.tif
  60. BIN user-guide/src/docbkx/resources/images/admons/prev.gif
  61. BIN user-guide/src/docbkx/resources/images/admons/prev.png
  62. BIN user-guide/src/docbkx/resources/images/admons/tip.gif
  63. BIN user-guide/src/docbkx/resources/images/admons/tip.png
  64. BIN user-guide/src/docbkx/resources/images/admons/tip.tif
  65. BIN user-guide/src/docbkx/resources/images/admons/toc-blank.png
  66. BIN user-guide/src/docbkx/resources/images/admons/toc-minus.png
  67. BIN user-guide/src/docbkx/resources/images/admons/toc-plus.png
  68. BIN user-guide/src/docbkx/resources/images/admons/up.gif
  69. BIN user-guide/src/docbkx/resources/images/admons/up.png
  70. BIN user-guide/src/docbkx/resources/images/admons/warning.gif
  71. BIN user-guide/src/docbkx/resources/images/admons/warning.png
  72. BIN user-guide/src/docbkx/resources/images/admons/warning.tif
  73. +0 −449 user-guide/src/docbkx/resources/xsl/fopdf.xsl
  74. +0 −44 user-guide/src/docbkx/resources/xsl/highlight-fo.xsl
  75. +0 −42 user-guide/src/docbkx/resources/xsl/highlight.xsl
  76. +0 −107 user-guide/src/docbkx/resources/xsl/html.xsl
  77. +0 −221 user-guide/src/docbkx/resources/xsl/html_chunk.xsl
  78. +0 −15 user-guide/src/main/assembly/assembly.xml
  79. BIN user-guide/src/{docbkx/resources → reference/docbook}/images/logo.png
  80. BIN user-guide/src/{docbkx/resources → reference/docbook}/images/report.png
  81. +42 −40 user-guide/src/{docbkx → reference/docbook}/index.xml
  82. +3 −3 util/src/test/java/org/springframework/migrationanalyzer/util/IoUtilsTests.java
  83. +4 −4 util/src/test/java/org/springframework/migrationanalyzer/util/ZipUtilsTests.java
View
@@ -1,6 +1,8 @@
-target
+build
+bin
.classpath
.freemarker-ide.xml
.project
.settings
-.springBeans
+.springBeans
+.gradle
View
@@ -0,0 +1,5 @@
+dependencies {
+ compile project(':util')
+ compile "org.springframework:spring-core:$springVersion"
+ compile "org.springframework:spring-context:$springVersion"
+}
@@ -72,7 +72,7 @@ public void toStringProvidesAbsolutePathOfRoot() {
@Test
public void cleanup() throws IOException {
- File root = new File("target/directory-file-system");
+ File root = new File("build/directory-file-system");
root.mkdirs();
File content = new File(root, "content");
content.createNewFile();
View
@@ -0,0 +1,133 @@
+configure(allprojects) {
+ group = 'org.springframework.migrationanalyzer'
+}
+
+subprojects { project ->
+ apply plugin: 'eclipse'
+ if (project.name != 'user-guide') {
+
+ apply plugin: 'java'
+
+ repositories {
+ mavenCentral()
+ }
+
+ configurations {
+ jacoco
+ }
+
+ dependencies {
+ compile "org.slf4j:slf4j-api:$slf4jVersion"
+ testCompile "junit:junit:4.8.2"
+ testCompile "org.mockito:mockito-core:$mockitoVersion"
+ testCompile "org.slf4j:slf4j-simple:$slf4jVersion"
+ jacoco "org.jacoco:org.jacoco.agent:$jacocoVersion:runtime"
+ }
+
+ test {
+ jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=org.springframework.migrationanalyzer.*"
+ }
+ }
+}
+
+ext {
+ distRoot = "${project.name}-${project.version}"
+}
+
+apply plugin: "sonar"
+
+sonar {
+
+ server {
+ if (rootProject.hasProperty('sonarHostUrl')) {
+ url = rootProject.sonarHostUrl
+ }
+ }
+
+ database {
+ if (rootProject.hasProperty('sonarJdbcUrl')) {
+ url = rootProject.sonarJdbcUrl
+ }
+ if (rootProject.hasProperty('sonarJdbcDriver')) {
+ driverClassName = rootProject.sonarJdbcDriver
+ }
+ if (rootProject.hasProperty('sonarJdbcUsername')) {
+ username = rootProject.sonarJdbcUsername
+ }
+ if (rootProject.hasProperty('sonarJdbcPassword')) {
+ password = rootProject.sonarJdbcPassword
+ }
+ }
+
+ project {
+ dynamicAnalysis = 'reuseReports'
+ withProjectProperties { props ->
+ props['sonar.core.codeCoveragePlugin'] = 'jacoco'
+ props['sonar.jacoco.reportPath'] = "${buildDir.name}/jacoco.exec"
+ }
+ }
+
+ logger.info("Sonar parameters used: server.url='${server.url}'; database.url='${database.url}'; database.driverClassName='${database.driverClassName}'; database.username='${database.username}'")
+}
+
+configure(rootProject) {
+
+ apply plugin: 'base'
+
+ configurations {
+ lib
+ }
+
+ dependencies {
+ lib "ch.qos.logback:logback-classic:$logbackVersion"
+ }
+
+ repositories {
+ mavenCentral()
+ }
+
+ task distZip(type: Zip) { zipTask ->
+ gradle.taskGraph.whenReady { taskGraph ->
+ if (taskGraph.hasTask(":${zipTask.name}")) {
+ def projectNames = rootProject.subprojects*.name
+ def artifacts = new HashSet()
+ subprojects.each { subproject ->
+ if (subproject.name != 'user-guide') {
+ subproject.configurations.runtime.resolvedConfiguration.resolvedArtifacts.each { artifact ->
+ def dependency = artifact.moduleVersion.id
+ if (!projectNames.contains(dependency.name)) {
+ artifacts << artifact.file
+ }
+ }
+ }
+ }
+ configurations.lib.each { artifact ->
+ artifacts << artifact
+ }
+ zipTask.from(artifacts) {
+ into "${distRoot}/lib"
+ }
+ }
+ }
+ subprojects.each { subproject ->
+ if (subproject.name != 'user-guide') {
+ into ("${distRoot}/dist") {
+ from subproject.jar
+ }
+ }
+ }
+ from('src/main/resources') {
+ into "${distRoot}"
+ }
+ }
+
+ task dist(dependsOn: distZip)
+
+ artifacts {
+ distZip
+ }
+
+ task wrapper(type: Wrapper) {
+ gradleVersion = '1.2'
+ }
+}
@@ -0,0 +1,7 @@
+dependencies {
+ compile project(':analyze')
+ compile project(':render')
+ compile "commons-cli:commons-cli:$commonsCliVersion"
+ compile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
+ compile "org.springframework:spring-context:$springVersion"
+}
@@ -26,6 +26,9 @@
import org.apache.commons.cli.PosixParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.context.ConfigurableApplicationContext;
abstract class AbstractMigrationAnalysis {
@@ -54,7 +57,11 @@ final void run(String[] args) {
String inputPath = getInputPath(commandLine);
try {
- getExecutor(new Configuration(inputPath, outputPath, outputType, excludes)).execute();
+ ConfigurableApplicationContext applicationContext = getApplicationContext();
+ applicationContext.addBeanFactoryPostProcessor(new ConfigurationRegisteringBeanFactoryPostProcessor(new Configuration(inputPath,
+ outputPath, outputType, excludes)));
+ applicationContext.refresh();
+ applicationContext.getBean(MigrationAnalysisExecutor.class).execute();
} catch (RuntimeException re) {
this.logger.error("A failure occurred. Please see earlier output for details.");
exit(-1);
@@ -102,7 +109,21 @@ private String getInputPath(CommandLine commandLine) throws ParseException {
}
}
- protected abstract MigrationAnalysisExecutor getExecutor(Configuration configuration);
+ protected abstract ConfigurableApplicationContext getApplicationContext();
protected abstract void exit(int code);
+
+ private static final class ConfigurationRegisteringBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
+
+ private final Configuration configuration;
+
+ private ConfigurationRegisteringBeanFactoryPostProcessor(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
+ beanFactory.registerSingleton("configuration", this.configuration);
+ }
+ }
}
@@ -16,10 +16,7 @@
package org.springframework.migrationanalyzer.commandline;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
@@ -32,8 +29,6 @@
*/
public final class MigrationAnalysis extends AbstractMigrationAnalysis {
- private final Logger logger = LoggerFactory.getLogger(getClass());
-
/**
* Main method for invoking the application
*
@@ -44,24 +39,8 @@ public static void main(String[] args) {
}
@Override
- protected MigrationAnalysisExecutor getExecutor(final Configuration configuration) {
- try {
- ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
- new String[] { "META-INF/spring/application-context.xml" }, false);
- applicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
-
- @Override
- public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
- beanFactory.registerSingleton("configuration", configuration);
-
- }
- });
- applicationContext.refresh();
- return applicationContext.getBean(MigrationAnalysisExecutor.class);
- } catch (RuntimeException re) {
- this.logger.error("Failed to initialize the application context", re);
- throw re;
- }
+ protected ConfigurableApplicationContext getApplicationContext() {
+ return new ClassPathXmlApplicationContext(new String[] { "META-INF/spring/application-context.xml" }, false);
}
@Override
@@ -17,9 +17,13 @@
package org.springframework.migrationanalyzer.commandline;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import org.junit.Test;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.StaticApplicationContext;
public class AbstraktMigrationAnalysisTests {
@@ -28,7 +32,8 @@
@Test
public void execute() {
this.migrationAnalysis.run(new String[] { "test input path", "-t", "test output type" });
- assertTrue(this.migrationAnalysis.getStubExecutor().getCalled());
+ assertNotNull(this.migrationAnalysis.applicationContext.getBean(Configuration.class));
+ verify(this.migrationAnalysis.executor).execute();
}
@Test
@@ -39,13 +44,14 @@ public void executeParseFailure() {
private static class StubMigrationAnalysis extends AbstractMigrationAnalysis {
- private final StubMigrationAnalysisExecutor executor = new StubMigrationAnalysisExecutor();
+ private final MigrationAnalysisExecutor executor = mock(MigrationAnalysisExecutor.class);
+
+ private final StaticApplicationContext applicationContext = new StaticApplicationContext();
private volatile int code;
- @Override
- protected MigrationAnalysisExecutor getExecutor(Configuration configuration) {
- return this.executor;
+ public StubMigrationAnalysis() {
+ this.applicationContext.getDefaultListableBeanFactory().registerSingleton("executor", this.executor);
}
@Override
@@ -57,23 +63,9 @@ public int getCode() {
return this.code;
}
- public StubMigrationAnalysisExecutor getStubExecutor() {
- return this.executor;
- }
-
- }
-
- private static class StubMigrationAnalysisExecutor implements MigrationAnalysisExecutor {
-
- private volatile boolean called = false;
-
@Override
- public void execute() {
- this.called = true;
- }
-
- public boolean getCalled() {
- return this.called;
+ protected ConfigurableApplicationContext getApplicationContext() {
+ return this.applicationContext;
}
}
}
View
@@ -0,0 +1,10 @@
+dependencies {
+ compile project(":analyze")
+ compile project(":render")
+ compile project(":util")
+ compile "asm:asm:$asmVersion"
+ compile "asm:asm-commons:$asmVersion"
+ compile "org.springframework:spring-context:$springVersion"
+ testCompile "org.apache.geronimo.specs:geronimo-ejb_3.0_spec:$ejb3Version"
+ testCompile "org.apache.geronimo.specs:geronimo-jta_1.1_spec:$jtaVersion"
+}
@@ -19,7 +19,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
@@ -94,9 +93,7 @@ public void annotatedType() throws FileNotFoundException, IOException {
}
private void assertApiUsage(Class<?> clazz, ApiUsageType... expectedUsage) throws FileNotFoundException, IOException {
- String fileName = "target/test-classes/" + clazz.getName().replace(".", "/") + ".class";
-
- ClassReader reader = new ClassReader(new FileInputStream(fileName));
+ ClassReader reader = new ClassReader(getClass().getResourceAsStream("/" + clazz.getName().replace(".", "/") + ".class"));
ApiUsageDetector detector = new StubApiUsageDetector();
ApiUsageDetectingAsmVisitor visitor = new ApiUsageDetectingAsmVisitor(detector);
@@ -21,8 +21,7 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.InputStream;
import org.junit.Test;
import org.springframework.migrationanalyzer.analyze.fs.FileSystemEntry;
@@ -45,10 +44,9 @@ public DelegatingByteCodeEntryAnalyzerTests() {
private final DelegatingByteCodeEntryAnalyzer analyzer = new DelegatingByteCodeEntryAnalyzer(this.factory);
@Test
- public void analyze() throws AnalysisFailedException, FileNotFoundException {
+ public void analyze() throws AnalysisFailedException {
when(this.fileSystemEntry.getName()).thenReturn("Test.class");
- FileInputStream input = new FileInputStream(
- "target/test-classes/org/springframework/migrationanalyzer/contributions/bytecode/DelegatingByteCodeEntryAnalyzerTests.class");
+ InputStream input = getClass().getResourceAsStream(getClass().getSimpleName() + ".class");
try {
when(this.fileSystemEntry.getInputStream()).thenReturn(input);
this.analyzer.analyze(this.fileSystemEntry);
Oops, something went wrong.

0 comments on commit b1d41ff

Please sign in to comment.