Skip to content

Commit

Permalink
Add RR change
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed May 16, 2024
1 parent 69d2433 commit 1d9313a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ public RecordFactory(RemoteRepositorySearchBackend backend) {
/**
* Creates {@link Record} on behalf of backend. Only {@code groupId} is mandatory, all the other values are optional (nullable).
*/
public Record create(String groupId, String artifactId, String version, String classifier, String fileExtension) {
public Record create(
String groupId,
String artifactId,
String version,
String classifier,
String fileExtension,
Long lastUpdated) {
requireNonNull(groupId);
HashMap<Field, Object> result = new HashMap<>();
mayPut(result, MAVEN.GROUP_ID, groupId);
mayPut(result, MAVEN.ARTIFACT_ID, artifactId);
mayPut(result, MAVEN.VERSION, version);
mayPut(result, MAVEN.CLASSIFIER, classifier);
mayPut(result, MAVEN.FILE_EXTENSION, fileExtension);
return new Record(backend.getBackendId(), backend.getRepositoryId(), null, null, result);
return new Record(backend.getBackendId(), backend.getRepositoryId(), null, lastUpdated, result);
}

private static void mayPut(Map<Field, Object> result, Field fieldName, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class MavenCentralResponseExtractor extends ResponseExtractorSupport {
/**
* Extracts the "name" from {@code href} attribute. In case of Maven Central, the href
* attribute contains name in realative form as {@code "name/"} (followed by slash), if name denotes
* attribute contains name in relative form as {@code "name/"} (followed by slash), if name denotes
* a directory. The trailing slash is removed by this method, if any.
*/
private String nameInHref(Element element) {
Expand All @@ -51,7 +51,7 @@ public int populateG(Context context, Document document, RecordFactory recordFac
for (Element element : contents.getElementsByTag("a")) {
String name = nameInHref(element);
if (accept(name)) {
page.add(recordFactory.create(context.getGroupId(), name, null, null, null));
page.add(recordFactory.create(context.getGroupId(), name, null, null, null, null));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int populateG(Context context, Document document, RecordFactory recordFac
for (Element element : elements) {
String name = name(element);
if (accept(name)) {
page.add(recordFactory.create(context.getGroupId(), name, null, null, null));
page.add(recordFactory.create(context.getGroupId(), name, null, null, null, null));
}
}
return page.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public int populateGA(Context context, Document document, RecordFactory recordFa
if (versions != null) {
for (Element version : versions.getElementsByTag("version")) {
page.add(recordFactory.create(
context.getGroupId(), context.getArtifactId(), version.text(), null, null));
context.getGroupId(), context.getArtifactId(), version.text(), null, null, null));
}
}
}
Expand Down Expand Up @@ -103,7 +103,12 @@ protected void populateGAVName(Context context, String name, RecordFactory recor
ext = name;
}
page.add(recordFactory.create(
context.getGroupId(), context.getArtifactId(), context.getVersion(), classifier, ext));
context.getGroupId(),
context.getArtifactId(),
context.getVersion(),
classifier,
ext,
null));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
Expand Down Expand Up @@ -188,12 +192,19 @@ public RemoteRepositorySearchResponse search(SearchRequest searchRequest) throws
}
}
if (matches) {
String lastModifiedHeader = response.getHeaders().get("last-modified");
Long lastModified = lastModifiedHeader == null
? null
: ZonedDateTime.parse(lastModifiedHeader, RFC7231)
.toInstant()
.toEpochMilli();
page.add(recordFactory.create(
context.getGroupId(),
context.getArtifactId(),
context.getVersion(),
context.getClassifier(),
context.getFileExtension()));
context.getFileExtension(),
lastModified));
totalHits = 1;
}
}
Expand All @@ -202,6 +213,10 @@ public RemoteRepositorySearchResponse search(SearchRequest searchRequest) throws
return new RemoteRepositorySearchResponseImpl(searchRequest, totalHits, page, uri, document);
}

private static final DateTimeFormatter RFC7231 = DateTimeFormatter.ofPattern(
"EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH)
.withZone(ZoneId.of("GMT"));

private static String readChecksum(InputStream inputStream) throws IOException {
String checksum = "";
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), 512)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
Expand Down Expand Up @@ -156,6 +157,21 @@ public void gav() throws IOException {
dumpPage(searchResponse);
}

@Test
public void gave() throws IOException {
// LIST GAVCEs
SearchRequest searchRequest = new SearchRequest(BooleanQuery.and(
FieldQuery.fieldQuery(MAVEN.GROUP_ID, "org.apache.maven.plugins"),
FieldQuery.fieldQuery(MAVEN.ARTIFACT_ID, "maven-clean-plugin"),
FieldQuery.fieldQuery(MAVEN.VERSION, "3.1.0"),
FieldQuery.fieldQuery(MAVEN.FILE_EXTENSION, "jar")));
RemoteRepositorySearchResponse searchResponse = backend.search(searchRequest);
assertEquals(1, searchResponse.getTotalHits());
assertNotNull(searchResponse.getPage().get(0).getLastUpdated());
System.out.println("TOTAL HITS: " + searchResponse.getTotalHits());
dumpPage(searchResponse);
}

@Test
public void gavWithTarGz() throws IOException {
// LIST GAVCEs
Expand Down

0 comments on commit 1d9313a

Please sign in to comment.