HHH-6937 - Process database profiles just once per build

This commit is contained in:
Steve Ebersole 2012-01-04 13:43:10 -06:00
parent 76a3ad2021
commit 959e048fd0
2 changed files with 10 additions and 10 deletions

View File

@ -75,7 +75,7 @@ public class DatabaseProfilePlugin implements Plugin<Project> {
} }
private void processStandardProfiles(Map<String, DatabaseProfile> profileMap) { private void processStandardProfiles(Map<String, DatabaseProfile> profileMap) {
final File standardDatabasesDirectory = getRootProject( project ).file( STANDARD_DATABASES_DIRECTORY ); final File standardDatabasesDirectory = project.file( STANDARD_DATABASES_DIRECTORY );
if ( standardDatabasesDirectory == null || ! standardDatabasesDirectory.exists() ) { if ( standardDatabasesDirectory == null || ! standardDatabasesDirectory.exists() ) {
log.debug( "Standard databases directory [{}] did not exist", STANDARD_DATABASES_DIRECTORY ); log.debug( "Standard databases directory [{}] did not exist", STANDARD_DATABASES_DIRECTORY );
return; return;
@ -89,10 +89,6 @@ public class DatabaseProfilePlugin implements Plugin<Project> {
processProfiles( standardDatabasesDirectory, profileMap ); processProfiles( standardDatabasesDirectory, profileMap );
} }
private Project getRootProject(Project project) {
return project.getParent() != null ? getRootProject( project.getParent() ) : project;
}
private void processProfiles(File directory, Map<String, DatabaseProfile> profileMap) { private void processProfiles(File directory, Map<String, DatabaseProfile> profileMap) {
// the directory itself is a "database directory" if it contains either: // the directory itself is a "database directory" if it contains either:
// 1) a file named 'matrix.gradle' // 1) a file named 'matrix.gradle'
@ -124,11 +120,15 @@ public class DatabaseProfilePlugin implements Plugin<Project> {
return; return;
} }
if ( profileMap.containsKey( databaseProfile.getName() ) ) { DatabaseProfile previousEntry = profileMap.put( profileName, databaseProfile );
throw new DuplicateDatabaseProfileException( "There is already a profile named " + profileName ); if ( previousEntry != null ) {
log.lifecycle(
"Found duplicate profile definitions [name={}], [{}] taking precedence over [{}]",
profileName,
databaseProfile.getDirectory().getAbsolutePath(),
previousEntry.getDirectory().getAbsolutePath()
);
} }
profileMap.put( profileName, databaseProfile );
} }
private Set<String> ignored; private Set<String> ignored;

View File

@ -71,7 +71,7 @@ public class MatrixTestingPlugin implements Plugin<Project> {
public void apply(Project project) { public void apply(Project project) {
this.project = project; this.project = project;
project.plugins.apply( DatabaseProfilePlugin ); project.rootProject.plugins.apply( DatabaseProfilePlugin );
List<MatrixNode> matrixNodes = locateMatrixNodes(); List<MatrixNode> matrixNodes = locateMatrixNodes();
if ( matrixNodes == null || matrixNodes.isEmpty() ) { if ( matrixNodes == null || matrixNodes.isEmpty() ) {
// no db profiles defined // no db profiles defined