Search in sources :

Example 1 with EtaRepl

use of com.typelead.gradle.eta.tasks.EtaRepl in project gradle-eta by typelead.

the class EtaBasePlugin method configureEtaRootTasks.

private void configureEtaRootTasks() {
    /* The global, consistent dependency resolution must be done in the
           root project. */
    if (isRootProject()) {
        EtaSetupEnvironment setupEnvironmentTask = project.getTasks().create(ETA_SETUP_ENVIRONMENT_TASK_NAME, EtaSetupEnvironment.class);
        EtaResolveDependencies resolveDependenciesTask = project.getTasks().create(ETA_RESOLVE_DEPENDENCIES_TASK_NAME, EtaResolveDependencies.class);
        EtaInstallAllDependencies installAllDependenciesTask = project.getTasks().create(ETA_INSTALL_ALL_DEPENDENCIES_TASK_NAME, EtaInstallAllDependencies.class);
        EtaRepl replTask = project.getTasks().create(ETA_REPL_TASK_NAME, EtaRepl.class);
        EtlasUpdate updateTask = project.getTasks().create(ETLAS_UPDATE_TASK_NAME, EtlasUpdate.class);
        resolveDependenciesTask.setVersionsChanged(setupEnvironmentTask.getVersionsChanged());
        resolveDependenciesTask.dependsOn(setupEnvironmentTask);
        installAllDependenciesTask.dependsOn(resolveDependenciesTask);
        replTask.setDestinationDir(project.provider(() -> project.getLayout().getProjectDirectory()));
        replTask.dependsOn(setupEnvironmentTask);
        updateTask.dependsOn(setupEnvironmentTask);
        // We need to wait until the Eta dependencies of *all* subprojects
        // have been configured.
        project.getGradle().projectsEvaluated(gradle -> {
            if (extension.shouldPreInstallDependencies()) {
                setupEnvironmentTask.setupEnvironment();
                resolveDependenciesTask.resolveDependencies();
                installAllDependenciesTask.installAllDependencies();
            }
        });
        project.getGradle().getTaskGraph().whenReady(graph -> {
            List<Task> tasks = graph.getAllTasks();
            for (Task task : tasks) {
                if (task instanceof EtaRepl) {
                    boolean inDaemon = false;
                    Set<Thread> allThreads = Thread.getAllStackTraces().keySet();
                    for (Thread thread : allThreads) {
                        if (thread.getName().contains("Daemon")) {
                            inDaemon = true;
                            break;
                        }
                    }
                    if (inDaemon) {
                        throw new GradleException("You are running a REPL task '" + task.getName() + "' in daemon mode, which is not supported.\n\nAdd the flags '--no-daemon -q --console plain' for the best REPL experience.");
                    }
                    if (project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.QUIET) < 0) {
                        project.getLogger().warn("WARNING: You are running a REPL task without '-q'. You are missing out on a better REPL experience.");
                    }
                    if (!project.getGradle().getStartParameter().getConsoleOutput().equals(ConsoleOutput.Plain)) {
                        project.getLogger().warn("WARNING: You are running a REPL task without '--console plain'. You are missing out on a better REPL experience.");
                    }
                }
            }
        });
    }
}
Also used : EtaInstallAllDependencies(com.typelead.gradle.eta.tasks.EtaInstallAllDependencies) Task(org.gradle.api.Task) EtlasUpdate(com.typelead.gradle.eta.tasks.EtlasUpdate) GradleException(org.gradle.api.GradleException) EtaResolveDependencies(com.typelead.gradle.eta.tasks.EtaResolveDependencies) EtaSetupEnvironment(com.typelead.gradle.eta.tasks.EtaSetupEnvironment) EtaRepl(com.typelead.gradle.eta.tasks.EtaRepl)

Example 2 with EtaRepl

use of com.typelead.gradle.eta.tasks.EtaRepl in project gradle-eta by typelead.

the class EtaPlugin method configureSourceSet.

