org.apache.maven.shared.invoker.MavenInvocationException Java Examples

The following examples show how to use org.apache.maven.shared.invoker.MavenInvocationException. 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: MavenDependencyResolver.java    From carnotzet with Apache License 2.0 6 votes vote down vote up
private void executeMavenBuild(List<String> goals, InvocationOutputHandler outputHandler) {
	log.debug("Invoking maven with goals {}", goals);
	InvocationRequest request = new DefaultInvocationRequest();
	request.setBatchMode(true);
	request.setGoals(goals);
	// reset MAVEN_DEBUG_OPTS to allow debugging without blocking the invoker calls
	request.addShellEnvironment("MAVEN_DEBUG_OPTS", "");
	InvocationOutputHandler outHandler = outputHandler;
	if (outHandler == null) {
		outHandler = log::debug;
	}
	request.setOutputHandler(outHandler);
	try {
		InvocationResult result = maven.execute(request);
		if (result.getExitCode() != 0) {
			throw new MavenInvocationException("Maven process exited with non-zero code [" + result.getExitCode() + "]. "
					+ "Retry with debug log level enabled to see the maven invocation logs");
		}
	}
	catch (MavenInvocationException e) {
		throw new CarnotzetDefinitionException("Error invoking mvn " + goals, e);
	}
}
 
Example #2
Source File: WADFlow.java    From wad with MIT License 6 votes vote down vote up
void build() {
    long start = System.currentTimeMillis();
    try {
        System.out.printf("[%s%s%s]", TerminalColors.TIME.value(), currentFormattedTime(), TerminalColors.RESET.value());
        InvocationResult result = this.builder.build();
        if (result.getExitCode() == 0) {
            System.out.printf("[%d]", successCounter.incrementAndGet());
            System.out.print("\uD83D\uDC4D");
            long buildTime = (System.currentTimeMillis() - start);
            buildTimes.add(buildTime);
            System.out.println(" built in " + buildTime + " ms");
            if (buildTimes.size() % 10 == 0) {
                this.printStatistics();
            }
        } else {
            System.out.printf("[%d] ", buildErrorCounter.incrementAndGet());
            System.out.println("\uD83D\uDC4E ");
        }
    } catch (MavenInvocationException ex) {
        System.err.println(ex.getClass().getName() + " " + ex.getMessage());
    }
}
 
Example #3
Source File: DevMojoIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatClassAppCanRun() throws MavenInvocationException, IOException {
    testDir = initProject("projects/classic", "projects/project-classic-run");
    runAndCheck();

    //make sure that the Class.getPackage() works for app classes
    String pkg = DevModeTestUtils.getHttpResponse("/app/hello/package");
    assertThat(pkg).isEqualTo("org.acme");

    //make sure the proper profile is set
    String profile = DevModeTestUtils.getHttpResponse("/app/hello/profile");
    assertThat(profile).isEqualTo("dev");

    //make sure webjars work
    DevModeTestUtils.getHttpResponse("webjars/bootstrap/3.1.0/css/bootstrap.min.css");

    assertThatOutputWorksCorrectly(running.log());

    assertApplicationPropertiesSetCorrectly();
}
 
Example #4
Source File: DevMojoIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiModuleProjectWithRevisionVersion() throws MavenInvocationException, IOException {
    testDir = initProject("projects/multimodule-revision-prop");
    final String projectVersion = System.getProperty("project.version");
    runAndCheck("-Dquarkus.platform.version=" + projectVersion,
            "-Dquarkus-plugin.version=" + projectVersion);

    // Edit the "Hello" message.
    File source = new File(testDir, "rest/src/main/java/org/acme/HelloResource.java");
    final String uuid = UUID.randomUUID().toString();
    filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));

    // Wait until we get "uuid"
    await()
            .pollDelay(100, TimeUnit.MILLISECONDS)
            .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));

    await()
            .pollDelay(100, TimeUnit.MILLISECONDS)
            .pollInterval(1, TimeUnit.SECONDS)
            .until(source::isFile);
}
 
