From d75c1e4956bd8252612b20b3b3dd8088a9d1a0a6 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 16 Jul 2013 10:23:14 +0100 Subject: [PATCH] Speed up CLI tests if jar is cached locally --- .../cli/runner/SpringApplicationRunner.java | 2 +- spring-cli/src/main/resources/.gitignore | 0 .../springframework/cli/GrapesCleaner.java | 53 +++++++++++++++++++ .../cli/SampleIntegrationTests.java | 3 +- .../cli/command/ScriptCommandTests.java | 3 +- 5 files changed, 57 insertions(+), 4 deletions(-) delete mode 100644 spring-cli/src/main/resources/.gitignore create mode 100644 spring-cli/src/test/java/org/springframework/cli/GrapesCleaner.java diff --git a/spring-cli/src/main/java/org/springframework/cli/runner/SpringApplicationRunner.java b/spring-cli/src/main/java/org/springframework/cli/runner/SpringApplicationRunner.java index 30956f23c14..ade7d11b96f 100644 --- a/spring-cli/src/main/java/org/springframework/cli/runner/SpringApplicationRunner.java +++ b/spring-cli/src/main/java/org/springframework/cli/runner/SpringApplicationRunner.java @@ -131,7 +131,7 @@ public class SpringApplicationRunner { // User reflection to load and call Spring Class application = getContextClassLoader().loadClass( "org.springframework.bootstrap.SpringApplication"); - Method method = application.getMethod("runFromScript", Object[].class, + Method method = application.getMethod("run", Object[].class, String[].class); this.applicationContext = method.invoke(null, this.sources, SpringApplicationRunner.this.args); diff --git a/spring-cli/src/main/resources/.gitignore b/spring-cli/src/main/resources/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/spring-cli/src/test/java/org/springframework/cli/GrapesCleaner.java b/spring-cli/src/test/java/org/springframework/cli/GrapesCleaner.java new file mode 100644 index 00000000000..d2489705299 --- /dev/null +++ b/spring-cli/src/test/java/org/springframework/cli/GrapesCleaner.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-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.springframework.cli; + +import java.io.File; + +import org.springframework.cli.command.CleanCommand; + +/** + * @author Dave Syer + */ +public class GrapesCleaner { + + // FIXME get the version + private static final String VERSION = "0.5.0.BUILD-SNAPSHOT"; + + public static void cleanIfNecessary() throws Exception { + File installedJar = new File(getMavenRepository(), String.format( + "org/springframework/zero/spring-bootstrap/%s/spring-bootstrap-%s.jar", + VERSION, VERSION)); + File grapesJar = new File(getGrapesCache(), String.format( + "org.springframework.zero/spring-bootstrap/jars/spring-bootstrap-%s.jar", + VERSION)); + if (!VERSION.contains("SNAPSHOT") || installedJar.exists() && grapesJar.exists() + && installedJar.lastModified() <= grapesJar.lastModified()) { + return; + } + new CleanCommand().run(); + } + + private static File getMavenRepository() { + return new File(System.getProperty("user.home"), ".m2/repository"); + } + + private static File getGrapesCache() { + return new File(System.getProperty("user.home"), ".groovy/grapes"); + } + +} diff --git a/spring-cli/src/test/java/org/springframework/cli/SampleIntegrationTests.java b/spring-cli/src/test/java/org/springframework/cli/SampleIntegrationTests.java index c028c8435a7..28b9473f947 100644 --- a/spring-cli/src/test/java/org/springframework/cli/SampleIntegrationTests.java +++ b/spring-cli/src/test/java/org/springframework/cli/SampleIntegrationTests.java @@ -30,7 +30,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import org.springframework.cli.command.CleanCommand; import org.springframework.cli.command.RunCommand; import static org.junit.Assert.assertEquals; @@ -45,7 +44,7 @@ public class SampleIntegrationTests { @BeforeClass public static void cleanGrapes() throws Exception { - new CleanCommand().run("--all"); + GrapesCleaner.cleanIfNecessary(); } private RunCommand command; diff --git a/spring-cli/src/test/java/org/springframework/cli/command/ScriptCommandTests.java b/spring-cli/src/test/java/org/springframework/cli/command/ScriptCommandTests.java index 1a222f8909d..f33c215b59b 100644 --- a/spring-cli/src/test/java/org/springframework/cli/command/ScriptCommandTests.java +++ b/spring-cli/src/test/java/org/springframework/cli/command/ScriptCommandTests.java @@ -21,6 +21,7 @@ import groovy.lang.Script; import org.junit.BeforeClass; import org.junit.Test; +import org.springframework.cli.GrapesCleaner; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; @@ -37,7 +38,7 @@ public class ScriptCommandTests { @BeforeClass public static void cleanGrapes() throws Exception { - new CleanCommand().run("--all"); + GrapesCleaner.cleanIfNecessary(); } @Test(expected = IllegalStateException.class)