Skip to content

Commit ac431a1

Browse files
committed
Fallback to the filename URL as specified in the module file, when the file is not available under its locally cached filename (fixes #3)
1 parent dd72076 commit ac431a1

File tree

5 files changed

+381
-9
lines changed

5 files changed

+381
-9
lines changed

plugin/src/main/java/io/github/jwharm/flatpakgradlegenerator/ArtifactResolver.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ Optional<byte[]> tryResolve(DependencyDetails dep,
118118
* @param id the id of the dependency
119119
* @param dep a DependencyDetail instance with the Maven coordinates of the artifact
120120
* @param repository the repository to try to download from
121-
* @param filename the filename of the artifact
121+
* @param fileUrl the remote filename of the artifact
122+
* @param checkName whether to verify if the cached file name matches fileUrl or fileName
123+
* @param fileName the local filename of the artifact (as specified in module file)
122124
*
123125
* @throws IOException error while reading the jar file
124126
* @throws NoSuchAlgorithmException no provider for the SHA-512 algorithm
@@ -127,9 +129,9 @@ void tryResolveCached(Set<ResolvedArtifact> artifacts,
127129
ModuleVersionIdentifier id,
128130
DependencyDetails dep,
129131
String repository,
130-
String filename,
132+
String fileUrl,
131133
boolean checkName,
132-
String altName)
134+
String fileName)
133135
throws IOException, NoSuchAlgorithmException, InterruptedException {
134136

135137
for (var artifact : artifacts) {
@@ -138,12 +140,12 @@ void tryResolveCached(Set<ResolvedArtifact> artifacts,
138140

139141
// Check against filenames in the .module file
140142
if (checkName)
141-
if (!(file.getName().equals(filename) ||
142-
file.getName().equals(altName)))
143+
if (!(file.getName().equals(fileUrl) ||
144+
file.getName().equals(fileName)))
143145
continue;
144146

145147
// Skip files that are already included in the output
146-
if (output.containsKey(dep.path() + "/" + (checkName ? filename : file.getName())))
148+
if (output.containsKey(dep.path() + "/" + (checkName ? fileUrl : file.getName())))
147149
continue;
148150

149151
// Build the url and check if it exists
@@ -153,12 +155,21 @@ void tryResolveCached(Set<ResolvedArtifact> artifacts,
153155
+ file.getName();
154156
var isValid = isValid(url);
155157

156-
if ((!isValid) && filename.contains("SNAPSHOT")) {
158+
// Try the filename from the .module
159+
if (!isValid) {
160+
url = repository
161+
+ dep.path()
162+
+ "/"
163+
+ fileUrl;
164+
isValid = isValid(url);
165+
}
166+
167+
if ((!isValid) && fileUrl.contains("SNAPSHOT")) {
157168
// Try again, but this time, replace SNAPSHOT with snapshot details
158169
url = repository
159170
+ dep.path()
160171
+ "/"
161-
+ filename.replace("SNAPSHOT", dep.snapshotDetail());
172+
+ fileUrl.replace("SNAPSHOT", dep.snapshotDetail());
162173
isValid = isValid(url);
163174
}
164175

@@ -175,7 +186,7 @@ void tryResolveCached(Set<ResolvedArtifact> artifacts,
175186
url,
176187
sha512,
177188
dep.path(),
178-
checkName ? filename : file.getName()
189+
checkName ? fileUrl : file.getName()
179190
);
180191
}
181192
}

plugin/src/test/java/io/github/jwharm/flatpakgradlegenerator/TestDependencyOutput.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void testLog4j() throws IOException {
8787
testDependencyOutput("log4j");
8888
}
8989

90+
@Test
91+
void testFilekitCore() throws IOException {
92+
testDependencyOutput("filekit-core");
93+
}
94+
9095
/**
9196
* Run the flatpakGradleGenerator task on a temporary Gradle build, and
9297
* compare the results with the expected output.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id 'io.github.jwharm.flatpak-gradle-generator'
3+
id 'java'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
implementation group: 'io.github.vinceglb',
12+
name: 'filekit-core-jvm',
13+
version: '0.8.3'
14+
}
15+
16+
tasks.flatpakGradleGenerator {
17+
outputFile = file('%s')
18+
}

0 commit comments

Comments
 (0)