Example #5
Source File: DevMojoIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatExternalConfigOverridesConfigInJar() throws MavenInvocationException, IOException {
    testDir = initProject("projects/classic", "projects/project-classic-external-config");
    File configurationFile = new File(testDir, "target/config/application.properties");
    assertThat(configurationFile).doesNotExist();

    String uuid = UUID.randomUUID().toString();

    FileUtils.write(configurationFile,
            "greeting=" + uuid,
            "UTF-8");
    await()
            .pollDelay(100, TimeUnit.MILLISECONDS)
            .pollInterval(1, TimeUnit.SECONDS)
            .until(configurationFile::isFile);

    run(true);

    // Wait until we get "uuid"
    await()
            .pollDelay(100, TimeUnit.MILLISECONDS)
            .atMost(60, TimeUnit.SECONDS)
            .until(() -> DevModeTestUtils.getHttpResponse("/app/hello/greeting").contains(uuid));
}
 
Example #6
Source File: PackageIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPackageWorksWhenUberjarIsFalse()
        throws MavenInvocationException, IOException, InterruptedException {
    testDir = initProject("projects/uberjar-check", "projects/project-uberjar-false");

    running = new RunningInvoker(testDir, false);
    final MavenProcessInvocationResult result = running.execute(Collections.singletonList("package"),
            Collections.singletonMap("QUARKUS_PACKAGE_UBER_JAR", "false"));

    assertThat(result.getProcess().waitFor()).isEqualTo(0);

    final File targetDir = getTargetDir();
    List<File> jars = getFilesEndingWith(targetDir, ".jar");
    assertThat(jars).hasSize(2);

    // make sure the jar can be read by JarInputStream
    ensureManifestOfJarIsReadableByJarInputStream(
            jars.stream().filter(f -> f.getName().contains("-runner")).findFirst().get());
}
 
Example #7
Source File: PackageIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void createAndVerifyUberJar() throws IOException, MavenInvocationException, InterruptedException {
    Properties p = new Properties();
    p.setProperty("quarkus.package.uber-jar", "true");

    running = new RunningInvoker(testDir, false);
    final MavenProcessInvocationResult result = running.execute(Collections.singletonList("package"),
            Collections.emptyMap(), p);
    assertThat(result.getProcess().waitFor()).isEqualTo(0);

    final File targetDir = getTargetDir();
    List<File> jars = getFilesEndingWith(targetDir, ".jar");
    assertThat(jars).hasSize(1);
    assertThat(getNumberOfFilesEndingWith(targetDir, ".original")).isEqualTo(1);

    ensureManifestOfJarIsReadableByJarInputStream(jars.get(0));
}
 
Example #8
Source File: CreateProjectMojoIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private InvocationResult setup(Properties params)
        throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException {

    params.setProperty("platformGroupId", ToolsConstants.IO_QUARKUS);
    params.setProperty("platformArtifactId", "quarkus-bom");
    params.setProperty("platformVersion", getPluginVersion());

    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections.singletonList(
            getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":create"));
    request.setDebug(false);
    request.setShowErrors(false);
    request.setProperties(params);
    getEnv().forEach(request::addShellEnvironment);
    File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);
    return invoker.execute(request);
}
 
Example #9
Source File: GenerateConfigIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
void testAddExtensionWithASingleExtension() throws MavenInvocationException, IOException {
    testDir = initProject(PROJECT_SOURCE_DIR, "projects/testGenerateConfig");
    invoker = initInvoker(testDir);
    generateConfig("test.properties");

    String file = loadFile("test.properties");
    Assertions.assertTrue(file.contains("#quarkus.log.level"));
    Assertions.assertTrue(file.contains("The log level of the root category"));
    Assertions.assertTrue(file.contains("#quarkus.thread-pool.growth-resistance=0"));
    Assertions.assertTrue(file.contains("The executor growth resistance"));

    generateConfig("application.properties");
    //the existing file should not add properties that already exist
    file = loadFile("application.properties");
    Assertions.assertTrue(file.contains("quarkus.log.level=INFO"));
    Assertions.assertFalse(file.contains("The log level of the root category"));
    Assertions.assertTrue(file.contains("#quarkus.thread-pool.growth-resistance=0"));
    Assertions.assertTrue(file.contains("The executor growth resistance"));
}
 
