This repository was archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathCreateProjectTask.groovy
136 lines (117 loc) · 4.47 KB
/
CreateProjectTask.groovy
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
/*
* Copyright 2018 John Ahlroos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.devsoap.plugin.tasks
import com.devsoap.plugin.Util
import com.devsoap.plugin.actions.SpringBootAction
import com.devsoap.plugin.creators.ProjectCreator
import com.devsoap.plugin.creators.ThemeCreator
import com.devsoap.plugin.extensions.VaadinPluginExtension
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.options.Option
import org.gradle.api.tasks.TaskAction
/**
* Creates a new Vaadin Project
*
* @author John Ahlroos
* @since 1.0
*/
class CreateProjectTask extends DefaultTask {
static final String NAME = 'vaadinCreateProject'
private static final String DOT = '.'
/**
* The application class name
*/
@Input
@Optional
@Option(option = 'name', description = 'Application name')
String applicationName
/**
* The application package
*/
@Input
@Optional
@Option(option = 'package', description = 'Application UI package')
String applicationPackage
/**
* The fully qualified name of the widgetset
*/
@Input
@Optional
@Option(option = 'widgetset', description = 'Widgetset name')
String widgetsetFQN
CreateProjectTask() {
description = "Creates a new Vaadin Project."
finalizedBy UpdateAddonStylesTask.NAME, CompileThemeTask.NAME
}
/**
* Creates a new project
*/
@TaskAction
void run() {
CompileWidgetsetTask compileWidgetsetTask = project.tasks.getByName(CompileWidgetsetTask.NAME)
String widgetset
if(widgetsetFQN) {
widgetset = widgetsetFQN
} else if(compileWidgetsetTask.widgetset) {
widgetset = compileWidgetsetTask.widgetset
}
VaadinPluginExtension vaadin = project.extensions.getByType(VaadinPluginExtension)
new ProjectCreator(
applicationName:resolveApplicationName(),
applicationPackage:resolveApplicationPackage(),
widgetsetCDN: compileWidgetsetTask.widgetsetCDN,
widgetsetFQN:widgetset,
pushSupported:Util.isPushEnabled(project),
javaDir:Util.getMainSourceSet(project).srcDirs.first(),
resourceDir:project.sourceSets.main.resources.srcDirs.iterator().next(),
templateDir: 'simpleProject',
projectType: Util.getProjectType(project),
bootEnabled: SpringBootAction.isSpringBootPresent(project)
).run()
new ThemeCreator(
themeName:resolveApplicationName(),
themesDirectory:Util.getThemesDirectory(project),
vaadinVersion:vaadin.version
).run()
UpdateWidgetsetTask.ensureWidgetPresent(project, widgetsetFQN)
}
private String resolveApplicationName() {
// Use capitalized project name if no application name is given
if ( !applicationName ) {
applicationName = project.name.capitalize()
}
// Ensure name is Java compatible
Util.makeStringJavaCompatible(applicationName).capitalize()
}
private String resolveApplicationPackage() {
CompileWidgetsetTask compileWidgetsetTask = project.tasks.getByName(CompileWidgetsetTask.NAME)
if ( !applicationPackage ) {
int endSlashSize = 2
if ( widgetsetFQN?.contains(DOT) ) {
String widgetsetName = widgetsetFQN.tokenize(DOT).last()
return widgetsetFQN[0..(-widgetsetName.size() - endSlashSize)]
} else if ( compileWidgetsetTask.widgetset?.contains(DOT) ) {
String widgetsetName = compileWidgetsetTask.widgetset.tokenize(DOT).last()
return compileWidgetsetTask.widgetset[0..(-widgetsetName.size() - endSlashSize)]
} else {
return "com.example.${resolveApplicationName().toLowerCase()}"
}
}
applicationPackage
}
}