минимальный функционал maven
может сохранять артефакты; может отдавать артефакты
This commit is contained in:
20
build.gradle
20
build.gradle
@@ -5,26 +5,16 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'ru.di9'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '11'
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom annotationProcessor
|
||||
}
|
||||
}
|
||||
version = '1.0-SNAPSHOT'
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
annotationProcessor('org.projectlombok:lombok')
|
||||
compileOnly('org.projectlombok:lombok')
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
implementation('org.springframework.boot:spring-boot-starter-web')
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ProjectMirrorApplication {
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ProjectMirrorApplication.class, args);
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
74
src/main/java/ru/di9/mirror/controller/WebController.java
Normal file
74
src/main/java/ru/di9/mirror/controller/WebController.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package ru.di9.mirror.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(path = "/maven")
|
||||
public class WebController {
|
||||
private final Path storagePath;
|
||||
|
||||
public WebController(@Value("${maven.storage:./storage}") String storagePath) {
|
||||
this.storagePath = Paths.get(storagePath);
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/{*path}")
|
||||
public ResponseEntity<Resource> httpGetFile(@PathVariable("path") String httpPath) throws IOException {
|
||||
ResponseEntity<Resource> responseEntity;
|
||||
|
||||
Path path = resolve(httpPath);
|
||||
if (Files.notExists(path)) {
|
||||
responseEntity = ResponseEntity.notFound().build();
|
||||
} else {
|
||||
long size = Files.size(path);
|
||||
|
||||
responseEntity = ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + path.toFile().getName() + "\"")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.contentLength(size)
|
||||
.body(new InputStreamResource(Files.newInputStream(path)));
|
||||
}
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/{*path}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public ResponseEntity<?> httpPutFile(@PathVariable("path") String httpPath, HttpServletRequest httpRequest) throws IOException {
|
||||
Path path = resolve(httpPath);
|
||||
Files.createDirectories(path.getParent());
|
||||
|
||||
try (InputStream inputStream = httpRequest.getInputStream();
|
||||
OutputStream outputStream = Files.newOutputStream(path)
|
||||
) {
|
||||
byte[] buff = new byte[8 * 1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buff)) > 0) {
|
||||
outputStream.write(buff, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
private Path resolve(String httpPath) {
|
||||
return storagePath.resolve(httpPath.substring(1));
|
||||
}
|
||||
}
|
||||
@@ -1 +1,8 @@
|
||||
server:
|
||||
address: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
debug: false
|
||||
|
||||
maven:
|
||||
storage: './storage'
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package ru.di9.mirror;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ProjectMirrorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user