diff --git a/devtools/gradle/gradle-extension-plugin/build.gradle b/devtools/gradle/gradle-extension-plugin/build.gradle index d29046312b702..76bd0d92c10dc 100644 --- a/devtools/gradle/gradle-extension-plugin/build.gradle +++ b/devtools/gradle/gradle-extension-plugin/build.gradle @@ -7,6 +7,7 @@ dependencies { implementation platform("io.quarkus:quarkus-bom:${version}") implementation project(":gradle-model") implementation "io.quarkus:quarkus-core-deployment" + implementation "io.quarkus:quarkus-devtools-common" implementation "io.quarkus:quarkus-bootstrap-gradle-resolver" implementation "com.fasterxml.jackson.core:jackson-databind" implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml" diff --git a/devtools/gradle/gradle-extension-plugin/pom.xml b/devtools/gradle/gradle-extension-plugin/pom.xml index e09fb76e89f81..167202ad095dd 100644 --- a/devtools/gradle/gradle-extension-plugin/pom.xml +++ b/devtools/gradle/gradle-extension-plugin/pom.xml @@ -42,6 +42,10 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml + + io.quarkus + quarkus-devtools-common + diff --git a/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTask.java b/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTask.java index 58da521e0706f..5b5b067b11b0d 100644 --- a/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTask.java +++ b/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTask.java @@ -7,7 +7,6 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -39,6 +38,7 @@ import io.quarkus.bootstrap.model.AppArtifactCoords; import io.quarkus.bootstrap.model.AppArtifactKey; import io.quarkus.bootstrap.model.ApplicationModelBuilder; +import io.quarkus.devtools.project.extensions.ScmInfoProvider; import io.quarkus.extension.gradle.QuarkusExtensionConfiguration; import io.quarkus.extension.gradle.dsl.Capability; import io.quarkus.extension.gradle.dsl.RemovedResource; @@ -311,7 +311,7 @@ private void computeArtifactCoords(ObjectNode extObject) { } private void computeSourceLocation(ObjectNode extObject) { - Map repo = getSourceRepo(); + Map repo = ScmInfoProvider.getSourceRepo(); if (repo != null) { ObjectNode scm = extObject.putObject("scm"); for (Map.Entry e : repo.entrySet()) { @@ -321,22 +321,6 @@ private void computeSourceLocation(ObjectNode extObject) { } } - static Map getSourceRepo() { - // We could try and parse the .git/config file, but that will be fragile - // Let's assume we only care about the repo for official-ish builds produced via github actions - String repo = System.getenv("GITHUB_REPOSITORY"); - if (repo != null) { - Map info = new HashMap(); - String qualifiedRepo = "https://github.com/" + repo; - // Don't try and guess where slashes will be, just deal with any double slashes by brute force - qualifiedRepo = qualifiedRepo.replace("github.com//", "github.com/"); - - info.put("url", qualifiedRepo); - return info; - } - return null; - } - private void computeQuarkusCoreVersion(ObjectNode extObject) { String coreVersion = getQuarkusCoreVersionOrNull(); if (coreVersion != null) { diff --git a/devtools/gradle/gradle-extension-plugin/src/test/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTaskTest.java b/devtools/gradle/gradle-extension-plugin/src/test/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTaskTest.java index 00b83ca50efe4..c4d8acf9b22da 100644 --- a/devtools/gradle/gradle-extension-plugin/src/test/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTaskTest.java +++ b/devtools/gradle/gradle-extension-plugin/src/test/java/io/quarkus/extension/gradle/tasks/ExtensionDescriptorTaskTest.java @@ -187,7 +187,7 @@ public void shouldGenerateDescriptorWithCapabilities() throws IOException { * that is increasingly hard to do on Java 17+; see https://github.com/junit-pioneer/junit-pioneer/issues/509 */ @Test - public void shouldGenerateSourcePointer() throws IOException { + public void shouldGenerateScmInformation() throws IOException { TestUtils.writeFile(buildFile, TestUtils.getDefaultGradleBuildFileContent(true, Collections.emptyList(), "")); File metaInfDir = new File(testProjectDir, "src/main/resources/META-INF"); metaInfDir.mkdirs(); diff --git a/independent-projects/extension-maven-plugin/pom.xml b/independent-projects/extension-maven-plugin/pom.xml index c5f5e7c45a98d..172741fdf7cb8 100644 --- a/independent-projects/extension-maven-plugin/pom.xml +++ b/independent-projects/extension-maven-plugin/pom.xml @@ -239,6 +239,17 @@ io.quarkus quarkus-bootstrap-maven-resolver + + io.quarkus + quarkus-devtools-common + ${project.version} + + + io.quarkus + quarkus-devtools-codestarts + + + org.apache.maven maven-plugin-api diff --git a/independent-projects/extension-maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java b/independent-projects/extension-maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java index 9a16b296c42f6..79c7599a78fe2 100644 --- a/independent-projects/extension-maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java +++ b/independent-projects/extension-maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java @@ -68,6 +68,7 @@ import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject; import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace; import io.quarkus.bootstrap.util.DependencyUtils; +import io.quarkus.devtools.project.extensions.ScmInfoProvider; import io.quarkus.fs.util.ZipUtils; import io.quarkus.maven.capabilities.CapabilitiesConfig; import io.quarkus.maven.capabilities.CapabilityConfig; @@ -574,22 +575,6 @@ static String getCodestartArtifact(String originalArtifact, String projectVersio return originalArtifact.replace("${project.version}", projectVersion); } - static Map getSourceRepo() { - // We could try and parse the .git/config file, but that will be fragile - // Let's assume we only care about the repo for official-ish builds produced via github actions - String repo = System.getenv("GITHUB_REPOSITORY"); - if (repo != null) { - Map info = new HashMap(); - String qualifiedRepo = "https://github.com/" + repo; - // Don't try and guess where slashes will be, just deal with any double slashes by brute force - qualifiedRepo = qualifiedRepo.replace("github.com//", "github.com/"); - - info.put("url", qualifiedRepo); - return info; - } - return null; - } - private static JsonNode getJsonElement(ObjectNode extObject, String... elements) { JsonNode mvalue = extObject.get(elements[0]); int i = 1; @@ -689,7 +674,7 @@ public boolean visitLeave(DependencyNode node) { } private void addSource(ObjectNode extObject) throws MojoExecutionException { - Map repo = getSourceRepo(); + Map repo = ScmInfoProvider.getSourceRepo(); if (repo != null) { ObjectNode scm = extObject.putObject("scm"); for (Map.Entry e : repo.entrySet()) { diff --git a/independent-projects/extension-maven-plugin/src/test/java/io/quarkus/maven/ExtensionDescriptorMojoTest.java b/independent-projects/extension-maven-plugin/src/test/java/io/quarkus/maven/ExtensionDescriptorMojoTest.java index 6494a5db21883..4d2b39a424d52 100644 --- a/independent-projects/extension-maven-plugin/src/test/java/io/quarkus/maven/ExtensionDescriptorMojoTest.java +++ b/independent-projects/extension-maven-plugin/src/test/java/io/quarkus/maven/ExtensionDescriptorMojoTest.java @@ -1,7 +1,6 @@ package io.quarkus.maven; import static io.quarkus.maven.ExtensionDescriptorMojo.getCodestartArtifact; -import static io.quarkus.maven.ExtensionDescriptorMojo.getSourceRepo; import java.io.File; import java.io.IOException; @@ -9,7 +8,6 @@ import java.nio.file.Path; import java.util.Collections; import java.util.Comparator; -import java.util.Map; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; @@ -104,7 +102,6 @@ public void shouldCreateMetadata() // Lazily test that the scm is there but is an object assertYamlContainsObject(fileContents, "scm"); assertYamlContains(fileContents, "url", "https://github.com/some/repo"); - } } @@ -206,18 +203,6 @@ public void testGetCodestartArtifact() { getCodestartArtifact("io.quarkus:my-ext:${project.version}", "999-SN")); } - @Test - void testGetSourceControlCoordinates() { - // From maven this property should be set, running in an IDE it won't be unless specially configured - if (System.getenv("GITHUB_REPOSITORY") != null) { - Map repo = getSourceRepo(); - assertNotNull(repo); - assertTrue(repo.get("url").toString().matches("https://github.com/some/repo")); - } else { - assertNull(getSourceRepo()); - } - } - private ExtensionDescriptorMojo makeMojo(String dirName) throws Exception { File basedir = getTestFile(TEST_RESOURCES + dirName); File pom = new File(basedir, "pom.xml"); diff --git a/independent-projects/tools/devtools-common/pom.xml b/independent-projects/tools/devtools-common/pom.xml index 32a939793de66..974af9b668fd1 100644 --- a/independent-projects/tools/devtools-common/pom.xml +++ b/independent-projects/tools/devtools-common/pom.xml @@ -125,6 +125,12 @@ assertj-core test + + uk.org.webcompere + system-stubs-jupiter + test + 2.0.1 + diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/extensions/ScmInfoProvider.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/extensions/ScmInfoProvider.java new file mode 100644 index 0000000000000..ba53f037a5e54 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/extensions/ScmInfoProvider.java @@ -0,0 +1,24 @@ +package io.quarkus.devtools.project.extensions; + +import java.util.HashMap; +import java.util.Map; + +public class ScmInfoProvider { + + public static Map getSourceRepo() { + // We could try and parse the .git/config file, but that will be fragile + // Let's assume we only care about the repo for official-ish builds produced via github actions + String repo = System.getenv("GITHUB_REPOSITORY"); + if (repo != null) { + Map info = new HashMap(); + String qualifiedRepo = "https://github.com/" + repo; + // Don't try and guess where slashes will be, just deal with any double slashes by brute force + qualifiedRepo = qualifiedRepo.replace("github.com//", "github.com/"); + + info.put("url", qualifiedRepo); + return info; + } + return null; + } + +} diff --git a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/extensions/ScmInfoProviderTest.java b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/extensions/ScmInfoProviderTest.java new file mode 100644 index 0000000000000..0e1ae7d2d07b7 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/devtools/project/extensions/ScmInfoProviderTest.java @@ -0,0 +1,44 @@ +package io.quarkus.devtools.project.extensions; + +import static io.quarkus.devtools.project.extensions.ScmInfoProvider.getSourceRepo; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; + +@ExtendWith(SystemStubsExtension.class) +public class ScmInfoProviderTest { + + @SystemStub + private EnvironmentVariables environment; + + @BeforeEach + public void setUp() { + environment.set("GITHUB_REPOSITORY", null); + } + + @Test + public void shouldReturnNullWhenNoEnvironmentOrBuildConfigIsPresent() { + Map scm = getSourceRepo(); + // We shouldn't throw an exception or get upset, we should just quietly return null + assertNull(scm); + } + + @Test + void testGetSourceControlCoordinates() { + String repoName = "org/place"; + environment.set("GITHUB_REPOSITORY", repoName); + Map repo = getSourceRepo(); + assertNotNull(repo); + assertEquals(repo.get("url").toString(), "https://github.com/org/place"); + } +}