use of org.gradle.api.file.FileTree in project hibernate-orm by hibernate.
the class HibernatePlugin method applyEnhancement.
private void applyEnhancement(final Project project, final HibernateExtension hibernateExtension) {
if (!hibernateExtension.enhance.shouldApply()) {
project.getLogger().warn("Skipping Hibernate bytecode enhancement since no feature is enabled");
return;
}
for (final SourceSet sourceSet : hibernateExtension.getSourceSets()) {
project.getLogger().debug("Applying Hibernate enhancement action to SourceSet.{}", sourceSet.getName());
final Task compileTask = project.getTasks().findByName(sourceSet.getCompileJavaTaskName());
compileTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
project.getLogger().debug("Starting Hibernate enhancement on SourceSet.{}", sourceSet.getName());
final ClassLoader classLoader = toClassLoader(sourceSet.getRuntimeClasspath());
EnhancementContext enhancementContext = new DefaultEnhancementContext() {
@Override
public ClassLoader getLoadingClassLoader() {
return classLoader;
}
@Override
public boolean doBiDirectionalAssociationManagement(UnloadedField field) {
return hibernateExtension.enhance.getEnableAssociationManagement();
}
@Override
public boolean doDirtyCheckingInline(UnloadedClass classDescriptor) {
return hibernateExtension.enhance.getEnableDirtyTracking();
}
@Override
public boolean hasLazyLoadableAttributes(UnloadedClass classDescriptor) {
return hibernateExtension.enhance.getEnableLazyInitialization();
}
@Override
public boolean isLazyLoadable(UnloadedField field) {
return hibernateExtension.enhance.getEnableLazyInitialization();
}
@Override
public boolean doExtendedEnhancement(UnloadedClass classDescriptor) {
return hibernateExtension.enhance.getEnableExtendedEnhancement();
}
};
if (hibernateExtension.enhance.getEnableExtendedEnhancement()) {
logger.warn("Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk.");
}
final Enhancer enhancer = Environment.getBytecodeProvider().getEnhancer(enhancementContext);
final FileTree fileTree = project.fileTree(sourceSet.getOutput().getClassesDir());
for (File file : fileTree) {
if (!file.getName().endsWith(".class")) {
continue;
}
final byte[] enhancedBytecode = doEnhancement(sourceSet.getOutput().getClassesDir(), file, enhancer);
if (enhancedBytecode != null) {
writeOutEnhancedClass(enhancedBytecode, file);
logger.info("Successfully enhanced class [" + file + "]");
} else {
logger.info("Skipping class [" + file.getAbsolutePath() + "], not an entity nor embeddable");
}
}
}
});
}
}
use of org.gradle.api.file.FileTree in project gradle by gradle.
the class CompositeFileTreeTest method matchingWithActionReturnsUnionOfFilteredSets.
@Test
public void matchingWithActionReturnsUnionOfFilteredSets() {
final Action<PatternFilterable> action = Actions.doNothing();
final FileTreeInternal filtered1 = context.mock(FileTreeInternal.class);
final FileTreeInternal filtered2 = context.mock(FileTreeInternal.class);
context.checking(new Expectations() {
{
oneOf(source1).matching(action);
will(returnValue(filtered1));
oneOf(source2).matching(action);
will(returnValue(filtered2));
}
});
FileTree filtered = tree.matching(action);
assertThat(filtered, instanceOf(CompositeFileTree.class));
CompositeFileTree filteredCompositeSet = (CompositeFileTree) filtered;
assertThat(toList(filteredCompositeSet.getSourceCollections()), equalTo(toList(filtered1, filtered2)));
}
use of org.gradle.api.file.FileTree in project gradle by gradle.
the class CompositeFileTreeTest method matchingWithPatternSetReturnsUnionOfFilteredSets.
@Test
public void matchingWithPatternSetReturnsUnionOfFilteredSets() {
final PatternSet patternSet = new PatternSet();
final FileTreeInternal filtered1 = context.mock(FileTreeInternal.class);
final FileTreeInternal filtered2 = context.mock(FileTreeInternal.class);
context.checking(new Expectations() {
{
oneOf(source1).matching(patternSet);
will(returnValue(filtered1));
oneOf(source2).matching(patternSet);
will(returnValue(filtered2));
}
});
FileTree filtered = tree.matching(patternSet);
assertThat(filtered, instanceOf(CompositeFileTree.class));
CompositeFileTree filteredCompositeSet = (CompositeFileTree) filtered;
assertThat(toList(filteredCompositeSet.getSourceCollections()), equalTo(toList(filtered1, filtered2)));
}
use of org.gradle.api.file.FileTree in project gradle by gradle.
the class CompositeFileTreeTest method plusReturnsUnionOfThisTreeAndSourceTree.
@Test
public void plusReturnsUnionOfThisTreeAndSourceTree() {
FileTreeInternal other = context.mock(FileTreeInternal.class);
FileTree sum = tree.plus(other);
assertThat(sum, instanceOf(CompositeFileTree.class));
UnionFileTree sumCompositeTree = (UnionFileTree) sum;
assertThat(sumCompositeTree.getSourceCollections(), equalTo((Iterable) toList(source1, source2, other)));
}
use of org.gradle.api.file.FileTree in project gradle by gradle.
the class SerializableCoffeeScriptCompileSpec method toRelativeFiles.
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
FileTree fileTree = source.getAsFileTree();
fileTree.visit(new FileVisitor() {
public void visitDir(FileVisitDetails dirDetails) {
}
public void visitFile(FileVisitDetails fileDetails) {
targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
}
});
}
Aggregations