🚧 Add pom hashes

This commit is contained in:
Andreas Dinauer 2026-04-14 20:13:45 +02:00
parent 1545a2c70d
commit aec2a3b194
4 changed files with 101 additions and 146 deletions

View File

@ -7,6 +7,7 @@ import dev.dinauer.maven.maven.token.TokenService;
import io.quarkus.security.identity.SecurityIdentity; import io.quarkus.security.identity.SecurityIdentity;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -37,6 +38,23 @@ public class PomService
return Response.status(Response.Status.CONFLICT).build(); return Response.status(Response.Status.CONFLICT).build();
} }
public Response findHash(MavenContext context)
{
Version version = versionService.findOptional(context.groupId(), context.artifactId(), context.version().getRaw()).orElseThrow();
switch (context.file().getHash())
{
case SHA1 ->
{
return Response.status(Response.Status.OK).type(MediaType.TEXT_PLAIN).entity(version.getPom().getSha1()).build();
}
case MD5 ->
{
return Response.status(Response.Status.OK).type(MediaType.TEXT_PLAIN).entity(version.getPom().getMd5()).build();
}
}
throw new BadRequestException();
}
public Response find(MavenContext mavenContext) public Response find(MavenContext mavenContext)
{ {
Version version = versionService.findOptional(mavenContext.groupId(), mavenContext.artifactId(), mavenContext.version().getRaw()).orElseThrow(); Version version = versionService.findOptional(mavenContext.groupId(), mavenContext.artifactId(), mavenContext.version().getRaw()).orElseThrow();

View File

@ -89,7 +89,7 @@ public class Service
{ {
return pomService.find(mavenContext); return pomService.find(mavenContext);
} }
throw new NotImplementedException(); return pomService.findHash(mavenContext);
} }
case XML -> case XML ->
{ {

View File

@ -1,147 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>dev.dinauer.maven</groupId> <groupId>org.postgresql</groupId>
<artifactId>demo</artifactId> <artifactId>postgresql</artifactId>
<version>1.0.3</version> <version>42.7.9</version>
<name>PostgreSQL JDBC Driver</name>
<properties> <description>PostgreSQL JDBC Driver Postgresql</description>
<compiler-plugin.version>3.14.1</compiler-plugin.version> <url>https://jdbc.postgresql.org</url>
<maven.compiler.release>21</maven.compiler.release> <inceptionYear>1997</inceptionYear>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <organization>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <name>PostgreSQL Global Development Group</name>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> <url>https://jdbc.postgresql.org/</url>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> </organization>
<quarkus.platform.version>3.30.8</quarkus.platform.version> <licenses>
<skipITs>true</skipITs> <license>
<surefire-plugin.version>3.5.4</surefire-plugin.version> <name>BSD-2-Clause</name>
</properties> <url>https://jdbc.postgresql.org/about/license.html</url>
<distribution>repo</distribution>
<distributionManagement> <comments>BSD-2-Clause, copyright PostgreSQL Global Development Group</comments>
<repository> </license>
<id>demo</id> </licenses>
<url>http://localhost:8080/maven2</url> <developers>
</repository> <developer>
</distributionManagement> <id>davecramer</id>
<name>Dave Cramer</name>
<dependencyManagement> </developer>
<dependencies> <developer>
<dependency> <id>jurka</id>
<groupId>${quarkus.platform.group-id}</groupId> <name>Kris Jurka</name>
<artifactId>${quarkus.platform.artifact-id}</artifactId> </developer>
<version>${quarkus.platform.version}</version> <developer>
<type>pom</type> <id>oliver</id>
<scope>import</scope> <name>Oliver Jowett</name>
</dependency> </developer>
</dependencies> <developer>
</dependencyManagement> <id>ringerc</id>
<name>Craig Ringer</name>
<dependencies> </developer>
<dependency> <developer>
<groupId>io.quarkus</groupId> <id>vlsi</id>
<artifactId>quarkus-arc</artifactId> <name>Vladimir Sitnikov</name>
</dependency> </developer>
<dependency> <developer>
<groupId>io.quarkus</groupId> <id>bokken</id>
<artifactId>quarkus-rest</artifactId> <name>Brett Okken</name>
</dependency> </developer>
<dependency> </developers>
<groupId>io.quarkus</groupId> <mailingLists>
<artifactId>quarkus-junit5</artifactId> <mailingList>
<scope>test</scope> <name>PostgreSQL JDBC development list</name>
</dependency> <subscribe>https://lists.postgresql.org/</subscribe>
<dependency> <unsubscribe>https://lists.postgresql.org/unsubscribe/</unsubscribe>
<groupId>io.rest-assured</groupId> <post>pgsql-jdbc@postgresql.org</post>
<artifactId>rest-assured</artifactId> <archive>https://www.postgresql.org/list/pgsql-jdbc/</archive>
<scope>test</scope> </mailingList>
</dependency> </mailingLists>
</dependencies> <scm>
<connection>scm:git:https://github.com/pgjdbc/pgjdbc.git</connection>
<build> <developerConnection>scm:git:https://github.com/pgjdbc/pgjdbc.git</developerConnection>
<plugins> <url>https://github.com/pgjdbc/pgjdbc</url>
<plugin> </scm>
<groupId>${quarkus.platform.group-id}</groupId> <issueManagement>
<artifactId>quarkus-maven-plugin</artifactId> <system>GitHub issues</system>
<version>${quarkus.platform.version}</version> <url>https://github.com/pgjdbc/pgjdbc/issues</url>
<extensions>true</extensions> </issueManagement>
<executions> <dependencies>
<execution> <dependency>
<goals> <groupId>org.checkerframework</groupId>
<goal>build</goal> <artifactId>checker-qual</artifactId>
<goal>generate-code</goal> <version>3.52.0</version>
<goal>generate-code-tests</goal> <scope>runtime</scope>
<goal>native-image-agent</goal> </dependency>
</goals> <dependency>
</execution> <groupId>com.github.waffle</groupId>
</executions> <artifactId>waffle-jna</artifactId>
</plugin> <version>1.9.1</version>
<plugin> <scope>runtime</scope>
<artifactId>maven-compiler-plugin</artifactId> <optional>true</optional>
<version>${compiler-plugin.version}</version> </dependency>
<configuration> </dependencies>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.jar.enabled>false</quarkus.package.jar.enabled>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
</profiles>
</project> </project>

View File

@ -37,12 +37,14 @@ public class ResourceTest
RestAssured.given().body(readFile("/jar/postgresql-42.7.9.pom")).put("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.pom"); RestAssured.given().body(readFile("/jar/postgresql-42.7.9.pom")).put("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.pom");
byte[] responseJar = RestAssured.given().get("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.jar").getBody().asByteArray(); byte[] responseJar = RestAssured.given().get("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.jar").getBody().asByteArray();
String responsePom = RestAssured.given().get("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.pom").getBody().asString(); String responsePom = RestAssured.given().get("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.pom").getBody().asString();
String responsePomMd5 = RestAssured.given().get("/maven2/org/postgresql/postgresql/42.7.9/postgresql-42.7.9.pom.md5").getBody().asString();
Optional<Version> version = versionService.findOptional("org.postgresql", "postgresql", "42.7.9"); Optional<Version> version = versionService.findOptional("org.postgresql", "postgresql", "42.7.9");
Assertions.assertTrue(version.isPresent()); Assertions.assertTrue(version.isPresent());
Assertions.assertTrue(responseJar.length > 0); Assertions.assertTrue(responseJar.length > 0);
Assertions.assertTrue(responsePom !=null && responsePom.startsWith("<?xml")); Assertions.assertTrue(responsePom !=null && responsePom.startsWith("<?xml"));
Assertions.assertEquals("a6b97b8d22c55f296040344dd75641b2", responsePomMd5);
} }
private InputStream readFile(String path) private InputStream readFile(String path)