Example #10
Source File: GenerateConfigIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void generateConfig(String filename)
        throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections
            .singletonList(getPluginGroupId() + ":" + getPluginArtifactId() + ":"
                    + getPluginVersion() + ":generate-config"));
    Properties properties = new Properties();
    properties.setProperty("file", filename);
    request.setProperties(properties);
    getEnv().forEach(request::addShellEnvironment);
    File log = new File(testDir, "build-generate-config-" + testDir.getName() + ".log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);
    invoker.execute(request);
}
 
Example #11
Source File: MavenRun.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
	InvocationRequest request = new DefaultInvocationRequest();
	request.setPomFile(new File("pom.xml"));
	if (args.length > 0) {
		if (args[0] != null && args[1] != null) {
			Properties projectProperties = new Properties();
			projectProperties.setProperty("deviceOS", args[0]);
			projectProperties.setProperty("appPath", args[1]);
			projectProperties.setProperty("osVersion", args[2]);
			projectProperties.setProperty("deviceName", args[3]);
			projectProperties.setProperty("udid", args[4]);
			request.setProperties(projectProperties);
		}
	}

	request.setGoals(Collections.singletonList("test"));
	Invoker invoker = new DefaultInvoker();
	invoker.setMavenHome(new File(System.getenv("M2_HOME")));
	try {
		invoker.execute(request);
	} catch (MavenInvocationException e) {
		e.printStackTrace();
	}
}
 
Example #12
Source File: ListExtensionsIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
void testListExtensionsWithManagedDependencyWithoutScope() throws MavenInvocationException, IOException {
    testDir = initProject(PROJECT_SOURCE_DIR, "projects/testListExtensionsWithManagedDependencyWithoutScope");
    invoker = initInvoker(testDir);
    // Edit the pom.xml.
    File source = new File(testDir, "pom.xml");
    filter(source, Collections.singletonMap("<!-- insert managed dependencies here -->",
            "      <dependency>\n" +
                    "        <groupId>org.assertj</groupId>\n" +
                    "        <artifactId>assertj-core</artifactId>\n" +
                    "        <version>3.16.1</version>\n" +
                    "      </dependency>"));

    List<String> outputLogLines = listExtensions();

    assertThat(outputLogLines).anyMatch(line -> line.contains(VERTX_ARTIFACT_ID));
}
 
Example #13
Source File: AddExtensionIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
void testAddExtensionWithMultipleExtension() throws MavenInvocationException, IOException {
    testDir = initProject(PROJECT_SOURCE_DIR, "projects/testAddExtensionWithMultipleExtension");
    invoker = initInvoker(testDir);
    addExtension(false, "quarkus-vertx, commons-io:commons-io:2.6");

    Model model = loadPom(testDir);
    Dependency expected1 = new Dependency();
    expected1.setGroupId(QUARKUS_GROUPID);
    expected1.setArtifactId(VERTX_ARTIFACT_ID);
    Dependency expected2 = new Dependency();
    expected2.setGroupId(COMMONS_IO);
    expected2.setArtifactId(COMMONS_IO);
    expected2.setVersion("2.6");
    assertThat(contains(model.getDependencies(), expected1)).isTrue();
    assertThat(contains(model.getDependencies(), expected2)).isTrue();
}
 
