HHH-6937 - Process database profiles just once per build

This commit is contained in:
Steve Ebersole 2012-01-05 09:58:42 -06:00
parent 959e048fd0
commit 2795994b22
5 changed files with 23 additions and 20 deletions

View File

@ -36,6 +36,9 @@ import org.gradle.api.logging.Logging;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.hibernate.build.qalab.DatabaseAllocation;
import org.hibernate.build.qalab.DatabaseAllocator;
/** /**
* Basic support for {@link DatabaseProfile} implementations * Basic support for {@link DatabaseProfile} implementations
* *
@ -49,6 +52,7 @@ public abstract class AbstractDatabaseProfileImpl implements DatabaseProfile {
private final File profileDirectory; private final File profileDirectory;
private final Project project; private final Project project;
private final Map<String,String> hibernateProperties; private final Map<String,String> hibernateProperties;
private final DatabaseAllocation databaseAllocation;
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
protected AbstractDatabaseProfileImpl(File profileDirectory, Project project) { protected AbstractDatabaseProfileImpl(File profileDirectory, Project project) {
@ -83,6 +87,8 @@ public abstract class AbstractDatabaseProfileImpl implements DatabaseProfile {
hibernateProperties.put( propName, props.getProperty( propName ) ); hibernateProperties.put( propName, props.getProperty( propName ) );
} }
} }
this.databaseAllocation = DatabaseAllocator.locate( project ).getAllocation( this );
} }
@Override @Override
@ -100,6 +106,11 @@ public abstract class AbstractDatabaseProfileImpl implements DatabaseProfile {
return hibernateProperties; return hibernateProperties;
} }
@Override
public DatabaseAllocation getDatabaseAllocation() {
return databaseAllocation;
}
protected Configuration prepareConfiguration(String name) { protected Configuration prepareConfiguration(String name) {
Configuration configuration = getOrCreateConfiguration( name ); Configuration configuration = getOrCreateConfiguration( name );
configuration.setDescription( "The JDBC dependency configuration for the [" + name + "] profile" ); configuration.setDescription( "The JDBC dependency configuration for the [" + name + "] profile" );

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.build.gradle.testing.matrix; package org.hibernate.build.gradle.testing.database;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@ -28,6 +28,8 @@ import java.util.Map;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.hibernate.build.qalab.DatabaseAllocation;
/** /**
* Contract for database "profiles". * Contract for database "profiles".
* *
@ -39,4 +41,5 @@ public interface DatabaseProfile {
public File getDirectory(); public File getDirectory();
public Map<String,String> getHibernateProperties(); public Map<String,String> getHibernateProperties();
public Configuration getTestingRuntimeConfiguration(); public Configuration getTestingRuntimeConfiguration();
public DatabaseAllocation getDatabaseAllocation();
} }

View File

@ -71,7 +71,13 @@ public class DatabaseProfilePlugin implements Plugin<Project> {
processStandardProfiles( profileMap ); processStandardProfiles( profileMap );
processCustomProfiles( profileMap ); processCustomProfiles( profileMap );
this.profiles = new ArrayList<DatabaseProfile>(); this.profiles = new ArrayList<DatabaseProfile>();
this.profiles.addAll( profileMap.values() );
DatabaseAllocationCleanUp listener = new DatabaseAllocationCleanUp();
project.getGradle().addBuildListener( listener );
for ( DatabaseProfile profile : profileMap.values() ) {
this.profiles.add( profile );
listener.addDatabaseAllocation( profile.getDatabaseAllocation() );
}
} }
private void processStandardProfiles(Map<String, DatabaseProfile> profileMap) { private void processStandardProfiles(Map<String, DatabaseProfile> profileMap) {

View File

@ -40,8 +40,6 @@ import static org.gradle.api.plugins.JavaPlugin.COMPILE_CONFIGURATION_NAME
import static org.gradle.api.plugins.JavaPlugin.RUNTIME_CONFIGURATION_NAME import static org.gradle.api.plugins.JavaPlugin.RUNTIME_CONFIGURATION_NAME
import static org.gradle.api.plugins.JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME import static org.gradle.api.plugins.JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME
import static org.gradle.api.plugins.JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME import static org.gradle.api.plugins.JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME
import org.gradle.BuildAdapter
import org.gradle.BuildResult
/** /**
* TODO : 1) add a base configuration of common attribute across all matrix node tasks (convention) * TODO : 1) add a base configuration of common attribute across all matrix node tasks (convention)
@ -83,12 +81,9 @@ public class MatrixTestingPlugin implements Plugin<Project> {
matrixSourceSet = prepareSourceSet(); matrixSourceSet = prepareSourceSet();
matrixTask = prepareGroupingTask(); matrixTask = prepareGroupingTask();
DatabaseAllocationCleanUp listener = new DatabaseAllocationCleanUp();
project.rootProject.gradle.addBuildListener( listener );
for ( MatrixNode matrixNode: matrixNodes ) { for ( MatrixNode matrixNode: matrixNodes ) {
Task matrixNodeTask = prepareNodeTask( matrixNode ); Task matrixNodeTask = prepareNodeTask( matrixNode );
matrixTask.dependsOn( matrixNodeTask ); matrixTask.dependsOn( matrixNodeTask );
listener.addDatabaseAllocation( matrixNode.databaseAllocation );
} }
if ( !System.properties[SKIP_UNIT_TEST].equals('true') ) { if ( !System.properties[SKIP_UNIT_TEST].equals('true') ) {
@ -97,20 +92,8 @@ public class MatrixTestingPlugin implements Plugin<Project> {
} }
private List<MatrixNode> locateMatrixNodes() { private List<MatrixNode> locateMatrixNodes() {
return locateMatrixNodes( this.project );
}
private List<MatrixNode> locateMatrixNodes(Project project) {
if ( project == null ) {
return null; // EARLY EXIT!!!
}
if ( ! project.plugins.hasPlugin(DatabaseProfilePlugin) ) {
return locateMatrixNodes( project.parent ); // EARLY EXIT!!!
}
List<MatrixNode> matrixNodes = new ArrayList<MatrixNode>(); List<MatrixNode> matrixNodes = new ArrayList<MatrixNode>();
Iterable<DatabaseProfile> profiles = project.plugins[DatabaseProfilePlugin].databaseProfiles; Iterable<DatabaseProfile> profiles = project.rootProject.plugins[DatabaseProfilePlugin].databaseProfiles;
if ( profiles != null ) { if ( profiles != null ) {
for ( DatabaseProfile profile : profiles ) { for ( DatabaseProfile profile : profiles ) {
matrixNodes.add( new MatrixNode( project, profile, theJdk ) ); matrixNodes.add( new MatrixNode( project, profile, theJdk ) );