Skip to content

Commit

Permalink
Added support for Gradle (#3443)
Browse files Browse the repository at this point in the history
Co-authored-by: badido18 <hm_boudis@esi.dz>
  • Loading branch information
zeabdelkhalek and madjique authored Apr 29, 2022
1 parent ca8eaee commit 3211982
Show file tree
Hide file tree
Showing 15 changed files with 522 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
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
63 changes: 63 additions & 0 deletions components/prism-gradle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
(function (Prism) {
var interpolation = {
pattern: /((?:^|[^\\$])(?:\\{2})*)\$(?:\w+|\{[^{}]*\})/,
lookbehind: true,
inside: {
'interpolation-punctuation': {
pattern: /^\$\{?|\}$/,
alias: 'punctuation',
},
'expression': {
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,
'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.

54 changes: 54 additions & 0 deletions examples/prism-gradle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<h2>Full example</h2>
<pre><code>apply plugin: "java"
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"gml": "clike",
"glsl": "c",
"go": "clike",
"gradle": "clike",
"groovy": "clike",
"haml": "ruby",
"handlebars": "markup-templating",
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
implementation
val tasks dependencies project plugin plugins
repository repositories apply def sourceSets import
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions tests/languages/gradle/shebang_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!foobar
#!/usr/bin/env groovy

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

[
["shebang", "#!foobar"],
["shebang", "#!/usr/bin/env groovy"]
]

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

Check for shebang comments.
Loading

0 comments on commit 3211982

Please sign in to comment.