Skip to content

Commit

Permalink
Merge pull request #2071 from piotrkwiecinski/idea-2024-1-compatibility
Browse files Browse the repository at this point in the history
plugin compatibility for 2024.1
  • Loading branch information
VitaliyBoyko authored Jul 4, 2024
2 parents 75ffe6e + f3efc91 commit 93fed17
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 64 deletions.
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

plugins {
id 'org.jetbrains.intellij' version '1.13.3'
id 'org.jetbrains.intellij' version '1.17.3'
id 'checkstyle'
id 'pmd'
id 'org.jetbrains.changelog' version '2.0.0'
id 'org.jetbrains.changelog' version '2.2.0'
}

repositories {
Expand All @@ -23,12 +23,14 @@ apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'org.jetbrains.changelog'

def phpPluginVersion = System.getProperty("phpPluginVersion", "231.8109.199")
def ideaVersion = System.getProperty("ideaVersion", "2023.1")
def phpPluginVersion = System.getProperty("phpPluginVersion", "241.14494.158")
def ideaVersion = System.getProperty("ideaVersion", "2024.1")
def javaVersion = 17

sourceCompatibility = javaVersion
targetCompatibility = javaVersion
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

intellij {
version = ideaVersion
Expand All @@ -41,7 +43,7 @@ intellij {
'properties',
'com.intellij.css',
'JavaScript',
'com.intellij.lang.jsgraphql:3.4.0',
'com.intellij.lang.jsgraphql:241.14494.150',
'platform-images',
'copyright'
]
Expand Down
12 changes: 6 additions & 6 deletions gradle-tasks/staticChecks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ pmd {
ruleSets = []
}

tasks.withType(Checkstyle) {
tasks.withType(Checkstyle).configureEach {
// Specify all files that should be checked
classpath = files()
source "${project.rootDir}"
}

// Execute Checkstyle on all files
task checkstyle(type: Checkstyle) {
tasks.register('checkstyle', Checkstyle) {
}

// Execute Checkstyle on all modified files
task checkstyleCI(type: Checkstyle) {
tasks.register('checkstyleCI', Checkstyle) {
def changedFiles = getChangedFiles()
include changedFiles
}

tasks.withType(Pmd) {
tasks.withType(Pmd).configureEach {
// Specify all files that should be checked
classpath = files()
source "${project.rootDir}"
}

// Execute Checkstyle on all files
task pmd(type: Pmd) {
tasks.register('pmd', Pmd) {
}

// Execute Checkstyle on all modified files
task pmdCI(type: Pmd) {
tasks.register('pmdCI', Pmd) {
def changedFiles = getChangedFiles()
include changedFiles
}
Expand Down
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</change-notes>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="231.8109.175"/>
<idea-version since-build="241.14494.158"/>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

public class ClassPropertyData {
private final List<String> data = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import javax.swing.KeyStroke;
import javax.swing.event.DocumentEvent;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import javax.swing.KeyStroke;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings({"PMD.TooManyFields", "PMD.DataClass", "PMD.UnusedPrivateMethod"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

public final class ClassPropertyFormatterUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.WordUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -236,7 +236,7 @@ public List<Method> collect(final @NotNull Method psiElement) {

final List<PluginData> pluginDataList = pluginClassCache.getPluginsForClass(methodClass);
final List<PluginMethodData> pluginMethods = pluginClassCache.getPluginMethods(pluginDataList);
final String classMethodName = WordUtils.capitalize(psiElement.getName());
final String classMethodName = StringUtils.capitalize(psiElement.getName());

pluginMethods.removeIf(pluginMethod -> !isPluginMethodName(pluginMethod.getMethodName(), classMethodName));
sortMethods(pluginMethods, results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.magento.packages;

import org.jetbrains.annotations.Nullable;
import com.intellij.json.psi.JsonValue;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface ComposerPackageModel {
@Nullable
Expand All @@ -25,4 +28,7 @@ public interface ComposerPackageModel {

@Nullable
Map<String, String> getAutoloadPsr4();

<T extends JsonValue> T getPropertyValueOfType(String propertyName,
@NotNull Class<T> thisClass);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.magento.packages;

import com.intellij.json.psi.*;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.json.psi.JsonArray;
import com.intellij.json.psi.JsonObject;
import com.intellij.json.psi.JsonProperty;
import com.intellij.json.psi.JsonStringLiteral;
import com.intellij.json.psi.JsonValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ComposerPackageModelImpl implements ComposerPackageModel {
private JsonObject sourceComposerJson;
private final JsonObject sourceComposerJson;
private static final int VENDOR_AND_PACKAGE_PARTS_LENGTH = 2;

public static final String NAME = "name";
public static final String TYPE = "type";
Expand All @@ -23,7 +29,7 @@ public class ComposerPackageModelImpl implements ComposerPackageModel {
public static final String PSR4 = "psr4";
public static final String FILES = "file";

public ComposerPackageModelImpl(@NotNull JsonObject sourceComposerJson) {
public ComposerPackageModelImpl(@NotNull final JsonObject sourceComposerJson) {
this.sourceComposerJson = sourceComposerJson;
}

Expand All @@ -42,10 +48,10 @@ public String getType() {
@Nullable
@Override
public String getVendor() {
String nameProperty = getStringPropertyValue(NAME);
final String nameProperty = getStringPropertyValue(NAME);
if (nameProperty != null) {
String[] vendorAndPackage = nameProperty.split("/");
if (vendorAndPackage.length == 2) {
final String[] vendorAndPackage = nameProperty.split("/");
if (vendorAndPackage.length == VENDOR_AND_PACKAGE_PARTS_LENGTH) {
return vendorAndPackage[0];
}
}
Expand All @@ -62,63 +68,69 @@ public String getVersion() {
@Nullable
@Override
public String[] getAutoloadFiles() {
JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
final JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
if (autoloadObject != null) {
JsonArray jsonArray = getPropertyValueOfType(FILES, JsonArray.class);
if (jsonArray != null) {
List<String> files = new ArrayList<>();
for(JsonValue value: jsonArray.getValueList()) {
if (value instanceof JsonStringLiteral) {
files.add(StringUtils.strip(value.getText(), "\""));
}
return new String[0];
}

final JsonArray jsonArray = getPropertyValueOfType(FILES, JsonArray.class);
if (jsonArray != null) {
final List<String> files = new ArrayList<>();
for (final JsonValue value : jsonArray.getValueList()) {
if (value instanceof JsonStringLiteral) {
files.add(StringUtils.strip(value.getText(), "\""));
}
return files.size() > 0 ? files.toArray(new String[files.size()]) : null;
}
return files.isEmpty() ? new String[0] : files.toArray(new String[0]);
}

return null;
return new String[0];
}

@Nullable
@Override
public Map<String, String> getAutoloadPsr4() {
JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
if (autoloadObject != null) {
JsonObject jsonObject = getPropertyValueOfType(PSR4, JsonObject.class);
if (jsonObject != null) {
Map <String, String> map = new HashMap<String, String>();
for (JsonProperty property: jsonObject.getPropertyList()) {
JsonValue value = property.getValue();

if (value != null && value instanceof JsonStringLiteral) {
map.put(property.getName(), StringUtils.strip(value.getText(), "\""));
}
}
final JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
final Map<String, String> map = new HashMap<>();
if (autoloadObject == null) {
return map;
}

return map.size() > 0 ? map : null;
final JsonObject jsonObject = getPropertyValueOfType(PSR4, JsonObject.class);
if (jsonObject != null) {
for (final JsonProperty property : jsonObject.getPropertyList()) {
final JsonValue value = property.getValue();
if (value instanceof JsonStringLiteral) {
map.put(property.getName(), StringUtils.strip(value.getText(), "\""));
}
}
}

return null;
return map;
}

@Nullable
public <T extends JsonValue> T getPropertyValueOfType(String propertyName, @NotNull Class<T> aClass) {
JsonProperty property = sourceComposerJson.findProperty(propertyName);
@Override
public <T extends JsonValue> T getPropertyValueOfType(final String propertyName,
@NotNull final Class<T> thisClass) {
final JsonProperty property = sourceComposerJson.findProperty(propertyName);
if (property == null) {
return null;
}
JsonValue value = property.getValue();
if (value != null && aClass.isInstance(value)) {
return aClass.cast(value);
final JsonValue value = property.getValue();
if (thisClass.isInstance(value)) {
return thisClass.cast(value);
}

return null;
}

@Nullable
private String getStringPropertyValue(String propertyName) {
JsonStringLiteral stringLiteral = getPropertyValueOfType(propertyName, JsonStringLiteral.class);
private String getStringPropertyValue(final String propertyName) {
final JsonStringLiteral stringLiteral = getPropertyValueOfType(
propertyName,
JsonStringLiteral.class
);

if (stringLiteral != null) {
return StringUtils.strip(stringLiteral.getText(), "\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@
package com.magento.idea.magento2plugin.project.startup;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.ProjectActivity;
import com.intellij.openapi.startup.StartupActivity;
import com.magento.idea.magento2plugin.init.ConfigurationManager;
import com.magento.idea.magento2plugin.project.Settings;
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CheckIfMagentoPathIsValidActivity implements StartupActivity {
public class CheckIfMagentoPathIsValidActivity implements StartupActivity, ProjectActivity {

@Override
public void runActivity(final @NotNull Project project) {
registerSettings(project);
}

@Nullable
@Override
public Object execute(@NotNull final Project project,
@NotNull final Continuation<? super Unit> continuation) {
registerSettings(project);
return null;
}

private void registerSettings(final @NotNull Project project) {
final Settings settings = Settings.getInstance(project);
final String path = settings.magentoPath;
if (settings.pluginEnabled && (path == null || path.isEmpty())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("PMD.GodClass")
Expand Down
Loading

0 comments on commit 93fed17

Please sign in to comment.