Skip to content

Commit

Permalink
ARTEMIS-4504: add a stop goal that runs the cli script, update exampl…
Browse files Browse the repository at this point in the history
…es to use it
  • Loading branch information
gemmellr committed Nov 15, 2023
1 parent 5e51233 commit 6f14de7
Show file tree
Hide file tree
Showing 119 changed files with 278 additions and 700 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ boolean isArtemisHome(Path path) {
return Files.exists(artemisScript, LinkOption.NOFOLLOW_LINKS);
}

protected File findArtemisHome(final File home, final File alternateHome) throws MojoExecutionException {
if (isArtemisHome(home.toPath())) {
return home;
}

if (isArtemisHome(alternateHome.toPath())) {
return alternateHome;
}

getLog().error("********************************************************************************************");
getLog().error("Could not locate suitable Artemis.home on either " + home + " or " + alternateHome);
getLog().error("Use the binary distribution or build the distribution before running the examples");
getLog().error("********************************************************************************************");

throw new MojoExecutionException("Couldn't find artemis.home");
}

protected abstract boolean isIgnore();

protected Artifact newArtifact(String artifactID) throws MojoFailureException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {

MavenProject project = (MavenProject) getPluginContext().get("project");

if (!isArtemisHome(home.toPath())) {
if (isArtemisHome(alternateHome.toPath())) {
home = alternateHome;
} else {
getLog().error("********************************************************************************************");
getLog().error("Could not locate suitable Artemis.home on either " + home + " or " + alternateHome);
getLog().error("Use the binary distribution or build the distribution before running the examples");
getLog().error("********************************************************************************************");

throw new MojoExecutionException("Couldn't find artemis.home");
}
}
home = findArtemisHome(home, alternateHome);

try {
if (spawn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
getLog().debug("Local " + localRepository);
MavenProject project = (MavenProject) getPluginContext().get("project");

if (!isArtemisHome(home.toPath())) {
if (isArtemisHome(alternateHome.toPath())) {
home = alternateHome;
} else {
getLog().error("********************************************************************************************");
getLog().error("Could not locate suitable Artemis.home on either " + home + " or " + alternateHome);
getLog().error("Use the binary distribution or build the distribution before running the examples");
getLog().error("********************************************************************************************");

throw new MojoExecutionException("Couldn't find artemis.home");
}
}
home = findArtemisHome(home, alternateHome);

Map properties = getPluginContext();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.activemq.artemis.maven;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
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;

@Mojo(name = "stop", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
public class ArtemisStopPlugin extends ArtemisAbstractPlugin {

private static final String STOP = "stop";

private PluginDescriptor descriptor;

@Parameter(defaultValue = "${noServer}")
boolean ignore;

@Parameter(defaultValue = "server")
String name;

@Parameter(defaultValue = "${activemq.basedir}", required = true)
private File home;

@Parameter(defaultValue = "${activemq.basedir}/artemis-distribution/target/apache-artemis-${project.version}-bin/apache-artemis-${project.version}/", required = true)
private File alternateHome;

@Parameter(defaultValue = "${basedir}/target/server0", required = true)
private File location;

@Parameter(defaultValue = "30000")
private long spawnTimeout;

@Parameter
boolean useSystemOutput = getLog().isDebugEnabled();

@Override
protected boolean isIgnore() {
return ignore;
}

@Override
protected void doExecute() throws MojoExecutionException, MojoFailureException {
MavenProject project = (MavenProject) getPluginContext().get("project");

home = findArtemisHome(home, alternateHome);

try {
final Process process = org.apache.activemq.artemis.cli.process.ProcessBuilder.build(name, location, true, new String[] {STOP});
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
process.destroy();
}
});

boolean complete = process.waitFor(spawnTimeout, TimeUnit.MILLISECONDS);
if (!complete) {
getLog().error("Stop process did not exit within the spawnTimeout of " + spawnTimeout);

throw new MojoExecutionException("Stop process did not exit within the spawnTimeout of " + spawnTimeout);
}

Thread.sleep(600);
} catch (Throwable e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
org.apache.activemq.artemis.cli.process.ProcessBuilder.cleanupProcess();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
getLog().debug("Local " + localRepository);
MavenProject project = (MavenProject) getPluginContext().get("project");

if (!isArtemisHome(home.toPath())) {
if (isArtemisHome(alternateHome.toPath())) {
home = alternateHome;
} else {
getLog().error("********************************************************************************************");
getLog().error("Could not locate suitable Artemis.home on either " + home + " or " + alternateHome);
getLog().error("Use the binary distribution or build the distribution before running the examples");
getLog().error("********************************************************************************************");

throw new MojoExecutionException("Couldn't find artemis.home");
}
}
home = findArtemisHome(home, alternateHome);

Map properties = getPluginContext();

Expand Down
5 changes: 1 addition & 4 deletions docs/user-manual/maven-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,10 @@ You may refer to it directly under the examples directory tree.
<execution>
<id>stop</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
Expand Down
10 changes: 2 additions & 8 deletions examples/features/broker-connection/amqp-federation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,21 @@ under the License.
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,21 @@ under the License.
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,21 @@ under the License.
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,21 @@ under the License.
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
Expand Down
10 changes: 2 additions & 8 deletions examples/features/broker-connection/amqp-sending-overssl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,21 @@ under the License.
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

Expand Down
10 changes: 2 additions & 8 deletions examples/features/broker-connection/disaster-recovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,21 @@ under the License.
<execution>
<id>stop0</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
<execution>
<id>stop1</id>
<goals>
<goal>cli</goal>
<goal>stop</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<location>${basedir}/target/server1</location>
<args>
<param>stop</param>
</args>
</configuration>
</execution>

Expand Down

0 comments on commit 6f14de7

Please sign in to comment.