Example #14
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected void runMavenGoals(File outputDir, String... goals) throws MavenInvocationException {
    List<String> goalList = Arrays.asList(goals);
    LOG.info("Invoking maven with goals: " + goalList + " in folder: " + outputDir);
    File pomFile = new File(outputDir, "pom.xml");

    InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localMavenRepo);
    request.setInteractive(false);
    request.setPomFile(pomFile);
    request.setGoals(goalList);

    // lets use a dummy service name to avoid it being too long
    request.setMavenOpts("-Dfabric8.service.name=dummy-name");

    Invoker invoker = new DefaultInvoker();
    InvocationResult result = invoker.execute(request);
    int exitCode = result.getExitCode();
    LOG.info("maven result " + exitCode + " exception: " + result.getExecutionException());
    if (exitCode != 0) {
        LOG.error("Failed to invoke maven goals: " + goalList + " in folder: " + outputDir + ". Exit Code: " + exitCode);
        failedFolders.add(outputDir);
    }
}
 
Example #15
Source File: AddExtensionIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
void testAddExtensionWithMultipleExtensionsAndPluralForm() throws MavenInvocationException, IOException {
    testDir = initProject(PROJECT_SOURCE_DIR,
            "projects/testAddExtensionWithMultipleExtensionAndPluralForm");
    invoker = initInvoker(testDir);
    addExtension(true, "quarkus-vertx, commons-io:commons-io:2.6");

    Model model = loadPom(testDir);
    Dependency expected1 = new Dependency();
    expected1.setGroupId(QUARKUS_GROUPID);
    expected1.setArtifactId(VERTX_ARTIFACT_ID);
    Dependency expected2 = new Dependency();
    expected2.setGroupId(COMMONS_IO);
    expected2.setArtifactId(COMMONS_IO);
    expected2.setVersion("2.6");
    assertThat(contains(model.getDependencies(), expected1)).isTrue();
    assertThat(contains(model.getDependencies(), expected2)).isTrue();
}
 
Example #16
Source File: BuildIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiModuleAppRootWithNoSources()
        throws MavenInvocationException, IOException, InterruptedException {
    testDir = initProject("projects/multimodule-root-no-src", "projects/multimodule-root-no-src-build");

    running = new RunningInvoker(testDir, false);
    MavenProcessInvocationResult result = running.execute(Collections.singletonList("install -pl .,html,rest"),
            Collections.emptyMap());
    assertThat(result.getProcess().waitFor()).isEqualTo(0);

    result = running.execute(Collections.singletonList("quarkus:build -f runner"), Collections.emptyMap());

    assertThat(result.getProcess().waitFor()).isEqualTo(0);

    final File targetDir = new File(testDir, "runner" + File.separator + "target");
    List<File> jars = getFilesEndingWith(targetDir, ".jar");
    assertThat(jars).hasSize(1);

    // make sure the jar can be read by JarInputStream
    ensureManifestOfJarIsReadableByJarInputStream(
            jars.stream().filter(f -> f.getName().contains("-runner")).findFirst().get());
}
 
Example #17
Source File: AbstractSundrioMojo.java    From sundrio with Apache License 2.0 6 votes vote down vote up
void backGroundBuild(MavenProject project) throws MojoExecutionException {
    MavenExecutionRequest executionRequest = session.getRequest();

    InvocationRequest request = new DefaultInvocationRequest();
    request.setBaseDirectory(project.getBasedir());
    request.setPomFile(project.getFile());
    request.setGoals(executionRequest.getGoals());
    request.setRecursive(false);
    request.setInteractive(false);

    request.setProfiles(executionRequest.getActiveProfiles());
    request.setProperties(executionRequest.getUserProperties());
    Invoker invoker = new DefaultInvoker();
    try {
        InvocationResult result = invoker.execute(request);
        if (result.getExitCode() != 0) {
            throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", result.getExecutionException());
        }
    } catch (MavenInvocationException e) {
        throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", e);
    }
}
 
