aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/build.gradle
blob: e00b88d88a72f956cfca371f2908a211ada77f3e (plain) (blame)
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
apply from: "${rootDir}/gradle/xtext-common.gradle"

dependencies {
	compile project(':language')
	compile project(':language-ide')
	compile "org.eclipse.xtext:org.eclipse.xtext.xbase.web:${xtextVersion}"
	compile "org.eclipse.xtext:org.eclipse.xtext.web.servlet:${xtextVersion}"
	compile "org.eclipse.xtend:org.eclipse.xtend.lib:${xtextVersion}"
	compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
	compile "org.eclipse.jetty:jetty-annotations:${jettyVersion}"
	compile "org.slf4j:slf4j-simple:${slf4JVersion}"
}

def webpackOutputDir = "${buildDir}/webpack"
def productionResources = "${webpackOutputDir}/production"
def mainClass = 'org.eclipse.viatra.solver.language.web.ServerLauncher'
def devMode = System.getenv('NODE_ENV') != 'production'
def currentNodeEnv =  devMode ? 'development' : 'production'

apply plugin: 'com.moowork.node'

node {
	version = nodeVersion
	npmVersion = project.ext.npmVersion
	download = true
}

for (environment in ['production', 'development']) {
	def taskName = 'webpack' + environment.substring(0, 1).toUpperCase() + environment.substring(1);
	task(taskName, type: NpmTask) {
		dependsOn ':language:generateXtext'
		dependsOn npmInstall
		inputs.dir 'src/main/css'
		inputs.dir 'src/main/html'
		inputs.dir 'src/main/js'
		inputs.dir "${buildDir}/generated/sources/xtext/js"
		inputs.file 'webpack.config.js'
		outputs.dir "${webpackOutputDir}/${environment}"
		args = ['run', 'build']
		setEnvironment NODE_ENV: environment
	}
}

apply plugin: 'application'
mainClassName = mainClass
distTar.enabled = false
distZip.enabled = false

jar {
	dependsOn webpackProduction
	from(productionResources) {
		into 'webapp'
	}
}

apply plugin: 'com.github.johnrengelman.shadow'
shadowDistTar.enabled = false
shadowDistZip.enabled = false

shadowJar {
	dependsOn webpackProduction
	from(project.convention.getPlugin(JavaPluginConvention).sourceSets.main.output)
	configurations = [project.configurations.runtime]
	exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA','schema/*',
		'.options', '.api_description', '*.profile', 'about.*', 'about_*.html', 'about_files/*',
		'plugin.xml', 'systembundle.properties', 'profile.list', 'META-INF/resources/xtext/**')
	append('plugin.properties')
	from(productionResources) {
		into 'webapp'
	}
}

task jettyRun(type: JavaExec) {
	if (devMode) {
		dependsOn webpackDevelopment
	} else {
		dependsOn webpackProduction
	}
	dependsOn sourceSets.main.runtimeClasspath
	classpath = sourceSets.main.runtimeClasspath.filter{it.exists()}
	main = mainClass
	standardInput = System.in
	environment BASE_RESOURCE: "${webpackOutputDir}/${currentNodeEnv}"
	group = 'run'
	description = 'Start a Jetty web server serving the Xtex API and assets'
}

task webpackServe(type: NpmTask) {
	dependsOn ':language:generateXtext'
	dependsOn npmInstall
	outputs.dir "${webpackOutputDir}/hmr"
	args = ['run', 'serve']
	setEnvironment NODE_ENV: 'hmr'
	group = 'run'
	description = 'Start a Webpack dev server with hot module replacement'
}

eclipse {
	project.file.whenMerged {
		natures.remove('org.eclipse.wst.common.modulecore.ModuleCoreNature')
	}
}