diff --git a/documentation/documentation.gradle b/documentation/documentation.gradle index 8a227bc642..19c9a9ad32 100644 --- a/documentation/documentation.gradle +++ b/documentation/documentation.gradle @@ -14,14 +14,29 @@ plugins { apply from: rootProject.file( 'gradle/java-module.gradle' ) apply plugin: 'org.hibernate.matrix-test' +apply plugin: 'org.hibernate.orm.build.reports' tasks.build.dependsOn 'buildDocs' defaultTasks 'buildDocs' - dependencies { ext.pressgangVersion = '3.0.0' + reportAggregation project( ':hibernate-agroal' ) + reportAggregation project( ':hibernate-c3p0' ) + reportAggregation project( ':hibernate-core' ) + reportAggregation project(':hibernate-envers') + reportAggregation project(':hibernate-graalvm') + reportAggregation project(':hibernate-hikaricp') + reportAggregation project(':hibernate-jcache') + reportAggregation project(':hibernate-micrometer') + reportAggregation project(':hibernate-proxool') + reportAggregation project(':hibernate-spatial') + reportAggregation project(':hibernate-vibur') + reportAggregation project(':hibernate-ant') + reportAggregation project(':hibernate-enhance-maven-plugin') + reportAggregation project(':hibernate-jpamodelgen') + implementation project( ':hibernate-core' ) annotationProcessor project( ':hibernate-jpamodelgen' ) diff --git a/gradle/published-java-module.gradle b/gradle/published-java-module.gradle index 80597ecb02..608b5abb2a 100644 --- a/gradle/published-java-module.gradle +++ b/gradle/published-java-module.gradle @@ -8,7 +8,6 @@ apply plugin: 'signing' apply from: rootProject.file( 'gradle/java-module.gradle' ) apply from: rootProject.file( 'gradle/publishing-pom.gradle' ) -apply plugin: 'org.hibernate.orm.build.post-collector' configurations { javadocSources { diff --git a/hibernate-core/src/main/java/org/hibernate/Internal.java b/hibernate-core/src/main/java/org/hibernate/Internal.java index 7aeb96e7cb..7925b2d372 100644 --- a/hibernate-core/src/main/java/org/hibernate/Internal.java +++ b/hibernate-core/src/main/java/org/hibernate/Internal.java @@ -14,7 +14,7 @@ import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PACKAGE; import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.CLASS; +import static java.lang.annotation.RetentionPolicy.RUNTIME; /** * Annotation used to identify a package, class, interface or method @@ -24,7 +24,7 @@ import static java.lang.annotation.RetentionPolicy.CLASS; * @author Steve Ebersole */ @Target({PACKAGE, TYPE, METHOD, FIELD, CONSTRUCTOR}) -@Retention(CLASS) +@Retention(RUNTIME) public @interface Internal { } diff --git a/hibernate-orm-build/build.gradle b/hibernate-orm-build/build.gradle index f080fa0cc4..27357660f6 100644 --- a/hibernate-orm-build/build.gradle +++ b/hibernate-orm-build/build.gradle @@ -43,9 +43,9 @@ gradlePlugin { id = 'org.hibernate.orm.jakarta-publish' implementationClass = 'org.hibernate.orm.jakarta.JakartaPublishingPlugin' } - collectorPlugin { - id = 'org.hibernate.orm.build.post-collector' - implementationClass = 'org.hibernate.orm.post.CollectorPlugin' + reportsPlugin { + id = 'org.hibernate.orm.build.reports' + implementationClass = 'org.hibernate.orm.post.ReportGenerationPlugin' } } } diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IncubatingCollectorTask.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/AbstractJandexAwareTask.java similarity index 51% rename from hibernate-orm-build/src/main/java/org/hibernate/orm/post/IncubatingCollectorTask.java rename to hibernate-orm-build/src/main/java/org/hibernate/orm/post/AbstractJandexAwareTask.java index 4d126715a5..24867fb247 100644 --- a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IncubatingCollectorTask.java +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/AbstractJandexAwareTask.java @@ -11,19 +11,16 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; -import java.util.Comparator; import java.util.List; import java.util.TreeSet; - import javax.inject.Inject; import org.gradle.api.DefaultTask; -import org.gradle.api.Project; import org.gradle.api.file.RegularFile; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; -import org.gradle.api.tasks.TaskAction; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; @@ -32,19 +29,25 @@ import org.jboss.jandex.FieldInfo; import org.jboss.jandex.Index; import org.jboss.jandex.MethodInfo; +import static org.hibernate.orm.post.ReportGenerationPlugin.TASK_GROUP_NAME; + /** * @author Steve Ebersole */ -public abstract class IncubatingCollectorTask extends DefaultTask { - public static final String INCUBATING_ANN_NAME = "org.hibernate.Incubating"; - +public class AbstractJandexAwareTask extends DefaultTask { private final IndexManager indexManager; private final Provider reportFileReferenceAccess; @Inject - public IncubatingCollectorTask(IndexManager indexManager, Project project) { + public AbstractJandexAwareTask(IndexManager indexManager, Provider reportFileReferenceAccess) { this.indexManager = indexManager; - this.reportFileReferenceAccess = project.getLayout().getBuildDirectory().file( "reports/orm/" + project.getName() + "-incubating.txt" ); + this.reportFileReferenceAccess = reportFileReferenceAccess; + setGroup( TASK_GROUP_NAME ); + } + + @Internal + protected IndexManager getIndexManager() { + return indexManager; } @InputFile @@ -57,138 +60,108 @@ public abstract class IncubatingCollectorTask extends DefaultTask { return reportFileReferenceAccess; } - @TaskAction - public void collectIncubationDetails() { - final Index index = indexManager.getIndex(); - - final List usages = index.getAnnotations( DotName.createSimple( INCUBATING_ANN_NAME ) ); - final TreeSet incubations = new TreeSet<>( Comparator.comparing( Incubation::getPath ) ); - - usages.forEach( (usage) -> { - final AnnotationTarget usageLocation = usage.target(); - final Incubation incubation = determinePath( usageLocation ); - if ( incubation != null ) { - incubations.add( incubation ); - } - } ); - - // NOTE : at this point, `usagePathSet` contains a set of incubating - // names ordered alphabetically.. - - reportIncubations( incubations ); - } - - private void reportIncubations(TreeSet incubations) { - final File reportFile = prepareReportFile(); - assert reportFile.exists(); - - try ( final OutputStreamWriter fileWriter = new OutputStreamWriter( new FileOutputStream( reportFile ) ) ) { - generateReport( incubations, fileWriter ); - } - catch (FileNotFoundException e) { - throw new RuntimeException( "Should never happen" ); - } - catch (IOException e) { - throw new RuntimeException( "Error writing to `@Incubating` report file", e ); - } - } - - private File prepareReportFile() { - final File reportFile = reportFileReferenceAccess.get().getAsFile(); + protected File prepareReportFile() { + final File reportFile = getReportFileReferenceAccess().get().getAsFile(); if ( reportFile.getParentFile().exists() ) { if ( reportFile.exists() ) { if ( !reportFile.delete() ) { - throw new RuntimeException( "Unable to delete `@Incubating` report file" ); + throw new RuntimeException( "Unable to delete report file - " + reportFile.getAbsolutePath() ); } } } else { if ( !reportFile.getParentFile().mkdirs() ) { - throw new RuntimeException( "Unable to create directories for `@Incubating` report file" ); + throw new RuntimeException( "Unable to create report file directories - " + reportFile.getAbsolutePath() ); } } try { if ( !reportFile.createNewFile() ) { - throw new RuntimeException( "Unable to create file for `@Incubating` report file" ); + throw new RuntimeException( "Unable to create report file - " + reportFile.getAbsolutePath() ); } } catch (IOException e) { - throw new RuntimeException( "Unable to create file for `@Incubating` report file" ); + throw new RuntimeException( "Unable to create report file - " + reportFile.getAbsolutePath() ); } return reportFile; } - private void generateReport(TreeSet incubations, OutputStreamWriter fileWriter) { + protected void processAnnotations(DotName annotationName, TreeSet inclusions) { + final Index index = getIndexManager().getIndex(); + final List usages = index.getAnnotations( annotationName ); + + usages.forEach( (usage) -> { + final AnnotationTarget usageLocation = usage.target(); + final Inclusion inclusion = determinePath( usageLocation ); + if ( inclusion != null ) { + inclusions.add( inclusion ); + } + } ); + } + + protected void writeReport(TreeSet inclusions) { + final File reportFile = prepareReportFile(); + assert reportFile.exists(); + + try ( final OutputStreamWriter fileWriter = new OutputStreamWriter( new FileOutputStream( reportFile ) ) ) { + writeReport( inclusions, fileWriter ); + } + catch (FileNotFoundException e) { + throw new RuntimeException( "Should never happen" ); + } + catch (IOException e) { + throw new RuntimeException( "Error writing to report file", e ); + } + } + + private void writeReport(TreeSet inclusions, OutputStreamWriter fileWriter) { String previousPath = null; - for ( Incubation incubation : incubations ) { - if ( previousPath != null && incubation.path.startsWith( previousPath ) ) { + for ( Inclusion inclusion : inclusions ) { + if ( previousPath != null && inclusion.getPath().startsWith( previousPath ) ) { continue; } - // `usagePath` is a path we want to document + // `inclusion` is a path we want to document try { - fileWriter.write( incubation.path ); - if ( incubation.isPackage ) { + fileWriter.write( inclusion.getPath() ); + if ( inclusion.isPackage() ) { fileWriter.write( ".*" ); } fileWriter.write( '\n' ); fileWriter.flush(); } catch (IOException e) { - throw new RuntimeException( "Error writing entry (" + incubation.path + ") to `@Incubating` report file", e ); + throw new RuntimeException( "Error writing entry (" + inclusion.getPath() + ") to report file", e ); } - previousPath = incubation.path; + previousPath = inclusion.getPath(); } } - private static class Incubation { - private final String path; - private final boolean isPackage; - - public Incubation(String path, boolean isPackage) { - this.path = path; - this.isPackage = isPackage; - } - - public Incubation(String path) { - this( path, false ); - } - - public String getPath() { - return path; - } - - public boolean isPackage() { - return isPackage; - } - } - - private Incubation determinePath(AnnotationTarget usageLocation) { + private Inclusion determinePath(AnnotationTarget usageLocation) { switch ( usageLocation.kind() ) { case CLASS: { final DotName name = usageLocation.asClass().name(); if ( name.local().equals( "package-info" ) ) { - return new Incubation( name.packagePrefix(), true ); + return new Inclusion( name.packagePrefix(), true ); } - return new Incubation( name.toString() ); + return new Inclusion( name.toString() ); } case FIELD: { final FieldInfo fieldInfo = usageLocation.asField(); final String path = fieldInfo.declaringClass().name().toString() + "#" + fieldInfo.name(); - return new Incubation( path ); + return new Inclusion( path ); } case METHOD: { final MethodInfo methodInfo = usageLocation.asMethod(); final String path = methodInfo.declaringClass().name().toString() + "#" + methodInfo.name(); - return new Incubation( path ); + return new Inclusion( path ); } default: { return null; diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/CollectorPlugin.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/CollectorPlugin.java deleted file mode 100644 index 7e8c18002c..0000000000 --- a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/CollectorPlugin.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.post; - -import org.gradle.api.Plugin; -import org.gradle.api.Project; -import org.gradle.api.file.Directory; -import org.gradle.api.plugins.JavaPluginExtension; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.SourceSet; - -import static org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME; - -/** - * @author Steve Ebersole - */ -public class CollectorPlugin implements Plugin { - @Override - public void apply(Project project) { - final JavaPluginExtension javaPluginExtension = project.getExtensions().getByType( JavaPluginExtension.class ); - final SourceSet projectMainSourceSet = javaPluginExtension.getSourceSets().getByName( MAIN_SOURCE_SET_NAME ); - final Provider classesDirectory = projectMainSourceSet.getJava().getClassesDirectory(); - - final IndexManager indexManager = new IndexManager( classesDirectory, project ); - - final IndexerTask indexerTask = project.getTasks().create( - "indexProject", - IndexerTask.class, - indexManager - ); - - // NOTE : `indexProject` implicitly depends on the compilation task. - // it uses the `classesDirectory` from the `main` sourceSet. Gradle - // understands that the `classesDirectory` is generated from the - // compilation task and implicitly creates the task dependency - - final IncubatingCollectorTask incubatingTask = project.getTasks().create( - "createIncubatingReport", - IncubatingCollectorTask.class, - indexManager - ); - incubatingTask.dependsOn( indexerTask ); - - final LoggingCollectorTask loggingTask = project.getTasks().create( - "createLoggingReport", - LoggingCollectorTask.class, - indexManager - ); - loggingTask.dependsOn( indexerTask ); - } -} diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/Inclusion.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/Inclusion.java new file mode 100644 index 0000000000..52d6c77fa6 --- /dev/null +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/Inclusion.java @@ -0,0 +1,33 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.post; + +/** + * @author Steve Ebersole + */ +class Inclusion { + private final String path; + private final boolean isPackage; + + public Inclusion(String path, boolean isPackage) { + this.path = path; + this.isPackage = isPackage; + } + + public Inclusion(String path) { + this( path, false ); + } + + public String getPath() { + return path; + } + + public boolean isPackage() { + return isPackage; + } + +} diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IncubationReportTask.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IncubationReportTask.java new file mode 100644 index 0000000000..c1594d4b9b --- /dev/null +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IncubationReportTask.java @@ -0,0 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.post; + +import java.util.Comparator; +import java.util.TreeSet; +import javax.inject.Inject; + +import org.gradle.api.Project; +import org.gradle.api.tasks.TaskAction; + +import org.jboss.jandex.DotName; + +/** + * @author Steve Ebersole + */ +public abstract class IncubationReportTask extends AbstractJandexAwareTask { + public static final String INCUBATING_ANN_NAME = "org.hibernate.Incubating"; + + @Inject + public IncubationReportTask(IndexManager indexManager, Project project) { + super( + indexManager, + project.getLayout().getBuildDirectory().file( "reports/orm/incubating.txt" ) + ); + setDescription( "Generates a report for things considered incubating" ); + } + + @TaskAction + public void generateIncubationReport() { + final TreeSet incubations = new TreeSet<>( Comparator.comparing( Inclusion::getPath ) ); + + processAnnotations( DotName.createSimple( INCUBATING_ANN_NAME ), incubations ); + + // NOTE : at this point, `incubations` contains a set of incubating + // names ordered alphabetically.. + + writeReport( incubations ); + } + +} diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexManager.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexManager.java index fe784d8e22..2fb7ef0086 100644 --- a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexManager.java +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexManager.java @@ -10,12 +10,19 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; +import java.util.Comparator; import java.util.Set; +import java.util.TreeSet; import org.gradle.api.Project; -import org.gradle.api.file.Directory; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.FileTree; +import org.gradle.api.file.FileVisitDetails; +import org.gradle.api.file.FileVisitor; import org.gradle.api.file.RegularFile; +import org.gradle.api.file.RelativePath; import org.gradle.api.provider.Provider; import org.jboss.jandex.ClassInfo; @@ -29,30 +36,41 @@ import org.jboss.jandex.Indexer; * @author Steve Ebersole */ public class IndexManager { - private final Provider classesDirectoryReferenceAccess; + private final Configuration artifactsToProcess; private final Provider indexFileReferenceAccess; + private final Provider packageFileReferenceAccess; private final Project project; private Index index; + private TreeSet internalPackageNames; - public IndexManager( - Provider classesDirectoryReferenceAccess, - Project project) { - this.classesDirectoryReferenceAccess = classesDirectoryReferenceAccess; + public IndexManager(Configuration artifactsToProcess, Project project) { + this.artifactsToProcess = artifactsToProcess; this.indexFileReferenceAccess = project.getLayout() .getBuildDirectory() - .file( "reports/orm/" + project.getName() + ".idx" ); + .file( "reports/orm/indexing/jandex.idx" ); + this.packageFileReferenceAccess = project.getLayout() + .getBuildDirectory() + .file( "reports/orm/indexing/internal-packages.txt" ); this.project = project; } - public Provider getClassesDirectoryReferenceAccess() { - return classesDirectoryReferenceAccess; + public Configuration getArtifactsToProcess() { + return artifactsToProcess; } public Provider getIndexFileReferenceAccess() { return indexFileReferenceAccess; } + public Provider getPackageFileReferenceAccess() { + return packageFileReferenceAccess; + } + + public TreeSet getInternalPackageNames() { + return internalPackageNames; + } + public Index getIndex() { if ( index == null ) { throw new IllegalStateException( "Index has not been created yet" ); @@ -60,55 +78,81 @@ public class IndexManager { return index; } + + /** + * Used from {@link IndexerTask} as its action + */ void index() { if ( index != null ) { + assert internalPackageNames != null; return; } final Indexer indexer = new Indexer(); + internalPackageNames = new TreeSet<>( Comparator.comparing( Inclusion::getPath ) ); - final Directory classesDirectory = classesDirectoryReferenceAccess.get(); - final Set classFiles = classesDirectory.getAsFileTree().getFiles(); - for ( File classFile : classFiles ) { - if ( !classFile.getName().endsWith( ".class" ) ) { - continue; - } + // note: each of `artifacts` is a jar-file + final Set artifacts = artifactsToProcess.resolve(); - if ( !classFile.getAbsolutePath().contains( "org/hibernate" ) ) { - continue; - } + artifacts.forEach( (jar) -> { + final FileTree jarFileTree = project.zipTree( jar ); + jarFileTree.visit( + new FileVisitor() { + private boolean isInOrmPackage(RelativePath relativePath) { + return relativePath.getPathString().startsWith( "org/hibernate/" ); + } - try ( final FileInputStream stream = new FileInputStream( classFile ) ) { - final ClassInfo indexedClassInfo = indexer.index( stream ); - if ( indexedClassInfo == null ) { - project.getLogger().lifecycle( "Problem indexing class file - " + classFile.getAbsolutePath() ); - } - } - catch (FileNotFoundException e) { - throw new RuntimeException( "Problem locating project class file - " + classFile.getAbsolutePath(), e ); - } - catch (IOException e) { - throw new RuntimeException( "Error accessing project class file - " + classFile.getAbsolutePath(), e ); - } - } + @Override + public void visitDir(FileVisitDetails details) { + final RelativePath relativePath = details.getRelativePath(); + if ( !isInOrmPackage( relativePath ) ) { + return; + } + + if ( relativePath.getPathString().endsWith( "internal" ) + || relativePath.getPathString().endsWith( "internal/" ) ) { + final String packageName = relativePath.toString().replace( '/', '.' ); + internalPackageNames.add( new Inclusion( packageName, true ) ); + } + } + + @Override + public void visitFile(FileVisitDetails details) { + final RelativePath relativePath = details.getRelativePath(); + if ( !isInOrmPackage( relativePath ) ) { + return; + } + + if ( relativePath.getPathString().endsWith( ".class" ) ) { + try ( final FileInputStream stream = new FileInputStream( details.getFile() ) ) { + final ClassInfo indexedClassInfo = indexer.index( stream ); + if ( indexedClassInfo == null ) { + project.getLogger() + .lifecycle( "Problem indexing class file - " + details.getFile() + .getAbsolutePath() ); + } + } + catch (FileNotFoundException e) { + throw new RuntimeException( "Problem locating project class file - " + details.getFile() + .getAbsolutePath(), e ); + } + catch (IOException e) { + throw new RuntimeException( "Error accessing project class file - " + details.getFile() + .getAbsolutePath(), e ); + } + } + } + } + ); + } ); this.index = indexer.complete(); - storeIndex( index ); + storeIndex(); + storePackageNames(); } - private void storeIndex(Index index) { - final File indexFile = indexFileReferenceAccess.get().getAsFile(); - if ( indexFile.exists() ) { - indexFile.delete(); - } - - try { - indexFile.getParentFile().mkdirs(); - indexFile.createNewFile(); - } - catch (IOException e) { - throw new RuntimeException( "Unable to create index file - " + indexFile.getAbsolutePath(), e ); - } + private void storeIndex() { + final File indexFile = prepareOutputFile( indexFileReferenceAccess ); try ( final FileOutputStream stream = new FileOutputStream( indexFile ) ) { final IndexWriter indexWriter = new IndexWriter( stream ); @@ -121,4 +165,43 @@ public class IndexManager { throw new RuntimeException( "Error accessing index file - " + indexFile.getAbsolutePath(), e ); } } + + private void storePackageNames() { + final File packageNameFile = prepareOutputFile( packageFileReferenceAccess ); + + try ( final FileWriter fileWriter = new FileWriter( packageNameFile ) ) { + internalPackageNames.forEach( (inclusion) -> { + try { + fileWriter.write( inclusion.getPath() ); + fileWriter.write( '\n' ); + } + catch (IOException e) { + throw new RuntimeException( "Unable to write to package-name file - " + packageNameFile.getAbsolutePath(), e ); + } + } ); + } + catch (FileNotFoundException e) { + throw new RuntimeException( "Should never happen", e ); + } + catch (IOException e) { + throw new RuntimeException( "Error accessing package-name file - " + packageNameFile.getAbsolutePath(), e ); + } + } + + private File prepareOutputFile(Provider outputFileReferenceAccess) { + final File outputFile = outputFileReferenceAccess.get().getAsFile(); + if ( outputFile.exists() ) { + outputFile.delete(); + } + + try { + outputFile.getParentFile().mkdirs(); + outputFile.createNewFile(); + } + catch (IOException e) { + throw new RuntimeException( "Unable to create index file - " + outputFile.getAbsolutePath(), e ); + } + + return outputFile; + } } diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexerTask.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexerTask.java index 745bf751d5..3ddbb6a060 100644 --- a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexerTask.java +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/IndexerTask.java @@ -9,14 +9,17 @@ package org.hibernate.orm.post; import javax.inject.Inject; import org.gradle.api.DefaultTask; -import org.gradle.api.file.Directory; +import org.gradle.api.artifacts.Configuration; import org.gradle.api.file.RegularFile; import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.InputDirectory; +import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.SkipWhenEmpty; import org.gradle.api.tasks.TaskAction; +import static org.hibernate.orm.post.ReportGenerationPlugin.CONFIG_NAME; +import static org.hibernate.orm.post.ReportGenerationPlugin.TASK_GROUP_NAME; + /** * Task for creating Jandex Index within Gradle UP-TO-DATE handling * @@ -28,12 +31,14 @@ public abstract class IndexerTask extends DefaultTask { @Inject public IndexerTask(IndexManager indexManager) { this.indexManager = indexManager; + setGroup( TASK_GROUP_NAME ); + setDescription( "Builds a Jandex Index from the artifacts attached to the `" + CONFIG_NAME + "` Configuration" ); } - @InputDirectory + @InputFiles @SkipWhenEmpty - public Provider getClassesDirectory() { - return indexManager.getClassesDirectoryReferenceAccess(); + public Configuration getArtifactsToProcess() { + return indexManager.getArtifactsToProcess(); } @OutputFile @@ -41,6 +46,11 @@ public abstract class IndexerTask extends DefaultTask { return indexManager.getIndexFileReferenceAccess(); } + @OutputFile + public Provider getPackageFileReferenceAccess() { + return indexManager.getPackageFileReferenceAccess(); + } + @TaskAction public void createIndex() { indexManager.index(); diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/InternalsReportTask.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/InternalsReportTask.java new file mode 100644 index 0000000000..192b41af2c --- /dev/null +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/InternalsReportTask.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.post; + +import java.io.File; +import java.nio.file.Path; +import java.util.Comparator; +import java.util.TreeSet; +import javax.inject.Inject; + +import org.gradle.api.Project; +import org.gradle.api.tasks.TaskAction; + +import org.jboss.jandex.DotName; + +/** + * @author Steve Ebersole + */ +public abstract class InternalsReportTask extends AbstractJandexAwareTask { + public static final String INTERNAL_ANN_NAME = "org.hibernate.Internal"; + + @Inject + public InternalsReportTask(IndexManager indexManager, Project project) { + super( + indexManager, + project.getLayout().getBuildDirectory().file( "reports/orm/internal.txt" ) + ); + } + + @TaskAction + public void generateInternalsReport() { + final TreeSet internals = new TreeSet<>( Comparator.comparing( Inclusion::getPath ) ); + internals.addAll( getIndexManager().getInternalPackageNames() ); + processAnnotations( DotName.createSimple( INTERNAL_ANN_NAME ), internals ); + + writeReport( internals ); + } + +} diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/LoggingCollectorTask.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/LoggingCollectorTask.java deleted file mode 100644 index 2cf855d583..0000000000 --- a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/LoggingCollectorTask.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.post; - -import javax.inject.Inject; - -import org.gradle.api.DefaultTask; -import org.gradle.api.tasks.TaskAction; - -import org.jboss.jandex.Index; - -/** - * @author Steve Ebersole - */ -public abstract class LoggingCollectorTask extends DefaultTask { - private final IndexManager indexManager; - - @Inject - public LoggingCollectorTask(IndexManager indexManager) { - this.indexManager = indexManager; - } - - @TaskAction - public void collectLoggingDetails() { - getProject().getLogger().lifecycle( "Logging collection not implemented yet" ); - } -} diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/LoggingReportTask.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/LoggingReportTask.java new file mode 100644 index 0000000000..c1d5389c6b --- /dev/null +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/LoggingReportTask.java @@ -0,0 +1,30 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.post; + +import javax.inject.Inject; + +import org.gradle.api.Project; +import org.gradle.api.tasks.TaskAction; + +/** + * @author Steve Ebersole + */ +public abstract class LoggingReportTask extends AbstractJandexAwareTask { + @Inject + public LoggingReportTask(IndexManager indexManager, Project project) { + super( + indexManager, + project.getLayout().getBuildDirectory().file( "reports/orm/logging.txt" ) + ); + } + + @TaskAction + public void generateLoggingReport() { + getProject().getLogger().lifecycle( "Logging report not implemented yet" ); + } +} diff --git a/hibernate-orm-build/src/main/java/org/hibernate/orm/post/ReportGenerationPlugin.java b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/ReportGenerationPlugin.java new file mode 100644 index 0000000000..cfa0b0c1a5 --- /dev/null +++ b/hibernate-orm-build/src/main/java/org/hibernate/orm/post/ReportGenerationPlugin.java @@ -0,0 +1,54 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.post; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; + +/** + * @author Steve Ebersole + */ +public class ReportGenerationPlugin implements Plugin { + public static final String CONFIG_NAME = "reportAggregation"; + public static final String TASK_GROUP_NAME = "hibernate-reports"; + + @Override + public void apply(Project project) { + final Configuration artifactsToProcess = project.getConfigurations() + .maybeCreate( CONFIG_NAME ) + .setDescription( "Used to collect the jars with classes files to be used in the aggregation reports for `@Internal`, `@Incubating`, etc" ); + + final IndexManager indexManager = new IndexManager( artifactsToProcess, project ); + final IndexerTask indexerTask = project.getTasks().create( + "buildAggregatedIndex", + IndexerTask.class, + indexManager + ); + + final IncubationReportTask incubatingTask = project.getTasks().create( + "createIncubationReport", + IncubationReportTask.class, + indexManager + ); + incubatingTask.dependsOn( indexerTask ); + + final InternalsReportTask internalsTask = project.getTasks().create( + "createInternalsReport", + InternalsReportTask.class, + indexManager + ); + internalsTask.dependsOn( indexerTask ); + + final LoggingReportTask loggingTask = project.getTasks().create( + "createLoggingReport", + LoggingReportTask.class, + indexManager + ); + loggingTask.dependsOn( indexerTask ); + } +}