Example #18
Source File: NativeBuildMojo.java    From client-maven-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void execute() throws MojoExecutionException {
    getLog().debug("Start building");

    // prepare the execution:
    final InvocationRequest invocationRequest = new DefaultInvocationRequest();
    invocationRequest.setProfiles(project.getActiveProfiles().stream()
            .map(Profile::getId)
            .collect(Collectors.toList()));
    invocationRequest.setPomFile(new File(pom));

    invocationRequest.setGoals(Arrays.asList("client:compile", "client:link"));

    final Invoker invoker = new DefaultInvoker();
    // execute:
    try {
        final InvocationResult invocationResult = invoker.execute(invocationRequest);
        if (invocationResult.getExitCode() != 0) {
            throw new MojoExecutionException("Error, client:build failed", invocationResult.getExecutionException());
        }
    } catch (MavenInvocationException e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error", e);
    }

}
 
Example #19
Source File: ExecuteUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static void executeMaven(File projectDirectory, CommandInvocation invocation, String buildTarget) {
    String mvnPath = findExecutable("mvn");
    System.setProperty("maven.home", mvnPath);

    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(new File(projectDirectory.getAbsolutePath() + File.separatorChar + "pom.xml"));
    request.setGoals(Collections.singletonList(buildTarget));

    Invoker invoker = new DefaultInvoker();

    InvocationResult result = null;
    try {
        result = invoker.execute(request);
    } catch (MavenInvocationException e) {
        invocation.println("Failed during invocation: " + e.getMessage());
    }

    if (result.getExitCode() != 0) {
        invocation.println("Build failed.");
    }
}
 
Example #20
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public File getArtifactJar(String groupId, String artifactId, String version) {
    Properties properties = new Properties();
    properties.put("groupId", groupId);
    properties.put("artifactId", artifactId);
    properties.put("version", version);

    InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localMavenRepo);
    request.setInteractive(false);
    List<String> goalList = Arrays.asList("org.apache.maven.plugins:maven-dependency-plugin:2.10:get");
    request.setGoals(goalList);
    request.setProperties(properties);

    try {
        Invoker invoker = new DefaultInvoker();
        InvocationResult result = invoker.execute(request);
        int exitCode = result.getExitCode();
        LOG.info("maven result " + exitCode + " exception: " + result.getExecutionException());
        assertEquals("Failed to invoke maven goals: " + goalList + " with properties: " + properties + ". Exit Code: ", 0, exitCode);
    } catch (MavenInvocationException e) {
        fail("Failed to invoke maven goals: " + goalList + " with properties: " + properties + ". Exception " + e, e);
    }
    String path = groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar";
    return new File(localMavenRepo, path);
}
 
Example #21
Source File: RunningInvoker.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public MavenProcessInvocationResult execute(List<String> goals, Map<String, String> envVars, Properties properties)
        throws MavenInvocationException {

    DefaultInvocationRequest request = new DefaultInvocationRequest();
    request.setGoals(goals);
    request.setDebug(debug);
    request.setLocalRepositoryDirectory(getLocalRepositoryDirectory());
    request.setBaseDirectory(getWorkingDirectory());
    request.setPomFile(new File(getWorkingDirectory(), "pom.xml"));
    request.setProperties(properties);

    if (System.getProperty("mavenOpts") != null) {
        request.setMavenOpts(System.getProperty("mavenOpts"));
    } else {
        //we need to limit the memory consumption, as we can have a lot of these processes
        //running at once, if they add default to 75% of total mem we can easily run out
        //of physical memory as they will consume way more than what they need instead of
        //just running GC
        request.setMavenOpts("-Xmx128m");
    }

    request.setShellEnvironmentInherited(true);
    envVars.forEach(request::addShellEnvironment);
    request.setOutputHandler(outStreamHandler);
    request.setErrorHandler(errStreamHandler);
    this.result = (MavenProcessInvocationResult) execute(request);
    return result;
}
 
