Skip to content

Commit

Permalink
Merge pull request #87 from witspirit/v1.62.0
Browse files Browse the repository at this point in the history
V1.62.0
  • Loading branch information
picimako authored Oct 15, 2023
2 parents 5ad5bb3 + 3fafcd7 commit 0dd7805
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 97 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

## [1.62.0]
### Changed
- New supported IDE version range: 2022.1-2023.3
- Removed some deprecated API usage, and simplified some related code.

## [1.61.0]
### Changed
- Added support for IJ-2023.2 and dropped support for IJ-2021.2.
Expand Down
73 changes: 36 additions & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML

fun properties(key: String) = project.findProperty(key).toString()
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)

plugins {
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.7.21"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.13.3"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "2.0.0"
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
}

group = properties("pluginGroup")
version = properties("pluginVersion")
group = properties("pluginGroup").get()
version = properties("pluginVersion").get()

// Configure project's dependencies
repositories {
Expand All @@ -38,53 +35,55 @@ dependencies {

// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))
pluginName = properties("pluginName")
version = properties("platformVersion")
type = properties("platformType")

// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }
}

// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
groups.set(emptyList())
repositoryUrl.set(properties("pluginRepositoryUrl"))
groups.empty()
repositoryUrl = properties("pluginRepositoryUrl")
}

tasks {
wrapper {
gradleVersion = properties("gradleVersion")
gradleVersion = properties("gradleVersion").get()
}

patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))
version = properties("pluginVersion")
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription.set(
file("README.md").readText().lines().run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end))
}.joinToString("\n").let { markdownToHTML(it) }
)
pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

with (it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
}
}

val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
changeNotes.set(provider {
changeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
getOrNull(properties("pluginVersion"))
?: runCatching { getLatest() }.getOrElse { getUnreleased() },
Changelog.OutputType.HTML,
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
})
}
}

test {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ pluginGroup = com.github.kumaraman21.intellijbehave
pluginName = JBehave Support
pluginRepositoryUrl = https://github.com/witspirit/IntelliJBehave
# SemVer format -> https://semver.org
pluginVersion = 1.61.0
pluginVersion = 1.62.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 213
pluginUntilBuild = 232.*
pluginSinceBuild = 221
pluginUntilBuild = 233.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2021.3
platformVersion = 2022.1

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =java,Kotlin

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.1.1
gradleVersion = 8.4

# Opt-out flag for bundling Kotlin standard library -> https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
# suppress inspection "UnusedProperty"
Expand Down
16 changes: 16 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[versions]
# libraries
annotations = "24.0.1"

# plugins
kotlin = "1.9.0"
changelog = "2.1.2"
gradleIntelliJPlugin = "1.16.0"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }

