@@ -28,9 +28,12 @@ subprojects {
|
|||||||
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
|
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
|
||||||
compileOnly("org.projectlombok:lombok:${lombokVersion}")
|
compileOnly("org.projectlombok:lombok:${lombokVersion}")
|
||||||
|
|
||||||
|
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
|
||||||
|
|
||||||
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
|
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
|
||||||
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
|
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
|
||||||
|
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
|
||||||
testImplementation("org.mockito:mockito-core:${mockitoCoreVersion}")
|
testImplementation("org.mockito:mockito-core:${mockitoCoreVersion}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.di9.mirror.core.domain;
|
||||||
|
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
|
public record ArtifactRecord(String group, String artifactId, String version, boolean isSnapshot) {
|
||||||
|
private static final String SNAPSHOT = "SNAPSHOT";
|
||||||
|
|
||||||
|
public static ArtifactRecord fromHttpPath(String httpPath) {
|
||||||
|
if (httpPath.startsWith("/")) {
|
||||||
|
httpPath = httpPath.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] partsPath = httpPath.split("/");
|
||||||
|
String version = partsPath[partsPath.length-2];
|
||||||
|
boolean isSnapshot = version.contains(SNAPSHOT);
|
||||||
|
|
||||||
|
String fileName = partsPath[partsPath.length-1];
|
||||||
|
|
||||||
|
String artifactId;
|
||||||
|
if (isSnapshot) {
|
||||||
|
String partVersion = version.substring(0, version.lastIndexOf(SNAPSHOT));
|
||||||
|
artifactId = fileName.substring(0, fileName.indexOf(partVersion) - 1);
|
||||||
|
} else {
|
||||||
|
artifactId = fileName.substring(0, (fileName.lastIndexOf('.') - version.length() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
StringJoiner sj = new StringJoiner(".");
|
||||||
|
for (int i = 0; i < partsPath.length - 3; i++) {
|
||||||
|
sj.add(partsPath[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArtifactRecord(sj.toString(), artifactId, version, isSnapshot);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package ru.di9.mirror.core.domain;
|
||||||
|
|
||||||
|
public record FileInfo(String fullName, String name, String ext) {
|
||||||
|
|
||||||
|
public static FileInfo of(String fileName) {
|
||||||
|
int idx = fileName.lastIndexOf('.');
|
||||||
|
return new FileInfo(
|
||||||
|
fileName,
|
||||||
|
fileName.substring(0, idx),
|
||||||
|
fileName.substring(idx + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package ru.di9.mirror.core.handler;
|
package ru.di9.mirror.core.handler;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import ru.di9.mirror.core.domain.ArtifactRecord;
|
||||||
|
import ru.di9.mirror.core.domain.FileInfo;
|
||||||
import ru.di9.mirror.core.handler.response.GetFileResponse;
|
import ru.di9.mirror.core.handler.response.GetFileResponse;
|
||||||
import ru.di9.mirror.core.service.ExternalMavenService;
|
import ru.di9.mirror.core.service.ExternalMavenService;
|
||||||
import ru.di9.mirror.core.service.MinioService;
|
import ru.di9.mirror.core.service.MinioService;
|
||||||
@@ -9,6 +12,7 @@ import java.io.InputStream;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class MavenHandler {
|
public class MavenHandler {
|
||||||
|
|
||||||
@@ -16,14 +20,21 @@ public class MavenHandler {
|
|||||||
private final List<ExternalMavenService> externalMavenServices;
|
private final List<ExternalMavenService> externalMavenServices;
|
||||||
|
|
||||||
public Optional<GetFileResponse> getFile(String path) {
|
public Optional<GetFileResponse> getFile(String path) {
|
||||||
final String fileName = path.substring(path.lastIndexOf("/") + 1);
|
var fileInfo = FileInfo.of(path.substring(path.lastIndexOf("/") + 1));
|
||||||
|
|
||||||
|
if (!fileInfo.fullName().equalsIgnoreCase("maven-metadata.xml")
|
||||||
|
|| !fileInfo.ext().equalsIgnoreCase("sha1")) {
|
||||||
|
|
||||||
|
ArtifactRecord artifactRecord = ArtifactRecord.fromHttpPath(path);
|
||||||
|
log.info(artifactRecord.toString());
|
||||||
|
}
|
||||||
|
|
||||||
Optional<InputStream> optionalInputStream = minioService.get("/local/" + path);
|
Optional<InputStream> optionalInputStream = minioService.get("/local/" + path);
|
||||||
if (optionalInputStream.isPresent()) {
|
if (optionalInputStream.isPresent()) {
|
||||||
return optionalInputStream
|
return optionalInputStream
|
||||||
.map(inputStream -> new GetFileResponse(fileName, inputStream));
|
.map(inputStream -> new GetFileResponse(fileInfo.name(), inputStream));
|
||||||
} else {
|
} else {
|
||||||
return findInMirrors(path, fileName);
|
return findInMirrors(path, fileInfo.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +61,15 @@ public class MavenHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void putFile(String path, InputStream inputStream) {
|
public void putFile(String path, InputStream inputStream) {
|
||||||
|
var fileInfo = FileInfo.of(path.substring(path.lastIndexOf("/") + 1));
|
||||||
|
|
||||||
|
if (!fileInfo.fullName().equalsIgnoreCase("maven-metadata.xml")
|
||||||
|
|| !fileInfo.ext().equalsIgnoreCase("sha1")) {
|
||||||
|
|
||||||
|
ArtifactRecord artifactRecord = ArtifactRecord.fromHttpPath(path);
|
||||||
|
log.info(artifactRecord.toString());
|
||||||
|
}
|
||||||
|
|
||||||
minioService.put("/local/" + path, inputStream);
|
minioService.put("/local/" + path, inputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package ru.di9.mirror.core.domain;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
class ArtifactRecordTest {
|
||||||
|
|
||||||
|
@ParameterizedTest(name = "[{index}] {0}")
|
||||||
|
@MethodSource("fromHttpPathSource")
|
||||||
|
void fromHttpPath(String httpPath, ArtifactRecord expected) {
|
||||||
|
ArtifactRecord actual = ArtifactRecord.fromHttpPath(httpPath);
|
||||||
|
Assertions.assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Stream<Arguments> fromHttpPathSource() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of("com/google/guava/guava/21.0/guava-21.0.jar",
|
||||||
|
new ArtifactRecord("com.google.guava", "guava", "21.0", false)),
|
||||||
|
Arguments.of("org/bukkit/bukkit/1.12.2-R0.1-SNAPSHOT/bukkit-1.12.2-R0.1-20180712.012114-155.jar",
|
||||||
|
new ArtifactRecord("org.bukkit", "bukkit", "1.12.2-R0.1-SNAPSHOT", true)),
|
||||||
|
Arguments.of("/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar",
|
||||||
|
new ArtifactRecord("org.projectlombok", "lombok", "1.18.22", false))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
ext {
|
ext {
|
||||||
lombokVersion = '1.18.20'
|
lombokVersion = '1.18.20'
|
||||||
|
slf4jVersion = '1.7.36'
|
||||||
minioVersion = '8.3.9'
|
minioVersion = '8.3.9'
|
||||||
springBootVerson = '2.6.6'
|
springBootVerson = '2.6.6'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user