Skip to content

Commit 0bf4c1e

Browse files
committed
check: add a check for plugin class input from user
1 parent 911bd2a commit 0bf4c1e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

plugin/src/main/java/com/icst/plugin/builder/PluginExtensionConfigurator.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.icst.plugin.builder;
1919

20+
import java.util.regex.Pattern;
21+
2022
import org.gradle.api.GradleException;
2123
import org.gradle.api.Project;
2224
import org.gradle.api.artifacts.Configuration;
@@ -40,6 +42,12 @@ public static void configure(Project project) {
4042
throw new GradleException("Please provide sdk version for building plugin for BlockIDLE");
4143
}
4244

45+
if (!ext.getAppPluginClass().isPresent()) {
46+
throw new GradleException("Please provide appPluginClass as entry point of plugin for BlockIDLE");
47+
}
48+
49+
validateFqcn(ext.getAppPluginClass().get(), "appPluginClass");
50+
4351
String sdkVersion = ext.getSdkVersion().get();
4452

4553
project.getDependencies().add(
@@ -52,4 +60,19 @@ public static void configure(Project project) {
5260
});
5361
}
5462

63+
private static final Pattern FQCN_PATTERN = Pattern.compile(
64+
"^[a-zA-Z_$][a-zA-Z\\d_$]*(\\.[a-zA-Z_$][a-zA-Z\\d_$]*)+$");
65+
66+
private static void validateFqcn(String value, String propertyName) {
67+
if (value == null || value.isEmpty()) {
68+
throw new GradleException(propertyName + " must not be empty");
69+
}
70+
71+
if (!FQCN_PATTERN.matcher(value).matches()) {
72+
throw new GradleException(
73+
propertyName + " must be a fully qualified class name. " +
74+
"Example: com.example.MyPlugin");
75+
}
76+
}
77+
5578
}

0 commit comments

Comments
 (0)