mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Speed up CLI tests if jar is cached locally
This commit is contained in:
parent
eba5b74910
commit
d75c1e4956
@ -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);
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user