Merge branch '1.5.x'
commit
98a3ae9ac4
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2016 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.test.autoconfigure.orm.jpa;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||||
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration tests for {@link AutoConfigureTestDatabase} when there are multiple
|
||||||
|
* datasources.
|
||||||
|
*
|
||||||
|
* @author Greg Potter
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@DataJpaTest
|
||||||
|
@AutoConfigureTestDatabase
|
||||||
|
public class AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TestEntityManager entities;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ExampleRepository repository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRepository() throws Exception {
|
||||||
|
this.entities.persist(new ExampleEntity("boot", "124"));
|
||||||
|
this.entities.flush();
|
||||||
|
ExampleEntity found = this.repository.findByReference("124");
|
||||||
|
assertThat(found.getName()).isEqualTo("boot");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void replacesDefinedDataSourceWithExplicit() throws Exception {
|
||||||
|
// Look that the datasource is replaced with an H2 DB.
|
||||||
|
String product = this.dataSource.getConnection().getMetaData()
|
||||||
|
.getDatabaseProductName();
|
||||||
|
assertThat(product).startsWith("H2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public DataSource dataSource() {
|
||||||
|
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||||
|
.setType(EmbeddedDatabaseType.HSQL);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSource secondaryDataSource() {
|
||||||
|
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||||
|
.setType(EmbeddedDatabaseType.HSQL);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2015 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.loader.tools;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strategy for creating instances of {@link Layout}.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface LayoutFactory {
|
|
||||||
|
|
||||||
Layout getLayout();
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2015 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.loader.tools;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Archive layout types.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public enum LayoutType {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Jar Layout.
|
|
||||||
*/
|
|
||||||
JAR(new Layouts.Jar()),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* War Layout.
|
|
||||||
*/
|
|
||||||
WAR(new Layouts.War()),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zip Layout.
|
|
||||||
*/
|
|
||||||
ZIP(new Layouts.Expanded()),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dir Layout.
|
|
||||||
*/
|
|
||||||
DIR(new Layouts.Expanded()),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module Layout.
|
|
||||||
*/
|
|
||||||
MODULE(new Layouts.Module()),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* No Layout.
|
|
||||||
*/
|
|
||||||
NONE(new Layouts.None());
|
|
||||||
|
|
||||||
private static Map<String, Layout> customTypes;
|
|
||||||
|
|
||||||
private final Layout layout;
|
|
||||||
|
|
||||||
public Layout layout() {
|
|
||||||
return this.layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
LayoutType(Layout layout) {
|
|
||||||
this.layout = layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Layout layout(String value) {
|
|
||||||
try {
|
|
||||||
return valueOf(value).layout();
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
if (customTypes == null) {
|
|
||||||
customTypes = new HashMap<String, Layout>();
|
|
||||||
lookupCustomTypes();
|
|
||||||
}
|
|
||||||
Layout layout = customTypes.get(value);
|
|
||||||
if (layout == null) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Cannot resolve custom layout type: " + value);
|
|
||||||
}
|
|
||||||
return layout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void lookupCustomTypes() {
|
|
||||||
ClassLoader classLoader = LayoutType.class.getClassLoader();
|
|
||||||
List<LayoutFactory> factories = SpringFactoriesLoader
|
|
||||||
.loadFactories(LayoutFactory.class, classLoader);
|
|
||||||
for (LayoutFactory factory : factories) {
|
|
||||||
customTypes.put(factory.getName(), factory.getLayout());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2015 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.loader.tools;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class LayoutTypeTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void standardType() {
|
|
||||||
assertThat(LayoutType.layout("DIR"))
|
|
||||||
.isEqualTo(LayoutType.valueOf("DIR").layout());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void customType() {
|
|
||||||
assertThat(LayoutType.layout("CUSTOM")).isNotNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TestLayoutFactory implements LayoutFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Layout getLayout() {
|
|
||||||
return new Layouts.Jar();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "CUSTOM";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
org.springframework.boot.loader.tools.LayoutFactory=\
|
|
||||||
org.springframework.boot.loader.tools.LayoutTypeTests.TestLayoutFactory
|
|
@ -1,57 +0,0 @@
|
|||||||
-----
|
|
||||||
Use a custom layout
|
|
||||||
-----
|
|
||||||
Dave Syer
|
|
||||||
-----
|
|
||||||
2016-10-30
|
|
||||||
-----
|
|
||||||
|
|
||||||
Spring Boot repackages the jar file for this project using a custom
|
|
||||||
layout defined in the additional jar file, provided as a dependency
|
|
||||||
to the build plugin:
|
|
||||||
|
|
||||||
---
|
|
||||||
<project>
|
|
||||||
...
|
|
||||||
<build>
|
|
||||||
...
|
|
||||||
<plugins>
|
|
||||||
...
|
|
||||||
<plugin>
|
|
||||||
<groupId>${project.groupId}</groupId>
|
|
||||||
<artifactId>${project.artifactId}</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<layout>CUSTOM</layout>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.example</groupId>
|
|
||||||
<artifactId>custom-layout</artifactId>
|
|
||||||
<version>0.0.1.BUILD-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
...
|
|
||||||
</plugin>
|
|
||||||
...
|
|
||||||
</plugins>
|
|
||||||
...
|
|
||||||
</build>
|
|
||||||
...
|
|
||||||
</project>
|
|
||||||
---
|
|
||||||
|
|
||||||
The layout is provided as an implementation of <<LayoutFactory>>
|
|
||||||
(from spring-boot-loader-tools) listed in
|
|
||||||
<<META-INF/spring-factories>> inside the <<custom-layout>> jar.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2016 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.context.embedded.tomcat;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TLD Skip Patterns used by Spring Boot.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
final class TldSkipPatterns {
|
||||||
|
|
||||||
|
private static final Set<String> TOMCAT;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Same as Tomcat
|
||||||
|
Set<String> patterns = new LinkedHashSet<String>();
|
||||||
|
patterns.add("ant-*.jar");
|
||||||
|
patterns.add("aspectj*.jar");
|
||||||
|
patterns.add("commons-beanutils*.jar");
|
||||||
|
patterns.add("commons-codec*.jar");
|
||||||
|
patterns.add("commons-collections*.jar");
|
||||||
|
patterns.add("commons-dbcp*.jar");
|
||||||
|
patterns.add("commons-digester*.jar");
|
||||||
|
patterns.add("commons-fileupload*.jar");
|
||||||
|
patterns.add("commons-httpclient*.jar");
|
||||||
|
patterns.add("commons-io*.jar");
|
||||||
|
patterns.add("commons-lang*.jar");
|
||||||
|
patterns.add("commons-logging*.jar");
|
||||||
|
patterns.add("commons-math*.jar");
|
||||||
|
patterns.add("commons-pool*.jar");
|
||||||
|
patterns.add("geronimo-spec-jaxrpc*.jar");
|
||||||
|
patterns.add("h2*.jar");
|
||||||
|
patterns.add("hamcrest*.jar");
|
||||||
|
patterns.add("hibernate*.jar");
|
||||||
|
patterns.add("jmx*.jar");
|
||||||
|
patterns.add("jmx-tools-*.jar");
|
||||||
|
patterns.add("jta*.jar");
|
||||||
|
patterns.add("junit-*.jar");
|
||||||
|
patterns.add("httpclient*.jar");
|
||||||
|
patterns.add("log4j-*.jar");
|
||||||
|
patterns.add("mail*.jar");
|
||||||
|
patterns.add("org.hamcrest*.jar");
|
||||||
|
patterns.add("slf4j*.jar");
|
||||||
|
patterns.add("tomcat-embed-core-*.jar");
|
||||||
|
patterns.add("tomcat-embed-logging-*.jar");
|
||||||
|
patterns.add("tomcat-jdbc-*.jar");
|
||||||
|
patterns.add("tomcat-juli-*.jar");
|
||||||
|
patterns.add("tools.jar");
|
||||||
|
patterns.add("wsdl4j*.jar");
|
||||||
|
patterns.add("xercesImpl-*.jar");
|
||||||
|
patterns.add("xmlParserAPIs-*.jar");
|
||||||
|
patterns.add("xml-apis-*.jar");
|
||||||
|
TOMCAT = Collections.unmodifiableSet(patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Set<String> ADDITIONAL;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Additional typical for Spring Boot applications
|
||||||
|
Set<String> patterns = new LinkedHashSet<String>();
|
||||||
|
patterns.add("antlr-*.jar");
|
||||||
|
patterns.add("aopalliance-*.jar");
|
||||||
|
patterns.add("aspectjrt-*.jar");
|
||||||
|
patterns.add("aspectjweaver-*.jar");
|
||||||
|
patterns.add("classmate-*.jar");
|
||||||
|
patterns.add("dom4j-*.jar");
|
||||||
|
patterns.add("ecj-*.jar");
|
||||||
|
patterns.add("ehcache-core-*.jar");
|
||||||
|
patterns.add("hibernate-core-*.jar");
|
||||||
|
patterns.add("hibernate-commons-annotations-*.jar");
|
||||||
|
patterns.add("hibernate-entitymanager-*.jar");
|
||||||
|
patterns.add("hibernate-jpa-2.1-api-*.jar");
|
||||||
|
patterns.add("hibernate-validator-*.jar");
|
||||||
|
patterns.add("hsqldb-*.jar");
|
||||||
|
patterns.add("jackson-annotations-*.jar");
|
||||||
|
patterns.add("jackson-core-*.jar");
|
||||||
|
patterns.add("jackson-databind-*.jar");
|
||||||
|
patterns.add("jandex-*.jar");
|
||||||
|
patterns.add("javassist-*.jar");
|
||||||
|
patterns.add("jboss-logging-*.jar");
|
||||||
|
patterns.add("jboss-transaction-api_*.jar");
|
||||||
|
patterns.add("jcl-over-slf4j-*.jar");
|
||||||
|
patterns.add("jdom-*.jar");
|
||||||
|
patterns.add("jul-to-slf4j-*.jar");
|
||||||
|
patterns.add("log4j-over-slf4j-*.jar");
|
||||||
|
patterns.add("logback-classic-*.jar");
|
||||||
|
patterns.add("logback-core-*.jar");
|
||||||
|
patterns.add("rome-*.jar");
|
||||||
|
patterns.add("slf4j-api-*.jar");
|
||||||
|
patterns.add("spring-aop-*.jar");
|
||||||
|
patterns.add("spring-aspects-*.jar");
|
||||||
|
patterns.add("spring-beans-*.jar");
|
||||||
|
patterns.add("spring-boot-*.jar");
|
||||||
|
patterns.add("spring-core-*.jar");
|
||||||
|
patterns.add("spring-context-*.jar");
|
||||||
|
patterns.add("spring-data-*.jar");
|
||||||
|
patterns.add("spring-expression-*.jar");
|
||||||
|
patterns.add("spring-jdbc-*.jar,");
|
||||||
|
patterns.add("spring-orm-*.jar");
|
||||||
|
patterns.add("spring-oxm-*.jar");
|
||||||
|
patterns.add("spring-tx-*.jar");
|
||||||
|
patterns.add("snakeyaml-*.jar");
|
||||||
|
patterns.add("tomcat-embed-el-*.jar");
|
||||||
|
patterns.add("validation-api-*.jar");
|
||||||
|
patterns.add("xml-apis-*.jar");
|
||||||
|
ADDITIONAL = Collections.unmodifiableSet(patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final Set<String> DEFAULT;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Set<String> patterns = new LinkedHashSet<String>();
|
||||||
|
patterns.addAll(TOMCAT);
|
||||||
|
patterns.addAll(ADDITIONAL);
|
||||||
|
DEFAULT = Collections.unmodifiableSet(patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TldSkipPatterns() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue