Skip to content

Commit b5451ef

Browse files
committed
Use fallbackRepository for Libby runtime deps
1 parent 34e3f75 commit b5451ef

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

core/src/main/java/com/alessiodp/libby/LibraryManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public Collection<String> resolveLibrary(@NotNull Library library) {
340340
* @param library the library to resolve repositories for
341341
* @return the resolved repositories
342342
*/
343-
protected Collection<String> resolveRepositories(@NotNull Library library) {
343+
public Collection<String> resolveRepositories(@NotNull Library library) {
344344
switch (getRepositoryResolutionMode()) {
345345
case GLOBAL_FIRST:
346346
return Stream.of(

core/src/main/java/com/alessiodp/libby/classloader/ClassLoaderHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected Instrumentation initInstrumentation(LibraryManager libraryManager) thr
304304
.artifactId("byte-buddy-agent")
305305
.version("1.12.1")
306306
.checksumFromBase64("mcCtBT9cljUEniB5ESpPDYZMfVxEs1JRPllOiWTP+bM=")
307-
.repository(Repositories.MAVEN_CENTRAL)
307+
.fallbackRepository(Repositories.MAVEN_CENTRAL)
308308
.build()
309309
));
310310

core/src/main/java/com/alessiodp/libby/configuration/ConfigurationFetcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public ConfigurationFetcher(@NotNull LibraryManager libraryManager) {
105105
.artifactId("nanojson")
106106
.version("1.8")
107107
.checksumFromBase64("qyhAVZM8LYvqhGQrbmW2aHV4hRzn+2flPCV98wAimJo=")
108-
.repository(Repositories.MAVEN_CENTRAL)
108+
.fallbackRepository(Repositories.MAVEN_CENTRAL)
109109
.build()
110110
));
111111

core/src/main/java/com/alessiodp/libby/relocation/RelocationHelper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public RelocationHelper(@NotNull LibraryManager libraryManager) {
6767
.artifactId("asm-commons")
6868
.version("9.2")
6969
.checksumFromBase64("vkzlMTiiOLtSLNeBz5Hzulzi9sqT7GLUahYqEnIl4KY=")
70-
.repository(Repositories.MAVEN_CENTRAL)
70+
.fallbackRepository(Repositories.MAVEN_CENTRAL)
7171
.build()
7272
));
7373

@@ -78,7 +78,7 @@ public RelocationHelper(@NotNull LibraryManager libraryManager) {
7878
.artifactId("asm")
7979
.version("9.2")
8080
.checksumFromBase64("udT+TXGTjfOIOfDspCqqpkz4sxPWeNoDbwyzyhmbR/U=")
81-
.repository(Repositories.MAVEN_CENTRAL)
81+
.fallbackRepository(Repositories.MAVEN_CENTRAL)
8282
.build()
8383
));
8484

@@ -89,7 +89,7 @@ public RelocationHelper(@NotNull LibraryManager libraryManager) {
8989
.artifactId("jar-relocator")
9090
.version("1.7")
9191
.checksumFromBase64("b30RhOF6kHiHl+O5suNLh/+eAr1iOFEFLXhwkHHDu4I=")
92-
.repository(Repositories.MAVEN_CENTRAL)
92+
.fallbackRepository(Repositories.MAVEN_CENTRAL)
9393
.build()
9494
));
9595

core/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyHelper.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public TransitiveDependencyHelper(@NotNull LibraryManager libraryManager, @NotNu
7979
.artifactId("libby-maven-resolver")
8080
.version("1.0.1")
8181
.checksumFromBase64("EmsSUwjtqSeYTt8WEw7LPI/5Yz8bWSxf23XcdLEM7dk=")
82-
.repository(Repositories.MAVEN_CENTRAL)
83-
.repository("https://repo.alessiodp.com/releases")
82+
.fallbackRepository(Repositories.MAVEN_CENTRAL)
83+
.fallbackRepository("https://repo.alessiodp.com/releases")
8484
.build()
8585
));
8686

@@ -134,11 +134,12 @@ public Collection<Library> findTransitiveLibraries(@NotNull Library library) {
134134

135135
Collection<String> globalRepositories = libraryManager.getRepositories();
136136
Collection<String> libraryRepositories = library.getRepositories();
137-
if (globalRepositories.isEmpty() && libraryRepositories.isEmpty()) {
137+
Collection<String> libraryFallbackRepositories = library.getFallbackRepositories();
138+
if (globalRepositories.isEmpty() && libraryRepositories.isEmpty() && libraryFallbackRepositories.isEmpty()) {
138139
throw new IllegalArgumentException("No repositories have been added before resolving transitive dependencies");
139140
}
140141

141-
Stream<String> repositories = Stream.of(globalRepositories, libraryRepositories).flatMap(Collection::stream);
142+
Stream<String> repositories = libraryManager.resolveRepositories(library).stream();
142143
try {
143144
Collection<?> resolvedArtifacts = (Collection<?>) resolveTransitiveDependenciesMethod.invoke(transitiveDependencyCollectorObject,
144145
library.getGroupId(),
@@ -186,7 +187,7 @@ public Collection<Library> findTransitiveLibraries(@NotNull Library library) {
186187
// TODO Uncomment the line below once LibraryManager#resolveLibrary stops resolving snapshots
187188
// for every repository before trying direct URLs
188189
// Make sure the repository is added as fallback if the dependency isn't found at the constructed URL
189-
// libraryBuilder.repository(repository);
190+
// libraryBuilder.fallbackRepository(repository);
190191

191192
// For snapshots, getVersion() returns version-timestamp-buildNumber instead of version-SNAPSHOT
192193
String version = (String) artifactGetVersionMethod.invoke(artifact);
@@ -197,6 +198,7 @@ public Collection<Library> findTransitiveLibraries(@NotNull Library library) {
197198
libraryBuilder.url(repository + path);
198199
} else {
199200
library.getRepositories().forEach(libraryBuilder::repository);
201+
library.getFallbackRepositories().forEach(libraryBuilder::fallbackRepository);
200202
}
201203

202204
transitiveLibraries.add(libraryBuilder.build());

0 commit comments

Comments
 (0)