forked from atomist/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaven.ts
122 lines (114 loc) · 3.84 KB
/
maven.ts
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
/*
* Copyright © 2019 Atomist, Inc.
*
* 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.
*/
import {
GitHubRepoRef,
} from "@atomist/automation-client";
import {
DoNotSetAnyGoals,
ExecuteGoalResult,
GeneratorRegistration,
goal,
hasFile,
not,
slackSuccessMessage,
} from "@atomist/sdm";
import { configure } from "@atomist/sdm-core";
import { Build } from "@atomist/sdm-pack-build";
import {
mavenBuilder,
MvnVersion,
SpringProjectCreationParameterDefinitions,
SpringProjectCreationParameters,
TransformMavenSpringBootSeedToCustomProject,
} from "@atomist/sdm-pack-spring";
import { executeMavenPerBranchSpringBootDeploy } from "@atomist/sdm-pack-spring/lib/java/deploy/MavenPerBranchSpringBootDeploymentGoal";
import {
codeLine,
url,
} from "@atomist/slack-messages";
import { UpdateReadmeTitle } from "../transform/updateReadmeTitle";
/**
* Atomist SDM Sample
* @description SDM to create and build Maven projects
* @tag sdm,generator,maven
* @instructions <p>Now that the SDM is up and running, create a new Maven
* project by running '@atomist create maven project' and
* observe how the SDM will build and run the new project.</p>
*/
// atomist:code-snippet:start=mavenGenerator
/**
* Maven generator registration
*/
const MavenGenerator: GeneratorRegistration<SpringProjectCreationParameters> = {
name: "MavenGenerator",
intent: "create maven project",
description: "Creates a new Maven project",
tags: ["maven"],
autoSubmit: true,
parameters: SpringProjectCreationParameterDefinitions,
startingPoint: GitHubRepoRef.from({ owner: "atomist-seeds", repo: "spring-rest", branch: "master" }),
transform: [
UpdateReadmeTitle,
...TransformMavenSpringBootSeedToCustomProject,
],
};
// atomist:code-snippet:end
export const configuration = configure(async sdm => {
// Register the generator and stop command with the SDM
sdm.addGeneratorCommand(MavenGenerator);
// Build goal that runs "maven package", after running "mvn version" which
// sets a unique version for the build
const buildGoal = new Build(
{ displayName: "maven build" })
.with({
name: "maven-build",
builder: mavenBuilder(),
}).withProjectListener(MvnVersion);
const mavenSpringBootRun = goal(
{ displayName: "maven spring boot run" },
async gi => {
const { goalEvent } = gi;
const execution = await executeMavenPerBranchSpringBootDeploy({})(gi) as ExecuteGoalResult;
const appUrl = execution.externalUrls[0].url;
await gi.addressChannels(
slackSuccessMessage(
"Maven Spring Boot Run",
`Started ${codeLine(goalEvent.sha.slice(0, 7))} at ${url(appUrl)}`,
{},
),
{});
return execution;
},
);
// This SDM has three PushRules: no goals, build and run
return {
no_goals: {
test: not(hasFile("pom.xml")),
goals: DoNotSetAnyGoals.andLock(),
},
build: {
goals: [
buildGoal,
],
},
run: {
dependsOn: "build",
goals: [
mavenSpringBootRun,
],
},
};
}, { name: "maven" });