use of org.gradle.api.Task 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.Task in project atlas by alibaba.
the class PublishHooker method hookPublish.
public void hookPublish() {
project.getTasks().whenTaskAdded(new Action<Task>() {
@Override
public void execute(Task task) {
if ("publishMavenPublicationToMavenRepository".equals(task.getName())) {
publishTask = (PublishToMavenRepository) task;
task.setEnabled(false);
if (null != hookTask) {
hookTask.setRepository(publishTask.getRepository());
hookTask.setPublication(publishTask.getPublication());
}
}
}
});
final TaskContainer tasks = project.getTasks();
Task publishLifecycleTask = tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME);
String taskName = "publishMavenPublicationToMavenRepositoryHook";
hookTask = tasks.create(taskName, PublishToMavenRepositoryHook.class, new Action<PublishToMavenRepositoryHook>() {
public void execute(PublishToMavenRepositoryHook publishTask) {
publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
}
});
publishLifecycleTask.dependsOn(taskName);
}
use of org.gradle.api.Task in project atlas by alibaba.
the class MergeResAwbsConfigAction method execute.
@Override
public void execute(MtlParallelTask parallelTask) {
super.execute(parallelTask);
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
if (null == androidDependencyTree) {
return;
}
List<DefaultTask> tasks = new ArrayList<DefaultTask>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
MergeAwbResourceConfigAction mergeAwbResourceConfigAction = new MergeAwbResourceConfigAction(appVariantContext, baseVariantOutputData, awbBundle);
final MergeResources mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbResourceConfigAction.getName(), mergeAwbResourceConfigAction.getType());
mergeAwbResourceConfigAction.execute(mergeTask);
tasks.add(mergeTask);
mergeTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
File publicRes = new File(awbBundle.getResFolder(), "values/public.xml");
if (publicRes.exists()) {
try {
FileUtils.copyFile(publicRes, new File(mergeTask.getOutputDir(), "values/public.xml"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
parallelTask.parallelTask = tasks;
parallelTask.uniqueTaskName = getName();
parallelTask.concurrent = true;
}
use of org.gradle.api.Task in project atlas by alibaba.
the class MtlTaskFactoryImpl method createTask.
@Override
public Task createTask(VariantContext variantContext, BaseVariantOutputData vod, Class<? extends MtlBaseTaskAction> baseTaskAction) {
if (null == baseTaskAction) {
return null;
}
try {
MtlBaseTaskAction mtlBaseTaskAction = getConstructor(baseTaskAction, variantContext.getClass()).newInstance(variantContext, vod);
Task task = variantContext.getProject().getTasks().create(mtlBaseTaskAction.getName(), mtlBaseTaskAction.getType());
mtlBaseTaskAction.execute(task);
return task;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
use of org.gradle.api.Task in project atlas by alibaba.
the class MtlTaskInjector method injectTasks.
public void injectTasks(List<MtlTaskContext> mtlTaskContexts, AndroidBuilder androidBuilder) {
List<BaseVariantOutputData> baseVariantOutputDataList = variantContext.getVariantOutputData();
for (final BaseVariantOutputData vod : baseVariantOutputDataList) {
//TODO 如果中间步骤没有生成task怎么办
List<Task> beforeTasks = new ArrayList<Task>();
for (MtlTaskContext mtlTaskContext : mtlTaskContexts) {
//获取task实例
List<Task> tasks = new ArrayList<Task>();
if (mtlTaskContext.isSystemTask()) {
if (null != mtlTaskContext.getSysTask()) {
tasks.add(mtlTaskContext.getSysTask());
} else if (null != mtlTaskContext.getSysTaskClazz()) {
Class taskClazz = mtlTaskContext.getSysTaskClazz();
tasks.addAll(findTask(taskClazz, vod.variantData.getName()));
} else {
Task task = project.getTasks().findByName(vod.getScope().getTaskName(mtlTaskContext.getTaskName()));
if (null != task) {
tasks.add(task);
}
}
} else {
Task task = mtlTaskFactory.createTask(variantContext, vod, mtlTaskContext.getTaskActionClazz());
if (null != task) {
if (null != androidBuilder && task instanceof BaseTask) {
((BaseTask) task).setAndroidBuilder(androidBuilder);
}
tasks.add(task);
}
}
if (tasks.isEmpty()) {
// throw new RuntimeException("task is not found " + mtlTaskContext);
project.getLogger().info("task is not found " + vod.getFullName() + mtlTaskContext);
} else {
if (!beforeTasks.isEmpty()) {
for (Task task : tasks) {
project.getLogger().debug("[MtlTaskInjector]" + vod.getFullName() + ":" + task + "->" + StringUtils.join(beforeTasks.toArray()));
for (Task before : beforeTasks) {
project.getLogger().info("[tasks] set task " + task.getProject().getName() + ":" + task.getName() + "->" + before.getProject().getName() + ":" + before.getName());
task.dependsOn(before);
}
}
}
beforeTasks.clear();
beforeTasks.addAll(tasks);
if (null != mtlTaskContext.getTaskFilter()) {
List<Task> beforeTasks2 = mtlTaskContext.getTaskFilter().getBeforeTasks(project, vod);
for (Task task : tasks) {
project.getLogger().debug("[MtlTaskInjector]" + vod.getFullName() + ":" + task + "->" + StringUtils.join(beforeTasks2.toArray()));
for (Task before : beforeTasks2) {
project.getLogger().info("[tasks] set task " + task.getProject().getName() + ":" + task.getName() + "->" + before.getProject().getName() + ":" + before.getName());
task.dependsOn(before);
}
}
}
}
}
}
}
Aggregations