diff --git a/.gitignore b/.gitignore index e0d53d8..ec4837f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .gradle .idea build +.intellijPlatform diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 8e16601..0000000 --- a/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'java' - id 'org.jetbrains.intellij' version '1.16.0' -} - -group 'ch.repnik' -version '1.4.1' - -repositories { - mavenCentral() -} - -dependencies { - testImplementation 'org.hamcrest:hamcrest:2.2' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.3' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.3' - testCompileOnly 'org.projectlombok:lombok:1.18.34' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.34' - -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -test { - useJUnitPlatform() - testLogging { - events "passed", "skipped", "failed" - } -} - -// See https://github.com/JetBrains/gradle-intellij-plugin/ -intellij { - version.set('2023.2.4') - plugins = ['Git4Idea'] -} - -runPluginVerifier{ - ideVersions = ["IC-2023.2.4"] -} - -patchPluginXml { - sinceBuild.set("232") - untilBuild.set("") -} - - - diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..ce5b3f6 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,58 @@ +plugins { + id("java") + id("org.jetbrains.intellij.platform") version "2.18.1" +} + +group = "ch.repnik" +version = "1.4.2" + +repositories { + mavenCentral() + intellijPlatform { + defaultRepositories() + } +} + +// See https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html +dependencies { + intellijPlatform { + intellijIdea("2026.1.4") + bundledPlugin("Git4Idea") + pluginVerifier() + } + + testImplementation("org.hamcrest:hamcrest:3.0") + testImplementation("org.junit.jupiter:junit-jupiter-api:6.1.2") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:6.1.2") + testImplementation("org.junit.jupiter:junit-jupiter-params:6.1.2") + testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.1.2") + testCompileOnly("org.projectlombok:lombok:1.18.46") + testAnnotationProcessor("org.projectlombok:lombok:1.18.46") +} + +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + +tasks.test { + useJUnitPlatform() + testLogging { + events("passed", "skipped", "failed") + } +} + +intellijPlatform { + pluginConfiguration { + ideaVersion { + sinceBuild = "261" + untilBuild = provider { null } + } + } + + pluginVerification { + ides { + recommended() + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..b1b8ef5 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 e411586..a9db115 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,9 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb..249efbb 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 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. @@ -15,10 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # -# Gradle start up script for POSIX generated by Gradle. +# gradlew start up script for POSIX generated by Gradle. # # Important for running: # @@ -27,7 +29,7 @@ # bash, then to run this script, type that shell name before the whole # command line, like: # -# ksh Gradle +# ksh gradlew # # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: @@ -55,7 +57,7 @@ # 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 +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 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"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,22 +132,29 @@ location of your Java installation." fi else 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. + if ! command -v java >/dev/null 2>&1 + then + 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 location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -165,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -193,16 +198,19 @@ if "$cygwin" || "$msys" ; then done fi -# 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. + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 53a6b23..8508ef6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,19 +13,22 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem -@rem Gradle startup script for Windows +@rem gradlew startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -42,13 +45,13 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% @@ -56,36 +59,24 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% -:mainEnd -if "%OS%"=="Windows_NT" endlocal +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel -:omega +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 1a64418..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'commit-prefix-plugin' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..2120703 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "commit-prefix-plugin" diff --git a/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java b/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java index 22ae908..4da9199 100644 --- a/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java +++ b/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java @@ -26,6 +26,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.JComponent; + import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -43,7 +45,11 @@ public class CommitPrefixCheckinHandler extends CheckinHandler implements GitRep public CommitPrefixCheckinHandler(CheckinProjectPanel panel) { this.panel = panel; - MessageBusConnection connect = panel.getProject().getMessageBus().connect(); + // Tie the subscription to the commit UI's lifecycle so stale handlers stop firing + CommitMessage commitMessage = findCommitMessageComponent(); + MessageBusConnection connect = commitMessage != null + ? panel.getProject().getMessageBus().connect(commitMessage) + : panel.getProject().getMessageBus().connect(); connect.subscribe(GitRepository.GIT_REPO_CHANGE, this); // Sets the new message on the new commit UI @@ -55,7 +61,19 @@ private void updateCommitMessage() { PsiDocumentManager psiInstance = PsiDocumentManager.getInstance(this.panel.getProject()); if (psiInstance instanceof PsiDocumentManagerImpl) { if (!((PsiDocumentManagerImpl) psiInstance).isCommitInProgress()) { - getNewCommitMessage().ifPresent(this::setCommitMessageWithoutFocus); + String newMessage = getNewCommitMessage(); + if (newMessage.equals(panel.getCommitMessage())) { + return; + } + + CommitMessage commitMessage = findCommitMessageComponent(); + if (commitMessage != null) { + // Sets the text without requesting focus, unlike panel.setCommitMessage() + // which activates the Commit tool window (e.g. stealing focus from the terminal) + commitMessage.setText(newMessage); + } else { + panel.setCommitMessage(newMessage); + } } else { log.info("PsiDocumentManager reported commit in progress. Skipping Git Auto Prefix"); } @@ -81,6 +99,12 @@ private void setCommitMessageWithoutFocus(String newMessage) { } } + @Nullable + private CommitMessage findCommitMessageComponent() { + JComponent component = panel.getComponent(); + return component == null ? null : UIUtil.findComponentOfType(component, CommitMessage.class); + } + @Nullable @Override public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {