Java Code Examples for org.apache.maven.plugin.Mojo#execute()
The following examples show how to use
org.apache.maven.plugin.Mojo#execute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommandScriptContinueOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-script-continueOnError-pom.xml"); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "scriptContinueOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("continue on error", ServerOperations.readResultAsString(result)); } finally { // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); } }
Example 2
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommandScriptFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-script-failOnError-pom.xml"); try { executeCommandsMojo.execute(); fail("MojoExecutionException expected."); } catch (MojoExecutionException e) { assertEquals(CommandLineException.class, e.getCause().getClass()); } final ModelNode address = ServerOperations.createAddress("system-property", "scriptFailOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("initial value", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
Example 3
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommandsContinueOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-continueOnError-pom.xml"); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "propertyContinueOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("continue on error", ServerOperations.readResultAsString(result)); } finally { // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); } }
Example 4
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommandsForkCmdFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-fork-cmd-failOnError-pom.xml"); // Set the JBoss home field so commands will be executed in a new process setValue(executeCommandsMojo, "jbossHome", TestEnvironment.WILDFLY_HOME.toString()); try { executeCommandsMojo.execute(); fail("MojoExecutionException expected."); } catch (MojoExecutionException ignore) { } // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "propertyFailOnError.in.try"); final ModelNode result = executeOperation(ServerOperations.createReadAttributeOperation(address, "value")); try { assertEquals("inside catch", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
Example 5
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommandsForkOpFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-fork-op-failOnError-pom.xml"); // Set the JBoss home field so commands will be executed in a new process setValue(executeCommandsMojo, "jbossHome", TestEnvironment.WILDFLY_HOME.toString()); try { executeCommandsMojo.execute(); fail("MojoExecutionException expected."); } catch (MojoExecutionException ignore) { } final ModelNode address = ServerOperations.createAddress("system-property", "propertyFailOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("initial value", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
Example 6
Source File: ExecuteCommandsTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommands() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-pom.xml"); executeCommandsMojo.execute(); // Read the attribute ModelNode address = ServerOperations.createAddress("system-property", "org.wildfly.maven.plugin-exec-cmd"); ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); ModelNode result = executeOperation(op); assertEquals("true", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); // Read the attribute address = ServerOperations.createAddress("system-property", "property2"); op = ServerOperations.createReadAttributeOperation(address, "value"); result = executeOperation(op); assertEquals("property 2", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); }
Example 7
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteCommandsFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-failOnError-pom.xml"); try { executeCommandsMojo.execute(); fail("MojoExecutionException expected."); } catch (MojoExecutionException e) { assertEquals(CommandLineException.class, e.getCause().getClass()); } final ModelNode address = ServerOperations.createAddress("system-property", "propertyFailOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("initial value", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
Example 8
Source File: ExecuteCommandsTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testExecuteBatchCommands() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-batch-commands-pom.xml"); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "org.wildfly.maven.plugin-batch"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); assertEquals("true", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); }
Example 9
Source File: ExecuteCommandsTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testExecuteForkCommands() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-fork-pom.xml"); setValue(executeCommandsMojo, "jbossHome", TestEnvironment.WILDFLY_HOME.toString()); executeCommandsMojo.execute(); // Read the attribute ModelNode address = ServerOperations.createAddress("system-property", "org.wildfly.maven.plugin-fork-cmd"); ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); ModelNode result = executeOperation(op); assertEquals("true", ServerOperations.readResultAsString(result)); // Ensure the module has been added final Path moduleDir = Paths.get(TestEnvironment.WILDFLY_HOME.toString(), "modules", "org", "wildfly", "plugin", "tests", "main"); assertTrue(String.format("Expected %s to exist.", moduleDir), Files.exists(moduleDir)); assertTrue("Expected the module.xml to exist in " + moduleDir, Files.exists(moduleDir.resolve("module.xml"))); assertTrue("Expected the test.jar to exist in " + moduleDir, Files.exists(moduleDir.resolve("test.jar"))); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); // Read the attribute address = ServerOperations.createAddress("system-property", "fork-command"); op = ServerOperations.createReadAttributeOperation(address, "value"); result = executeOperation(op); assertEquals("set", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); // Remove the module deleteRecursively(TestEnvironment.WILDFLY_HOME.resolve("modules").resolve("org")); }
Example 10
Source File: GenerateMojoIT.java From swagger-maven-plugin with MIT License | 5 votes |
/** * Tests the generated Swagger specifications based on the given method parameters. * * @param folder The base folder of the expected output. * @param basename The basename for the generated Swagger specifications. * @param pom The name of the POM file to be used for the test. * @param prettyPrinted If true, the generated JSON Swagger specification should be pretty-printed. * @param outputFormats The output formats that should be generated and checked. * * @throws Exception If a JSON parsing or file-read exception happens. */ private void testGenerate(String folder, String basename, String pom, boolean prettyPrinted, OutputFormat... outputFormats) throws Exception { Path output = Paths.get(folder); if (Files.exists(output)) { Files.walkFileTree(output, new DeleteVisitor()); } Mojo mojo = rule.lookupMojo("generate", new File("src/test/resources/" + pom)); mojo.execute(); List<OutputFormat> formats = Arrays.asList(outputFormats); if (formats.contains(OutputFormat.JSON)) { Path expectedJson = Paths.get("src/test/resources/expectedOutput", folder, basename + ".json"); Path generatedJson = Paths.get("target", folder, basename + ".json"); assertJsonEquals(expectedJson, generatedJson); // We test the indentation by simply checking that the generated JSON contains 2 spaces String json = new String(Files.readAllBytes(generatedJson), StandardCharsets.UTF_8); Assert.assertEquals(prettyPrinted, json.contains(" ")); } if (formats.contains(OutputFormat.YAML)) { Path expectedYaml = Paths.get("src/test/resources/expectedOutput", folder, basename + ".yaml"); Path generatedYaml = Paths.get("target", folder, basename + ".yaml"); assertYamlEquals(expectedYaml, generatedYaml); } }
Example 11
Source File: ExecuteCommandsTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testExecuteOfflineCommands() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-offline-pom.xml"); setValue(executeCommandsMojo, "jbossHome", System.getProperty("jboss.home")); executeCommandsMojo.execute(); }
Example 12
Source File: ExecuteCommandsTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testExecuteCommandsFromOfflineScript() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-offline-script-pom.xml"); setValue(executeCommandsMojo, "jbossHome", System.getProperty("jboss.home")); executeCommandsMojo.execute(); }
Example 13
Source File: ByteBuddyMojoTest.java From byte-buddy with Apache License 2.0 | 5 votes |
private void execute(String goal, String target) throws Exception { InputStream in = ByteBuddyMojoTest.class.getResourceAsStream("/net/bytebuddy/test/" + target + ".pom.xml"); if (in == null) { throw new AssertionError("Cannot find resource for: " + target); } try { File pom = File.createTempFile("maven", ".pom"); OutputStream out = new FileOutputStream(pom); try { byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) != -1) { out.write(buffer, 0, length); } } finally { out.close(); } Mojo mojo = mojoRule.lookupMojo(goal, pom); if (goal.equals("transform")) { mojoRule.setVariableValueToObject(mojo, "outputDirectory", project.getAbsolutePath()); mojoRule.setVariableValueToObject(mojo, "compileClasspathElements", Collections.emptyList()); } else if (goal.equals("transform-test")) { mojoRule.setVariableValueToObject(mojo, "testOutputDirectory", project.getAbsolutePath()); mojoRule.setVariableValueToObject(mojo, "testClasspathElements", Collections.emptyList()); } else { throw new AssertionError("Unknown goal: " + goal); } mojoRule.setVariableValueToObject(mojo, "repositorySystem", repositorySystem); mojoRule.setVariableValueToObject(mojo, "groupId", FOO); mojoRule.setVariableValueToObject(mojo, "artifactId", BAR); mojoRule.setVariableValueToObject(mojo, "version", QUX); mojoRule.setVariableValueToObject(mojo, "packaging", JAR); mojo.setLog(new SilentLog()); mojo.execute(); } finally { in.close(); } }
Example 14
Source File: NoClassesVisitorPluginTest.java From jaxb-visitor with Apache License 2.0 | 5 votes |
@Override public void testExecute() throws Exception { final Mojo mojo = initMojo(); mojo.execute(); generatedCodeFixture.assertInterfaces(); }
Example 15
Source File: ExecuteCommandsTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testExecuteCommandsFromScript() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-script-pom.xml"); executeCommandsMojo.execute(); // Create the address final ModelNode address = ServerOperations.createAddress("system-property", "org.wildfly.maven.plugin"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); // The script adds a new system property that's value should be true assertEquals("true", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); }
Example 16
Source File: FailOnErrorTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testExecuteCommandsForkContinueOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-fork-continueOnError-pom.xml"); // Set the JBoss home field so commands will be executed in a new process setValue(executeCommandsMojo, "jbossHome", TestEnvironment.WILDFLY_HOME.toString()); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "propertyContinueOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); // Read the attribute final ModelNode inTryAddress = ServerOperations.createAddress("system-property", "propertyContinueOnError.in.try"); final ModelNode inTryResult = executeOperation(ServerOperations.createReadAttributeOperation(inTryAddress, "value")); try { assertEquals("continue on error", ServerOperations.readResultAsString(result)); assertEquals("inside catch", ServerOperations.readResultAsString(inTryResult)); // The invalid module directory should not exist final Path baseModuleDir = Paths.get(TestEnvironment.WILDFLY_HOME.toString(), "modules", "org", "wildfly", "plugin", "tests"); final Path invalidModuleDir = baseModuleDir.resolve("invalid"); assertTrue(String.format("Expected %s to not exist.", invalidModuleDir), Files.notExists(invalidModuleDir)); // The valid module directory should exist final Path moduleDir = baseModuleDir.resolve("main"); assertTrue(String.format("Expected %s to exist.", moduleDir), Files.exists(moduleDir)); assertTrue("Expected the module.xml to exist in " + moduleDir, Files.exists(moduleDir.resolve("module.xml"))); assertTrue("Expected the test.jar to exist in " + moduleDir, Files.exists(moduleDir.resolve("test.jar"))); } finally { // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); executeOperation(ServerOperations.createRemoveOperation(inTryAddress)); // Remove the module deleteRecursively(TestEnvironment.WILDFLY_HOME.resolve("modules").resolve("org")); } }
Example 17
Source File: RunXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 4 votes |
public void testExecute() throws Exception { final Mojo mojo = initMojo(); mojo.execute(); }