Example #22
Source File: ScalaRemoteDevModeIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatTheApplicationIsReloadedOnScalaChange()
        throws MavenInvocationException, IOException, InterruptedException {
    testDir = initProject("projects/classic-scala", "projects/project-classic-run-scala-change-remote");
    agentDir = initProject("projects/classic-scala", "projects/project-classic-run-scala-change-local");
    runAndCheck();

    // Edit the "Hello" message.
    File source = new File(agentDir, "src/main/scala/org/acme/HelloResource.scala");
    String uuid = UUID.randomUUID().toString();
    filter(source, ImmutableMap.of("= \"hello\"", "= \"" + uuid + "\""));

    // Wait until we get "uuid"
    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));

    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .pollInterval(1, TimeUnit.SECONDS)
            .until(source::isFile);

    filter(source, ImmutableMap.of(uuid, "carambar"));

    // Wait until we get "carambar"
    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar"));
}
 
Example #23
Source File: ScalaDevModeIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatTheApplicationIsReloadedOnScalaChange() throws MavenInvocationException, IOException {
    testDir = initProject("projects/classic-scala", "projects/project-classic-run-scala-change");
    runAndCheck();

    // Edit the "Hello" message.
    File source = new File(testDir, "src/main/scala/org/acme/HelloResource.scala");
    String uuid = UUID.randomUUID().toString();
    filter(source, ImmutableMap.of("= \"hello\"", "= \"" + uuid + "\""));

    // Wait until we get "uuid"
    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));

    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .pollInterval(1, TimeUnit.SECONDS)
            .until(source::isFile);

    filter(source, ImmutableMap.of(uuid, "carambar"));

    // Wait until we get "carambar"
    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar"));
}
 
Example #24
Source File: AbstractBuildMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
private void invokeGoals( String goals, File projectBasedir) throws MavenInvocationException {
    getLog().info( "[" + projectBasedir +"] Invoking goals: " + goals );

    InvocationRequest request = new DefaultInvocationRequest()
            .setBaseDirectory(projectBasedir)
            .setGoals(Arrays.asList(StringUtils.split(goals, ",")));

    invoker.execute( request );
}
 
Example #25
Source File: AddExtensionIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
void testAddExtensionWithASingleExtension() throws MavenInvocationException, IOException {
    testDir = initProject(PROJECT_SOURCE_DIR, "projects/testAddExtensionWithASingleExtension");
    invoker = initInvoker(testDir);
    addExtension(false, VERTX_ARTIFACT_ID);

    Model model = loadPom(testDir);
    Dependency expected = new Dependency();
    expected.setGroupId(QUARKUS_GROUPID);
    expected.setArtifactId(VERTX_ARTIFACT_ID);
    assertThat(contains(model.getDependencies(), expected)).isTrue();
}
 
Example #26
Source File: JarRunnerIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatJarRunnerConsoleOutputWorksCorrectly() throws MavenInvocationException, IOException {
    File testDir = initProject("projects/classic", "projects/project-classic-console-output");
    RunningInvoker running = new RunningInvoker(testDir, false);

    MavenProcessInvocationResult result = running.execute(Arrays.asList("package", "-DskipTests"), Collections.emptyMap());
    await().atMost(1, TimeUnit.MINUTES).until(() -> result.getProcess() != null && !result.getProcess().isAlive());
    assertThat(running.log()).containsIgnoringCase("BUILD SUCCESS");
    running.stop();

    Path jar = testDir.toPath().toAbsolutePath()
            .resolve(Paths.get("target/acme-1.0-SNAPSHOT-runner.jar"));
    File output = new File(testDir, "target/output.log");
    output.createNewFile();

    Process process = doLaunch(jar, output).start();
    try {
        // Wait until server up
        await()
                .pollDelay(1, TimeUnit.SECONDS)
                .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello/package", 200));

        String logs = FileUtils.readFileToString(output, "UTF-8");

        assertThatOutputWorksCorrectly(logs);

        // test that the application name and version are properly set
        assertApplicationPropertiesSetCorrectly();
        assertResourceReadingFromClassPathWorksCorrectly("");
    } finally {
        process.destroy();
    }

}
 
