Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
afadac27
Commit
afadac27
authored
Aug 27, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
cc53f881
97f15d60
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
176 additions
and
8 deletions
+176
-8
invoker.properties
...lugin/src/it/start-stop-automatic-fork/invoker.properties
+1
-0
pom.xml
...oot-maven-plugin/src/it/start-stop-automatic-fork/pom.xml
+58
-0
SampleApplication.java
...omatic-fork/src/main/java/org/test/SampleApplication.java
+82
-0
verify.groovy
...ven-plugin/src/it/start-stop-automatic-fork/verify.groovy
+5
-0
AbstractRunMojo.java
.../java/org/springframework/boot/maven/AbstractRunMojo.java
+8
-3
StartMojo.java
...c/main/java/org/springframework/boot/maven/StartMojo.java
+1
-1
StopMojo.java
...rc/main/java/org/springframework/boot/maven/StopMojo.java
+21
-4
No files found.
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/invoker.properties
0 → 100644
View file @
afadac27
invoker.goals
=
clean verify
\ No newline at end of file
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/pom.xml
0 → 100644
View file @
afadac27
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.springframework.boot.maven.it
</groupId>
<artifactId>
start-stop-automatic-fork
</artifactId>
<version>
0.0.1.BUILD-SNAPSHOT
</version>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<executions>
<execution>
<id>
reserve-jmx-port
</id>
<goals>
<goal>
reserve-network-port
</goal>
</goals>
<phase>
process-resources
</phase>
<configuration>
<portNames>
<portName>
jmx.port
</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
@project.groupId@
</groupId>
<artifactId>
@project.artifactId@
</artifactId>
<version>
@project.version@
</version>
<executions>
<execution>
<id>
pre-integration-test
</id>
<goals>
<goal>
start
</goal>
</goals>
<configuration>
<jvmArguments>
-Dfoo=bar
</jvmArguments>
</configuration>
</execution>
<execution>
<id>
post-integration-test
</id>
<goals>
<goal>
stop
</goal>
</goals>
</execution>
</executions>
<configuration>
<jmxPort>
${jmx.port}
</jmxPort>
</configuration>
</plugin>
</plugins>
</build>
</project>
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/src/main/java/org/test/SampleApplication.java
0 → 100644
View file @
afadac27
/*
* Copyright 2012-2016 the original author or authors.
*
* 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
org
.
test
;
import
java.lang.management.ManagementFactory
;
import
javax.management.MBeanServer
;
import
javax.management.ObjectName
;
/**
* This sample app simulates the JMX Mbean that is exposed by the Spring Boot application.
*/
public
class
SampleApplication
{
private
static
final
Object
lock
=
new
Object
();
public
static
void
main
(
String
[]
args
)
throws
Exception
{
MBeanServer
mbs
=
ManagementFactory
.
getPlatformMBeanServer
();
ObjectName
name
=
new
ObjectName
(
"org.springframework.boot:type=Admin,name=SpringApplication"
);
SpringApplicationAdmin
mbean
=
new
SpringApplicationAdmin
();
mbs
.
registerMBean
(
mbean
,
name
);
// Flag the app as ready
mbean
.
ready
=
true
;
int
waitAttempts
=
0
;
while
(!
mbean
.
shutdownInvoked
)
{
if
(
waitAttempts
>
30
)
{
throw
new
IllegalStateException
(
"Shutdown should have been invoked by now"
);
}
synchronized
(
lock
)
{
lock
.
wait
(
250
);
}
waitAttempts
++;
}
}
public
interface
SpringApplicationAdminMXBean
{
boolean
isReady
();
void
shutdown
();
}
static
class
SpringApplicationAdmin
implements
SpringApplicationAdminMXBean
{
private
boolean
ready
;
private
boolean
shutdownInvoked
;
@Override
public
boolean
isReady
()
{
System
.
out
.
println
(
"isReady: "
+
this
.
ready
);
return
this
.
ready
;
}
@Override
public
void
shutdown
()
{
this
.
shutdownInvoked
=
true
;
System
.
out
.
println
(
"Shutdown requested"
);
}
}
}
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-automatic-fork/verify.groovy
0 → 100644
View file @
afadac27
import
static
org
.
junit
.
Assert
.
assertTrue
def
file
=
new
File
(
basedir
,
"build.log"
)
assertTrue
'Start should have waited for application to be ready'
,
file
.
text
.
contains
(
"isReady: true"
)
assertTrue
'Shutdown should have been invoked'
,
file
.
text
.
contains
(
"Shutdown requested"
)
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java
View file @
afadac27
...
...
@@ -90,6 +90,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
/**
* JVM arguments that should be associated with the forked process used to run the
* application. On command line, make sure to wrap multiple values between quotes.
* NOTE: the use of JVM arguments means that processes will be started by forking
* a new JVM.
* @since 1.1
*/
@Parameter
(
property
=
"run.jvmArguments"
)
...
...
@@ -137,8 +139,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private
File
classesDirectory
;
/**
* Flag to indicate if the run processes should be forked.
By default process forking
*
is only us
ed if an agent or jvmArguments are specified.
* Flag to indicate if the run processes should be forked.
{@code fork } is
*
automatically enabl
ed if an agent or jvmArguments are specified.
* @since 1.2
*/
@Parameter
(
property
=
"fork"
)
...
...
@@ -212,7 +214,10 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private
void
run
(
String
startClassName
)
throws
MojoExecutionException
,
MojoFailureException
{
findAgent
();
if
(
isFork
())
{
boolean
forkEnabled
=
isFork
();
this
.
project
.
getProperties
().
setProperty
(
"_spring.boot.fork.enabled"
,
Boolean
.
toString
(
forkEnabled
));
if
(
forkEnabled
)
{
doRunWithForkedJvm
(
startClassName
);
}
else
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java
View file @
afadac27
...
...
@@ -181,7 +181,7 @@ public class StartMojo extends AbstractRunMojo {
private
void
waitForSpringApplication
()
throws
MojoFailureException
,
MojoExecutionException
{
try
{
if
(
Boolean
.
TRUE
.
equals
(
isFork
()
))
{
if
(
isFork
(
))
{
waitForForkedSpringApplication
();
}
else
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StopMojo.java
View file @
afadac27
...
...
@@ -29,6 +29,7 @@ import org.apache.maven.plugin.MojoFailureException;
import
org.apache.maven.plugins.annotations.LifecyclePhase
;
import
org.apache.maven.plugins.annotations.Mojo
;
import
org.apache.maven.plugins.annotations.Parameter
;
import
org.apache.maven.project.MavenProject
;
/**
* Stop a spring application that has been started by the "start" goal. Typically invoked
...
...
@@ -41,9 +42,17 @@ import org.apache.maven.plugins.annotations.Parameter;
public
class
StopMojo
extends
AbstractMojo
{
/**
* Flag to indicate if the run processes should be forked. Must be aligned to the
* value used to {@link StartMojo start} the process
* @since 1.2
* The Maven project.
* @since 1.4.1
*/
@Parameter
(
defaultValue
=
"${project}"
,
readonly
=
true
,
required
=
true
)
private
MavenProject
project
;
/**
* Flag to indicate if process to stop was forked. By default, the value is inherited
* from the {@link MavenProject}. If it is set, it must match the value used to
* {@link StartMojo start} the process.
* @since 1.3
*/
@Parameter
(
property
=
"fork"
)
private
Boolean
fork
;
...
...
@@ -77,7 +86,7 @@ public class StopMojo extends AbstractMojo {
}
getLog
().
info
(
"Stopping application..."
);
try
{
if
(
Boolean
.
TRUE
.
equals
(
this
.
fork
))
{
if
(
isForked
(
))
{
stopForkedProcess
();
}
else
{
...
...
@@ -90,6 +99,14 @@ public class StopMojo extends AbstractMojo {
}
}
private
boolean
isForked
()
{
if
(
this
.
fork
!=
null
)
{
return
this
.
fork
;
}
String
property
=
this
.
project
.
getProperties
().
getProperty
(
"_spring.boot.fork.enabled"
);
return
Boolean
.
valueOf
(
property
);
}
private
void
stopForkedProcess
()
throws
IOException
,
MojoFailureException
,
MojoExecutionException
{
JMXConnector
connector
=
SpringApplicationAdminClient
.
connect
(
this
.
jmxPort
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment