Update CLI to use spring-boot-dependency-tools

Update `GroovyCompiler` and `AetherGrapeEngineFactory` to use the
recently added `spring-boot-dependency-tools` in favor of loading
dependency information from a generated properties file.
This commit is contained in:
Phillip Webb
2014-01-24 22:48:27 -08:00
parent ab4baa3c43
commit 49ef1cd236
15 changed files with 263 additions and 269 deletions

View File

@@ -54,8 +54,7 @@ public class GrabCommandIntegrationTests {
// Use --autoconfigure=false to limit the amount of downloaded dependencies
String output = this.cli.grab("grab.groovy", "--autoconfigure=false");
assertTrue(new File("target/repository/net/sf/jopt-simple/jopt-simple")
.isDirectory());
assertTrue(new File("target/repository/joda-time/joda-time").isDirectory());
// Should be resolved from local repository cache
assertTrue(output.contains("Downloading: file:"));
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2012-2014 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.boot.cli.compiler;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.dependency.tools.Dependency;
import org.springframework.boot.dependency.tools.ManagedDependencies;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link ManagedDependenciesArtifactCoordinatesResolver}.
*
* @author Phillip Webb
*/
public class ManagedDependenciesArtifactCoordinatesResolverTests {
private ManagedDependencies dependencies;
private ManagedDependenciesArtifactCoordinatesResolver resolver;
@Before
public void setup() {
this.dependencies = mock(ManagedDependencies.class);
given(this.dependencies.find("a1")).willReturn(new Dependency("g1", "a1", "0"));
given(this.dependencies.getVersion()).willReturn("1");
this.resolver = new ManagedDependenciesArtifactCoordinatesResolver(
this.dependencies);
}
@Test
public void getGroupIdForBootArtifact() throws Exception {
assertThat(this.resolver.getGroupId("spring-boot-something"),
equalTo("org.springframework.boot"));
verify(this.dependencies, never()).find(anyString());
}
@Test
public void getGroupIdFound() throws Exception {
assertThat(this.resolver.getGroupId("a1"), equalTo("g1"));
}
@Test
public void getGroupIdNotFound() throws Exception {
assertThat(this.resolver.getGroupId("a2"), nullValue());
}
@Test
public void getVersionForBootArtifact() throws Exception {
assertThat(this.resolver.getVersion("spring-boot-something"), equalTo("1"));
verify(this.dependencies, never()).find(anyString());
}
@Test
public void getVersionFound() throws Exception {
assertThat(this.resolver.getVersion("a1"), equalTo("0"));
}
@Test
public void getVersionNotFound() throws Exception {
assertThat(this.resolver.getVersion("a2"), nullValue());
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2012-2014 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.boot.cli.compiler.grape;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.springframework.boot.dependency.tools.Dependency;
import org.springframework.boot.dependency.tools.ManagedDependencies;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link ManagedDependenciesFactory}.
*
* @author Phillip Webb
*/
public class ManagedDependenciesFactoryTests {
@Test
public void getManagedDependencies() {
List<Dependency> dependencyList = new ArrayList<Dependency>();
dependencyList.add(new Dependency("g1", "a1", "1"));
dependencyList.add(new Dependency("g1", "a2", "1"));
ManagedDependencies dependencies = mock(ManagedDependencies.class);
given(dependencies.iterator()).willReturn(dependencyList.iterator());
ManagedDependenciesFactory factory = new ManagedDependenciesFactory(dependencies);
List<org.eclipse.aether.graph.Dependency> result = factory
.getManagedDependencies();
assertThat(result.size(), equalTo(2));
assertThat(result.get(0).toString(), equalTo("g1:a1:jar:1 (compile)"));
assertThat(result.get(1).toString(), equalTo("g1:a2:jar:1 (compile)"));
}
}