[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
gradleIntelliJPlugin = { id = "org.jetbrains.intellij", version.ref = "gradleIntelliJPlugin" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package com.github.kumaraman21.intellijbehave.creator;

import static com.github.kumaraman21.intellijbehave.language.StoryFileType.STORY_FILE_TYPE;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.actions.CreateElementActionBase;
import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.openapi.actionSystem.AnActionEvent;
Expand All @@ -28,49 +29,45 @@
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.codeStyle.CodeStyleManager;
import org.jetbrains.annotations.NotNull;

import static com.github.kumaraman21.intellijbehave.language.StoryFileType.STORY_FILE_TYPE;
import java.util.function.Consumer;

public class CreateStoryAction extends CreateElementActionBase {

public CreateStoryAction() {
super("Create New Story File", STORY_FILE_TYPE.getDescription(), STORY_FILE_TYPE.getIcon());
}

@NotNull
@Override
protected PsiElement[] invokeDialog(Project project, PsiDirectory directory) {
CreateElementActionBase.MyInputValidator validator = new CreateElementActionBase.MyInputValidator(project, directory);
protected void invokeDialog(@NotNull Project project, @NotNull PsiDirectory directory, @NotNull Consumer<? super PsiElement[]> elementsConsumer) {
var validator = new CreateElementActionBase.MyInputValidator(project, directory);
Messages.showInputDialog(project, "Enter a new file name:", "New Story File", Messages.getQuestionIcon(), "", validator);
return validator.getCreatedElements();
elementsConsumer.accept(validator.getCreatedElements());
}

@NotNull
@Override
protected PsiElement[] create(@NotNull String newName, PsiDirectory directory) throws Exception {
final FileTemplate template = FileTemplateManager.getDefaultInstance().getTemplate(STORY_FILE_TYPE.getName());
protected PsiElement @NotNull [] create(@NotNull String newName, PsiDirectory directory) throws Exception {
final var template = FileTemplateManager.getDefaultInstance().getTemplate(STORY_FILE_TYPE.getName());

String fileName = getFileName(newName);
Project project = directory.getProject();

directory.checkCreateFile(fileName);
PsiFile psiFile = PsiFileFactory.getInstance(project)
.createFileFromText(fileName, STORY_FILE_TYPE, template.getText());
var psiFile = PsiFileFactory.getInstance(project).createFileFromText(fileName, STORY_FILE_TYPE, template.getText());

if (template.isReformatCode()) {
CodeStyleManager.getInstance(project).reformat(psiFile);
}
psiFile = (PsiFile)directory.add(psiFile);

final VirtualFile virtualFile = psiFile.getVirtualFile();
FileEditorManager.getInstance(project).openFile(virtualFile, true);
FileEditorManager.getInstance(project).openFile(psiFile.getVirtualFile(), true);

return new PsiElement[]{psiFile};
}
Expand All @@ -80,27 +77,23 @@ protected String getErrorTitle() {
return "Cannot Create Story File";
}

@NotNull
@Override
protected String getActionName(PsiDirectory directory, String newName) {
protected String getActionName(PsiDirectory directory, @NotNull String newName) {
return IdeBundle.message("progress.creating.file", STORY_FILE_TYPE.getName(), newName, directory.getName());
}

public void update(final AnActionEvent e) {
@Override
public void update(final @NotNull AnActionEvent e) {
super.update(e);
Presentation presentation = e.getPresentation();
final FileTypeManager manager = FileTypeManager.getInstance();
final FileType fileType = manager.getFileTypeByExtension(HtmlFileType.DOT_DEFAULT_EXTENSION);
final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(HtmlFileType.DOT_DEFAULT_EXTENSION);
if (fileType == FileTypes.PLAIN_TEXT) {
presentation.setEnabled(false);
presentation.setVisible(false);
presentation.setEnabledAndVisible(false);
}
}

private String getFileName(String name) {
if (name.endsWith("." + STORY_FILE_TYPE.getDefaultExtension())) {
return name;
} else {
return name + "." + STORY_FILE_TYPE.getDefaultExtension();
}
}
return name.endsWith("." + STORY_FILE_TYPE.getDefaultExtension()) ? name : name + "." + STORY_FILE_TYPE.getDefaultExtension();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.kumaraman21.intellijbehave.kotlin.KotlinConfigKt;
import com.github.kumaraman21.intellijbehave.kotlin.support.services.KotlinAnnotationsLoader;
import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
Expand All @@ -27,18 +18,25 @@
import com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.QualifiedName;
import com.intellij.util.ReflectionUtil;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Project service that provides Java step definitions for JBehave Story steps.
*/
@Service(Service.Level.PROJECT)
public final class JBehaveStepsIndex {

//Argument is necessary for project-level service creation
public JBehaveStepsIndex(Project project) {
}

Expand Down Expand Up @@ -119,24 +117,11 @@ private static Collection<PsiAnnotation> getAllStepAnnotations(@NotNull final Ps

@Nullable
private PsiClass findStepAnnotation(String stepClass, Module module, GlobalSearchScope dependenciesScope) {
Method getPre20221 = ReflectionUtil.getDeclaredMethod(JavaFullClassNameIndex.class, "get", Integer.class, Project.class, GlobalSearchScope.class);
Method get20221 = ReflectionUtil.getDeclaredMethod(JavaFullClassNameIndex.class, "get", CharSequence.class, Project.class, GlobalSearchScope.class);

try {
Object javaFullClassNameIndexInstance = JavaFullClassNameIndex.class.getDeclaredMethod("getInstance").invoke(JavaFullClassNameIndex.class);
Collection<PsiClass> stepDefAnnotationCandidates = Collections.emptyList();
if (getPre20221 != null) {
stepDefAnnotationCandidates = (Collection<PsiClass>) getPre20221.invoke(javaFullClassNameIndexInstance, stepClass.hashCode(), module.getProject(), dependenciesScope);
} else if (get20221 != null) {
stepDefAnnotationCandidates = (Collection<PsiClass>) get20221.invoke(javaFullClassNameIndexInstance, stepClass, module.getProject(), dependenciesScope);
}
for (PsiClass stepDefAnnotations : stepDefAnnotationCandidates) {
if (stepClass.equals(stepDefAnnotations.getQualifiedName())) {
return stepDefAnnotations;
}
var stepDefAnnotationCandidates = JavaFullClassNameIndex.getInstance().get(stepClass, module.getProject(), dependenciesScope);
for (PsiClass stepDefAnnotations : stepDefAnnotationCandidates) {
if (stepClass.equals(stepDefAnnotations.getQualifiedName())) {
return stepDefAnnotations;
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
//fall through and return null
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.kumaraman21.intellijbehave.utility;

import org.apache.commons.lang.LocaleUtils;
import org.apache.commons.lang3.LocaleUtils;
import org.jbehave.core.i18n.LocalizedKeywords;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
]]></description>
<vendor url="https://github.com/witspirit" email="[email protected]">Bert Van Vlerken, Victor Rosenberg</vendor>

<idea-version since-build="213" until-build="232.*"/>
<idea-version since-build="221" until-build="233.*"/>

<depends>com.intellij.modules.java</depends>
<depends optional="true" config-file="kotlin-config.xml">org.jetbrains.kotlin</depends>
Expand Down

0 comments on commit 0dd7805

Please sign in to comment.