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

Support codestarts of extensions outside catalog #24949

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Integer call() throws Exception {
setCodegenOptions(codeGeneration);

QuarkusCommandInvocation invocation = build(buildTool, targetQuarkusVersion,
propertiesOptions.properties);
propertiesOptions.properties, extensions);

boolean success = true;

Expand Down
2 changes: 1 addition & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Integer call() throws Exception {
setCodegenOptions(codeGeneration);

QuarkusCommandInvocation invocation = build(buildTool, targetQuarkusVersion,
propertiesOptions.properties);
propertiesOptions.properties, extensions);

boolean success = true;
if (runMode.isDryRun()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.cli.create;

import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -197,18 +198,17 @@ private void setValue(String name, Object value) {
* @param buildTool The build tool the project should use (maven, gradle, jbang)
* @param targetVersion The target quarkus version
* @param properties Additional properties that should be used whiel creating the properties
* @param extensions requested extensions
* @return Quarkus command invocation that can be printed (dry-run) or run to create the project
* @throws RegistryResolutionException
*/
public QuarkusCommandInvocation build(BuildTool buildTool, TargetQuarkusVersionGroup targetVersion,
Map<String, String> properties)
Map<String, String> properties, Collection<String> extensions)
throws RegistryResolutionException {

CreateProjectHelper.handleSpringConfiguration(values);
output.debug("Creating an app using the following settings: %s", values);

QuarkusProject qp = registryClient.createQuarkusProject(projectRoot(), targetVersion, buildTool, output);

// TODO: knock on effect with properties.. here?
properties.entrySet().forEach(x -> {
if (x.getValue().length() > 0) {
Expand All @@ -219,6 +219,9 @@ public QuarkusCommandInvocation build(BuildTool buildTool, TargetQuarkusVersionG
output.info("property: %s", x.getKey());
}
});

QuarkusProject qp = registryClient.createQuarkusProject(projectRoot(), targetVersion, buildTool, output, extensions);

return new QuarkusCommandInvocation(qp, values);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package io.quarkus.cli.registry;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.List;

import io.quarkus.cli.Version;
import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.codegen.CreateProjectHelper;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.platform.tools.ToolsUtils;
Expand Down Expand Up @@ -44,16 +46,22 @@ public String getConfigArg() {
public RegistriesConfig resolveConfig() throws RegistryResolutionException {
return config == null
? RegistriesConfig.resolveConfig()
: RegistriesConfig.resolveFromFile(Paths.get(config));
: RegistriesConfig.resolveFromFile(Path.of(config));
}

public QuarkusProject createQuarkusProject(Path projectRoot, TargetQuarkusVersionGroup targetVersion, BuildTool buildTool,
OutputOptionMixin log) throws RegistryResolutionException {
return createQuarkusProject(projectRoot, targetVersion, buildTool, log, List.of());
}

public QuarkusProject createQuarkusProject(Path projectRoot, TargetQuarkusVersionGroup targetVersion, BuildTool buildTool,
OutputOptionMixin log, Collection<String> extensions) throws RegistryResolutionException {
ExtensionCatalog catalog = getExtensionCatalog(targetVersion, log);
if (VALIDATE && catalog.getQuarkusCoreVersion().startsWith("1.")) {
throw new UnsupportedOperationException("The version 2 CLI can not be used with Quarkus 1.x projects.\n"
+ "Use the maven/gradle plugins when working with Quarkus 1.x projects.");
}
catalog = CreateProjectHelper.completeCatalog(catalog, extensions, QuarkusProjectHelper.artifactResolver());
return QuarkusProjectHelper.getProject(projectRoot, catalog, buildTool, log);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,24 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;

import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Repository;
import org.apache.maven.settings.RepositoryPolicy;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.DefaultSettingsReader;
import org.apache.maven.settings.io.DefaultSettingsWriter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.testing.registry.client.TestRegistryClientBuilder;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.GACTV;
import io.quarkus.registry.config.RegistriesConfigLocator;
import picocli.CommandLine;

public class MavenProjectInfoAndUpdateTest {

private static Path workDir;
private static Path settingsXml;
private static Path testRepo;
private static String prevConfigPath;
private static String prevRegistryClient;
public class MavenProjectInfoAndUpdateTest extends RegistryClientBuilderTestBase {

@BeforeAll
static void setup() throws Exception {
workDir = Path.of(System.getProperty("user.dir")).resolve("target").resolve("test-work-dir");
final Path registryConfigDir = workDir.resolve("registry");

final BootstrapMavenContext mavenContext = new BootstrapMavenContext(
BootstrapMavenContext.config().setWorkspaceDiscovery(false));

static void configureRegistryAndMavenRepo() {
TestRegistryClientBuilder.newInstance()
.baseDir(registryConfigDir)
.baseDir(registryConfigDir())
.newRegistry("registry.acme.org")
.newPlatform("org.acme.quarkus.platform")
.newStream("2.0")
Expand All @@ -73,142 +45,67 @@ static void setup() throws Exception {
.registry()
.clientBuilder()
.build();

prevConfigPath = System.setProperty(RegistriesConfigLocator.CONFIG_FILE_PATH_PROPERTY,
registryConfigDir.resolve("config.yaml").toString());
prevRegistryClient = System.setProperty("quarkusRegistryClient", "true");
QuarkusProjectHelper.reset();

final Settings settings = getBaseMavenSettings(mavenContext.getUserSettings().toPath());

Profile profile = new Profile();
settings.addActiveProfile("qs-test-registry");
profile.setId("qs-test-registry");

Repository repo = configureRepo("original-local",
Path.of(mavenContext.getLocalRepo()).toUri().toURL().toExternalForm());
profile.addRepository(repo);
profile.addPluginRepository(repo);

settings.addProfile(profile);
repo = configureRepo("qs-test-registry",
TestRegistryClientBuilder.getMavenRepoDir(registryConfigDir).toUri().toURL().toExternalForm());
profile.addRepository(repo);
profile.addPluginRepository(repo);

settingsXml = workDir.resolve("settings.xml");
try (BufferedWriter writer = Files.newBufferedWriter(settingsXml)) {
new DefaultSettingsWriter().write(writer, Collections.emptyMap(), settings);
}
testRepo = registryConfigDir.resolve("test-repo");
}

private static Repository configureRepo(String id, String url)
throws MalformedURLException, BootstrapMavenException {
final Repository repo = new Repository();
repo.setId(id);
repo.setLayout("default");
repo.setUrl(url);
RepositoryPolicy policy = new RepositoryPolicy();
policy.setEnabled(true);
policy.setChecksumPolicy("ignore");
policy.setUpdatePolicy("never");
repo.setReleases(policy);
repo.setSnapshots(policy);
return repo;
}

private static String getCurrentQuarkusVersion() {
String v = System.getProperty("project.version");
if (v == null) {
throw new IllegalStateException("project.version property isn't available");
}
return v;
}

private static Settings getBaseMavenSettings(Path mavenSettings) throws IOException {
if (Files.exists(mavenSettings)) {
try (BufferedReader reader = Files.newBufferedReader(mavenSettings)) {
return new DefaultSettingsReader().read(reader, Collections.emptyMap());
}
}
return new Settings();
}

private static void resetProperty(String name, String value) {
if (value == null) {
System.clearProperty(name);
} else {
System.setProperty(name, value);
}
}

@AfterAll
static void cleanup() throws Exception {
//CliDriver.deleteDir(workDir);
resetProperty(RegistriesConfigLocator.CONFIG_FILE_PATH_PROPERTY, prevConfigPath);
resetProperty("quarkusRegistryClient", prevRegistryClient);
}

@Test
void testClean() throws Exception {

final CliDriver.Result createResult = execute(workDir, "create", "acme-clean",
final CliDriver.Result createResult = run(workDir(), "create", "acme-clean",
"-x supersonic,acme-quarkiverse-extension");
assertThat(createResult.exitCode).isEqualTo(CommandLine.ExitCode.OK)
.as(() -> "Expected OK return code." + createResult);
assertThat(createResult.stdout).contains("SUCCESS")
.as(() -> "Expected confirmation that the project has been created." + createResult);

final Path projectDir = workDir.resolve("acme-clean");
final CliDriver.Result infoResult = execute(projectDir, "info");
final Path projectDir = workDir().resolve("acme-clean");
final CliDriver.Result infoResult = run(projectDir, "info");

assertQuarkusPlatformBoms(infoResult.stdout,
GACTV.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
GACTV.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"));
assertPlatformBomExtensions(infoResult.stdout, GACTV.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
GACTV.jar("io.quarkus", "quarkus-arc", null));
assertPlatformBomExtensions(infoResult.stdout, GACTV.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"),
GACTV.jar("org.acme.quarkus.platform", "acme-quarkus-supersonic", null));
ArtifactCoords.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
ArtifactCoords.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"));
assertPlatformBomExtensions(infoResult.stdout, ArtifactCoords.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
ArtifactCoords.jar("io.quarkus", "quarkus-arc", null));
assertPlatformBomExtensions(infoResult.stdout, ArtifactCoords.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"),
ArtifactCoords.jar("org.acme.quarkus.platform", "acme-quarkus-supersonic", null));
assertRegistryExtensions(infoResult.stdout, "registry.acme.org",
GACTV.jar("org.acme", "acme-quarkiverse-extension", "1.0"));
ArtifactCoords.jar("org.acme", "acme-quarkiverse-extension", "1.0"));

final CliDriver.Result updateResult = execute(projectDir, "update");
final CliDriver.Result updateResult = run(projectDir, "update");
assertThat(updateResult.stdout).contains("[INFO] The project is up-to-date");
}

@Test
void testMissalignedPlatformExtensionVersion() throws Exception {

final CliDriver.Result createResult = execute(workDir, "create", "acme-misaligned-ext-version",
final CliDriver.Result createResult = run(workDir(), "create", "acme-misaligned-ext-version",
"-x supersonic,acme-quarkiverse-extension,org.acme.quarkus.platform:acme-quarkus-subatomic:1.0.0");
assertThat(createResult.exitCode).isEqualTo(CommandLine.ExitCode.OK)
.as(() -> "Expected OK return code." + createResult);
assertThat(createResult.stdout).contains("SUCCESS")
.as(() -> "Expected confirmation that the project has been created." + createResult);

Path projectDir = workDir.resolve("acme-misaligned-ext-version");
final CliDriver.Result infoResult = execute(projectDir, "info");
Path projectDir = workDir().resolve("acme-misaligned-ext-version");
final CliDriver.Result infoResult = run(projectDir, "info");

assertQuarkusPlatformBoms(infoResult.stdout,
GACTV.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
GACTV.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"));
assertPlatformBomExtensions(infoResult.stdout, GACTV.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
GACTV.jar("io.quarkus", "quarkus-arc", null));
assertPlatformBomExtensions(infoResult.stdout, GACTV.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"),
GACTV.jar("org.acme.quarkus.platform", "acme-quarkus-supersonic", null),
GACTV.jar("org.acme.quarkus.platform", "acme-quarkus-subatomic", "1.0.0 | misaligned"));
ArtifactCoords.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
ArtifactCoords.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"));
assertPlatformBomExtensions(infoResult.stdout, ArtifactCoords.pom("org.acme.quarkus.platform", "quarkus-bom", "2.0.0"),
ArtifactCoords.jar("io.quarkus", "quarkus-arc", null));
assertPlatformBomExtensions(infoResult.stdout, ArtifactCoords.pom("org.acme.quarkus.platform", "acme-bom", "2.0.0"),
ArtifactCoords.jar("org.acme.quarkus.platform", "acme-quarkus-supersonic", null),
ArtifactCoords.jar("org.acme.quarkus.platform", "acme-quarkus-subatomic", "1.0.0 | misaligned"));
assertRegistryExtensions(infoResult.stdout, "registry.acme.org",
GACTV.jar("org.acme", "acme-quarkiverse-extension", "1.0"));
ArtifactCoords.jar("org.acme", "acme-quarkiverse-extension", "1.0"));

final CliDriver.Result rectifyResult = execute(projectDir, "update", "--rectify");
final CliDriver.Result rectifyResult = run(projectDir, "update", "--rectify");
assertThat(rectifyResult.stdout)
.contains("[INFO] Update: org.acme.quarkus.platform:acme-quarkus-subatomic:1.0.0 -> remove version (managed)");

final CliDriver.Result updateResult = execute(projectDir, "update", "-Dquarkus.platform.version=1.0.0");
final CliDriver.Result updateResult = run(projectDir, "update", "-Dquarkus.platform.version=1.0.0");
assertQuarkusPlatformBomUpdates(updateResult.stdout,
GACTV.pom("org.acme.quarkus.platform", "quarkus-bom", "1.0.0 -> 2.0.0"),
GACTV.pom("org.acme.quarkus.platform", "acme-bom", "1.0.0 -> 2.0.0"));
ArtifactCoords.pom("org.acme.quarkus.platform", "quarkus-bom", "1.0.0 -> 2.0.0"),
ArtifactCoords.pom("org.acme.quarkus.platform", "acme-bom", "1.0.0 -> 2.0.0"));
}

private static void assertPlatformBomExtensions(String output, ArtifactCoords bom, ArtifactCoords... extensions) {
Expand Down Expand Up @@ -298,13 +195,4 @@ private static void assertQuarkusPlatformBomUpdates(String output, ArtifactCoord
}
assertThat(output).contains(buf.getBuffer().toString());
}

private CliDriver.Result execute(Path dir, String... args) throws Exception {
return CliDriver.builder()
.setStartingDir(dir)
.setMavenRepoLocal(testRepo.toString())
.setMavenSettings(settingsXml.toString())
.addArgs(args)
.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.cli;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Path;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.quarkus.devtools.testing.registry.client.TestRegistryClientBuilder;
import picocli.CommandLine;

public class NotRegisteredExtensionWithCodestartTest extends RegistryClientBuilderTestBase {

@BeforeAll
static void configureRegistryAndMavenRepo() {
TestRegistryClientBuilder.newInstance()
.baseDir(registryConfigDir())
.newRegistry("registry.acme.org")
.newPlatform("org.acme.quarkus.platform")
.newStream("2.0")
.newRelease("2.0.0")
.quarkusVersion(getCurrentQuarkusVersion())
.addCoreMember()
.alignPluginsOnQuarkusVersion()
.addDefaultCodestartExtensions()
.registry()
.clientBuilder()
.addExternalExtensionWithCodestart("org.acme.quarkus", "acme-outlaw", "6.6.6")
.clientBuilder()
.build();
}

@Test
void test() throws Exception {
final CliDriver.Result createResult = run(workDir(), "create", "acme-outlaw-codestart",
"-x org.acme.quarkus:acme-outlaw:6.6.6");
assertThat(createResult.exitCode).isEqualTo(CommandLine.ExitCode.OK)
.as(() -> "Expected OK return code." + createResult);
assertThat(createResult.stdout).contains("SUCCESS")
.as(() -> "Expected confirmation that the project has been created." + createResult);

final Path acmeOutlawJava = workDir().resolve("acme-outlaw-codestart")
.resolve("src/main/java/org/acme/AcmeOutlaw.java");
assertThat(acmeOutlawJava).exists();
}
}
Loading