recode
This commit is contained in:
24
web-spring/build.gradle
Normal file
24
web-spring/build.gradle
Normal file
@@ -0,0 +1,24 @@
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
dependencies {
|
||||
implementation(project(':core'))
|
||||
|
||||
annotationProcessor(deps.springboot.config_processor)
|
||||
implementation(deps.springboot.web)
|
||||
}
|
||||
|
||||
tasks.named('compileJava') {
|
||||
it.dependsOn('moveSpringConfigurationMetadata')
|
||||
}
|
||||
|
||||
tasks.register('moveSpringConfigurationMetadata').configure {
|
||||
it.dependsOn('processResources')
|
||||
doLast {
|
||||
def metafile = file("${sourceSets.main.output.resourcesDir}/META-INF/additional-spring-configuration-metadata.json")
|
||||
if (metafile.exists()) {
|
||||
def metafileTo = file("${sourceSets.main.output.classesDirs.asPath}/META-INF/spring-configuration-metadata.json")
|
||||
metafileTo.parentFile.mkdirs()
|
||||
metafile.renameTo(metafileTo)
|
||||
}
|
||||
}
|
||||
}
|
||||
12
web-spring/src/main/java/ru/di9/mirror/web/Application.java
Normal file
12
web-spring/src/main/java/ru/di9/mirror/web/Application.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package ru.di9.mirror.web;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.di9.mirror.web.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "maven-mirrors")
|
||||
public class MavenMirrorsProperties {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String storage;
|
||||
|
||||
@Getter
|
||||
private final List<MirrorData> list = new ArrayList<>();
|
||||
|
||||
public record MirrorData(String id, String url) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package ru.di9.mirror.web.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.di9.mirror.core.FileStorage;
|
||||
import ru.di9.mirror.core.MavenClient;
|
||||
import ru.di9.mirror.core.MirrorService;
|
||||
import ru.di9.mirror.core.MirrorService.MirrorPair;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class WebConfig {
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("java:S3864")
|
||||
public MirrorService mirrorService(MavenMirrorsProperties mirrorsProperties) {
|
||||
Path storagePath = Paths.get(mirrorsProperties.getStorage());
|
||||
|
||||
return new MirrorService(mirrorsProperties.getList()
|
||||
.stream()
|
||||
.peek(v -> log.info("read config mirror: {}|{}", v.id(), v.url()))
|
||||
.map(mirrorData -> new MirrorPair(
|
||||
new FileStorage(mirrorData.id(), storagePath),
|
||||
new MavenClient(mirrorData.url())
|
||||
))
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package ru.di9.mirror.web.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import ru.di9.mirror.core.MirrorService;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(path = "/maven")
|
||||
public class MavenController {
|
||||
|
||||
private final MirrorService mirrorService;
|
||||
|
||||
public MavenController(MirrorService mirrorService) {
|
||||
this.mirrorService = mirrorService;
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{*path}")
|
||||
public ResponseEntity<InputStreamResource> artifactFileGet(@PathVariable("path") String httpPath) {
|
||||
return mirrorService.getFile(httpPath)
|
||||
.map(fileRecord -> ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=\"" + fileRecord.name() + "\"")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.contentLength(fileRecord.size())
|
||||
.body(new InputStreamResource(fileRecord.inputStream())))
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "maven-mirrors.storage",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"name": "maven-mirrors.list",
|
||||
"type": "java.util.List<ru.di9.mirror.web.config.MavenMirrorsProperties.MirrorData>",
|
||||
"sourceType": "java.util.List<ru.di9.mirror.web.config.MavenMirrorsProperties.MirrorData>"
|
||||
}
|
||||
]
|
||||
}
|
||||
11
web-spring/src/main/resources/application.yml
Normal file
11
web-spring/src/main/resources/application.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
server:
|
||||
address: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
debug: false
|
||||
|
||||
maven-mirrors:
|
||||
storage: './storage'
|
||||
list:
|
||||
- id: 'maven-central'
|
||||
url: 'https://repo1.maven.org/maven2'
|
||||
Reference in New Issue
Block a user