Example #27
Source File: MavenCompatibilityTest.java    From multi-module-maven-release-plugin with MIT License 5 votes vote down vote up
private void buildProjectWithMavenVersion(String mavenVersionToTest) throws IOException, InterruptedException, MavenInvocationException {
    String buildNumber = mavenVersionToTest.replace(".", "") + String.valueOf(System.currentTimeMillis());
    String expected = "1.0." + buildNumber;
    testProject.setMvnRunner(MvnRunner.mvn(mavenVersionToTest));
    testProject.mvnRelease(buildNumber);
    MvnRunner.assertArtifactInLocalRepo("com.github.danielflower.mavenplugins.testprojects", "single-module", expected);
    assertThat(new File(testProject.localDir, "target/single-module-" + expected + "-package.jar").exists(), is(true));
}
 
Example #28
Source File: DevMojoIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatAddingConfigFileWorksCorrectly() throws MavenInvocationException, IOException {
    testDir = initProject("projects/classic-noconfig", "projects/project-classic-run-noconfig-add-config");
    assertThat(testDir).isDirectory();
    running = new RunningInvoker(testDir, false);
    final Properties mvnRunProps = new Properties();
    mvnRunProps.setProperty("debug", "false");
    running.execute(Arrays.asList("compile", "quarkus:dev"), Collections.emptyMap(), mvnRunProps);

    String resp = DevModeTestUtils.getHttpResponse();

    assertThat(resp).containsIgnoringCase("ready").containsIgnoringCase("application").containsIgnoringCase("org.acme")
            .containsIgnoringCase("1.0-SNAPSHOT");

    String greeting = DevModeTestUtils.getHttpResponse("/app/hello/greeting");
    assertThat(greeting).contains("initialValue");

    File configurationFile = new File(testDir, "src/main/resources/application.properties");
    assertThat(configurationFile).doesNotExist();

    String uuid = UUID.randomUUID().toString();

    FileUtils.write(configurationFile,
            "greeting=" + uuid,
            "UTF-8");
    await()
            .pollDelay(100, TimeUnit.MILLISECONDS)
            .pollInterval(1, TimeUnit.SECONDS)
            .until(configurationFile::isFile);

    // Wait until we get "uuid"
    await()
            .pollDelay(100, TimeUnit.MILLISECONDS)
            .atMost(10, TimeUnit.SECONDS)
            .until(() -> DevModeTestUtils.getHttpResponse("/app/hello/greeting").contains(uuid));
}
 
Example #29
Source File: ListExtensionsIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
void testListExtensions() throws MavenInvocationException, IOException {
    testDir = initProject(PROJECT_SOURCE_DIR, "projects/testListExtensions");
    invoker = initInvoker(testDir);

    List<String> outputLogLines = listExtensions();

    assertThat(outputLogLines).anyMatch(line -> line.contains(VERTX_ARTIFACT_ID));
}
 
Example #30
Source File: KotlinRemoteDevModeIT.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatTheApplicationIsReloadedOnKotlinChange()
        throws MavenInvocationException, IOException, InterruptedException {
    testDir = initProject("projects/classic-kotlin", "projects/project-classic-run-kotlin-change-remote");
    agentDir = initProject("projects/classic-kotlin", "projects/project-classic-run-kotlin-change-local");
    runAndCheck();

    // Edit the "Hello" message.
    File source = new File(agentDir, "src/main/kotlin/org/acme/HelloResource.kt");
    String uuid = UUID.randomUUID().toString();
    filter(source, ImmutableMap.of("return \"hello\"", "return \"" + uuid + "\""));

    // Wait until we get "uuid"
    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .atMost(3, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));

    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .pollInterval(1, TimeUnit.SECONDS)
            .until(source::isFile);

    filter(source, ImmutableMap.of(uuid, "carambar"));

    // Wait until we get "carambar"
    await()
            .pollDelay(1, TimeUnit.SECONDS)
            .atMost(3, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar"));
}