From 398cabe2a7ac932fa32f651805ecacc1bc4e2d72 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 21 Mar 2011 15:32:50 -0500 Subject: [PATCH 1/6] minor updates to upload auth gradle plugin --- buildSrc/build.gradle | 1 + .../build/gradle/upload/AuthenticationHandler.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index f19f7c3fb7..59dcfd0150 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -12,6 +12,7 @@ repositories { dependencies { compile gradleApi() compile localGroovy() + compile 'org.slf4j:slf4j-api:1.6.0' compile 'org.apache.ant:ant:1.7.0' compile 'org.apache.maven:maven-ant-tasks:2.1.0' compile 'org.apache.maven.wagon:wagon-http:1.0-beta-6' diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java index 955caf39d2..4bd52c860f 100644 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java @@ -33,8 +33,11 @@ import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.Upload; /** - * Responsible for locating and injecting authentication information into the JBoss Nexus repository config for upload - * which it does, based on set up in + * Acts as the main authentication coordinator for the upload. It will delegate to all {@link AuthenticationProvider} + * instances registered with the {@link AuthenticationProviderRegistry} looking for any that provide + * {@link Authentication} against the given {@link RemoteRepository} defined for each upload task. + *

+ * IMPL NOTE : This will need to change drastically whenever Gradle moves to its {@code Publication} scheme for uploads. * * @author Steve Ebersole */ From 4f188a934c48e442985c72a39f9c53bbe31fd301 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 21 Mar 2011 18:37:44 -0500 Subject: [PATCH 2/6] HHH-6033 - Migrate stats to api/spi/internal split --- .../src/main/java/org/hibernate/impl/SessionFactoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java index 0c012b1dd4..90e538ff49 100644 --- a/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java @@ -474,7 +474,7 @@ public final class SessionFactoryImpl private Statistics buildStatistics(Settings settings, ServiceRegistry serviceRegistry) { Statistics statistics = new ConcurrentStatisticsImpl( this ); - getStatistics().setStatisticsEnabled( settings.isStatisticsEnabled() ); + statistics.setStatisticsEnabled( settings.isStatisticsEnabled() ); LOG.debugf("Statistics initialized [enabled=%s]", settings.isStatisticsEnabled()); return statistics; } From 671ef3accd228b5f60f0aeada950557f5026a7c3 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 21 Mar 2011 20:33:19 -0500 Subject: [PATCH 3/6] HHH-6016 - Migrate version injection plugin to Gradle --- buildSrc/build.gradle | 8 + .../build/gradle/inject/Injection.java | 56 ++++ .../build/gradle/inject/InjectionAction.java | 252 ++++++++++++++++++ .../gradle/inject/InjectionException.java | 79 +++--- .../build/gradle/inject/InjectionPlugin.java | 45 ++++ .../build/gradle/inject/TargetMember.java | 96 +++---- hibernate-core/hibernate-core.gradle | 1 + .../src/main/java/org/hibernate/Version.java | 6 +- .../org/hibernate/ejb/Ejb3Configuration.java | 4 - 9 files changed, 452 insertions(+), 95 deletions(-) create mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/inject/Injection.java create mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionAction.java rename hibernate-core/src/main/java/org/hibernate/cfg/annotations/Version.java => buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionException.java (71%) create mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java rename hibernate-entitymanager/src/main/java/org/hibernate/ejb/Version.java => buildSrc/src/main/java/org/hibernate/build/gradle/inject/TargetMember.java (57%) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 59dcfd0150..4fc1c2b712 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -10,14 +10,22 @@ repositories { dependencies { + // common compile gradleApi() compile localGroovy() compile 'org.slf4j:slf4j-api:1.6.0' compile 'org.apache.ant:ant:1.7.0' compile 'org.apache.maven:maven-ant-tasks:2.1.0' + + // needed? compile 'org.apache.maven.wagon:wagon-http:1.0-beta-6' + + // upload-auth plugin compile 'dom4j:dom4j:1.6.1@jar' + // injection plugin + compile 'javassist:javassist:3.12.0.GA' + groovy localGroovy() } diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/inject/Injection.java b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/Injection.java new file mode 100644 index 0000000000..6e57ab1395 --- /dev/null +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/Injection.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.build.gradle.inject; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Steve Ebersole + */ +public class Injection { + private final String expression; + private List targetMembers = new ArrayList(); + + public Injection(String expression) { + this.expression = expression; + } + + public String getExpression() { + return expression; + } + + public void into(String className, String member) { + into( new TargetMember( className, member ) ); + } + + public void into(TargetMember targetMember) { + targetMembers.add( targetMember ); + } + + public Iterable getTargetMembers() { + return targetMembers; + } + +} diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionAction.java b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionAction.java new file mode 100644 index 0000000000..4eb2e3c65d --- /dev/null +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionAction.java @@ -0,0 +1,252 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.build.gradle.inject; + +import java.io.BufferedOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; + +import javassist.ClassPool; +import javassist.CtClass; +import javassist.CtField; +import javassist.CtMethod; +import javassist.LoaderClassPath; +import javassist.Modifier; +import javassist.NotFoundException; +import javassist.bytecode.ClassFile; +import javassist.bytecode.ConstantAttribute; +import javassist.bytecode.FieldInfo; +import org.gradle.api.Action; +import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.tasks.SourceSet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Steve Ebersole + */ +public class InjectionAction implements Action { + private static final Logger log = LoggerFactory.getLogger( InjectionAction.class ); + + private final Project project; + + private List injections = new ArrayList(); + + private LoaderClassPath loaderClassPath; + private ClassPool classPool; + + public InjectionAction(Project project) { + this.project = project; + } + + void addInjection(Injection injection) { + injections.add( injection ); + } + + @Override + public void execute(Object o) { + final ClassLoader runtimeScopeClassLoader = buildRuntimeScopeClassLoader(); + + loaderClassPath = new LoaderClassPath( runtimeScopeClassLoader ); + classPool = new ClassPool( true ); + classPool.appendClassPath( loaderClassPath ); + + try { + performInjections(); + } + finally { + loaderClassPath.close(); + } + } + + private ClassLoader buildRuntimeScopeClassLoader() { + final ArrayList classPathUrls = new ArrayList(); + final SourceSet mainSourceSet = project + .getConvention() + .getPlugin( JavaPluginConvention.class ) + .getSourceSets() + .findByName( SourceSet.MAIN_SOURCE_SET_NAME ); + for ( File file : mainSourceSet.getRuntimeClasspath() ) { + try { + classPathUrls.add( file.toURI().toURL() ); + } + catch (MalformedURLException e) { + throw new InjectionException( "Could not determine artifact URL [" + file.getPath() + "]", e ); + } + } + return new URLClassLoader( classPathUrls.toArray( new URL[classPathUrls.size()] ), getClass().getClassLoader() ); + } + + private void performInjections() { + for ( Injection injection : injections ) { + for ( TargetMember targetMember : injection.getTargetMembers() ) { + resolveInjectionTarget( targetMember ).inject( injection.getExpression() ); + } + } + } + + private InjectionTarget resolveInjectionTarget(TargetMember targetMember) { + try { + final CtClass ctClass = classPool.get( targetMember.getClassName() ); + // see if it is a field... + try { + CtField field = ctClass.getField( targetMember.getMemberName() ); + return new FieldInjectionTarget( targetMember, ctClass, field ); + } + catch( NotFoundException ignore ) { + } + + // see if it is a method... + for ( CtMethod method : ctClass.getMethods() ) { + if ( method.getName().equals( targetMember.getMemberName() ) ) { + return new MethodInjectionTarget( targetMember, ctClass, method ); + } + } + + // finally throw an exception + throw new InjectionException( "Unknown member [" + targetMember.getQualifiedName() + "]" ); + } + catch ( Throwable e ) { + throw new InjectionException( "Unable to resolve class [" + targetMember.getClassName() + "]", e ); + } + } + + /** + * Strategy for performing an injection + */ + private static interface InjectionTarget { + /** + * Inject the given value per this target's strategy. + * + * @param value The value to inject. + * + * @throws org.hibernate.build.gradle.inject.InjectionException Indicates a problem performing the injection. + */ + public void inject(String value); + } + + private abstract class BaseInjectionTarget implements InjectionTarget { + @SuppressWarnings( {"UnusedDeclaration"}) + private final TargetMember targetMember; + private final CtClass ctClass; + private final File classFileLocation; + + protected BaseInjectionTarget(TargetMember targetMember, CtClass ctClass) { + this.targetMember = targetMember; + this.ctClass = ctClass; + try { + classFileLocation = new File( loaderClassPath.find( targetMember.getClassName() ).toURI() ); + } + catch ( Throwable e ) { + throw new InjectionException( "Unable to resolve class file path", e ); + } + } + + @Override + public void inject(String value) { + doInjection( value ); + writeOutChanges(); + } + + protected abstract void doInjection(String value); + + protected void writeOutChanges() { + log.info( "writing injection changes back [" + classFileLocation.getAbsolutePath() + "]" ); + long timeStamp = classFileLocation.lastModified(); + ClassFile classFile = ctClass.getClassFile(); + classFile.compact(); + try { + DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( classFileLocation ) ) ); + try { + + classFile.write( out ); + out.flush(); + if ( ! classFileLocation.setLastModified( System.currentTimeMillis() ) ) { + log.info( "Unable to manually update class file timestamp" ); + } + } + finally { + out.close(); + classFileLocation.setLastModified( timeStamp ); + } + } + catch ( IOException e ) { + throw new InjectionException( "Unable to write out modified class file", e ); + } + } + } + + private class FieldInjectionTarget extends BaseInjectionTarget { + private final CtField ctField; + + private FieldInjectionTarget(TargetMember targetMember, CtClass ctClass, CtField ctField) { + super( targetMember, ctClass ); + this.ctField = ctField; + if ( ! Modifier.isStatic( ctField.getModifiers() ) ) { + throw new InjectionException( "Field is not static [" + targetMember.getQualifiedName() + "]" ); + } + } + + @Override + protected void doInjection(String value) { + final FieldInfo ctFieldInfo = ctField.getFieldInfo(); + + ctFieldInfo.addAttribute( + new ConstantAttribute( + ctFieldInfo.getConstPool(), + ctFieldInfo.getConstPool().addStringInfo( value ) + ) + ); + + } + } + + private class MethodInjectionTarget extends BaseInjectionTarget { + private final CtMethod ctMethod; + + private MethodInjectionTarget(TargetMember targetMember, CtClass ctClass, CtMethod ctMethod) { + super( targetMember, ctClass ); + this.ctMethod = ctMethod; + } + + @Override + protected void doInjection(String value) { + try { + ctMethod.setBody( "{return \"" + value + "\";}" ); + } + catch ( Throwable t ) { + throw new InjectionException( "Unable to replace method body", t ); + } + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/Version.java b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionException.java similarity index 71% rename from hibernate-core/src/main/java/org/hibernate/cfg/annotations/Version.java rename to buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionException.java index 615f121848..cfab911bfa 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/Version.java +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionException.java @@ -1,42 +1,37 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ - -// $Id$ - -package org.hibernate.cfg.annotations; - - -/** - * @author Emmanuel Bernard - * @deprecated Use {@link org.hibernate.Version} instead - */ -@Deprecated -public class Version { - public static String getVersionString() { - return org.hibernate.Version.getVersionString(); - } - - public static void touch() { - } -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.build.gradle.inject; + +/** + * @author Steve Ebersole + */ +public class InjectionException extends RuntimeException { + public InjectionException(String message) { + super( message ); + } + + public InjectionException(String message, Throwable cause) { + super( message, cause ); + } +} diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java new file mode 100644 index 0000000000..5e160bf1b5 --- /dev/null +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java @@ -0,0 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.build.gradle.inject; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; + +/** + * @author Steve Ebersole + */ +public class InjectionPlugin implements Plugin { + + @Override + public void apply(Project project) { + final InjectionAction injectionAction = new InjectionAction( project ); + + // For now, just do what Hibernate needs rather than a full blown "convention" object + Injection versionInjection = new Injection( project.getVersion().toString() ); + versionInjection.into( "org.hibernate.Version", "getVersionString" ); + injectionAction.addInjection( versionInjection ); + project.getTasks().findByName( "compileJava" ).doLast( injectionAction ); + } + +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Version.java b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/TargetMember.java similarity index 57% rename from hibernate-entitymanager/src/main/java/org/hibernate/ejb/Version.java rename to buildSrc/src/main/java/org/hibernate/build/gradle/inject/TargetMember.java index badab4d6e1..3b1b46df06 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Version.java +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/TargetMember.java @@ -1,46 +1,50 @@ -// $Id$ -/* - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ - -//$Id$ -package org.hibernate.ejb; -import org.jboss.logging.Logger; - - -/** - * @author Emmanuel Bernard - */ -public class Version { - - public static final EntityManagerLogger LOG = Logger.getMessageLogger(EntityManagerLogger.class, Version.class.getName()); - - public static String getVersionString() { - return "[WORKING]"; - } - - static { - LOG.entityManagerVersion(getVersionString()); - } - - public static void touch() { - } -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.build.gradle.inject; + +/** + * @author Steve Ebersole + */ +public class TargetMember { + private final String className; + private final String memberName; + + public TargetMember(String className, String memberName) { + this.className = className; + this.memberName = memberName; + } + + public String getClassName() { + return className; + } + + public String getMemberName() { + return memberName; + } + + public String getQualifiedName() { + return getClassName() + "#" + getMemberName(); + } + +} diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index e777062524..d96d4f09b9 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -1,5 +1,6 @@ apply plugin: 'java' apply plugin: 'antlr' +apply plugin: org.hibernate.build.gradle.inject.InjectionPlugin dependencies { compile( libraries.commons_collections ) diff --git a/hibernate-core/src/main/java/org/hibernate/Version.java b/hibernate-core/src/main/java/org/hibernate/Version.java index aa9729a2f8..1b92ddfad9 100644 --- a/hibernate-core/src/main/java/org/hibernate/Version.java +++ b/hibernate-core/src/main/java/org/hibernate/Version.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -23,7 +23,6 @@ */ package org.hibernate; - /** * Information about the Hibernate version. * @@ -34,6 +33,7 @@ public class Version { return "[WORKING]"; } + public static void main(String[] args) { System.out.println( "Hibernate version " + getVersionString() ); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java index f3c85938ae..02b54aba83 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java @@ -137,10 +137,6 @@ public class Ejb3Configuration implements Serializable, Referenceable { } } - static { - Version.touch(); - } - private String persistenceUnitName; private String cfgXmlResource; From 29e21e9b257635a9319bde1ce269d53ffa225517 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 22 Mar 2011 08:29:49 -0500 Subject: [PATCH 4/6] HHH-6038 - Migrate to use newly separated gradle-upload-auth-plugin --- build.gradle | 15 ++- .../gradle/upload/AuthenticationHandler.java | 90 ------------- .../gradle/upload/AuthenticationProvider.java | 45 ------- .../AuthenticationProviderRegistry.java | 53 -------- .../StandardMavenAuthenticationProvider.java | 124 ------------------ .../upload/UploadAuthenticationManager.java | 68 ---------- 6 files changed, 13 insertions(+), 382 deletions(-) delete mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java delete mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java delete mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java delete mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java delete mode 100644 buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java diff --git a/build.gradle b/build.gradle index 113337409a..78846a521d 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,17 @@ allprojects { } } +buildscript { + repositories { + mavenLocal() + mavenRepo name: 'jboss-nexus', urls: "https://repository.jboss.org/nexus/content/groups/public/" + mavenRepo name: "jboss-snapshots", urls: "http://snapshots.jboss.org/maven2/" + } + dependencies { + classpath 'org.hibernate.build.gradle:gradle-upload-auth-plugin:1.0.0' + } +} + ideaProject { javaVersion = "1.6" withXml { provider -> @@ -86,11 +97,11 @@ subprojects { subProject -> // minimize changes, at least for now (gradle uses 'build' by default).. buildDir = "target" - + if ( ! subProject.name.startsWith( 'release' ) ) { apply plugin: 'java' apply plugin: 'maven' // for install task as well as deploy dependencies - apply plugin: org.hibernate.build.gradle.upload.UploadAuthenticationManager + apply plugin: 'uploadAuth' configurations { provided { diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java deleted file mode 100644 index 4bd52c860f..0000000000 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ - -package org.hibernate.build.gradle.upload; - -import org.apache.maven.artifact.ant.Authentication; -import org.apache.maven.artifact.ant.RemoteRepository; -import org.gradle.api.Action; -import org.gradle.api.DefaultTask; -import org.gradle.api.artifacts.maven.MavenDeployer; -import org.gradle.api.tasks.TaskAction; -import org.gradle.api.tasks.Upload; - -/** - * Acts as the main authentication coordinator for the upload. It will delegate to all {@link AuthenticationProvider} - * instances registered with the {@link AuthenticationProviderRegistry} looking for any that provide - * {@link Authentication} against the given {@link RemoteRepository} defined for each upload task. - *

- * IMPL NOTE : This will need to change drastically whenever Gradle moves to its {@code Publication} scheme for uploads. - * - * @author Steve Ebersole - */ -public class AuthenticationHandler extends DefaultTask { - private AuthenticationProviderRegistry authenticationProviderRegistry; - private Upload uploadTask; - - public void injectProviderRegistry(AuthenticationProviderRegistry authenticationProviderRegistry) { - this.authenticationProviderRegistry = authenticationProviderRegistry; - } - - public void injectUploadTask(Upload uploadTask) { - this.uploadTask = uploadTask; - } - - @TaskAction - public void configureUploadAuthentication() { - // todo : unfortunately I have no idea how to apply this to non MavenDeployer-type repos... - uploadTask.getRepositories().withType( MavenDeployer.class ).all( - new Action() { - public void execute(MavenDeployer deployer) { - final RemoteRepository repository = deployer.getRepository(); - if ( repository != null ) { - final Authentication authentication = locateAuthenticationDetails( repository ); - if ( authentication != null ) { - repository.addAuthentication( authentication ); - } - } - final RemoteRepository snapshotRepository = deployer.getSnapshotRepository(); - if ( snapshotRepository != null ) { - final Authentication authentication = locateAuthenticationDetails( snapshotRepository ); - if ( authentication != null ) { - snapshotRepository.addAuthentication( authentication ); - } - } - } - } - ); - } - - private Authentication locateAuthenticationDetails(RemoteRepository repository) { - for ( AuthenticationProvider provider : authenticationProviderRegistry.providers() ) { - Authentication authentication = provider.determineAuthentication( repository ); - if ( authentication != null ) { - return authentication; - } - } - return null; - } -} diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java deleted file mode 100644 index 26c592a4bb..0000000000 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.build.gradle.upload; - -import org.apache.maven.artifact.ant.Authentication; -import org.apache.maven.artifact.ant.RemoteRepository; - -/** - * Contract for providers of {@link Authentication} details for authenticating against remote repositories. - * - * @author Steve Ebersole - */ -public interface AuthenticationProvider { - /** - * The contract method. Given a repository, determine the {@link Authentication} according to this provider's - * contract. Return {@literal null} to indicate no {@link Authentication} applied for this repository by this - * provider. - * - * @param remoteRepository The repository to check for authentication details. - * - * @return The authentication details, or {@literal null} to indicate none. - */ - public Authentication determineAuthentication(RemoteRepository remoteRepository); -} diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java deleted file mode 100644 index 13590a5cf0..0000000000 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.build.gradle.upload; - -import java.util.LinkedList; - -/** - * A registry of {@link AuthenticationProvider} instances. - * - * @author Steve Ebersole - */ -public class AuthenticationProviderRegistry { - private final LinkedList authenticationProviders = buildStandardAuthenticationProviders(); - - private static LinkedList buildStandardAuthenticationProviders() { - LinkedList providers = new LinkedList(); - providers.add( new StandardMavenAuthenticationProvider() ); - return providers; - } - - public void appendAuthenticationProvider(AuthenticationProvider provider) { - authenticationProviders.addLast( provider ); - } - - public void prependAuthenticationProvider(AuthenticationProvider provider) { - authenticationProviders.addFirst( provider ); - } - - public Iterable providers() { - return authenticationProviders; - } -} diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java deleted file mode 100644 index 6b68b72a92..0000000000 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.build.gradle.upload; - -import org.apache.maven.artifact.ant.Authentication; -import org.apache.maven.artifact.ant.RemoteRepository; -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.Element; -import org.dom4j.io.SAXReader; -import org.xml.sax.InputSource; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.Iterator; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Provider of {@link org.apache.maven.artifact.ant.RemoteRepository} {@link Authentication} based on standard Maven - * conventions using {@literal settings.xml}. - * - * @author Steve Ebersole - */ -public class StandardMavenAuthenticationProvider implements AuthenticationProvider { - private static final Logger log = LoggerFactory.getLogger( StandardMavenAuthenticationProvider.class ); - - public static final String SETTINGS_LOCATION_OVERRIDE = "maven.settings"; - - private ConcurrentHashMap repositoryAuthenticationMap; - - @Override - public Authentication determineAuthentication(RemoteRepository remoteRepository) { - if ( repositoryAuthenticationMap == null ) { - loadRepositoryAuthenticationMap(); - } - - return repositoryAuthenticationMap.get( remoteRepository.getId() ); - } - - private void loadRepositoryAuthenticationMap() { - repositoryAuthenticationMap = new ConcurrentHashMap(); - - final File settingsFile = determineSettingsFileLocation(); - try { - InputSource inputSource = new InputSource( new FileInputStream( settingsFile ) ); - try { - final Document document = buildSAXReader().read( inputSource ); - final Element settingsElement = document.getRootElement(); - final Element serversElement = settingsElement.element( "servers" ); - final Iterator serversIterator = serversElement.elementIterator( "server" ); - while ( serversIterator.hasNext() ) { - final Element serverElement = (Element) serversIterator.next(); - final String id = extractValue( serverElement.element( "id" ) ); - if ( id == null ) { - continue; - } - final Authentication authentication = new Authentication(); - authentication.setUserName( extractValue( serverElement.element( "username" ) ) ); - authentication.setPassword( extractValue( serverElement.element( "password" ) ) ); - authentication.setPrivateKey( extractValue( serverElement.element( "privateKey" ) ) ); - authentication.setPassphrase( extractValue( serverElement.element( "passphrase" ) ) ); - repositoryAuthenticationMap.put( id, authentication ); - } - } - catch (DocumentException e) { - log.error( "Error reading Maven settings.xml", e ); - } - } - catch ( FileNotFoundException e ) { - log.info( "Unable to locate Maven settings.xml" ); - } - } - - private String extractValue(Element element) { - if ( element == null ) { - return null; - } - - final String value = element.getTextTrim(); - if ( value != null && value.length() == 0 ) { - return null; - } - - return value; - } - - private SAXReader buildSAXReader() { - SAXReader saxReader = new SAXReader(); - saxReader.setMergeAdjacentText( true ); - return saxReader; - } - - private File determineSettingsFileLocation() { - final String overrideLocation = System.getProperty( SETTINGS_LOCATION_OVERRIDE ); - return overrideLocation == null - ? new File( new File( System.getProperty( "user.home" ), ".m2" ), "settings.xml" ) - : new File( overrideLocation ); - } -} diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java deleted file mode 100644 index 2c8909fece..0000000000 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.build.gradle.upload; - -import org.gradle.api.Action; -import org.gradle.api.Plugin; -import org.gradle.api.Project; -import org.gradle.api.tasks.Upload; - -/** - * Manages authentication aspects of artifact uploading by delegation to registered {@link AuthenticationProvider} - * instances. - * - * @author Steve Ebersole - */ -public class UploadAuthenticationManager implements Plugin { - - @Override - public void apply(final Project project) { - // todo : ideally the registry would be handled by a convention to allow configuration (aka, adding more providers)... - // for our purposes here in Hibernate we only care about the Maven settings.xml based way so we - // code for just that. - final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry(); - - project.getTasks().withType( Upload.class ).all( - new Action() { - @Override - public void execute(final Upload uploadTask) { - // create a auth task for each upload task... - final AuthenticationHandler authenticationHandler = project.getTasks().add( - "uploadAuthenticationHandler-" + uploadTask.getName(), - AuthenticationHandler.class - ); - - // link the auth task with the upload task - authenticationHandler.injectUploadTask( uploadTask ); - - // todo: Also in conjunction, would be best to have the handler lookup the registry rather than pushing it - authenticationHandler.injectProviderRegistry( registry ); - - uploadTask.getDependsOn().add( authenticationHandler ); - } - } - ); - } - -} From 51b2fa1e2bac0d7b897ade1a2ae9c320c0cbb276 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 22 Mar 2011 09:53:42 -0500 Subject: [PATCH 5/6] HHH-6016 - Migrate version injection plugin to Gradle --- .../java/org/hibernate/build/gradle/inject/InjectionPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java index 5e160bf1b5..9acad9208b 100644 --- a/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java +++ b/buildSrc/src/main/java/org/hibernate/build/gradle/inject/InjectionPlugin.java @@ -39,7 +39,7 @@ public class InjectionPlugin implements Plugin { Injection versionInjection = new Injection( project.getVersion().toString() ); versionInjection.into( "org.hibernate.Version", "getVersionString" ); injectionAction.addInjection( versionInjection ); - project.getTasks().findByName( "compileJava" ).doLast( injectionAction ); + project.getTasks().findByName( "jar" ).doLast( injectionAction ); } } From a933851765c1362cee51bfa31a64461a159363ce Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 22 Mar 2011 11:35:28 -0500 Subject: [PATCH 6/6] HHH-6001 - Add a top-level directory inside the release bundle archives --- release/release.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/release/release.gradle b/release/release.gradle index f55de546f4..2f4950d5fa 100644 --- a/release/release.gradle +++ b/release/release.gradle @@ -144,10 +144,12 @@ releaseCopySpec = copySpec { } // todo : this closure is problematic as it does not write into the hibernate-release-$project.version directory - // asked on gradle mailing list... + // due to http://issues.gradle.org/browse/GRADLE-1450 [ 'hibernate-c3p0', 'hibernate-proxool', 'hibernate-ehcache', 'hibernate-infinispan' ].each { feature -> final String shortName = feature.substring( 'hibernate-'.length() ); - into('lib/optional/' + shortName) { +// WORKAROUND http://issues.gradle.org/browse/GRADLE-1450 +// into('lib/optional/' + shortName) { + owner.into('lib/optional/' + shortName) { from ( ( parent.project( feature ).configurations.archives.allArtifactFiles.filter{ file -> !file.name.endsWith('-sources.jar') } + parent.project( feature ).configurations.runtime )