Build task - collect @Incubating + logging refs
This commit is contained in:
parent
d4979ac547
commit
ef73522139
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
apply from: rootProject.file( 'gradle/java-module.gradle' )
|
apply from: rootProject.file( 'gradle/java-module.gradle' )
|
||||||
apply from: rootProject.file( 'gradle/publishing-pom.gradle' )
|
apply from: rootProject.file( 'gradle/publishing-pom.gradle' )
|
||||||
|
apply plugin: 'org.hibernate.orm.build.post-collector'
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
javadocSources {
|
javadocSources {
|
||||||
|
|
|
@ -16,6 +16,7 @@ buildDir = "target"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation gradleApi()
|
implementation gradleApi()
|
||||||
|
implementation 'org.jboss:jandex:2.4.2.Final'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.compileJava {
|
tasks.compileJava {
|
||||||
|
@ -42,6 +43,10 @@ gradlePlugin {
|
||||||
id = 'org.hibernate.orm.jakarta-publish'
|
id = 'org.hibernate.orm.jakarta-publish'
|
||||||
implementationClass = 'org.hibernate.orm.jakarta.JakartaPublishingPlugin'
|
implementationClass = 'org.hibernate.orm.jakarta.JakartaPublishingPlugin'
|
||||||
}
|
}
|
||||||
|
collectorPlugin {
|
||||||
|
id = 'org.hibernate.orm.build.post-collector'
|
||||||
|
implementationClass = 'org.hibernate.orm.post.CollectorPlugin'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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.RegularFile;
|
||||||
|
import org.gradle.api.provider.Provider;
|
||||||
|
import org.gradle.jvm.tasks.Jar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class CollectorPlugin implements Plugin<Project> {
|
||||||
|
@Override
|
||||||
|
public void apply(Project project) {
|
||||||
|
final Jar jarTask = (Jar) project.getTasks().findByName( "jar" );
|
||||||
|
final Provider<RegularFile> jarFileReferenceAccess = jarTask.getArchiveFile();
|
||||||
|
final Provider<RegularFile> indexFileReferenceAccess = project.getLayout()
|
||||||
|
.getBuildDirectory()
|
||||||
|
.file( "post/" + project.getName() + ".idx" );
|
||||||
|
|
||||||
|
final IndexManager indexManager = new IndexManager( jarFileReferenceAccess, indexFileReferenceAccess );
|
||||||
|
|
||||||
|
final IndexerTask indexerTask = project.getTasks().create(
|
||||||
|
"indexProjectJar",
|
||||||
|
IndexerTask.class,
|
||||||
|
indexManager
|
||||||
|
);
|
||||||
|
|
||||||
|
final IncubatingCollectorTask incubatingTask = project.getTasks().create(
|
||||||
|
"collectProjectIncubating",
|
||||||
|
IncubatingCollectorTask.class,
|
||||||
|
indexManager
|
||||||
|
);
|
||||||
|
incubatingTask.dependsOn( indexerTask );
|
||||||
|
|
||||||
|
final LoggingCollectorTask loggingTask = project.getTasks().create(
|
||||||
|
"collectProjectLogging",
|
||||||
|
LoggingCollectorTask.class,
|
||||||
|
indexManager
|
||||||
|
);
|
||||||
|
loggingTask.dependsOn( indexerTask );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* 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.List;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask;
|
||||||
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
import org.jboss.jandex.AnnotationTarget;
|
||||||
|
import org.jboss.jandex.DotName;
|
||||||
|
import org.jboss.jandex.FieldInfo;
|
||||||
|
import org.jboss.jandex.Index;
|
||||||
|
import org.jboss.jandex.MethodInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class IncubatingCollectorTask extends DefaultTask {
|
||||||
|
public static final String INCUBATING_ANN_NAME = "org.hibernate.Incubating";
|
||||||
|
|
||||||
|
private final IndexManager indexManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public IncubatingCollectorTask(IndexManager indexManager) {
|
||||||
|
this.indexManager = indexManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
public void collectIncubationDetails() {
|
||||||
|
final Index index = indexManager.getIndex();
|
||||||
|
|
||||||
|
final List<AnnotationInstance> usages = index.getAnnotations( DotName.createSimple( INCUBATING_ANN_NAME ) );
|
||||||
|
final TreeSet<String> usagePathSet = new TreeSet<>();
|
||||||
|
usages.forEach( (usage) -> {
|
||||||
|
final AnnotationTarget usageLocation = usage.target();
|
||||||
|
final String locationPath = determinePath( usageLocation );
|
||||||
|
if ( locationPath != null ) {
|
||||||
|
usagePathSet.add( locationPath );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
// at this point, `usagePathSet` contains a set of incubating names ordered alphabetically..
|
||||||
|
String previousPath = null;
|
||||||
|
for ( String usagePath : usagePathSet ) {
|
||||||
|
if ( previousPath != null && usagePath.startsWith( previousPath ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `usagePath` is a path we want to document
|
||||||
|
collectIncubation( usagePath );
|
||||||
|
|
||||||
|
previousPath = usagePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectIncubation(String usagePath) {
|
||||||
|
// todo - what to do with this?
|
||||||
|
}
|
||||||
|
|
||||||
|
private String determinePath(AnnotationTarget usageLocation) {
|
||||||
|
switch ( usageLocation.kind() ) {
|
||||||
|
case CLASS: {
|
||||||
|
final DotName name = usageLocation.asClass().name();
|
||||||
|
if ( name.local().equals( "package-info.class" ) ) {
|
||||||
|
return name.packagePrefix();
|
||||||
|
}
|
||||||
|
return name.toString();
|
||||||
|
}
|
||||||
|
case FIELD: {
|
||||||
|
final FieldInfo fieldInfo = usageLocation.asField();
|
||||||
|
return fieldInfo.declaringClass().name().toString()
|
||||||
|
+ "#"
|
||||||
|
+ fieldInfo.name();
|
||||||
|
}
|
||||||
|
case METHOD: {
|
||||||
|
final MethodInfo methodInfo = usageLocation.asMethod();
|
||||||
|
return methodInfo.declaringClass().name().toString()
|
||||||
|
+ "#"
|
||||||
|
+ methodInfo.name();
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
* 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.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gradle.api.file.RegularFile;
|
||||||
|
import org.gradle.api.provider.Provider;
|
||||||
|
|
||||||
|
import org.jboss.jandex.Index;
|
||||||
|
import org.jboss.jandex.IndexWriter;
|
||||||
|
import org.jboss.jandex.Indexer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates and manages a Jandex Index
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class IndexManager {
|
||||||
|
private final Provider<RegularFile> jarFileReference;
|
||||||
|
private final Provider<RegularFile> indexFileReference;
|
||||||
|
|
||||||
|
private Index index;
|
||||||
|
|
||||||
|
public IndexManager(Provider<RegularFile> jarFileReference, Provider<RegularFile> indexFileReference) {
|
||||||
|
this.jarFileReference = jarFileReference;
|
||||||
|
this.indexFileReference = indexFileReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Provider<RegularFile> getJarFileReference() {
|
||||||
|
return jarFileReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Provider<RegularFile> getIndexFileReference() {
|
||||||
|
return indexFileReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Index getIndex() {
|
||||||
|
if ( index == null ) {
|
||||||
|
throw new IllegalStateException( "Index has not been created yet" );
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void index() {
|
||||||
|
if ( index != null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final File jarFileAsFile = jarFileReference.get().getAsFile();
|
||||||
|
final Indexer indexer = new Indexer();
|
||||||
|
try ( final FileInputStream stream = new FileInputStream( jarFileAsFile ) ) {
|
||||||
|
indexer.index( stream );
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
throw new RuntimeException( "Unable to locate project jar file - " + jarFileAsFile.getAbsolutePath(), e );
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException( "Error accessing project jar file - " + jarFileAsFile.getAbsolutePath(), e );
|
||||||
|
}
|
||||||
|
|
||||||
|
this.index = indexer.complete();
|
||||||
|
storeIndex( index );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void storeIndex(Index index) {
|
||||||
|
final File indexFile = indexFileReference.get().getAsFile();
|
||||||
|
if ( indexFile.exists() ) {
|
||||||
|
indexFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
indexFile.mkdirs();
|
||||||
|
indexFile.createNewFile();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException( "Unable to create index file - " + indexFile.getAbsolutePath(), e );
|
||||||
|
}
|
||||||
|
|
||||||
|
try ( final FileOutputStream stream = new FileOutputStream( indexFile ) ) {
|
||||||
|
final IndexWriter indexWriter = new IndexWriter( stream );
|
||||||
|
indexWriter.write( index );
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
throw new RuntimeException( "Should never happen", e );
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException( "Error accessing index file - " + indexFile.getAbsolutePath(), e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask;
|
||||||
|
import org.gradle.api.file.RegularFile;
|
||||||
|
import org.gradle.api.provider.Provider;
|
||||||
|
import org.gradle.api.tasks.InputFile;
|
||||||
|
import org.gradle.api.tasks.OutputFile;
|
||||||
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task for creating Jandex Index within Gradle UP-TO-DATE handling
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class IndexerTask extends DefaultTask {
|
||||||
|
private final IndexManager indexManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public IndexerTask(IndexManager indexManager) {
|
||||||
|
this.indexManager = indexManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@InputFile
|
||||||
|
public Provider<RegularFile> getJarFileReference() {
|
||||||
|
return indexManager.getJarFileReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OutputFile
|
||||||
|
public Provider<RegularFile> getIndexFileReference() {
|
||||||
|
return indexManager.getIndexFileReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
public void createIndex() {
|
||||||
|
indexManager.index();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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() {
|
||||||
|
final Index index = indexManager.getIndex();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Support for a few tasks to be run as "post actions"
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.post;
|
Loading…
Reference in New Issue