минимальный функционал maven

может сохранять артефакты;
может отдавать артефакты
This commit is contained in:
2022-04-15 19:35:43 +03:00
parent c63bfbd369
commit f2b3558b52
5 changed files with 88 additions and 30 deletions

View File

@@ -5,26 +5,16 @@ plugins {
} }
group = 'ru.di9' group = 'ru.di9'
version = '0.0.1-SNAPSHOT' version = '1.0-SNAPSHOT'
sourceCompatibility = '11' sourceCompatibility = JavaVersion.VERSION_11
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' annotationProcessor('org.projectlombok:lombok')
compileOnly 'org.projectlombok:lombok' compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') { implementation('org.springframework.boot:spring-boot-starter-web')
useJUnitPlatform()
} }

View File

@@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class ProjectMirrorApplication { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ProjectMirrorApplication.class, args); SpringApplication.run(Application.class, args);
} }
} }

View 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));
}
}

View File

@@ -1 +1,8 @@
server:
address: 127.0.0.1
port: 8080
debug: false
maven:
storage: './storage'

View File

@@ -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() {
}
}