Search in sources :

Example 6 with Task

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");
                    }
                }
            }
        });
    }
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) UnloadedClass(org.hibernate.bytecode.enhance.spi.UnloadedClass) DefaultEnhancementContext(org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext) Enhancer(org.hibernate.bytecode.enhance.spi.Enhancer) URLClassLoader(java.net.URLClassLoader) FileTree(org.gradle.api.file.FileTree) File(java.io.File) UnloadedField(org.hibernate.bytecode.enhance.spi.UnloadedField) DefaultEnhancementContext(org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext) EnhancementContext(org.hibernate.bytecode.enhance.spi.EnhancementContext)

Example 7 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class BuildInvocationsBuilder method findTasks.

private void findTasks(Project project, Map<String, LaunchableGradleTaskSelector> taskSelectors, Collection<String> visibleTasks) {
    for (Project child : project.getChildProjects().values()) {
        findTasks(child, taskSelectors, visibleTasks);
    }
    for (Task task : taskLister.listProjectTasks(project)) {
        // this way, for each task selector, its description will be the one from the selected task with the 'smallest' path
        if (!taskSelectors.containsKey(task.getName())) {
            LaunchableGradleTaskSelector taskSelector = new LaunchableGradleTaskSelector().setDescription(task.getDescription()).setPath(task.getPath());
            taskSelectors.put(task.getName(), taskSelector);
        } else {
            LaunchableGradleTaskSelector taskSelector = taskSelectors.get(task.getName());
            if (hasPathWithLowerOrdering(task, taskSelector)) {
                taskSelector.setDescription(task.getDescription()).setPath(task.getPath());
            }
        }
        // visible tasks are specified as those that have a non-empty group
        if (PublicTaskSpecification.INSTANCE.isSatisfiedBy(task)) {
            visibleTasks.add(task.getName());
        }
    }
}
Also used : Project(org.gradle.api.Project) ToolingModelBuilderSupport.buildFromTask(org.gradle.plugins.ide.internal.tooling.ToolingModelBuilderSupport.buildFromTask) LaunchableGradleTask(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTask) Task(org.gradle.api.Task) LaunchableGradleTaskSelector(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTaskSelector)

Example 8 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class IdeaPlugin method createImlArtifact.

private static LocalComponentArtifactMetadata createImlArtifact(ProjectComponentIdentifier projectId, Project project) {
    String moduleName = project.getExtensions().getByType(IdeaModel.class).getModule().getName();
    File imlFile = new File(project.getProjectDir(), moduleName + ".iml");
    Task byName = project.getTasks().getByName("ideaModule");
    PublishArtifact publishArtifact = new DefaultPublishArtifact(moduleName, "iml", "iml", null, null, imlFile, byName);
    return new PublishArtifactLocalArtifactMetadata(projectId, publishArtifact);
}
Also used : Task(org.gradle.api.Task) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) PublishArtifactLocalArtifactMetadata(org.gradle.internal.component.local.model.PublishArtifactLocalArtifactMetadata) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) File(java.io.File)

Example 9 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class IdeaScalaConfigurer method configure.

public void configure() {
    rootProject.getGradle().addBuildListener(new BuildAdapter() {

        public void projectsEvaluated(Gradle gradle) {
            VersionNumber ideaTargetVersion = findIdeaTargetVersion();
            final boolean useScalaSdk = ideaTargetVersion == null || IDEA_VERSION_WHEN_SCALA_SDK_WAS_INTRODUCED.compareTo(ideaTargetVersion) <= 0;
            final Collection<Project> scalaProjects = findProjectsApplyingIdeaAndScalaPlugins();
            final Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newHashMap();
            rootProject.getTasks().getByName("ideaProject").doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    if (scalaProjects.size() > 0) {
                        scalaCompilerLibraries.clear();
                        scalaCompilerLibraries.putAll(resolveScalaCompilerLibraries(scalaProjects, useScalaSdk));
                        declareUniqueProjectLibraries(Sets.newLinkedHashSet(scalaCompilerLibraries.values()));
                    }
                }
            });
            rootProject.configure(scalaProjects, new Action<Project>() {

                @Override
                public void execute(final Project project) {
                    project.getExtensions().getByType(IdeaModel.class).getModule().getIml().withXml(new Action<XmlProvider>() {

                        @Override
                        public void execute(XmlProvider xmlProvider) {
                            if (useScalaSdk) {
                                declareScalaSdk(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            } else {
                                declareScalaFacet(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : Project(org.gradle.api.Project) Action(org.gradle.api.Action) Task(org.gradle.api.Task) IdeaModel(org.gradle.plugins.ide.idea.model.IdeaModel) XmlProvider(org.gradle.api.XmlProvider) FileCollection(org.gradle.api.file.FileCollection) Collection(java.util.Collection) BuildAdapter(org.gradle.BuildAdapter) Gradle(org.gradle.api.invocation.Gradle) Map(java.util.Map) VersionNumber(org.gradle.util.VersionNumber)

Example 10 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class ProjectConverter method addTasks.

/**
     * Adds the tasks from the project to the GradleProject.
     *
     * @param project the source parent project. Where we get the sub projects from.
     * @param projectView the destination of the tasks from project.
     */
private void addTasks(Project project, ProjectView projectView) {
    List<String> defaultTasks = project.getDefaultTasks();
    for (Task task : taskLister.listProjectTasks(project)) {
        String taskName = task.getName();
        boolean isDefault = defaultTasks.contains(taskName);
        projectView.createTask(taskName, task.getDescription(), isDefault);
    }
}
Also used : Task(org.gradle.api.Task)

Aggregations

Task (org.gradle.api.Task)101 Test (org.junit.Test)21 File (java.io.File)19 Expectations (org.jmock.Expectations)14 DefaultTask (org.gradle.api.DefaultTask)13 Project (org.gradle.api.Project)11 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)5 Map (java.util.Map)5 DefaultAndroidTask (com.android.build.gradle.internal.tasks.DefaultAndroidTask)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Callable (java.util.concurrent.Callable)4 Action (org.gradle.api.Action)4 Spec (org.gradle.api.specs.Spec)4 Closure (groovy.lang.Closure)3 GradleException (org.gradle.api.GradleException)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 TaskDependency (org.gradle.api.tasks.TaskDependency)3 AbstractArchiveTask (org.gradle.api.tasks.bundling.AbstractArchiveTask)3