Skip to content

Commit

Permalink
Introduce welcome page in /maven (#266)
Browse files Browse the repository at this point in the history
* Introduce welcome page in /maven

* Reworded as suggested by Alexey

* Reworded again

* Apply suggestions from code review

Co-authored-by: Alexey Loubyansky <[email protected]>

---------

Co-authored-by: Alexey Loubyansky <[email protected]>
  • Loading branch information
gastaldi and aloubyansky authored Nov 5, 2024
1 parent 89262f0 commit 9dba954
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/main/java/io/quarkus/registry/app/maven/MavenResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.jboss.logging.Logger;

import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.registry.app.model.PlatformRelease;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.PathSegment;
Expand Down Expand Up @@ -55,6 +57,33 @@ private ArtifactContentProvider[] getContentProviders() {
};
}

@GET
@Path("/")
@Produces("text/html")
@Operation(hidden = true)
public Response welcomePage(@Context MavenConfig mavenConfig) {
return Response.ok(String.format("""
<!DOCTYPE html>
<head>
<title>Quarkus Registry Maven Repository</title>
</head>
<h1>Welcome to the Quarkus Registry Maven Repository</h1>
This endpoint provides <a href="https://quarkus.io/guides/platform">Quarkus platform</a> and <a href="https://quarkus.io/guides/extension-metadata">extension metadata</a> in the form of Maven artifacts for <a href="https://quarkus.io/guides/extension-registry-user">Quarkus Registry clients</a>.
It provides the following artifacts:
<ul>
<li><a href="%1$s/%2$s/quarkus-platforms/1.0-SNAPSHOT/quarkus-platforms-1.0-SNAPSHOT.json">Platforms</a></li>
<li><a href="%1$s/%2$s/quarkus-non-platform-extensions/1.0-SNAPSHOT/quarkus-non-platform-extensions-1.0-SNAPSHOT-%3$s.json">Non-platform extensions</a></li>
<li><a href="%1$s/%2$s/quarkus-registry-descriptor/1.0-SNAPSHOT/quarkus-registry-descriptor-1.0-SNAPSHOT.json">Registry Descriptor</a></li>
</ul>
If you use a Nexus Repository Manager and are looking for a way to configure it to use this repository, please refer to the <a href="https://quarkus.io/guides/extension-registry-user#how-to-register-as-a-nexus-repository-proxy">How to register as a Nexus Repository proxy guide</a>.
""",mavenConfig.getRegistryUrl(),
mavenConfig.getRegistryGroupId().replace(".", "/"),
PlatformRelease.findLatestQuarkusCore()
)
).build();
}

@GET
@Path("{path:.+}")
@Operation(hidden = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@NamedQuery(name = "PlatformRelease.findQuarkusCores", query = """
select pr.version from PlatformRelease pr
where pr.platformStream.platform.isDefault = true
order by pr.versionSortable
order by pr.versionSortable desc
"""),
@NamedQuery(name = "PlatformRelease.findLatestByQuarkusCoreVersion", query = """
select pr from PlatformRelease pr
Expand Down Expand Up @@ -241,6 +241,14 @@ public static List<String> findQuarkusCores() {
.getResultList();
}

public static String findLatestQuarkusCore() {
return getEntityManager().createNamedQuery("PlatformRelease.findQuarkusCores", String.class)
.setMaxResults(1)
.getResultStream()
.findFirst().orElse(null);
}


public static boolean artifactCoordinatesExist(ArtifactCoords artifact) {
return count("#PlatformRelease.countArtifactCoordinates",
with("groupId", artifact.getGroupId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.net.HttpURLConnection;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;

import io.quarkus.registry.app.BaseTest;
Expand All @@ -20,6 +22,7 @@
import jakarta.ws.rs.core.MediaType;

@QuarkusTest
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
public class MavenResourceTest extends BaseTest {

@BeforeEach
Expand Down Expand Up @@ -170,4 +173,13 @@ void should_return_not_found_to_sha1_if_snapshot_version_is_invalid() {
.then()
.statusCode(HttpURLConnection.HTTP_NOT_FOUND);
}

@Test
void should_display_welcome_page() {
given()
.get("/maven")
.then()
.statusCode(HttpURLConnection.HTTP_OK);
}

}

0 comments on commit 9dba954

Please sign in to comment.