forked from stevehanson/mvn2gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
122 lines (90 loc) · 3.78 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!doctype html>
<html>
<head>
<title>Maven to Gradle Converter</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #eee; font: helvetica; }
#container { width:80%; max-width: 900px; background-color: #fff; margin: 30px auto; padding: 30px; border-radius: 5px; box-shadow: 5px; }
#out { margin-top: 10px; }
.footer { margin-top: 20px;}
</style>
</head>
<body>
<div id="container">
<h1>Maven to Gradle Dependency Converter</h1>
<div class="subtitle">Note: this is provided as-is. Currently only parses groupId, artifactId and version. Scope is ignored. If you are
using a variable for version, it will keep that, but you will still need to define the variable in your build.gradle file</div>
<hr/>
<div id="error"> </div>
<form class="form-inline" role="form">
<div class="form-group hide">
<label class="sr-only" for="nameInput">Variable declarations (if any..)</label>
<input type="text" id="vars" class="form-control" id="nameInput" placeholder="Variables" />
</div>
<div class="form-group">
<label class="sr-only" for="nameInput">Paste your POM dependencies below – can be full section or single dependencies</small></label>
<textarea id="maven" class="form-control" rows="6"></textarea>
</div>
<button id="convert" type="button" class="btn btn-default">Convert to Gradle</button>
</form>
<div id="out"> </div>
<div class="footer">
If you have suggestions or would like to contribute, <a href="http://codetutr.com/about">contact me</a> or submit a <a href="https://github.com/stevehanson/mvn2gradle">pull request</a>.
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
var outDepList = [];
$('#convert').click(function() {
deps = parseDependencies(vars);
if(deps && deps.length > 0)
$('#out').html('<textarea class="form-control" rows="6">' + deps.join('\r\n') + '</textarea>');
});
});
function parseDependencies() {
groupIdRegex = /<groupId>(.+)<\/groupId>/;
artifactIdRegex = /<artifactId>(.+)<\/artifactId>/;
versionRegex = /<version>(.+)<\/version>/;
classifierRegex = /<classifier>(.+)<\/classifier>/;
outDepList = [];
depList = $('#maven').val().split('<dependency>');
if(depList.length == 1) {
$('#error').html('<div class="alert alert-danger">Nothing to convert. Please include at least one <dependency></div>');
return;
}
for(var i = 0; i < depList.length; i++) {
dep = depList[i];
group = groupIdRegex.exec(dep);
artifact = artifactIdRegex.exec(dep);
version = versionRegex.exec(dep);
classifier = classifierRegex.exec(dep);
if(version != null && version.length > 1) {
version = version[1];
if(version.indexOf("${") !== -1) {
version = "$" + /\$\{(.*)\}/.exec(version)[1];
}
}
if(group !== null && artifact !== null && version !== null) {
gradleCommand = "compile \"" + group[1] + ':' + artifact[1] + ':' + version;
if( classifier !== null) {
gradleCommand += ":"+classifier[1];
}
gradleCommand += "\"";
outDepList.push(gradleCommand);
}
}
return outDepList;
}
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-38645896-2', 'codetutr.com');
ga('send', 'pageview');
</script>
</body>
</html>