diff --git a/README.md b/README.md index c1dcb71..486db29 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ IntelliJ Run configuration plugin for [Task](https://taskfile.dev/). ## Requirements * Install `task`. See [here](https://taskfile.dev/#/installation) -* JDK 11 to build from source +* JDK 8 or higher to build from source ## Install from JetBrains Plugin Marketplace @@ -29,5 +29,9 @@ Install [Taskfile Plugin](https://plugins.jetbrains.com/plugin/17058-taskfile) b 1. Open 'Run/Debug Configurations'. 2. Add `Taskfile`: + * Task executable: Select `task` executable to run. Set empty to run `task` in `$PATH`. * Taskfile: Select `Taskfile.yml` file to use. * Task: Input task name to run. + * CLI arguments: Input [CLI arguments](https://taskfile.dev/#/usage?id=forwarding-cli-arguments-to-commands) to use. + * Working directory + * Environment variables diff --git a/Taskfile.yml b/Taskfile.yml index b547cf9..f884514 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,4 +3,10 @@ version: '3' tasks: - runIde: ./gradlew runIde + build: + cmds: + - ./gradlew build + + runIde: + cmds: + - ./gradlew runIde diff --git a/build.gradle b/build.gradle index 138e7b0..53092f6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,31 @@ plugins { - id 'java' - id 'org.jetbrains.intellij' version '1.3.0' + id "java" + id "org.jetbrains.kotlin.jvm" version "1.5.32" + id "org.jetbrains.intellij" version "1.3.0" } +apply plugin: "kotlin" +apply plugin: "org.jetbrains.intellij" + group 'lechuck' -version '1.2.0' +version '1.3.0' + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +compileKotlin { + kotlinOptions.jvmTarget = "1.8" +} +compileTestKotlin { + kotlinOptions.jvmTarget = "1.8" +} repositories { mavenCentral() } dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' @@ -19,6 +34,7 @@ dependencies { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { version = '2021.3' + updateSinceUntilBuild = false } buildSearchableOptions { @@ -28,7 +44,6 @@ buildSearchableOptions { patchPluginXml { version = project.version sinceBuild = '204' - untilBuild = '213.*' } publishPlugin { diff --git a/docs/screenshot.png b/docs/screenshot.png index 24df12e..0d2dcbf 100644 Binary files a/docs/screenshot.png and b/docs/screenshot.png differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7454180 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..2e6e589 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..1b6c787 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/src/main/java/lechuck/intellij/TaskCommandLineState.java b/src/main/java/lechuck/intellij/TaskCommandLineState.java deleted file mode 100644 index 51a61f2..0000000 --- a/src/main/java/lechuck/intellij/TaskCommandLineState.java +++ /dev/null @@ -1,71 +0,0 @@ -package lechuck.intellij; - -import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.CommandLineState; -import com.intellij.execution.configurations.GeneralCommandLine; -import com.intellij.execution.process.ProcessHandler; -import com.intellij.execution.process.ProcessHandlerFactory; -import com.intellij.execution.process.ProcessTerminatedListener; -import com.intellij.execution.runners.ExecutionEnvironment; -import lechuck.intellij.util.RegexUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.HashMap; - -class TaskCommandLineState extends CommandLineState { - private final TaskRunConfiguration cfg; - - public TaskCommandLineState(@NotNull ExecutionEnvironment env, TaskRunConfiguration cfg) { - super(env); - this.cfg = cfg; - } - - @Override - @NotNull - protected ProcessHandler startProcess() throws ExecutionException { - var processHandler = ProcessHandlerFactory.getInstance() - .createColoredProcessHandler(createGeneralCommandLine()); - - ProcessTerminatedListener.attach(processHandler); - - return processHandler; - } - - private GeneralCommandLine createGeneralCommandLine() { - var options = cfg.getOptions(); - - var cmd = new ArrayList(); - - // taskPath - var taskPath = options.getTaskPath(); - if (taskPath == null || taskPath.isEmpty()) { - cmd.add("task"); - } else { - cmd.add(taskPath); - } - - // taskfile - var taskfile = options.getTaskfile(); - if (!taskfile.isEmpty()) { - cmd.add("--taskfile"); - cmd.add(taskfile); - } - - // task - cmd.add(options.getTask()); - - // arguments - var arguments = options.getArguments(); - var argumentList = RegexUtil.splitBySpacePreservingQuotes(arguments); - if (!argumentList.isEmpty()) { - cmd.add("--"); - cmd.addAll(argumentList); - } - - // environment variables - var envMap = new HashMap(); - - return new GeneralCommandLine(cmd).withEnvironment(envMap); - } -} \ No newline at end of file diff --git a/src/main/java/lechuck/intellij/TaskConfigurationFactory.java b/src/main/java/lechuck/intellij/TaskConfigurationFactory.java deleted file mode 100644 index 159314a..0000000 --- a/src/main/java/lechuck/intellij/TaskConfigurationFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -package lechuck.intellij; - -import com.intellij.execution.configurations.ConfigurationFactory; -import com.intellij.execution.configurations.ConfigurationType; -import com.intellij.execution.configurations.RunConfiguration; -import com.intellij.openapi.components.BaseState; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class TaskConfigurationFactory extends ConfigurationFactory { - - public TaskConfigurationFactory(ConfigurationType type) { - super(type); - } - - @Override - public @NotNull @NonNls String getId() { - return TaskRunConfigurationType.ID; - } - - @Override - public @NotNull RunConfiguration createTemplateConfiguration(@NotNull Project project) { - return new TaskRunConfiguration(project, this, "Task"); - } - - @Override - public @Nullable Class getOptionsClass() { - return TaskRunConfigurationOptions.class; - } -} diff --git a/src/main/java/lechuck/intellij/TaskExecutableFileChooserDescriptor.java b/src/main/java/lechuck/intellij/TaskExecutableFileChooserDescriptor.java deleted file mode 100644 index c567f30..0000000 --- a/src/main/java/lechuck/intellij/TaskExecutableFileChooserDescriptor.java +++ /dev/null @@ -1,35 +0,0 @@ -package lechuck.intellij; - -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileElement; -import com.intellij.openapi.vfs.VirtualFile; - -public class TaskExecutableFileChooserDescriptor extends FileChooserDescriptor { - public TaskExecutableFileChooserDescriptor() { - super(true, false, false, false, false, false); - - //noinspection DialogTitleCapitalization - setTitle("Select task executable"); - } - - @Override - public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { - if (!showHiddenFiles && FileElement.isFileHidden(file)) { - return false; - } - if (file.isDirectory()) { - return true; - } - String filename = file.getName(); - if (filename.equalsIgnoreCase("task") || filename.equalsIgnoreCase("task.exe")) { - return true; - } - - return super.isFileVisible(file, showHiddenFiles); - } - - @Override - public boolean isFileSelectable(VirtualFile file) { - return !file.isDirectory() && isFileVisible(file, true); - } -} diff --git a/src/main/java/lechuck/intellij/TaskPluginIcons.java b/src/main/java/lechuck/intellij/TaskPluginIcons.java deleted file mode 100644 index 2666347..0000000 --- a/src/main/java/lechuck/intellij/TaskPluginIcons.java +++ /dev/null @@ -1,9 +0,0 @@ -package lechuck.intellij; - -import com.intellij.openapi.util.IconLoader; - -import javax.swing.*; - -public interface TaskPluginIcons { - Icon Task = IconLoader.getIcon("/icons/task.png", TaskPluginIcons.class); -} diff --git a/src/main/java/lechuck/intellij/TaskRunConfiguration.java b/src/main/java/lechuck/intellij/TaskRunConfiguration.java deleted file mode 100644 index ad75a80..0000000 --- a/src/main/java/lechuck/intellij/TaskRunConfiguration.java +++ /dev/null @@ -1,82 +0,0 @@ -package lechuck.intellij; - -import com.intellij.execution.Executor; -import com.intellij.execution.configuration.EnvironmentVariablesData; -import com.intellij.execution.configurations.*; -import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.openapi.options.SettingsEditor; -import com.intellij.openapi.project.Project; -import org.apache.commons.lang.StringUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -class TaskRunConfiguration extends RunConfigurationBase { - - public TaskRunConfiguration(Project project, ConfigurationFactory factory, String name) { - super(project, factory, name); - } - - @Override - @NotNull - public TaskRunConfigurationOptions getOptions() { - return (TaskRunConfigurationOptions) super.getOptions(); - } - - public String getTaskPath() { - return getOptions().getTaskPath(); - } - - public void setTaskPath(String path) { - getOptions().setTaskPath(path); - } - - public String getTaskfile() { - return getOptions().getTaskfile(); - } - - public void setTaskfile(String filename) { - getOptions().setTaskfile(filename); - } - - public String getTask() { - return getOptions().getTask(); - } - - public void setTask(String task) { - getOptions().setTask(task); - } - - public String getArguments() { - return getOptions().getArguments(); - } - - public void setArguments(String arguments) { - getOptions().setArguments(arguments); - } - - public EnvironmentVariablesData getEnvironments() { - return getOptions().getEnvironments(); - } - - public void setEnvironments(EnvironmentVariablesData env) { - getOptions().setEnvironments(env); - } - - @Override - public @NotNull SettingsEditor getConfigurationEditor() { - return new TaskSettingsEditor(this.getProject()); - } - - @Override - public void checkConfiguration() throws RuntimeConfigurationException { - var task = getTask(); - if (StringUtils.isEmpty(task)) { - throw new RuntimeConfigurationError("Task is not set"); - } - } - - @Override - public @Nullable RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) { - return new TaskCommandLineState(env, this); - } -} diff --git a/src/main/java/lechuck/intellij/TaskRunConfigurationOptions.java b/src/main/java/lechuck/intellij/TaskRunConfigurationOptions.java deleted file mode 100644 index 6a71102..0000000 --- a/src/main/java/lechuck/intellij/TaskRunConfigurationOptions.java +++ /dev/null @@ -1,60 +0,0 @@ -package lechuck.intellij; - -import com.intellij.execution.configuration.EnvironmentVariablesData; -import com.intellij.execution.configurations.RunConfigurationOptions; -import com.intellij.openapi.components.StoredProperty; -import com.intellij.openapi.components.StoredPropertyBase; - -import java.util.Map; - -import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; - -public class TaskRunConfigurationOptions extends RunConfigurationOptions { - private final StoredProperty taskPath = string("").provideDelegate(this, "taskPath"); - private final StoredProperty taskfile = string("").provideDelegate(this, "taskfile"); - private final StoredProperty task = string("").provideDelegate(this, "task"); - private final StoredProperty arguments = string("").provideDelegate(this, "arguments"); - private final StoredPropertyBase> mapStoredPropertyBase = map(); - private final StoredProperty> environments = mapStoredPropertyBase.provideDelegate(this, "environments"); - - public String getTaskPath() { - return defaultIfEmpty(taskPath.getValue(this), ""); - } - - public void setTaskPath(String taskPath) { - this.taskPath.setValue(this, defaultIfEmpty(taskPath, "")); - } - - public String getTaskfile() { - return defaultIfEmpty(taskfile.getValue(this), ""); - } - - public void setTaskfile(String taskfile) { - this.taskfile.setValue(this, defaultIfEmpty(taskfile, "")); - } - - public String getTask() { - return defaultIfEmpty(task.getValue(this), ""); - } - - public void setTask(String task) { - this.task.setValue(this, defaultIfEmpty(task, "")); - } - - public String getArguments() { - return defaultIfEmpty(arguments.getValue(this), ""); - } - - public void setArguments(String arguments) { - this.arguments.setValue(this, defaultIfEmpty(arguments, "")); - } - - public EnvironmentVariablesData getEnvironments() { - var map = environments.getValue(this); - return EnvironmentVariablesData.create(map, true); - } - - public void setEnvironments(EnvironmentVariablesData env) { - this.environments.setValue(this, env.getEnvs()); - } -} diff --git a/src/main/java/lechuck/intellij/TaskRunConfigurationType.java b/src/main/java/lechuck/intellij/TaskRunConfigurationType.java deleted file mode 100644 index 823e379..0000000 --- a/src/main/java/lechuck/intellij/TaskRunConfigurationType.java +++ /dev/null @@ -1,12 +0,0 @@ -package lechuck.intellij; - -import com.intellij.execution.configurations.ConfigurationTypeBase; - -public class TaskRunConfigurationType extends ConfigurationTypeBase { - public static final String ID = "TaskRunConfiguration"; - - public TaskRunConfigurationType() { - super(ID, "Taskfile", "Taskfile run configuration type", TaskPluginIcons.Task); - addFactory(new TaskConfigurationFactory(this)); - } -} diff --git a/src/main/java/lechuck/intellij/TaskSettingsEditor.java b/src/main/java/lechuck/intellij/TaskSettingsEditor.java deleted file mode 100644 index 84f7ee1..0000000 --- a/src/main/java/lechuck/intellij/TaskSettingsEditor.java +++ /dev/null @@ -1,148 +0,0 @@ -package lechuck.intellij; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.intellij.execution.configuration.EnvironmentVariablesComponent; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.application.PathMacros; -import com.intellij.openapi.options.SettingsEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.FixedSizeButton; -import com.intellij.openapi.ui.LabeledComponent; -import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.ui.DocumentAdapter; -import com.intellij.ui.TextFieldWithAutoCompletion; -import com.intellij.ui.components.fields.ExpandableTextField; -import com.intellij.util.ui.FormBuilder; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import java.awt.*; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; - -public class TaskSettingsEditor extends SettingsEditor { - private JPanel panel; - private final Project project; - private final TextFieldWithBrowseButton taskExecutableField; - private final TextFieldWithBrowseButton filenameField; - private final TextFieldWithAutoCompletion.StringsCompletionProvider taskCompletionProvider; - private final TextFieldWithAutoCompletion taskField; - private final ExpandableTextField argumentsField; - private final EnvironmentVariablesComponent envVarsComponent; - private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - public TaskSettingsEditor(@NotNull Project project) { - this.project = project; - this.taskExecutableField = new TextFieldWithBrowseButton(); - this.filenameField = new TextFieldWithBrowseButton(); - this.taskCompletionProvider = new TextFieldWithAutoCompletion.StringsCompletionProvider(List.of(), null); - this.taskField = new TextFieldWithAutoCompletion<>(project, taskCompletionProvider, true, ""); - this.argumentsField = new ExpandableTextField(); - this.envVarsComponent = new EnvironmentVariablesComponent(); - - this.taskExecutableField.addBrowseFolderListener("Task Executable", "Select task executable to use", project, new TaskExecutableFileChooserDescriptor()); - this.filenameField.addBrowseFolderListener("Taskfile", "Select Taskfile.yml to run", project, new TaskfileFileChooserDescriptor()); - this.filenameField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(@NotNull DocumentEvent e) { - updateTargetCompletion(filenameField.getText()); - } - }); - } - - private void updateTargetCompletion(String filename) { - VirtualFile file = LocalFileSystem.getInstance().findFileByPath(filename); - if (file != null) { - PsiFile psiFile = PsiManager.getInstance(project).findFile(file); - if (psiFile != null) { - taskCompletionProvider.setItems(findTasks(psiFile)); - return; - } - } - taskCompletionProvider.setItems(List.of()); - } - - - private Collection findTasks(PsiFile file) { - try (InputStream is = file.getVirtualFile().getInputStream()) { - Taskfile taskfile = mapper.readValue(is, Taskfile.class); - Map tasks = taskfile.getTasks(); - return tasks == null ? List.of() : tasks.keySet(); - } catch (Exception e) { - e.printStackTrace(); - return List.of(); - } - } - - @Override - protected void resetEditorFrom(TaskRunConfiguration cfg) { - taskExecutableField.setText(defaultIfEmpty(cfg.getTaskPath(), "")); - filenameField.setText(defaultIfEmpty(cfg.getTaskfile(), "")); - taskField.setText(defaultIfEmpty(cfg.getTask(), "")); - argumentsField.setText(defaultIfEmpty(cfg.getArguments(), "")); - envVarsComponent.setEnvData(cfg.getEnvironments()); - } - - @Override - protected void applyEditorTo(@NotNull TaskRunConfiguration cfg) { - cfg.setTaskPath(taskExecutableField.getText()); - cfg.setTaskfile(filenameField.getText()); - cfg.setTask(taskField.getText()); - cfg.setArguments(argumentsField.getText()); - cfg.setEnvironments(envVarsComponent.getEnvData()); - } - - @NotNull - @Override - protected JComponent createEditor() { - if (panel == null) { - panel = FormBuilder.createFormBuilder() - .setAlignLabelOnRight(false) - .setHorizontalGap(UIUtil.DEFAULT_HGAP) - .setVerticalGap(UIUtil.DEFAULT_VGAP) - .addLabeledComponent("Task executable", taskExecutableField) - .addLabeledComponent("Taskfile", filenameField) - .addLabeledComponent("Task", taskField) - .addComponent(LabeledComponent.create(argumentsField, "CLI arguments")) - .getPanel(); - } - return panel; - } - - // TODO remove it? - @SuppressWarnings("unused") - private JComponent createComponentWithMacroBrowse(TextFieldWithBrowseButton textAccessor) { - var button = new FixedSizeButton(textAccessor); - button.setIcon(AllIcons.Actions.ListFiles); - button.addActionListener(e -> { - var userMacroNames = new ArrayList<>(PathMacros.getInstance().getUserMacroNames()); - JBPopupFactory.getInstance() - .createPopupChooserBuilder(userMacroNames) - .setItemChosenCallback(item -> textAccessor.setText("$$item$")) - .setMovable(false) - .setResizable(false) - .createPopup() - .showUnderneathOf(button); - }); - - var p = new JPanel(new BorderLayout()); - p.add(textAccessor, BorderLayout.CENTER); - p.add(button, BorderLayout.EAST); - return p; - } -} diff --git a/src/main/java/lechuck/intellij/Taskfile.java b/src/main/java/lechuck/intellij/Taskfile.java deleted file mode 100644 index 2c883f4..0000000 --- a/src/main/java/lechuck/intellij/Taskfile.java +++ /dev/null @@ -1,18 +0,0 @@ -package lechuck.intellij; - -import java.util.Collections; -import java.util.Map; - -public class Taskfile { - private Map tasks; - - public Map getTasks() { - return Collections.unmodifiableMap(tasks); - } - - // TODO remove? - @SuppressWarnings("unused") - public void setTasks(Map tasks) { - this.tasks = tasks; - } -} diff --git a/src/main/java/lechuck/intellij/TaskfileFileChooserDescriptor.java b/src/main/java/lechuck/intellij/TaskfileFileChooserDescriptor.java deleted file mode 100644 index 1568838..0000000 --- a/src/main/java/lechuck/intellij/TaskfileFileChooserDescriptor.java +++ /dev/null @@ -1,34 +0,0 @@ -package lechuck.intellij; - -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileElement; -import com.intellij.openapi.vfs.VirtualFile; - -public class TaskfileFileChooserDescriptor extends FileChooserDescriptor { - public TaskfileFileChooserDescriptor() { - super(true, false, false, false, false, false); - - setTitle("Select Taskfile"); - } - - @Override - public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { - if (!showHiddenFiles && FileElement.isFileHidden(file)) { - return false; - } - if (file.isDirectory()) { - return true; - } - String ext = file.getExtension(); - if ("yaml".equalsIgnoreCase(ext) || "yml".equalsIgnoreCase(ext)) { - return true; - } - - return super.isFileVisible(file, showHiddenFiles); - } - - @Override - public boolean isFileSelectable(VirtualFile file) { - return !file.isDirectory() && isFileVisible(file, true); - } -} diff --git a/src/main/java/lechuck/intellij/util/RegexUtil.java b/src/main/java/lechuck/intellij/util/RegexUtil.java deleted file mode 100644 index 3e40500..0000000 --- a/src/main/java/lechuck/intellij/util/RegexUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -package lechuck.intellij.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -public class RegexUtil { - - private RegexUtil() {} - - public static List splitBySpacePreservingQuotes(String str) { - if (str == null) { - return List.of(); - } - /* TODO Character classes should be preferred over reluctant quantifiers in regular expressions - Found by SonarQube: Code smell Minor java:S5857 - .+? MUST be replaced by <[^>]++> - */ - var matcher = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(str); - var result = new ArrayList(); - while (matcher.find()) { - String item = matcher.group(1).replace("\"", ""); - result.add(item); - } - return result; - } -} diff --git a/src/main/kotlin/lechuck/intellij/TaskConfigurationFactory.kt b/src/main/kotlin/lechuck/intellij/TaskConfigurationFactory.kt new file mode 100644 index 0000000..cb54275 --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskConfigurationFactory.kt @@ -0,0 +1,13 @@ +package lechuck.intellij + +import com.intellij.execution.configurations.ConfigurationFactory +import com.intellij.openapi.project.Project + +class TaskConfigurationFactory(private val runCfgType: TaskRunConfigurationType) : ConfigurationFactory(runCfgType) { + + override fun getId() = TaskRunConfigurationType.ID + + override fun getName(): String = runCfgType.displayName + + override fun createTemplateConfiguration(project: Project) = TaskRunConfiguration(project, this, "Task") +} \ No newline at end of file diff --git a/src/main/kotlin/lechuck/intellij/TaskExecutableFileChooserDescriptor.kt b/src/main/kotlin/lechuck/intellij/TaskExecutableFileChooserDescriptor.kt new file mode 100644 index 0000000..d9af34b --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskExecutableFileChooserDescriptor.kt @@ -0,0 +1,31 @@ +package lechuck.intellij + +import com.intellij.openapi.fileChooser.FileChooserDescriptor +import com.intellij.openapi.fileChooser.FileElement +import com.intellij.openapi.vfs.VirtualFile + +class TaskExecutableFileChooserDescriptor : FileChooserDescriptor(true, false, false, false, false, false) { + init { + title = "Select Task Executable" + } + + override fun isFileVisible(file: VirtualFile, showHiddenFiles: Boolean): Boolean { + if (!showHiddenFiles && FileElement.isFileHidden(file)) { + return false + } + if (file.isDirectory) { + return true + } + val filename = file.name + return if ("task".equals(filename, ignoreCase = true) || "task.exe".equals(filename, ignoreCase = true)) { + true + } else super.isFileVisible(file, showHiddenFiles) + } + + override fun isFileSelectable(file: VirtualFile?): Boolean { + if (file != null) { + return !file.isDirectory && isFileVisible(file, true) + } + return false + } +} \ No newline at end of file diff --git a/src/main/kotlin/lechuck/intellij/TaskPluginIcons.kt b/src/main/kotlin/lechuck/intellij/TaskPluginIcons.kt new file mode 100644 index 0000000..dc2b6dd --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskPluginIcons.kt @@ -0,0 +1,10 @@ +package lechuck.intellij + +import com.intellij.openapi.util.IconLoader +import javax.swing.Icon + +interface TaskPluginIcons { + companion object { + val Task: Icon = IconLoader.getIcon("/icons/task.png", TaskPluginIcons::class.java) + } +} \ No newline at end of file diff --git a/src/main/kotlin/lechuck/intellij/TaskRunConfiguration.kt b/src/main/kotlin/lechuck/intellij/TaskRunConfiguration.kt new file mode 100644 index 0000000..795c28d --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskRunConfiguration.kt @@ -0,0 +1,141 @@ +package lechuck.intellij + +import com.intellij.execution.Executor +import com.intellij.execution.configuration.EnvironmentVariablesData +import com.intellij.execution.configurations.* +import com.intellij.execution.process.ColoredProcessHandler +import com.intellij.execution.process.ProcessHandler +import com.intellij.execution.process.ProcessTerminatedListener +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.openapi.components.PathMacroManager +import com.intellij.openapi.project.Project +import com.intellij.util.EnvironmentUtil +import com.intellij.util.getOrCreate +import org.jdom.Element +import java.io.File + +class TaskRunConfiguration(project: Project, factory: TaskConfigurationFactory, name: String) : + LocatableConfigurationBase(project, factory, name) { + + var taskPath = "" + var filename = "" + var task = "" + var arguments = "" + var workingDirectory = "" + var environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT + var pty = false + + private companion object { + const val TASKFILE = "taskfile" + const val TASKPATH = "taskPath" + const val FILENAME = "filename" + const val TASK = "task" + const val WORKING_DIRECTORY = "workingDirectory" + const val ARGUMENTS = "arguments" + const val PTY = "pty" + } + + override fun checkConfiguration() { + if (task.isEmpty()) { + throw RuntimeConfigurationError("Task is not set") + } + } + + override fun getConfigurationEditor() = TaskRunConfigurationEditor(project) + + override fun writeExternal(element: Element) { + super.writeExternal(element) + val child = element.getOrCreate(TASKFILE) + child.setAttribute(TASKPATH, taskPath) + child.setAttribute(FILENAME, filename) + child.setAttribute(TASK, task) + child.setAttribute(WORKING_DIRECTORY, workingDirectory) + child.setAttribute(ARGUMENTS, arguments) + child.setAttribute(PTY, if (pty) "true" else "false") + environmentVariables.writeExternal(child) + } + + override fun readExternal(element: Element) { + super.readExternal(element) + + // support v1 format + readExternalV1(element) + + val child = element.getChild(TASKFILE) + if (child != null) { + taskPath = child.getAttributeValue(TASKPATH) ?: "" + filename = child.getAttributeValue(FILENAME) ?: "" + task = child.getAttributeValue(TASK) ?: "" + workingDirectory = child.getAttributeValue(WORKING_DIRECTORY) ?: "" + arguments = child.getAttributeValue(ARGUMENTS) ?: "" + pty = child.getAttributeValue(PTY) == "true" + environmentVariables = EnvironmentVariablesData.readExternal(child) + } + } + + private fun readExternalV1(element: Element) { + val list = element.getChildren("option") + val valueMap = list.associate { option: Element -> + val name = option.getAttributeValue("name") + val value = option.getAttributeValue("value") + name to value + } + taskPath = valueMap["taskPath"] ?: "" + task = valueMap["task"] ?: "" + filename = valueMap["taskfile"] ?: "" + arguments = valueMap["arguments"] ?: "" + } + + override fun getState(executor: Executor, executionEnvironment: ExecutionEnvironment): RunProfileState { + return object : CommandLineState(executionEnvironment) { + override fun startProcess(): ProcessHandler { + val params = ParametersList() + + // taskfile + val macroManager = PathMacroManager.getInstance(project) + val taskfilePath = macroManager.expandPath(filename) + if (taskfilePath.isNotEmpty()) { + params.addAll("--taskfile", taskfilePath) + } + + // task + if (task.isNotEmpty()) { + params.addParametersString(task) + } + + // arguments + if (arguments.isNotEmpty()) { + params.add("--") + params.addParametersString(arguments) + } + + // working directory + val workDirectory = if (workingDirectory.isNotEmpty()) { + macroManager.expandPath(workingDirectory) + } else { + File(taskfilePath).parent + } + + // environment variables + val parentEnvs = + if (environmentVariables.isPassParentEnvs) EnvironmentUtil.getEnvironmentMap() else emptyMap() + val envs = parentEnvs + environmentVariables.envs.toMutableMap() + + // build cmd + val command = arrayOf(taskPath.ifEmpty { "task" }) + params.array + val cmdLine = if (pty) PtyCommandLine() else GeneralCommandLine() + val cmd = cmdLine + .withExePath(command[0]) + .withWorkDirectory(workDirectory) + .withEnvironment(envs) + .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.NONE) + .withParameters(command.slice(1 until command.size)) + + val processHandler = ColoredProcessHandler(cmd) + processHandler.setShouldKillProcessSoftly(true) + ProcessTerminatedListener.attach(processHandler) + return processHandler + } + } + } +} diff --git a/src/main/kotlin/lechuck/intellij/TaskRunConfigurationEditor.kt b/src/main/kotlin/lechuck/intellij/TaskRunConfigurationEditor.kt new file mode 100644 index 0000000..6eda7c0 --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskRunConfigurationEditor.kt @@ -0,0 +1,149 @@ +package lechuck.intellij + +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import com.intellij.execution.configuration.EnvironmentVariablesComponent +import com.intellij.icons.AllIcons +import com.intellij.openapi.application.PathMacros +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory +import com.intellij.openapi.options.SettingsEditor +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.FixedSizeButton +import com.intellij.openapi.ui.LabeledComponent +import com.intellij.openapi.ui.TextFieldWithBrowseButton +import com.intellij.openapi.ui.popup.JBPopupFactory +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiManager +import com.intellij.ui.DocumentAdapter +import com.intellij.ui.TextFieldWithAutoCompletion +import com.intellij.ui.components.fields.ExpandableTextField +import com.intellij.util.ui.FormBuilder +import com.intellij.util.ui.UIUtil +import java.awt.BorderLayout +import javax.swing.JComponent +import javax.swing.JPanel +import javax.swing.event.DocumentEvent + +class TaskRunConfigurationEditor(private val project: Project) : SettingsEditor() { + private val taskExecutableField = TextFieldWithBrowseButton() + private val filenameField = TextFieldWithBrowseButton() + private val taskCompletionProvider = + TextFieldWithAutoCompletion.StringsCompletionProvider(emptyList(), TaskPluginIcons.Task) + private val taskField = TextFieldWithAutoCompletion(project, taskCompletionProvider, true, "") + private val argumentsField = ExpandableTextField() + private val envVarsComponent = EnvironmentVariablesComponent() + private val workingDirectoryField = TextFieldWithBrowseButton() + private val mapper = ObjectMapper(YAMLFactory()).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + + private val panel: JPanel by lazy { + FormBuilder.createFormBuilder() + .setAlignLabelOnRight(false) + .setHorizontalGap(UIUtil.DEFAULT_HGAP) + .setVerticalGap(UIUtil.DEFAULT_VGAP) + .addLabeledComponent("Task executable", taskExecutableField) + .addLabeledComponent("Taskfile", filenameField) + .addLabeledComponent("Task", taskField) + .addComponent(LabeledComponent.create(argumentsField, "CLI arguments")) + .addLabeledComponent("Working directory", createComponentWithMacroBrowse(workingDirectoryField)) + .addComponent(envVarsComponent) + .panel + } + + init { + taskExecutableField.addBrowseFolderListener( + "Task Executable", + "Select task executable to use", + project, + TaskExecutableFileChooserDescriptor() + ) + + filenameField.addBrowseFolderListener( + "Taskfile", + "Select Taskfile.yml to run", + project, + TaskfileFileChooserDescriptor() + ) + + filenameField.textField.document.addDocumentListener(object : DocumentAdapter() { + override fun textChanged(event: DocumentEvent) { + updateTargetCompletion(filenameField.text) + } + }) + + workingDirectoryField.addBrowseFolderListener( + "Working Directory Chooser", + "Choose working directory", + project, + FileChooserDescriptorFactory.createSingleFolderDescriptor() + ) + } + + private fun updateTargetCompletion(filename: String) { + val file = LocalFileSystem.getInstance().findFileByPath(filename) + if (file != null) { + val psiFile = PsiManager.getInstance(project).findFile(file) + if (psiFile != null) { + taskCompletionProvider.setItems(findTasks(psiFile)) + return + } + } + taskCompletionProvider.setItems(emptyList()) + } + + private fun findTasks(file: PsiFile): Collection { + try { + file.virtualFile.inputStream.use { `is` -> + val taskfile: Taskfile = mapper.readValue(`is`, Taskfile::class.java) + val tasks = taskfile.tasks + return tasks?.keys ?: emptyList() + } + } catch (e: Exception) { + e.printStackTrace() + return emptyList() + } + } + + override fun createEditor() = panel + + override fun resetEditorFrom(cfg: TaskRunConfiguration) { + taskExecutableField.text = cfg.taskPath + filenameField.text = cfg.filename + taskField.text = cfg.task + argumentsField.text = cfg.arguments + envVarsComponent.envData = cfg.environmentVariables + workingDirectoryField.text = cfg.workingDirectory + + updateTargetCompletion(cfg.filename) + } + + override fun applyEditorTo(cfg: TaskRunConfiguration) { + cfg.taskPath = taskExecutableField.text + cfg.filename = filenameField.text + cfg.task = taskField.text + cfg.arguments = argumentsField.text + cfg.environmentVariables = envVarsComponent.envData + cfg.workingDirectory = workingDirectoryField.text + } + + private fun createComponentWithMacroBrowse(textAccessor: TextFieldWithBrowseButton): JComponent { + val button = FixedSizeButton(textAccessor) + button.icon = AllIcons.Actions.ListFiles + button.addActionListener { + JBPopupFactory.getInstance() + .createPopupChooserBuilder(PathMacros.getInstance().userMacroNames.toList()) + .setItemChosenCallback { item: String -> + textAccessor.text = "$$item$" + } + .setMovable(false) + .setResizable(false) + .createPopup() + .showUnderneathOf(button) + } + return JPanel(BorderLayout()).apply { + add(textAccessor, BorderLayout.CENTER) + add(button, BorderLayout.EAST) + } + } +} diff --git a/src/main/kotlin/lechuck/intellij/TaskRunConfigurationType.kt b/src/main/kotlin/lechuck/intellij/TaskRunConfigurationType.kt new file mode 100644 index 0000000..255259a --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskRunConfigurationType.kt @@ -0,0 +1,14 @@ +package lechuck.intellij + +import com.intellij.execution.configurations.ConfigurationTypeBase + +class TaskRunConfigurationType : + ConfigurationTypeBase(ID, "Taskfile", "Taskfile run configuration type", TaskPluginIcons.Task) { + companion object { + const val ID = "TaskRunConfiguration" + } + + init { + addFactory(TaskConfigurationFactory(this)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/lechuck/intellij/Taskfile.kt b/src/main/kotlin/lechuck/intellij/Taskfile.kt new file mode 100644 index 0000000..f190c42 --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/Taskfile.kt @@ -0,0 +1,5 @@ +package lechuck.intellij + +class Taskfile { + var tasks: Map? = null +} \ No newline at end of file diff --git a/src/main/kotlin/lechuck/intellij/TaskfileFileChooserDescriptor.kt b/src/main/kotlin/lechuck/intellij/TaskfileFileChooserDescriptor.kt new file mode 100644 index 0000000..9f7be9a --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/TaskfileFileChooserDescriptor.kt @@ -0,0 +1,31 @@ +package lechuck.intellij + +import com.intellij.openapi.fileChooser.FileChooserDescriptor +import com.intellij.openapi.fileChooser.FileElement +import com.intellij.openapi.vfs.VirtualFile + +class TaskfileFileChooserDescriptor : FileChooserDescriptor(true, false, false, false, false, false) { + init { + title = "Select Taskfile" + } + + override fun isFileVisible(file: VirtualFile, showHiddenFiles: Boolean): Boolean { + if (!showHiddenFiles && FileElement.isFileHidden(file)) { + return false + } + if (file.isDirectory) { + return true + } + val ext = file.extension + return if ("yaml".equals(ext, ignoreCase = true) || "yml".equals(ext, ignoreCase = true)) { + true + } else super.isFileVisible(file, showHiddenFiles) + } + + override fun isFileSelectable(file: VirtualFile?): Boolean { + if (file != null) { + return !file.isDirectory && isFileVisible(file, true) + } + return false + } +} \ No newline at end of file diff --git a/src/main/kotlin/lechuck/intellij/util/RegexUtil.kt b/src/main/kotlin/lechuck/intellij/util/RegexUtil.kt new file mode 100644 index 0000000..38afc47 --- /dev/null +++ b/src/main/kotlin/lechuck/intellij/util/RegexUtil.kt @@ -0,0 +1,19 @@ +package lechuck.intellij.util + +import java.util.regex.Pattern + +object RegexUtil { + fun splitBySpace(str: String?): List { + if (str == null) { + return emptyList() + } + val matcher = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*").matcher(str) + val result = ArrayList() + + while (matcher.find()) { + val item: String = matcher.group(1).replace("\"", "") + result.add(item) + } + return result + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index bc22258..2f508cb 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -27,6 +27,11 @@ ]]> +
  • add working directory
  • +
  • add environment variables
  • + v1.2.0
    • Support for 2021.3 Jetbrains releases
    • diff --git a/src/test/java/lechuck/intellij/util/RegexUtilTest.java b/src/test/java/lechuck/intellij/util/RegexUtilTest.java deleted file mode 100644 index 94e455b..0000000 --- a/src/test/java/lechuck/intellij/util/RegexUtilTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package lechuck.intellij.util; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -import java.util.List; - -public class RegexUtilTest { - - @Test - public void testSplitBySpacePreservingQuotes() { - assertEquals(List.of(), RegexUtil.splitBySpacePreservingQuotes(null)); - assertEquals(List.of(), RegexUtil.splitBySpacePreservingQuotes("")); - assertEquals(List.of("a", "b"), RegexUtil.splitBySpacePreservingQuotes("a b")); - assertEquals(List.of("a", "a b"), RegexUtil.splitBySpacePreservingQuotes("a \"a b\"")); - } -} diff --git a/src/test/kotlin/lechuck/intellij/util/RegexUtilTest.kt b/src/test/kotlin/lechuck/intellij/util/RegexUtilTest.kt new file mode 100644 index 0000000..8504ced --- /dev/null +++ b/src/test/kotlin/lechuck/intellij/util/RegexUtilTest.kt @@ -0,0 +1,15 @@ +package lechuck.intellij.util + +import lechuck.intellij.util.RegexUtil.splitBySpace +import org.junit.Assert +import org.junit.Test + +class RegexUtilTest { + @Test + fun testSplitBySpace() { + Assert.assertEquals(emptyList(), splitBySpace(null)) + Assert.assertEquals(emptyList(), splitBySpace("")) + Assert.assertEquals(listOf("a", "b"), splitBySpace("a b")) + Assert.assertEquals(listOf("a", "a b"), splitBySpace("""a "a b" """)) + } +} \ No newline at end of file