Skip to content

Commit bf3e9dc

Browse files
author
Gintas Grigelionis
committed
URL-based resolvers should accept query parameters in publish patterns
1 parent 95c076b commit bf3e9dc

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/java/org/apache/ivy/plugins/resolver/RepositoryResolver.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.ByteArrayInputStream;
2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.net.MalformedURLException;
24+
import java.net.URL;
2325
import java.text.ParseException;
2426
import java.util.ArrayList;
2527
import java.util.Arrays;
@@ -249,9 +251,9 @@ protected void putChecksum(Artifact artifact, File src, String dest, boolean ove
249251
try {
250252
FileUtil.copy(new ByteArrayInputStream(ChecksumHelper.computeAsString(src, algorithm)
251253
.getBytes()), csFile, null);
252-
repository.put(
253-
DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, algorithm, artifact.getExt()
254-
+ "." + algorithm), csFile, dest + "." + algorithm, overwrite);
254+
repository.put(DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, algorithm,
255+
artifact.getExt() + "." + algorithm), csFile,
256+
chopQuery(dest, algorithm), overwrite);
255257
} finally {
256258
csFile.delete();
257259
}
@@ -269,15 +271,30 @@ protected void putSignature(Artifact artifact, File src, String dest, boolean ov
269271

270272
try {
271273
gen.sign(src, tempFile);
272-
repository.put(
273-
DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, gen.getExtension(),
274+
repository.put(DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, gen.getExtension(),
274275
artifact.getExt() + "." + gen.getExtension()), tempFile,
275-
dest + "." + gen.getExtension(), overwrite);
276+
chopQuery(dest, gen.getExtension()), overwrite);
276277
} finally {
277278
tempFile.delete();
278279
}
279280
}
280281

282+
private String chopQuery(String dest, String algorithm) {
283+
if (!dest.contains("?")) {
284+
return dest + "." + algorithm;
285+
}
286+
try {
287+
URL url = new URL(dest);
288+
String query = url.getQuery();
289+
if (query == null ) {
290+
query = "";
291+
}
292+
return dest.replace("?" + query, "") + "." + algorithm;
293+
} catch (MalformedURLException e) {
294+
throw new IllegalArgumentException(e);
295+
}
296+
}
297+
281298
@Override
282299
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
283300
EventManager eventManager = getEventManager();

0 commit comments

Comments
 (0)