Build task - collect @Incubating + logging refs
This commit is contained in:
parent
ef73522139
commit
692fa24b34
|
@ -9,7 +9,9 @@ package org.hibernate;
|
|||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
||||
import static java.lang.annotation.ElementType.CONSTRUCTOR;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.PACKAGE;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
|
@ -24,7 +26,7 @@ import static java.lang.annotation.RetentionPolicy.CLASS;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Target({PACKAGE, TYPE, METHOD,CONSTRUCTOR})
|
||||
@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, FIELD, CONSTRUCTOR})
|
||||
@Retention(CLASS)
|
||||
public @interface Incubating {
|
||||
}
|
||||
|
|
|
@ -8,9 +8,12 @@ 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.file.Directory;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.jvm.tasks.Jar;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import static org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -18,29 +21,32 @@ import org.gradle.jvm.tasks.Jar;
|
|||
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 JavaPluginExtension javaPluginExtension = project.getExtensions().getByType( JavaPluginExtension.class );
|
||||
final SourceSet projectMainSourceSet = javaPluginExtension.getSourceSets().getByName( MAIN_SOURCE_SET_NAME );
|
||||
final Provider<Directory> classesDirectory = projectMainSourceSet.getJava().getClassesDirectory();
|
||||
|
||||
final IndexManager indexManager = new IndexManager( jarFileReferenceAccess, indexFileReferenceAccess );
|
||||
final IndexManager indexManager = new IndexManager( classesDirectory, project );
|
||||
|
||||
final IndexerTask indexerTask = project.getTasks().create(
|
||||
"indexProjectJar",
|
||||
"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(
|
||||
"collectProjectIncubating",
|
||||
"createIncubatingReport",
|
||||
IncubatingCollectorTask.class,
|
||||
indexManager
|
||||
);
|
||||
incubatingTask.dependsOn( indexerTask );
|
||||
|
||||
final LoggingCollectorTask loggingTask = project.getTasks().create(
|
||||
"collectProjectLogging",
|
||||
"createLoggingReport",
|
||||
LoggingCollectorTask.class,
|
||||
indexManager
|
||||
);
|
||||
|
|
|
@ -12,6 +12,11 @@ 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.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
|
@ -28,10 +33,22 @@ public abstract class IncubatingCollectorTask extends DefaultTask {
|
|||
public static final String INCUBATING_ANN_NAME = "org.hibernate.Incubating";
|
||||
|
||||
private final IndexManager indexManager;
|
||||
private final Provider<RegularFile> reportFileReferenceAccess;
|
||||
|
||||
@Inject
|
||||
public IncubatingCollectorTask(IndexManager indexManager) {
|
||||
public IncubatingCollectorTask(IndexManager indexManager, Project project) {
|
||||
this.indexManager = indexManager;
|
||||
this.reportFileReferenceAccess = project.getLayout().getBuildDirectory().file( "post/" + project.getName() + "-incubating.txt" );
|
||||
}
|
||||
|
||||
@InputFile
|
||||
public Provider<RegularFile> getIndexFileReference() {
|
||||
return indexManager.getIndexFileReferenceAccess();
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public Provider<RegularFile> getReportFileReferenceAccess() {
|
||||
return reportFileReferenceAccess;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
|
|
@ -11,10 +11,14 @@ import java.io.FileInputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.Directory;
|
||||
import org.gradle.api.file.RegularFile;
|
||||
import org.gradle.api.provider.Provider;
|
||||
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.Index;
|
||||
import org.jboss.jandex.IndexWriter;
|
||||
import org.jboss.jandex.Indexer;
|
||||
|
@ -25,22 +29,28 @@ import org.jboss.jandex.Indexer;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class IndexManager {
|
||||
private final Provider<RegularFile> jarFileReference;
|
||||
private final Provider<RegularFile> indexFileReference;
|
||||
private final Provider<Directory> classesDirectoryReferenceAccess;
|
||||
private final Provider<RegularFile> indexFileReferenceAccess;
|
||||
private final Project project;
|
||||
|
||||
private Index index;
|
||||
|
||||
public IndexManager(Provider<RegularFile> jarFileReference, Provider<RegularFile> indexFileReference) {
|
||||
this.jarFileReference = jarFileReference;
|
||||
this.indexFileReference = indexFileReference;
|
||||
public IndexManager(
|
||||
Provider<Directory> classesDirectoryReferenceAccess,
|
||||
Project project) {
|
||||
this.classesDirectoryReferenceAccess = classesDirectoryReferenceAccess;
|
||||
this.indexFileReferenceAccess = project.getLayout()
|
||||
.getBuildDirectory()
|
||||
.file( "post/" + project.getName() + ".idx" );
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public Provider<RegularFile> getJarFileReference() {
|
||||
return jarFileReference;
|
||||
public Provider<Directory> getClassesDirectoryReferenceAccess() {
|
||||
return classesDirectoryReferenceAccess;
|
||||
}
|
||||
|
||||
public Provider<RegularFile> getIndexFileReference() {
|
||||
return indexFileReference;
|
||||
public Provider<RegularFile> getIndexFileReferenceAccess() {
|
||||
return indexFileReferenceAccess;
|
||||
}
|
||||
|
||||
public Index getIndex() {
|
||||
|
@ -55,16 +65,31 @@ public class IndexManager {
|
|||
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 );
|
||||
|
||||
final Directory classesDirectory = classesDirectoryReferenceAccess.get();
|
||||
final Set<File> classFiles = classesDirectory.getAsFileTree().getFiles();
|
||||
for ( File classFile : classFiles ) {
|
||||
if ( !classFile.getName().endsWith( ".class" ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !classFile.getAbsolutePath().contains( "org/hibernate" ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
this.index = indexer.complete();
|
||||
|
@ -72,13 +97,13 @@ public class IndexManager {
|
|||
}
|
||||
|
||||
private void storeIndex(Index index) {
|
||||
final File indexFile = indexFileReference.get().getAsFile();
|
||||
final File indexFile = indexFileReferenceAccess.get().getAsFile();
|
||||
if ( indexFile.exists() ) {
|
||||
indexFile.delete();
|
||||
}
|
||||
|
||||
try {
|
||||
indexFile.mkdirs();
|
||||
indexFile.getParentFile().mkdirs();
|
||||
indexFile.createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
|
|
@ -9,10 +9,12 @@ package org.hibernate.orm.post;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.file.Directory;
|
||||
import org.gradle.api.file.RegularFile;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.InputDirectory;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.SkipWhenEmpty;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
|
@ -28,14 +30,15 @@ public abstract class IndexerTask extends DefaultTask {
|
|||
this.indexManager = indexManager;
|
||||
}
|
||||
|
||||
@InputFile
|
||||
public Provider<RegularFile> getJarFileReference() {
|
||||
return indexManager.getJarFileReference();
|
||||
@InputDirectory
|
||||
@SkipWhenEmpty
|
||||
public Provider<Directory> getClassesDirectory() {
|
||||
return indexManager.getClassesDirectoryReferenceAccess();
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public Provider<RegularFile> getIndexFileReference() {
|
||||
return indexManager.getIndexFileReference();
|
||||
return indexManager.getIndexFileReferenceAccess();
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
|
Loading…
Reference in New Issue