Merge branch '1.2.x'
commit
0335053139
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.autoconfigure.groovy.template;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer;
|
||||
import org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver;
|
||||
|
||||
import groovy.text.markup.MarkupTemplateEngine;
|
||||
import groovy.text.markup.TemplateConfiguration;
|
||||
import groovy.text.markup.TemplateResolver;
|
||||
|
||||
/**
|
||||
* A custom {@link groovy.text.markup.TemplateResolver template resolver} which resolves
|
||||
* templates using the locale found in the thread locale. This resolver ignores the
|
||||
* template engine configuration locale.
|
||||
*
|
||||
* @author Cédric Champeau
|
||||
* @since 1.1.0
|
||||
* @deprecated since 1.2 in favor of Spring 4.1's {@link GroovyMarkupViewResolver} and
|
||||
* {@link GroovyMarkupConfigurer}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class GroovyTemplateResolver implements TemplateResolver {
|
||||
|
||||
private ClassLoader templateClassLoader;
|
||||
|
||||
@Override
|
||||
public void configure(final ClassLoader templateClassLoader,
|
||||
final TemplateConfiguration configuration) {
|
||||
this.templateClassLoader = templateClassLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL resolveTemplate(final String templatePath) throws IOException {
|
||||
MarkupTemplateEngine.TemplateResource templateResource = MarkupTemplateEngine.TemplateResource
|
||||
.parse(templatePath);
|
||||
URL resource = this.templateClassLoader.getResource(templateResource.withLocale(
|
||||
LocaleContextHolder.getLocale().toString().replace("-", "_")).toString());
|
||||
if (resource == null) {
|
||||
// no resource found with the default locale, try without any locale
|
||||
resource = this.templateClassLoader.getResource(templateResource.withLocale(
|
||||
null).toString());
|
||||
}
|
||||
if (resource == null) {
|
||||
throw new IOException("Unable to load template:" + templatePath);
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.dependency.tools;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* {@link Dependencies} used by various spring boot tools. Provides programmatic access to
|
||||
* 'spring-boot-dependencies' and can also support user defined version managed
|
||||
* dependencies.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @see Dependency
|
||||
*/
|
||||
public abstract class ManagedDependencies implements Dependencies {
|
||||
|
||||
// NOTE: Take care if changing the API of this class, it is used by the third-party
|
||||
// Gretty tool (https://github.com/akhikhl/gretty)
|
||||
|
||||
private final Dependencies delegate;
|
||||
|
||||
ManagedDependencies(Dependencies delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the 'spring-boot-dependencies' POM version.
|
||||
* @return the version
|
||||
* @deprecated since 1.1.0 in favor of {@link #getSpringBootVersion()}
|
||||
*/
|
||||
@Deprecated
|
||||
public String getVersion() {
|
||||
return getSpringBootVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the 'spring-boot-dependencies' POM version.
|
||||
* @return the spring boot version
|
||||
*/
|
||||
public String getSpringBootVersion() {
|
||||
Dependency dependency = find("org.springframework.boot", "spring-boot");
|
||||
return (dependency == null ? null : dependency.getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single dependency for the given group and artifact IDs.
|
||||
* @param groupId the group ID
|
||||
* @param artifactId the artifact ID
|
||||
* @return a {@link Dependency} or {@code null}
|
||||
*/
|
||||
@Override
|
||||
public Dependency find(String groupId, String artifactId) {
|
||||
return this.delegate.find(groupId, artifactId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single dependency for the artifact IDs.
|
||||
* @param artifactId the artifact ID
|
||||
* @return a {@link Dependency} or {@code null}
|
||||
*/
|
||||
@Override
|
||||
public Dependency find(String artifactId) {
|
||||
return this.delegate.find(artifactId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an {@link Iterator} over all managed {@link Dependency Dependencies}.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Dependency> iterator() {
|
||||
return this.delegate.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return spring-boot managed dependencies.
|
||||
* @return The dependencies.
|
||||
* @see #get(Collection)
|
||||
*/
|
||||
public static ManagedDependencies get() {
|
||||
return get(Collections.<Dependencies>emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return spring-boot managed dependencies with optional version managed dependencies.
|
||||
* @param versionManagedDependencies a collection of {@link Dependencies} that take
|
||||
* precedence over the {@literal spring-boot-dependencies}.
|
||||
* @return the dependencies
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public static ManagedDependencies get(
|
||||
Collection<Dependencies> versionManagedDependencies) {
|
||||
return new ManagedDependencies(new ManagedDependenciesDelegate(
|
||||
versionManagedDependencies)) {
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.dependency.tools;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ManagedDependenciesDelegate}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ManagedDependenciesDelegateTests {
|
||||
|
||||
private ManagedDependenciesDelegate dependencies;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
PropertiesFileDependencies root = new PropertiesFileDependencies(getClass()
|
||||
.getResourceAsStream("external.properties"));
|
||||
PropertiesFileDependencies extra = new PropertiesFileDependencies(getClass()
|
||||
.getResourceAsStream("additional-external.properties"));
|
||||
this.dependencies = new ManagedDependenciesDelegate(root,
|
||||
Collections.<Dependencies>singleton(extra));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extra() throws Exception {
|
||||
assertThat(this.dependencies.find("org.sample", "sample03").toString(),
|
||||
equalTo("org.sample:sample03:2.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void override() throws Exception {
|
||||
assertThat(this.dependencies.find("org.sample", "sample02").toString(),
|
||||
equalTo("org.sample:sample02:2.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iterator() throws Exception {
|
||||
Iterator<Dependency> iterator = this.dependencies.iterator();
|
||||
assertThat(iterator.next().toString(), equalTo("org.sample:sample01:1.0.0"));
|
||||
assertThat(iterator.next().toString(), equalTo("org.sample:sample02:2.0.0"));
|
||||
assertThat(iterator.next().toString(),
|
||||
equalTo("org.springframework.boot:spring-boot:1.0.0.BUILD-SNAPSHOT"));
|
||||
assertThat(iterator.next().toString(), equalTo("org.sample:sample03:2.0.0"));
|
||||
assertThat(iterator.hasNext(), equalTo(false));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue