From c67d89f865523c51ca664446c2cf26be20322d5e Mon Sep 17 00:00:00 2001 From: Benj Boyer <15024379+benjboyer@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:36:13 -0400 Subject: [PATCH] * Fixed unit tests * Added Closure simulation for testing (#84) * Refactored defaults scripts to inv-repo --- .../java/io/peasoup/inv/run/InvExecutor.java | 7 + .../main/java/io/peasoup/inv/run/Logger.java | 2 +- .../io/peasoup/inv/testing/JunitRunner.java | 10 +- ...vTestingBase.java => JunitScriptBase.java} | 25 +-- ...InvTextListener.java => TextListener.java} | 7 +- .../public/imports/configure-parameters.js | 2 - .../io/peasoup/inv/defaults/FilesTests.groovy | 80 ---------- .../io/peasoup/inv/defaults/HttpTests.groovy | 61 ------- .../io/peasoup/inv/defaults/MavenTests.groovy | 73 --------- core/src/test/resources/defaults/files/file1 | 0 core/src/test/resources/defaults/files/file2 | 0 .../maven/SimpleMavenLookup/app1/pom.xml | 6 - .../maven/SimpleMavenLookup/app2/pom.xml | 15 -- .../src/test/resources/inv-test-script.groovy | 6 +- defaults/files/inv.groovy | 96 ----------- defaults/http/inv.groovy | 150 ------------------ defaults/maven/inv.groovy | 74 --------- defaults/ssh/inv.groovy | 37 ----- 18 files changed, 34 insertions(+), 617 deletions(-) rename core/src/main/java/io/peasoup/inv/testing/{JUnitInvTestingBase.java => JunitScriptBase.java} (63%) rename core/src/main/java/io/peasoup/inv/testing/{InvTextListener.java => TextListener.java} (79%) delete mode 100644 core/src/test/groovy/io/peasoup/inv/defaults/FilesTests.groovy delete mode 100644 core/src/test/groovy/io/peasoup/inv/defaults/HttpTests.groovy delete mode 100644 core/src/test/groovy/io/peasoup/inv/defaults/MavenTests.groovy delete mode 100644 core/src/test/resources/defaults/files/file1 delete mode 100644 core/src/test/resources/defaults/files/file2 delete mode 100644 core/src/test/resources/defaults/maven/SimpleMavenLookup/app1/pom.xml delete mode 100644 core/src/test/resources/defaults/maven/SimpleMavenLookup/app2/pom.xml delete mode 100644 defaults/files/inv.groovy delete mode 100644 defaults/http/inv.groovy delete mode 100644 defaults/maven/inv.groovy delete mode 100644 defaults/ssh/inv.groovy diff --git a/core/src/main/java/io/peasoup/inv/run/InvExecutor.java b/core/src/main/java/io/peasoup/inv/run/InvExecutor.java index d7bee4c..2363b7b 100644 --- a/core/src/main/java/io/peasoup/inv/run/InvExecutor.java +++ b/core/src/main/java/io/peasoup/inv/run/InvExecutor.java @@ -50,6 +50,13 @@ public PoolReport execute() { Logger.info("---- [DIGEST] completed ----"); + // TODO Horrible fix. PoolStacktraces print before pool has done printing even with flushing. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + Logger.error(e); + } + new PoolReportTrace(pool, report).printPoolTrace(); new PoolReportMarkdown(pool).printPoolMarkdown(); diff --git a/core/src/main/java/io/peasoup/inv/run/Logger.java b/core/src/main/java/io/peasoup/inv/run/Logger.java index 08db74d..e5d92ce 100644 --- a/core/src/main/java/io/peasoup/inv/run/Logger.java +++ b/core/src/main/java/io/peasoup/inv/run/Logger.java @@ -7,10 +7,10 @@ import java.util.Queue; public final class Logger { + private static Queue captureQueue = null; private static Closure captureClosure = null; - private static boolean systemEnabled = false; private static boolean debugEnabled = false; diff --git a/core/src/main/java/io/peasoup/inv/testing/JunitRunner.java b/core/src/main/java/io/peasoup/inv/testing/JunitRunner.java index de22ff8..16503cd 100644 --- a/core/src/main/java/io/peasoup/inv/testing/JunitRunner.java +++ b/core/src/main/java/io/peasoup/inv/testing/JunitRunner.java @@ -21,13 +21,13 @@ public class JunitRunner { public JunitRunner() { junit = new JUnitCore(); - junit.addListener(new InvTextListener(System.out)); + junit.addListener(new TextListener(System.out)); ImportCustomizer importCustomizer = new ImportCustomizer(); importCustomizer.addStarImports("org.junit"); importCustomizer.addStaticStars("org.junit.Assert"); - groovyLoader = new GroovyLoader(false, "io.peasoup.inv.testing.JUnitInvTestingBase", importCustomizer); + groovyLoader = new GroovyLoader(false, "io.peasoup.inv.testing.JunitScriptBase", importCustomizer); } public void add(String scriptLocation) { @@ -35,7 +35,6 @@ public void add(String scriptLocation) { if (!scriptFile.exists()) { Logger.warn(scriptFile.getAbsolutePath() + " does not exist on current filesystem."); return; - } // Load and put class into list @@ -56,12 +55,15 @@ public void add(String scriptLocation) { classes.add(scriptObj.getClass()); } - public void run() { + public boolean run() { Result result = junit.run(classes.toArray(new Class[0])); + System.out.println("Finished. Result: Failures: " + result.getFailureCount() + ". Ignored: " + result.getIgnoreCount() + ". Tests run: " + result.getRunCount() + ". Time: " + result.getRunTime() + "ms."); + + return result.getFailureCount() == 0; } diff --git a/core/src/main/java/io/peasoup/inv/testing/JUnitInvTestingBase.java b/core/src/main/java/io/peasoup/inv/testing/JunitScriptBase.java similarity index 63% rename from core/src/main/java/io/peasoup/inv/testing/JUnitInvTestingBase.java rename to core/src/main/java/io/peasoup/inv/testing/JunitScriptBase.java index f69c2f6..61a2042 100644 --- a/core/src/main/java/io/peasoup/inv/testing/JUnitInvTestingBase.java +++ b/core/src/main/java/io/peasoup/inv/testing/JunitScriptBase.java @@ -1,7 +1,9 @@ package io.peasoup.inv.testing; +import groovy.lang.Closure; import groovy.lang.Script; import io.peasoup.inv.run.InvExecutor; +import io.peasoup.inv.run.InvHandler; import io.peasoup.inv.run.InvInvoker; import io.peasoup.inv.run.PoolReport; import org.apache.commons.lang.StringUtils; @@ -10,7 +12,7 @@ import java.io.File; import java.net.URL; -public abstract class JUnitInvTestingBase extends Script { +public abstract class JunitScriptBase extends Script { protected InvExecutor invExecutor; protected PoolReport report; @@ -35,32 +37,33 @@ public boolean getHasExceptions() { return report != null && !report.getErrors().isEmpty(); } - public void invoke(String... files) throws IllegalAccessException { - if (files == null) throw new IllegalArgumentException("files"); - if (files.length == 0) return; + public void simulate(Object... invs) throws IllegalAccessException, InvHandler.INVOptionRequiredException { + if (invs == null) throw new IllegalArgumentException("invs"); + if (invs.length == 0) return; if (called) throw new IllegalAccessException("Only call sequence once for test method"); called = true; - for (String file : files) { - runInv(file); + for (Object inv : invs) { + if (inv instanceof CharSequence) loadInvScriptfile((String)inv); + if (inv instanceof Closure) new InvHandler(invExecutor).call((Closure)inv); } report = invExecutor.execute(); } - private void runInv(String value) { - if (StringUtils.isEmpty(value)) throw new IllegalArgumentException("Inv must be a valid non-null, non-empty value"); + private void loadInvScriptfile(String invScriptfile) { + if (StringUtils.isEmpty(invScriptfile)) throw new IllegalArgumentException("Inv must be a valid non-null, non-empty value"); - File invFile = new File(value); + File invFile = new File(invScriptfile); if (!invFile.exists()) { String testClassLocation = (String)getMetaClass().getProperty(this, "$0"); - invFile = new File(new File(testClassLocation).getParentFile(), value); + invFile = new File(new File(testClassLocation).getParentFile(), invScriptfile); } if (!invFile.exists()) { - URL location = this.getClass().getResource(value); + URL location = this.getClass().getResource(invScriptfile); if (location != null) invFile = new File(location.getPath()); } diff --git a/core/src/main/java/io/peasoup/inv/testing/InvTextListener.java b/core/src/main/java/io/peasoup/inv/testing/TextListener.java similarity index 79% rename from core/src/main/java/io/peasoup/inv/testing/InvTextListener.java rename to core/src/main/java/io/peasoup/inv/testing/TextListener.java index 6c98804..a320a2f 100644 --- a/core/src/main/java/io/peasoup/inv/testing/InvTextListener.java +++ b/core/src/main/java/io/peasoup/inv/testing/TextListener.java @@ -1,21 +1,20 @@ package io.peasoup.inv.testing; import org.junit.internal.JUnitSystem; -import org.junit.internal.TextListener; import org.junit.runner.Description; import org.junit.runner.notification.Failure; import java.io.PrintStream; -public class InvTextListener extends TextListener { +public class TextListener extends org.junit.internal.TextListener { private final PrintStream writer; - public InvTextListener(JUnitSystem system) { + public TextListener(JUnitSystem system) { this(system.out()); } - public InvTextListener(PrintStream writer) { + public TextListener(PrintStream writer) { super(writer); this.writer = writer; diff --git a/core/src/main/resources/public/imports/configure-parameters.js b/core/src/main/resources/public/imports/configure-parameters.js index ec968c5..fc34453 100644 --- a/core/src/main/resources/public/imports/configure-parameters.js +++ b/core/src/main/resources/public/imports/configure-parameters.js @@ -233,8 +233,6 @@ Vue.component('configure-parameters', { vm.$bus.$emit('toast', `warn:Reset parameters successfully!`) }, saveParameter: function(parameter) { - var vm = this - if (parameter.sending) return diff --git a/core/src/test/groovy/io/peasoup/inv/defaults/FilesTests.groovy b/core/src/test/groovy/io/peasoup/inv/defaults/FilesTests.groovy deleted file mode 100644 index 6cb5d12..0000000 --- a/core/src/test/groovy/io/peasoup/inv/defaults/FilesTests.groovy +++ /dev/null @@ -1,80 +0,0 @@ -package io.peasoup.inv.defaults - -import io.peasoup.inv.TempHome -import io.peasoup.inv.run.InvExecutor -import io.peasoup.inv.run.InvHandler -import io.peasoup.inv.utils.Stdout -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(TempHome.class) -class FilesTests { - - @Test - void glob() { - - def files = new File(FilesTests.class.getResource("/defaults/files").path) - - def executor = new InvExecutor() - executor.parse(new File("../defaults/files/inv.groovy")) - - new InvHandler(executor).call { - - require $inv.Files into '$files' - - step { - $files.glob(files).each { println it + "-GLOB-ALL" } - $files.glob(files, "*file*").each { println it + "-GLOB-PATTERN" } - $files.glob(files, "*file*", "*file2*").each { println it + "-GLOB-EXCLUDE" } - } - } - - - Stdout.capture ({ executor.execute() }, { - // GLOB All - assert it.contains("file1-GLOB-ALL") - assert it.contains("file2-GLOB-ALL") - - // GLOB Pattern - assert it.contains("file1-GLOB-ALL") - assert it.contains("file2-GLOB-ALL") - - // GLOB Exclude - assert it.contains("file1-GLOB-EXCLUDE") - assert !it.contains("file2-GLOB-EXCLUDE") - }) - } - - @Test - void find() { - - def files = new File(FilesTests.class.getResource("/defaults/files").path).absolutePath - def executor = new InvExecutor() - executor.parse(new File("../defaults/files/inv.groovy")) - - new InvHandler(executor).call { - - require $inv.Files into '$files' - - step { - $files.find(files as String).each { println it.path + "-FIND-ALL" } - $files.find(files, "file").each { println it.path + "-FIND-PATTERN" } - $files.find(files, "file", "file2").each { println it.path + "-FIND-EXCLUDE" } - } - } - - Stdout.capture ({ executor.execute() }, { - // Find All - assert it.contains("file1-FIND-ALL") - assert it.contains("file2-FIND-ALL") - - // Find Pattern - assert it.contains("file1-FIND-PATTERN") - assert it.contains("file2-FIND-PATTERN") - - // Find Exclude - assert it.contains("file1-FIND-EXCLUDE") - assert !it.contains("file2-FIND-EXCLUDE") - }) - } -} diff --git a/core/src/test/groovy/io/peasoup/inv/defaults/HttpTests.groovy b/core/src/test/groovy/io/peasoup/inv/defaults/HttpTests.groovy deleted file mode 100644 index 4c578a9..0000000 --- a/core/src/test/groovy/io/peasoup/inv/defaults/HttpTests.groovy +++ /dev/null @@ -1,61 +0,0 @@ -package io.peasoup.inv.defaults - -import io.peasoup.inv.TempHome -import io.peasoup.inv.run.InvExecutor -import io.peasoup.inv.run.InvHandler -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(TempHome.class) -class HttpTests { - - @Test - void get() { - - def executor = new InvExecutor() - executor.parse(new File("../defaults/http/inv.groovy")) - - new InvHandler(executor).call { - - require $inv.HTTP into '$http' - - step { - assert $http.newRequest("https://google.com") - .send() - .valid() - } - } - - def report = executor.execute() - assert report.isOk() - } - - @Test - void post() { - - def executor = new InvExecutor() - executor.parse(new File("../defaults/http/inv.groovy")) - - new InvHandler(executor).call { - - require $inv.HTTP into '$http' - - step { - - def data = "My super duper hyper mega data" - - def req = $http.newRequest("https://postman-echo.com/post") - .method("POST") - .parameter("value1", data) - .send() - - assert req.valid() - assert req.toText() - assert req.toJson().form.value1 == data - } - } - - def report = executor.execute() - assert report.isOk() - } -} diff --git a/core/src/test/groovy/io/peasoup/inv/defaults/MavenTests.groovy b/core/src/test/groovy/io/peasoup/inv/defaults/MavenTests.groovy deleted file mode 100644 index e7e336f..0000000 --- a/core/src/test/groovy/io/peasoup/inv/defaults/MavenTests.groovy +++ /dev/null @@ -1,73 +0,0 @@ -package io.peasoup.inv.defaults - -import io.peasoup.inv.TempHome -import io.peasoup.inv.run.InvExecutor -import io.peasoup.inv.run.InvHandler -import io.peasoup.inv.run.Logger -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(TempHome.class) -class MavenTests { - - @Before - void setup() { - Logger.capture(null) - } - - @Test - void mavenSimpleLookup() { - - // Enable capture - def logs = Logger.capture(new LinkedList()) - - def app1 = new File(FilesTests.class.getResource("/defaults/maven/SimpleMavenLookup/app1").path).absolutePath - def app2 = new File(FilesTests.class.getResource("/defaults/maven/SimpleMavenLookup/app2").path).absolutePath - - def executor = new InvExecutor() - executor.parse(new File("../defaults/files/inv.groovy")) - executor.parse(new File("../defaults/maven/inv.groovy")) - - new InvHandler(executor).call { - - name "app1" - path app1 - - // Using default - require $inv.Maven into '$maven' - - step { - assert $maven.poms - } - } - - new InvHandler(executor).call { - - name "app2" - - require $inv.Maven using { - - // Disabling defaults and calling manually - defaults false - - resolved { - response.analyze(app2) - } - } - } - - def report = executor.execute() - - report.errors.each { - it.throwable.printStackTrace() - } - assert report.isOk() - - def flattenLogs = logs.join() - - assert flattenLogs.contains("[app1] => [BROADCAST] [Artifact] com.mycompany.app:my-app-1") - assert flattenLogs.contains("[app2] => [BROADCAST] [Artifact] com.mycompany.app:my-app-2") - assert flattenLogs.contains("[app2] => [REQUIRE] [Artifact] com.mycompany.app:my-app-1") - } -} diff --git a/core/src/test/resources/defaults/files/file1 b/core/src/test/resources/defaults/files/file1 deleted file mode 100644 index e69de29..0000000 diff --git a/core/src/test/resources/defaults/files/file2 b/core/src/test/resources/defaults/files/file2 deleted file mode 100644 index e69de29..0000000 diff --git a/core/src/test/resources/defaults/maven/SimpleMavenLookup/app1/pom.xml b/core/src/test/resources/defaults/maven/SimpleMavenLookup/app1/pom.xml deleted file mode 100644 index 8f282c5..0000000 --- a/core/src/test/resources/defaults/maven/SimpleMavenLookup/app1/pom.xml +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - com.mycompany.app - my-app-1 - 1 - \ No newline at end of file diff --git a/core/src/test/resources/defaults/maven/SimpleMavenLookup/app2/pom.xml b/core/src/test/resources/defaults/maven/SimpleMavenLookup/app2/pom.xml deleted file mode 100644 index aa43492..0000000 --- a/core/src/test/resources/defaults/maven/SimpleMavenLookup/app2/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - 4.0.0 - com.mycompany.app - my-app-2 - 1 - - - - com.mycompany.app - my-app-1 - 1 - - - - \ No newline at end of file diff --git a/core/src/test/resources/inv-test-script.groovy b/core/src/test/resources/inv-test-script.groovy index 0d00f36..4a1b109 100644 --- a/core/src/test/resources/inv-test-script.groovy +++ b/core/src/test/resources/inv-test-script.groovy @@ -1,18 +1,18 @@ @Test void ok() { - invoke( + simulate( "/testing/inv1-provider.groovy", "/testing/inv1.groovy" ) - assertEquals true + assertTrue true assert isOk } @Test void missing_element() { - invoke( + simulate( "/testing/inv1.groovy" ) diff --git a/defaults/files/inv.groovy b/defaults/files/inv.groovy deleted file mode 100644 index 3ce2b1e..0000000 --- a/defaults/files/inv.groovy +++ /dev/null @@ -1,96 +0,0 @@ -import java.nio.file.Path -import java.nio.file.Paths - -inv { - - markdown ''' -Files (I/O) general tool. -it is more performant than FileNameFinder provided by groovy itself. -''' - - broadcast $inv.Files using { - markdown ''' -A default implementation for files interactions. - -Methods: -``` - $files.glob: Suitable for specific files using Ant style filtering - $files.find: Suitable for performances on generic file patterns -``` -''' - ready { new Files() } - } -} - -class Files { - - - /** - * Locate files based on Ant-style patterns - * - * @param pwd Parent working directory - * @param glob The Ant-style pattern to select files - * @param exclude the Ant-style pattern to exclude files - * @return List of String with file's absolute path - */ - List glob(File pwd, String glob = "*", String exclude = "") { - assert pwd, 'Pwd (print working directory) is required.' - assert glob, 'Glob is required' - - return this.glob(pwd.absolutePath, glob, exclude) - } - - /** - * Locate files based on Ant-style patterns - * - * @param pwd Parent working directory - * @param glob The Ant-style pattern to select files - * @param exclude the Ant-style pattern to exclude files - * @return List of String with file's absolute path - */ - List glob(String pwd, String glob = "*", String exclude = "") { - assert pwd, 'Parent working directory is required.' - assert glob, 'Glob is required. Can be empty' - assert glob, 'Glob is required. Can be empty' - - def regexGlob = glob - .replace("\\", "/") - .replace("/", "\\/") - .replace(".", "\\.") - .replace("*", ".*") - .replace("?", ".*") - - def regexExclude = exclude - .replace("\\", "/") - .replace("/", "\\/") - .replace(".", "\\.") - .replace("*", ".*") - .replace("?", ".*") - - return java.nio.file.Files.walk(Paths.get(pwd)) - .parallel() - .filter { Path p -> java.nio.file.Files.isRegularFile(p) } - .collect { Path p -> p.toFile() } - .findAll { File f -> !exclude || !f.absolutePath.matches(regexExclude) } - .findAll { File f -> !glob || f.absolutePath.matches(regexGlob) } - .collect { File f -> f.absolutePath } - } - - /** - * Locate files on pure Java framework - * @param pwd parent working directory - * @param pattern the pattern to select files - * @param exclude the pattern to exclude files - * @return List of File object. - */ - List find(String pwd, String pattern = "", String exclude = "") { - assert pwd, 'Pwd (print working directory) is required.' - - return java.nio.file.Files.walk(Paths.get(pwd)) - .parallel() - .filter({ Path p -> java.nio.file.Files.isRegularFile(p) }) - .collect{ Path p -> p.toFile() } - .findAll { File f -> !exclude || !f.absolutePath.contains(exclude) } - .findAll { File f -> !pattern || f.absolutePath.contains(pattern) } - } -} \ No newline at end of file diff --git a/defaults/http/inv.groovy b/defaults/http/inv.groovy deleted file mode 100644 index 8509dfe..0000000 --- a/defaults/http/inv.groovy +++ /dev/null @@ -1,150 +0,0 @@ -import groovy.json.JsonSlurper - -inv { - markdown ''' -Provide easy-to-use HTTP request methods. -''' - - broadcast $inv.HTTP using { - markdown ''' -Returns a new RequestHandler. -Methods: -``` - $http.newRequest: Create the default HTTP request (simple) - $http.newSimpleRequest: Create a simple request. -``` -''' - ready { return new RequestHandler() } - } -} - -class RequestHandler { - - /** - * Creates a new request. - * By default it uses a SimpleRequest. - * @param url String representation of the URL - * @return A new SimpleHttpRequest instance. - */ - SimpleHttpRequest newRequest(String url) { - return this.newSimpleRequest(url) - } - - /** - * Creates a new SimpleHttpRequest. - * By default it uses a SimpleRequest. - * @param url String representation of the URL - * @return A new SimpleHttpRequest instance. - */ - SimpleHttpRequest newSimpleRequest(String url) { - return new SimpleHttpRequest(url) - } - -} - -class SimpleHttpRequest { - - final private HttpURLConnection conn - - private boolean doValidations = true - private String sendCharset = "UTF-8" - private Integer connectionTimeout = null - private Integer readTimeout = null - - private String responseText = null - private Integer responseCode = null - - final String url - - SimpleHttpRequest(String url) { - assert url - - this.url = url - this.conn = (HttpURLConnection) new URL(url).openConnection() - } - - SimpleHttpRequest timeouts(int connection, int read) { - assert connection >= 0 - assert read >= 0 - - this.connectionTimeout = connection - this.readTimeout = read - - return this - } - - SimpleHttpRequest charsets(String sendCharset) { - assert sendCharset - - this.sendCharset = sendCharset - - return this - } - - SimpleHttpRequest header(String property, String value) { - assert property - assert value - - this.conn.setRequestProperty(property, value) - - return this - } - - SimpleHttpRequest method(String method) { - assert method - - this.conn.requestMethod = method - - return this - } - - SimpleHttpRequest parameter(String property, String value) { - assert property - assert sendCharset - - this.conn.setDoOutput(true) - - def bytes = "${property}=${value}".getBytes(this.sendCharset) - this.conn.outputStream.write(bytes) - - return this - } - - SimpleHttpRequest send(String data = null) { - if (data) { - assert this.sendCharset - - this.conn.setDoOutput(true) - this.conn.outputStream.write(data.getBytes(this.sendCharset)) - } - - doSend() - - return this - } - - // When sent - - String toText() { this.responseText } - Object toJson() { return new JsonSlurper().parseText(this.responseText) } - - int status() { this.responseCode } - boolean valid() { return this.responseCode >= 200 && this.responseCode < 400 } - - private void doSend() { - - if (this.connectionTimeout) - this.conn.connectTimeout = connectionTimeout - else if (this.doValidations) - println "[WARNING] ${this.url}: connection timeout not defined" - - if (this.readTimeout) - this.conn.readTimeout = this.readTimeout - else if (this.doValidations) - println "[WARNING] ${this.url}: read timeout not defined" - - this.responseText = this.conn.inputStream.text - this.responseCode = this.conn.responseCode - } -} - diff --git a/defaults/maven/inv.groovy b/defaults/maven/inv.groovy deleted file mode 100644 index af3c424..0000000 --- a/defaults/maven/inv.groovy +++ /dev/null @@ -1,74 +0,0 @@ -import org.apache.maven.model.Dependency -@Grab("org.apache.maven:maven-model:3.0.2") -import org.apache.maven.model.Model -import org.apache.maven.model.io.xpp3.MavenXpp3Reader - -inv { - markdown ''' -Provide a Maven reader that scan the callee current location for 'pom.xml' files. -It also analyzes the artifacts and the dependencies to generate broadcasts (artifacts) and requires (dependencies). -''' - - - require $inv.Files into '$files' - - broadcast $inv.Maven using { - markdown ''' -Returns a new Maven instance. - -Exposes: -``` - $: Default hook so it can analyze each callee individually. It uses the callee 'pwd' location. - analyze: Analyze the artifacts and dependencies for a specific folder. -``` -''' - - - ready { - def instance = [:] - instance << [ - $: { - def analyse = instance.analyze as Closure - def copy = analyse - .dehydrate() - .rehydrate( - delegate, - analyse.owner, - analyse.thisObject) - copy.resolveStrategy = Closure.DELEGATE_FIRST - - return copy(path) // using default path of Inv - }, - analyze: { String pwd, String exclude = "" -> - - def poms = [] - - // Using find makes it faster - for(File file : $files.find(pwd, "pom.xml", exclude)) { - - MavenXpp3Reader reader = new MavenXpp3Reader() - Model model = reader.read(new FileReader(file)) - - broadcast $inv.Artifact using { - id model.groupId + ":" + model.artifactId - - ready { [model: model] } - } - - for(Dependency dep : model.dependencies) { - require $inv.Artifact(dep.groupId + ":" + dep.artifactId) - } - - poms << model - } - - return [ - poms: poms - ] - } - ] - - return instance - } - } -} \ No newline at end of file diff --git a/defaults/ssh/inv.groovy b/defaults/ssh/inv.groovy deleted file mode 100644 index 53f21f8..0000000 --- a/defaults/ssh/inv.groovy +++ /dev/null @@ -1,37 +0,0 @@ -// Visit https://gradle-ssh-plugin.github.io/docs/ - -@Grab('ch.qos.logback:logback-classic:1.1.2') -@Grab("org.hidetake:groovy-ssh:2.10.1") -import org.hidetake.groovy.ssh.Ssh - -inv { - markdown ''' -Provide a wrapper to Hidetake groovy-ssh implementation. -It creates a new service per callee. -''' - - broadcast $inv.SSH using { - markdown ''' -Returns a new SSH handler. - -Methods: - $: Default hook so it can provide a specific service for each callee individually. -''' - - ready {[ - $: { - def instance = [:] - - instance += [ - ssh: Ssh.newService(), - debugMode: { - instance.ssh.runtime.logback(level: 'DEBUG') - } - ] - - return instance - } - ]} - } -} -