private void configureSourceSet(SourceSet sourceSet) {
    final EtaOptions etaOptions = createEtaOptions();
    final Provider<String> packageName = project.provider(() -> NamingScheme.getPackageName(project, sourceSet.getName()));
    final Provider<String> packageVersion = project.provider(() -> NamingScheme.fixVersion(project.getVersion().toString()));
    final DefaultEtaSourceSet etaSourceSet = project.getObjects().newInstance(DefaultEtaSourceSet.class, sourceSet, "eta", ((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
    ExtensionHelper.createConvention(sourceSet, "eta", etaSourceSet);
    final SourceDirectorySet etaSourceDirectorySet = etaSourceSet.getEta();
    etaSourceDirectorySet.srcDir("src/" + sourceSet.getName() + "/eta");
    /* Ensure that you exclude any Eta source files from the
           resources set. */
    sourceSet.getResources().getFilter().exclude(element -> etaSourceSet.getEta().contains(element.getFile()));
    sourceSet.getAllSource().source(etaSourceDirectorySet);
    final EtaResolveDependencies resolveDependenciesTask = (EtaResolveDependencies) project.getRootProject().getTasks().getByPath(EtaBasePlugin.ETA_RESOLVE_DEPENDENCIES_TASK_NAME);
    final FileCollection freezeConfigFile = resolveDependenciesTask.getOutputs().getFiles();
    final Provider<String> targetConfiguration = project.provider(() -> sourceSet.getCompileClasspathConfigurationName());
    final Provider<Directory> destinationDir = project.getLayout().getBuildDirectory().dir(etaSourceSet.getRelativeOutputDir());
    /* Create the install dependencies task. */
    final EtaInstallDependencies installDependenciesTask = project.getTasks().create(etaSourceSet.getInstallDependenciesTaskName(), EtaInstallDependencies.class);
    installDependenciesTask.setPackageName(packageName);
    installDependenciesTask.setPackageVersion(packageVersion);
    installDependenciesTask.setTargetConfiguration(targetConfiguration);
    installDependenciesTask.setFreezeConfigFile(freezeConfigFile);
    installDependenciesTask.setFreezeConfigChanged(project.provider(() -> resolveDependenciesTask.getDidWork()));
    installDependenciesTask.setDestinationDir(destinationDir);
    installDependenciesTask.setOptions(etaOptions);
    installDependenciesTask.setSource(etaSourceDirectorySet);
    installDependenciesTask.dependsOn(resolveDependenciesTask);
    installDependenciesTask.setDescription("Installs dependencies for the " + sourceSet.getName() + " Eta source.");
    installDependenciesTask.dependsOnOtherEtaProjects();
    final EtaRepl replTask = project.getTasks().create(etaSourceSet.getReplTaskName(), EtaRepl.class);
    replTask.setPackageName(packageName);
    replTask.setDestinationDir(destinationDir);
    replTask.dependsOn(installDependenciesTask);
    /* The install dependencies tasks injects into this configuration so we must
           ensure that it runs before the Java compilation. */
    final AbstractCompile javaCompileTask = (AbstractCompile) project.getTasks().getByName(sourceSet.getCompileJavaTaskName());
    javaCompileTask.dependsOn(installDependenciesTask);
    /* Create the compile task. */
    EtaCompile compileTask = project.getTasks().create(etaSourceSet.getCompileTaskName(), EtaCompile.class);
    Provider<Directory> classesDir = project.provider(() -> {
        final DirectoryProperty buildDir = project.getLayout().getBuildDirectory();
        if (sourceSet.getOutput().isLegacyLayout()) {
            return buildDir.dir(buildDir.getAsFile().get().toPath().relativize(sourceSet.getOutput().getClassesDir().toPath()).toString()).get();
        }
        return buildDir.dir(etaSourceSet.getClassesDir()).get();
    });
    compileTask.setPackageName(packageName);
    compileTask.setPackageVersion(packageVersion);
    compileTask.setClasspath(project.provider(() -> sourceSet.getCompileClasspath()));
    compileTask.setCabalProjectFile(installDependenciesTask.getCabalProjectFileProvider());
    compileTask.setCabalFile(installDependenciesTask.getCabalFileProvider());
    compileTask.setDestinationDir(destinationDir);
    compileTask.addExtraClasspath(javaCompileTask.getDestinationDir());
    compileTask.setClassesDir(classesDir);
    compileTask.setOptions(etaOptions);
    compileTask.setSource(etaSourceDirectorySet);
    compileTask.dependsOn(javaCompileTask);
    compileTask.setDescription("Compiles the " + sourceSet.getName() + " Eta source.");
    /* NOTE: We have commented out the code below since it may be useful later.

           Map<String, Object> builtByOptions = new HashMap<String, Object>();
           builtByOptions.put("builtBy", compileTask);
           sourceSet.getOutput().dir(builtByOptions, classesDir);
        */
    /* Register the Eta classes directory as an output so that the Jar task
           will pick it up nicely. */
    etaSourceDirectorySet.setOutputDir(project.provider(() -> classesDir.get().getAsFile()));
    ((DefaultSourceSetOutput) sourceSet.getOutput()).addClassesDir(() -> etaSourceDirectorySet.getOutputDir());
    project.getTasks().findByName(sourceSet.getClassesTaskName()).dependsOn(compileTask);
    /* Register the package databases as artifacts that will be collected
           upon dependency resolution of project dependencies. */
    addArtifacts(compileTask.getPackageDBProvider(), sourceSet.getApiElementsConfigurationName(), sourceSet.getRuntimeConfigurationName(), sourceSet.getRuntimeElementsConfigurationName());
}
Also used : EtaResolveDependencies(com.typelead.gradle.eta.tasks.EtaResolveDependencies) FileCollection(org.gradle.api.file.FileCollection) DefaultEtaSourceSet(com.typelead.gradle.eta.internal.DefaultEtaSourceSet) EtaOptions(com.typelead.gradle.eta.api.EtaOptions) AbstractCompile(org.gradle.api.tasks.compile.AbstractCompile) DirectoryProperty(org.gradle.api.file.DirectoryProperty) EtaInstallDependencies(com.typelead.gradle.eta.tasks.EtaInstallDependencies) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) EtaRepl(com.typelead.gradle.eta.tasks.EtaRepl) EtaCompile(com.typelead.gradle.eta.tasks.EtaCompile) Directory(org.gradle.api.file.Directory)

Aggregations

EtaRepl (com.typelead.gradle.eta.tasks.EtaRepl)2 EtaResolveDependencies (com.typelead.gradle.eta.tasks.EtaResolveDependencies)2 EtaOptions (com.typelead.gradle.eta.api.EtaOptions)1 DefaultEtaSourceSet (com.typelead.gradle.eta.internal.DefaultEtaSourceSet)1 EtaCompile (com.typelead.gradle.eta.tasks.EtaCompile)1 EtaInstallAllDependencies (com.typelead.gradle.eta.tasks.EtaInstallAllDependencies)1 EtaInstallDependencies (com.typelead.gradle.eta.tasks.EtaInstallDependencies)1 EtaSetupEnvironment (com.typelead.gradle.eta.tasks.EtaSetupEnvironment)1 EtlasUpdate (com.typelead.gradle.eta.tasks.EtlasUpdate)1 GradleException (org.gradle.api.GradleException)1 Task (org.gradle.api.Task)1 Directory (org.gradle.api.file.Directory)1 DirectoryProperty (org.gradle.api.file.DirectoryProperty)1 FileCollection (org.gradle.api.file.FileCollection)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 DefaultSourceSetOutput (org.gradle.api.internal.tasks.DefaultSourceSetOutput)1 AbstractCompile (org.gradle.api.tasks.compile.AbstractCompile)1