Skip to content

Commit 03636b1

Browse files
authored
Remove resource for better Quarkus support (#276)
2 parents 98a0a87 + 4d69ba5 commit 03636b1

5 files changed

Lines changed: 84 additions & 49 deletions

File tree

pom.xml

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<system.stubs.version>2.1.8</system.stubs.version>
7272

7373
<!-- Plugin version -->
74+
<build.helper-maven-plugin.version>3.6.0</build.helper-maven-plugin.version>
7475
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
7576
<spotless-maven-plugin.version>2.44.4</spotless-maven-plugin.version>
7677
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
@@ -254,15 +255,6 @@
254255
</dependencies>
255256

256257
<build>
257-
<resources>
258-
<resource>
259-
<filtering>true</filtering>
260-
<directory>src/main/resources</directory>
261-
<includes>
262-
<include>version.properties</include>
263-
</includes>
264-
</resource>
265-
</resources>
266258
<pluginManagement>
267259
<plugins>
268260
<plugin>
@@ -324,10 +316,50 @@
324316
<artifactId>maven-clean-plugin</artifactId>
325317
<version>${maven-clean-plugin.version}</version>
326318
</plugin>
319+
<plugin>
320+
<groupId>org.codehaus.mojo</groupId>
321+
<artifactId>build-helper-maven-plugin</artifactId>
322+
<version>${build.helper-maven-plugin.version}</version>
323+
<executions>
324+
<execution>
325+
<id>add-generated-sources</id>
326+
<goals>
327+
<goal>add-source</goal>
328+
</goals>
329+
<phase>generate-resources</phase>
330+
<configuration>
331+
<sources>
332+
<source>${project.build.directory}/generated-sources</source>
333+
</sources>
334+
</configuration>
335+
</execution>
336+
</executions>
337+
</plugin>
327338
<plugin>
328339
<groupId>org.apache.maven.plugins</groupId>
329340
<artifactId>maven-resources-plugin</artifactId>
330341
<version>${maven-resources-plugin.version}</version>
342+
<executions>
343+
<execution>
344+
<id>copy-const</id>
345+
<goals>
346+
<goal>copy-resources</goal>
347+
</goals>
348+
<phase>generate-sources</phase>
349+
<configuration>
350+
<outputDirectory>${project.build.directory}/generated-sources/land/oras/utils</outputDirectory>
351+
<resources>
352+
<resource>
353+
<directory>src/main/generated</directory>
354+
<filtering>true</filtering>
355+
<includes>
356+
<include>Versions.java</include>
357+
</includes>
358+
</resource>
359+
</resources>
360+
</configuration>
361+
</execution>
362+
</executions>
331363
</plugin>
332364
<plugin>
333365
<groupId>org.apache.maven.plugins</groupId>
@@ -556,6 +588,10 @@
556588
<groupId>org.apache.maven.plugins</groupId>
557589
<artifactId>maven-source-plugin</artifactId>
558590
</plugin>
591+
<plugin>
592+
<groupId>org.codehaus.mojo</groupId>
593+
<artifactId>build-helper-maven-plugin</artifactId>
594+
</plugin>
559595
</plugins>
560596

561597
</build>

src/main/generated/Versions.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*-
2+
* =LICENSE=
3+
* ORAS Java SDK
4+
* ===
5+
* Copyright (C) 2024 - 2025 ORAS
6+
* ===
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =LICENSEEND=
19+
*/
20+
21+
package land.oras.utils;
22+
23+
import java.time.Instant;
24+
import java.time.ZoneOffset;
25+
import java.time.format.DateTimeFormatter;
26+
import org.jspecify.annotations.NullMarked;
27+
28+
/**
29+
* SDK Version
30+
*/
31+
@NullMarked
32+
public final class Versions {
33+
/**
34+
* User agent value
35+
*/
36+
public static final String USER_AGENT_VALUE = "ORAS-Java-SDK/${project.version}";
37+
}

src/main/java/land/oras/auth/HttpClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import land.oras.exception.OrasException;
4545
import land.oras.utils.Const;
4646
import land.oras.utils.JsonUtils;
47+
import land.oras.utils.Versions;
4748
import org.jspecify.annotations.NullMarked;
4849
import org.jspecify.annotations.Nullable;
4950
import org.slf4j.Logger;
@@ -439,7 +440,7 @@ private <T> ResponseWrapper<T> executeRequest(
439440
headers.forEach(builder::header);
440441

441442
// Add user agent
442-
builder = builder.header(Const.USER_AGENT_HEADER, Const.USER_AGENT_VALUE);
443+
builder = builder.header(Const.USER_AGENT_HEADER, Versions.USER_AGENT_VALUE);
443444

444445
HttpRequest request = builder.build();
445446
logRequest(request, body);

src/main/java/land/oras/utils/Const.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020

2121
package land.oras.utils;
2222

23-
import java.io.IOException;
2423
import java.time.Instant;
2524
import java.time.ZoneOffset;
2625
import java.time.format.DateTimeFormatter;
27-
import java.util.Properties;
28-
import land.oras.exception.OrasException;
2926
import org.jspecify.annotations.NullMarked;
3027

3128
/**
@@ -41,16 +38,6 @@ private Const() {
4138
// Private constructor
4239
}
4340

44-
static {
45-
Properties properties = new Properties();
46-
try (var input = Const.class.getClassLoader().getResourceAsStream("version.properties")) {
47-
properties.load(input);
48-
} catch (IOException e) {
49-
throw new OrasException("Failed to load properties file", e);
50-
}
51-
USER_AGENT_VALUE = "ORAS-Java-SDK/%s".formatted(properties.getProperty("version"));
52-
}
53-
5441
/**
5542
* Default registry
5643
*/
@@ -193,11 +180,6 @@ public static String currentTimestamp() {
193180
*/
194181
public static final String USER_AGENT_HEADER = "User-Agent";
195182

196-
/**
197-
* User agent value
198-
*/
199-
public static final String USER_AGENT_VALUE;
200-
201183
/**
202184
* Content type header
203185
*/

src/main/resources/version.properties

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)