Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Gradle #3443

Merged
merged 9 commits into from Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

58 changes: 15 additions & 43 deletions components.json
Expand Up @@ -189,7 +189,7 @@
"owner": "Zinfidel"
},
"avro-idl": {
"title":"Avro IDL",
"title": "Avro IDL",
"alias": "avdl",
"owner": "RunDevelopment"
},
Expand Down Expand Up @@ -544,6 +544,11 @@
"alias": "go-mod",
"owner": "RunDevelopment"
},
"gradle": {
"title": "Gradle",
"require": "clike",
"owner": "zeabdelkhalek-badido18"
},
"graphql": {
"title": "GraphQL",
"optional": "markdown",
Expand Down Expand Up @@ -646,11 +651,7 @@
"ignore": {
"title": ".ignore",
"owner": "osipxd",
"alias": [
"gitignore",
"hgignore",
"npmignore"
],
"alias": ["gitignore", "hgignore", "npmignore"],
"aliasTitles": {
"gitignore": ".gitignore",
"hgignore": ".hgignore",
Expand Down Expand Up @@ -687,11 +688,7 @@
},
"javadoclike": {
"title": "JavaDoc-like",
"modify": [
"java",
"javascript",
"php"
],
"modify": ["java", "javascript", "php"],
"owner": "RunDevelopment"
},
"javastacktrace": {
Expand All @@ -715,10 +712,7 @@
"title": "JSDoc",
"require": ["javascript", "javadoclike", "typescript"],
"modify": "javascript",
"optional": [
"actionscript",
"coffeescript"
],
"optional": ["actionscript", "coffeescript"],
"owner": "RunDevelopment"
},
"js-extras": {
Expand Down Expand Up @@ -980,10 +974,7 @@
"opencl": {
"title": "OpenCL",
"require": "c",
"modify": [
"c",
"cpp"
],
"modify": ["c", "cpp"],
"owner": "Milania1"
},
"openqasm": {
Expand Down Expand Up @@ -1114,11 +1105,7 @@
},
"pure": {
"title": "Pure",
"optional": [
"c",
"cpp",
"fortran"
],
"optional": ["c", "cpp", "fortran"],
"owner": "Golmote"
},
"purebasic": {
Expand Down Expand Up @@ -1172,22 +1159,13 @@
"title": "Razor C#",
"alias": "razor",
"require": ["markup", "csharp"],
"optional":[
"css",
"css-extras",
"javascript",
"js-extras"
],
"optional": ["css", "css-extras", "javascript", "js-extras"],
"owner": "RunDevelopment"
},
"jsx": {
"title": "React JSX",
"require": ["markup", "javascript"],
"optional": [
"jsdoc",
"js-extras",
"js-templates"
],
"optional": ["jsdoc", "js-extras", "js-templates"],
"owner": "vkbansal"
},
"tsx": {
Expand Down Expand Up @@ -1409,10 +1387,7 @@
},
"tremor": {
"title": "Tremor",
"alias": [
"trickle",
"troy"
],
"alias": ["trickle", "troy"],
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
"owner": "darach",
"aliasTitles": {
"trickle": "trickle",
Expand Down Expand Up @@ -1591,10 +1566,7 @@
"show-invisibles": {
"title": "Show Invisibles",
"description": "Show hidden characters such as tabs and line breaks.",
"optional": [
"autolinker",
"data-uri-highlight"
]
"optional": ["autolinker", "data-uri-highlight"]
},
"autolinker": {
"title": "Autolinker",
Expand Down
63 changes: 63 additions & 0 deletions components/prism-gradle.js
@@ -0,0 +1,63 @@
(function (Prism) {
var interpolation = {
pattern: /((?:^|[^\\$])(?:\\{2})*)\$(?:\w+|\{[^{}]*\})/,
lookbehind: true,
inside: {
'interpolation-punctuation': {
pattern: /^\$\{?|\}$/,
alias: 'punctuation',
},
expression: {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
pattern: /[\s\S]+/,
inside: null,
},
},
};

Prism.languages.gradle = Prism.languages.extend('clike', {
string: {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
pattern: /'''(?:[^\\]|\\[\s\S])*?'''|'(?:\\.|[^\\'\r\n])*'/,
greedy: true,
},
keyword:
/\b(?:apply|def|dependencies|else|if|implementation|import|plugin|plugins|project|repositories|repository|sourceSets|tasks|val)\b/,
number: /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
operator: {
pattern:
/(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
lookbehind: true,
},
punctuation: /\.+|[{}[\];(),:$]/,
});

Prism.languages.insertBefore('gradle', 'string', {
shebang: {
pattern: /#!.+/,
alias: 'comment',
greedy: true,
},
'interpolation-string': {
pattern:
/"""(?:[^\\]|\\[\s\S])*?"""|(["/])(?:\\.|(?!\1)[^\\\r\n])*\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
greedy: true,
inside: {
interpolation: interpolation,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
string: /[\s\S]+/,
},
},
});

Prism.languages.insertBefore('gradle', 'punctuation', {
'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/,
});

Prism.languages.insertBefore('gradle', 'function', {
annotation: {
pattern: /(^|[^.])@\w+/,
lookbehind: true,
alias: 'punctuation',
},
});

interpolation.inside.expression.inside = Prism.languages.gradle;
}(Prism));
1 change: 1 addition & 0 deletions components/prism-gradle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions examples/prism-gradle.html
@@ -0,0 +1,56 @@
<h2>Full example</h2>
<pre><code>
apply plugin: "java"
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
apply plugin: "eclipse"
apply plugin: "idea"

group = "com.mycompany.hadoopproject"
version = "1.0"

repositories {
// Standard Maven
mavenCentral()
maven {
url "https://repository.cloudera.com/artifactory/cloudera-repos/"
}
}

// Mimic Maven 'provided' configuration, as suggested in GRADLE-784
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}

ext.hadoopVersion = "2.0.0-mr1-cdh4.0.1"
dependencies {
provided "org.apache.hadoop:hadoop-client:${hadoopVersion}"

// Example of adding a specific compile time dependency
compile "com.google.guava:guava:11.0.2"

testCompile "junit:junit:4.8.2"
}

// Java version selection
sourceCompatibility = 1.6
targetCompatibility = 1.6

eclipse {
classpath {
// Ensure Eclipse build output appears in build directory
defaultOutputDir = file("${buildDir}/eclipse-classes")
// Ensure the provided configuration jars are available in Eclipse
plusConfigurations += configurations.provided
}
}

// Emulate Maven shade plugin with a fat jar.
// http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -59,6 +59,7 @@
"glsl": "c",
"go": "clike",
"groovy": "clike",
"gradle": "clike",
"haml": "ruby",
"handlebars": "markup-templating",
"haxe": "clike",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/languages/gradle/annotation_feature.test
@@ -0,0 +1,17 @@
@BaseScript MyBaseClass baseScript
@DelegatesTo(EmailSpec)

----------------------------------------------------

[
["annotation", "@BaseScript"],
" MyBaseClass baseScript\r\n",
["annotation", "@DelegatesTo"],
["punctuation", "("],
"EmailSpec",
["punctuation", ")"]
]

----------------------------------------------------

Checks for annotations.
27 changes: 27 additions & 0 deletions tests/languages/gradle/keyword_feature.test
@@ -0,0 +1,27 @@
implementation
val tasks dependencies project plugin plugins
repository repositories apply def sourceSets import
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved

----------------------------------------------------

[
["keyword", "implementation"],

["keyword", "val"],
["keyword", "tasks"],
["keyword", "dependencies"],
["keyword", "project"],
["keyword", "plugin"],
["keyword", "plugins"],

["keyword", "repository"],
["keyword", "repositories"],
["keyword", "apply"],
["keyword", "def"],
["keyword", "sourceSets"],
["keyword", "import"]
]

----------------------------------------------------

Checks for all keywords.