-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptm_java.lua
167 lines (146 loc) · 2.94 KB
/
ptm_java.lua
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
-- mod-version:3
local ptm = require 'plugins.ptm'
-- This module installs 3 templates:
-- 1. Java, Simple (line 9)
-- 2. Java, Gradle (line 75)
-- 3. Java, Maven, quickstart (line 116)
-- Java, Simple
local readme = [[
# Java Project
...
]]
local build_simple = [[
#!/bin/bash
# Compile Main.java into Main.class
javac Main.java
# Create .jar archive from Main.Class as indicated by Manifest.txt
jar -cfm Main.jar Manifest.txt Main.class
# Run .jar executable archive
java -jar Main.jar
]]
local main_simple = [[
public class Main {
public static void main(string[] args) {
System.out.println("Hello World!")
}
}
]]
local manifest_simple = [[
Main-Class: Main
]]
ptm.add_template {
name = "java-simple",
desc = "A single-file template for Java.",
files = {
["README.md"] = {
content = readme,
path = ""
},
["build.sh"] = {
content = build_simple,
path = ""
},
["Main.java"] = {
content = main_simple,
path = ""
},
["Manifest.txt"] = {
content = manifest_simple,
path = ""
},
},
dirs = {
"bin",
"lib"
},
ext_libs = {},
lsp_config_files = {},
commands = {
{ "chmod", "+x", "build.sh" }
}
}
-- Java, Gradle
local build_gradle = [[
#!/usr/bin/bash
./gradlew run
]]
local run_gradle = [[
#!/usr/bin/bash
./gradlew build
]]
ptm.add_template {
name = "java-gradle",
desc = "",
files = {
["README.md"] = {
content = readme,
path = ""
},
["build.sh"] = {
content = build_gradle,
path = ""
},
["run.sh"] = {
content = run_gradle,
path = ""
}
},
dirs = {},
ext_libs = {},
lsp_config_files = {},
commands = {
-- Setup project
{ "gradle", "init" },
-- Make files executable
{ "chmod", "+x", "build.sh" },
{ "chmod", "+x", "run.sh" }
}
}
-- Java, Maven, quickstart
local setup_maven_quickstart = [[
#!/usr/bin/bash
mvn -B archetype:generate \
-DgroupId=com.mycompany.app \
-DartifactId=example \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4
# FIX
sed -i 's/<maven.compiler.source>1.7/<maven.compiler.source>1.8/g' ./example/pom.xml
sed -i 's/<maven.compiler.target>1.7/<maven.compiler.target>1.8/g' ./example/pom.xml
cp -v ./build.sh ./example/build.sh
]]
local build_maven = [[
#!/usr/bin/bash
mvn compile
mvn test
mvn package
mvn exec:java -Dexec.mainClass="com.mycompany.app.App"
]]
ptm.add_template {
name = "java-maven-quickstart",
desc = "Maven quickstart template.",
files = {
["README.md"] = {
content = readme,
path = ""
},
["setup.sh"] = {
content = setup_maven_quickstart,
path = ""
},
["build.sh"] = {
content = build_maven,
path = ""
},
},
dirs = {},
ext_libs = {},
lsp_config_files = {},
commands = {
-- Make files executable
{ "chmod", "+x", "setup.sh" },
{ "chmod", "+x", "build.sh" },
-- Setup project
{ "./setup.sh" }
}
}