Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for creating CLI apps from existing sources #1233

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import jakarta.inject.Inject;

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpStatus;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -199,6 +203,16 @@ public void testConfigCommand() {
.assertApplicationPropertiesDoesNotContain(propertyName);
}

@Test
public void testCreateApplicationFromExistingSources() {
Path srcPath = Paths.get("src/test/resources/existingSourcesApp");
QuarkusCliRestService app = cliClient.createApplicationFromExistingSources("app", null, srcPath);

app.start();
Awaitility.await().timeout(15, TimeUnit.SECONDS)
.untilAsserted(() -> app.given().get("/hello").then().statusCode(HttpStatus.SC_OK));
}

private void assertInstalledExtensions(QuarkusCliRestService app, String... expectedExtensions) {
List<String> extensions = app.getInstalledExtensions();
Stream.of(expectedExtensions).forEach(expectedExtension -> assertTrue(extensions.contains(expectedExtension),
Expand Down
70 changes: 70 additions & 0 deletions examples/quarkus-cli/src/test/resources/existingSourcesApp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>existingSourcesApp</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.12.3</quarkus.platform.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 3.13.0 is out
  2. What about updates and prod versions? I would like to have a way to change this value without editing the file

Copy link
Contributor Author

@mocenas mocenas Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is primarily aimed at CLI update-testing. Which means - we want to use old quarkus versions, and if we need up-to-date ones - we'll use "quarkus update" to get to it.
I will add an option to use either CliDevModeVersionLessQuarkusApplicationManagedResource or CliDevModeLocalhostQuarkusApplicationManagedResource (similar to #1232) but I can see potential problems here. See if I have an app with git-anchored sources, then those sources are probably made for specific version of quarkus and changing it to newer version, would possibly require to update the sources as well.

However I can see an use case where overwriting the version in app.start() would make sense. And that is all that matter. I will change it to have this option too.

3.13.0 is out

IMO that doesn't matter. As stated above, this feature is primarily for testing old-version apps, so having one in example is no harm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change made.

</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
<goal>native-image-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello from Quarkus REST";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.test.logging.FileLoggingHandler;
import io.quarkus.test.logging.Log;
import io.quarkus.test.services.quarkus.CliDevModeLocalhostQuarkusApplicationManagedResource;
import io.quarkus.test.services.quarkus.CliDevModeVersionLessQuarkusApplicationManagedResource;
import io.quarkus.test.services.quarkus.model.QuarkusProperties;
import io.quarkus.test.utils.FileUtils;
import io.quarkus.test.utils.ProcessBuilderProvider;
Expand Down Expand Up @@ -120,6 +121,21 @@ public QuarkusCliRestService createApplication(String name, CreateApplicationReq
return service;
}

public QuarkusCliRestService createApplicationFromExistingSources(String name, String targetFolderName, Path sourcesDir) {
Path serviceFolder = isNotEmpty(targetFolderName) ? TARGET.resolve(targetFolderName).resolve(name) : null;
QuarkusCliRestService service = new QuarkusCliRestService(this, serviceFolder);
ServiceContext serviceContext = service.register(name, context);

service.init(s -> new CliDevModeVersionLessQuarkusApplicationManagedResource(serviceContext, this));

// We need the service folder to be emptied before generating the project
FileUtils.deletePath(serviceContext.getServiceFolder());

FileUtils.copyDirectoryTo(sourcesDir, serviceContext.getServiceFolder());

return service;
}

public Result updateApplication(UpdateApplicationRequest request, Path serviceFolder) {
List<String> args = new ArrayList<>(List.of("update"));

Expand Down