From da06be192b190c5c1792cac519e16ed1946a668b Mon Sep 17 00:00:00 2001 From: Jiri Danek Date: Fri, 24 Feb 2017 11:31:47 +0100 Subject: [PATCH] ARTEMIS-996 Simplify what was lookupHome(path) in artemis-maven-plugin and deduplicate it --- .../artemis/maven/ArtemisAbstractPlugin.java | 12 +++++++ .../artemis/maven/ArtemisCLIPlugin.java | 31 ++----------------- .../artemis/maven/ArtemisCreatePlugin.java | 29 ++--------------- 3 files changed, 16 insertions(+), 56 deletions(-) diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java index ea6758bb53..304df892a9 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java @@ -19,6 +19,9 @@ package org.apache.activemq.artemis.maven; import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -76,6 +79,15 @@ public abstract class ArtemisAbstractPlugin extends AbstractMojo { } } + boolean isArtemisHome(Path path) { + if (path == null) { + return false; + } + + Path artemisScript = path.resolve("bin").resolve("artemis"); + return Files.exists(artemisScript, LinkOption.NOFOLLOW_LINKS); + } + protected abstract boolean isIgnore(); protected abstract void doExecute() throws MojoExecutionException, MojoFailureException; diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java index 140251355c..0e6d288b78 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCLIPlugin.java @@ -17,9 +17,6 @@ package org.apache.activemq.artemis.maven; import java.io.File; -import java.nio.file.Files; -import java.nio.file.LinkOption; -import java.nio.file.Path; import org.apache.activemq.artemis.boot.Artemis; import org.apache.activemq.artemis.cli.commands.Run; @@ -70,30 +67,6 @@ public class ArtemisCLIPlugin extends ArtemisAbstractPlugin { @Parameter private String testPassword = null; - /** - * Validate if the directory is a artemis.home * - * - * @param path - * @return - */ - private boolean lookupHome(Path path) { - - if (path == null) { - return false; - } - - Path binFolder = path.resolve("bin"); - - if (binFolder == null && Files.exists(binFolder, LinkOption.NOFOLLOW_LINKS)) { - return false; - } - - Path artemisScript = binFolder.resolve("artemis"); - - return artemisScript != null && Files.exists(artemisScript, LinkOption.NOFOLLOW_LINKS); - - } - @Override protected boolean isIgnore() { return ignore; @@ -106,8 +79,8 @@ public class ArtemisCLIPlugin extends ArtemisAbstractPlugin { MavenProject project = (MavenProject) getPluginContext().get("project"); - if (!lookupHome(home.toPath())) { - if (lookupHome(alternateHome.toPath())) { + if (!isArtemisHome(home.toPath())) { + if (isArtemisHome(alternateHome.toPath())) { home = alternateHome; } else { getLog().error("********************************************************************************************"); diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java index fdc308a250..86668da718 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java @@ -21,7 +21,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; -import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -134,30 +133,6 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin { @Parameter(defaultValue = "${noServer}") boolean ignore; - /** - * Validate if the directory is a artemis.home * - * - * @param path - * @return - */ - private boolean lookupHome(Path path) { - - if (path == null) { - return false; - } - - Path binFolder = path.resolve("bin"); - - if (binFolder == null && Files.exists(binFolder, LinkOption.NOFOLLOW_LINKS)) { - return false; - } - - Path artemisScript = binFolder.resolve("artemis"); - - return artemisScript != null && Files.exists(artemisScript, LinkOption.NOFOLLOW_LINKS); - - } - private void add(List list, String... str) { for (String s : str) { list.add(s); @@ -174,8 +149,8 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin { getLog().info("Local " + localRepository); MavenProject project = (MavenProject) getPluginContext().get("project"); - if (!lookupHome(home.toPath())) { - if (lookupHome(alternateHome.toPath())) { + if (!isArtemisHome(home.toPath())) { + if (isArtemisHome(alternateHome.toPath())) { home = alternateHome; } else { getLog().error("********************************************************************************************");