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 8 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.

7 changes: 6 additions & 1 deletion components.json
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 @@ -1729,4 +1734,4 @@
"owner": "Golmote"
}
}
}
}
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
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': {
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.
30 changes: 30 additions & 0 deletions tests/languages/gradle/keyword_feature.test
@@ -0,0 +1,30 @@
implementation
val tasks dependencies project plugin plugins
repository repositories apply def sourceSets import
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
if else
----------------------------------------------------

[
["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"],

["keyword", "if"],
["keyword", "else"]
]

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

Checks for all keywords.
43 changes: 43 additions & 0 deletions tests/languages/gradle/number_feature.test
@@ -0,0 +1,43 @@
0b0110
0b0110_1111_0000
0b01G 0b01L 0b01I
0b01D 0b01F

0xBABE
0xBad_Face
0x1.8p1
0xa.fp-2

42_000
3.14_15_9
1.2e3
3E+1
4E-2
42g 42l 42i
42d 42f

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

[
["number", "0b0110"],
["number", "0b0110_1111_0000"],
["number", "0b01G"], ["number", "0b01L"], ["number", "0b01I"],
["number", "0b01D"], ["number", "0b01F"],

["number", "0xBABE"],
["number", "0xBad_Face"],
["number", "0x1.8p1"],
["number", "0xa.fp-2"],

["number", "42_000"],
["number", "3.14_15_9"],
["number", "1.2e3"],
["number", "3E+1"],
["number", "4E-2"],
["number", "42g"], ["number", "42l"], ["number", "42i"],
["number", "42d"], ["number", "42f"]
]

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

Checks for binary, hexadecimal and decimal numbers.
45 changes: 45 additions & 0 deletions tests/languages/gradle/operator_feature.test
@@ -0,0 +1,45 @@
~
= == =~ ==~
? ?. ?:
* ** *. *= **=
.@ .&
5..8
5..<8
- -- -= ->
+ ++ +=
! !=
< << <<= <= <=>
> >> >>> >>= >>>= >=
& && &=
| || |=
/
/=
^ ^=
% %=

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

[
["operator", "~"],
["operator", "="], ["operator", "=="], ["operator", "=~"], ["operator", "==~"],
["operator", "?"], ["operator", "?."], ["operator", "?:"],
["operator", "*"], ["operator", "**"], ["operator", "*."], ["operator", "*="], ["operator", "**="],
["operator", ".@"], ["operator", ".&"],
["number", "5"], ["operator", ".."], ["number", "8"],
["number", "5"], ["operator", "..<"], ["number", "8"],
["operator", "-"], ["operator", "--"], ["operator", "-="], ["operator", "->"],
["operator", "+"], ["operator", "++"], ["operator", "+="],
["operator", "!"], ["operator", "!="],
["operator", "<"], ["operator", "<<"], ["operator", "<<="], ["operator", "<="], ["operator", "<=>"],
["operator", ">"], ["operator", ">>"], ["operator", ">>>"], ["operator", ">>="], ["operator", ">>>="], ["operator", ">="],
["operator", "&"], ["operator", "&&"], ["operator", "&="],
["operator", "|"], ["operator", "||"], ["operator", "|="],
["operator", "/"],
["operator", "/="],
["operator", "^"], ["operator", "^="],
["operator", "%"], ["operator", "%="]
]

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

Checks for all operators.