Skip to content

Commit

Permalink
Add support for partial-build-extension to extract version from pom.xml
Browse files Browse the repository at this point in the history
Closes gh-11
  • Loading branch information
rwinch committed Jun 28, 2023
1 parent b9f7b8d commit 1271e28
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ version::
The documentation version that corresponds to the refname.
This information is used to determine if the version provided by the refname is present in the site manifest.
May be provided by the `BUILD_VERSION` environment variable.
If not specified, the version will be retrieved from the [.path]_gradle.properties_ file at the root of the repository at the specified refname.
If not specified, the version will be retrieved from the [.path]_gradle.properties_ or [.path]_pom.xml_ file at the root of the repository at the specified refname.
Ideally, this option should be set by the workflow that invokes the partial build.

rawgit_url (default: {esc-https}://raw.githubusercontent.com)::
Expand Down
21 changes: 20 additions & 1 deletion lib/partial-build-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('node:fs')
const { promises: fsp } = fs
const ospath = require('node:path')
const { XMLParser } = require('fast-xml-parser')

const ExtractRepositoryPathRx = /^(?:\w+@.+?:|\w+:\/\/.+?\/)(.+?)(?:\.git)?$/

Expand All @@ -23,7 +24,14 @@ module.exports.register = function ({ config = {} }) {
const { rawgitUrl = 'https://raw.githubusercontent.com' } = config
const repositoryPath = await getRepositoryPath(this.require('isomorphic-git'), playbook.dir)
const baseUrl = `${rawgitUrl}/${repositoryPath}/${refname}`
version = await getGradleVersion(get, baseUrl, refname)
version = await getMavenVersion(get, baseUrl, refname).catch((me) =>
getGradleVersion(get, baseUrl, refname).catch((ge) => {
throw new Error(
`Could not obtain the version from a pom.xml (Error: ${me}) or gradle.properties (Error: ${ge})`,
{ cause: { maven: me, gradle: ge } }
)
})
)
}
if (isBranch && version.endsWith('-SNAPSHOT')) version = version.slice(0, -9)
const versionsInManifest = Object.values(siteManifestData.components)[0].versions
Expand Down Expand Up @@ -64,6 +72,17 @@ function extractGradleVersion (contents, fallback) {
}
}

function getMavenVersion (get, baseUrl, refname) {
const pomUrl = `${baseUrl}/pom.xml`
return download(get, pomUrl).then((contents) => extractMavenVersion(contents, refname))
}

function extractMavenVersion (contents, fallback) {
const parser = new XMLParser()
const jObj = parser.parse(contents)
return jObj.project.version
}

function getRepositoryPath (git, dir) {
return resolveGitdir(git, dir).then((gitdir) =>
git
Expand Down
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@antora/expand-path-helper": "~2.0",
"archiver": "^5.3.1",
"decompress": "4.2.1",
"fast-xml-parser": "latest",
"handlebars": "latest"
},
"devDependencies": {
Expand Down
250 changes: 250 additions & 0 deletions test/fixtures/org/repo/3.2.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.2.0</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
<description>Parent module for Spring Data JPA repositories.</description>
<url>https://spring.io/projects/spring-data-jpa</url>
<scm>
<connection>scm:git:git://github.com:spring-projects/spring-data-jpa.git</connection>
<developerConnection>scm:git:[email protected]:spring-projects/spring-data-jpa.git</developerConnection>
<url>https://github.com/spring-projects/spring-data-jpa</url>
</scm>
<issueManagement>
<url>https://github.com/spring-projects/spring-data-jpa/issues</url>
</issueManagement>

<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<properties>
<antlr>4.10.1</antlr> <!-- align with Hibernate's parser -->
<eclipselink>3.0.3</eclipselink>
<hibernate>6.2.4.Final</hibernate>
<hsqldb>2.7.1</hsqldb>
<h2>2.1.214</h2>
<jsqlparser>4.5</jsqlparser>
<mysql-connector-java>8.0.31</mysql-connector-java>
<postgresql>42.5.0</postgresql>
<springdata.commons>3.2.0-SNAPSHOT</springdata.commons>
<vavr>0.10.3</vavr>

<hibernate.groupId>org.hibernate</hibernate.groupId>

<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>

<!-- Antora -->
<node.version>v18.12.1</node.version>
<npm.version>8.19.2</npm.version>
<antora.version>3.2.0-alpha.2</antora.version>
<antora-atlas.version>1.0.0-alpha.1</antora-atlas.version>
<antora-collector.version>1.0.0-alpha.3</antora-collector.version>
<asciidoctor-tabs.version>1.0.0-beta.3</asciidoctor-tabs.version>
<spring-antora-extensions.version>1.4.0</spring-antora-extensions.version>
<spring-asciidoctor-extensions.version>1.0.0-alpha.9</spring-asciidoctor-extensions.version>

</properties>

<modules>
<module>spring-data-envers</module>
<module>spring-data-jpa</module>
<module>spring-data-jpa-distribution</module>
</modules>


<profiles>
<profile>
<id>hibernate-61</id>
<properties>
<hibernate>6.1.7.Final</hibernate>
</properties>
</profile>
<profile>
<id>all-dbs</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>mysql-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/MySql*IntegrationTests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>postgres-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/Postgres*IntegrationTests.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>eclipselink-next</id>
<properties>
<eclipselink>4.0.0</eclipselink>
</properties>
</profile>

</profiles>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<!-- override the default-test execution and exclude everything -->
<id>default-test</id>
<configuration>
<excludes>
<exclude>**/*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>unit-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<includes>
<include>**/*UnitTests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*UnitTests.java</exclude>
<exclude>**/OpenJpa*</exclude>
<exclude>**/EclipseLink*</exclude>
<exclude>**/MySql*</exclude>
<exclude>**/Postgres*</exclude>
</excludes>
<argLine>
-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring}/spring-instrument-${spring}.jar
</argLine>
</configuration>
</execution>
<execution>
<id>eclipselink-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<includes>
<include>**/EclipseLink*Tests.java</include>
</includes>
<argLine>
-javaagent:${settings.localRepository}/org/eclipse/persistence/org.eclipse.persistence.jpa/${eclipselink}/org.eclipse.persistence.jpa-${eclipselink}.jar
-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring}/spring-instrument-${spring}.jar
</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>spring-snapshot</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>

</project>
10 changes: 10 additions & 0 deletions test/fixtures/site-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
"title": "Start Page"
}
]
},
"3.2.0": {
"url": "/index.html",
"pages": [
{
"path": "index.adoc",
"url": "/index.html",
"title": "Start Page"
}
]
}
}
}
Expand Down
Loading

0 comments on commit 1271e28

Please sign in to comment.