Skip to content

Commit

Permalink
Add Backend Server Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 committed Jun 14, 2018
1 parent 43475a4 commit b7e9103
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.io.IOException;

interface MetadataReader {
public interface MetadataReader {
Node readNode() throws IOException;
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import castro.metadata.Node;

interface MetadataWriter {
public interface MetadataWriter {
MetadataWriter writeNode(Node node);
void close();
}
6 changes: 3 additions & 3 deletions analyzer/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ mainClassName = "castro.analyzer.java.Main"

compileJava {
options.compilerArgs += [
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=castro.analyzer.java",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=castro.analyzer.java",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=castro.analyzer.java"
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"
// "--add-exports=jdk.compiler/com.sun.tools.javac.comp=castro.analyzer.java",
]
}
18 changes: 18 additions & 0 deletions analyzer/java/src/main/java/castro/analyzer/java/IndexScanner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package castro.analyzer.java;

import castro.analyzer.MetadataWriter;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeScanner;

public class IndexScanner extends TreeScanner {
private MetadataWriter writer;
private CompilationUnitTree unit;


@Override
public void scan(JCTree tree) {

}

}
2 changes: 2 additions & 0 deletions analyzer/java/src/main/java/castro/analyzer/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


public class Main {
// Main(String)

public static void main(String[] args) {
JavaCompiler x;
JCTree y;
Expand Down
6 changes: 3 additions & 3 deletions analyzer/java/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module castro.analyzer.java {
requires jdk.compiler;
}
//module castro.analyzer.java {
// requires jdk.compiler;
//}
28 changes: 24 additions & 4 deletions backend/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
plugins {
id 'java'
id 'application'
id "org.springframework.boot" version "2.0.2.RELEASE"
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}

mainClassName = 'castro.backend.Main'
// https://dzone.com/articles/continuous-auto-restart-with-spring-boot-devtools
configurations {
dev
}

task backend(dependsOn: run)
bootRun {
// Use Spring Boot DevTool only when we run Gradle bootRun task
classpath = sourceSets.main.runtimeClasspath + configurations.dev
}

dependencies {
compile project(":model")

compile "org.springframework.boot:spring-boot-starter-web"
// http://localhost:8080/swagger-ui.html
// compile "com.hubspot.jackson:jackson-datatype-protobuf:0.9.9-jackson2.9-proto3"
// compile "io.springfox:springfox-swagger-ui:2.8.0"
// compile "io.springfox:springfox-swagger2:2.8.0"
// compile "javax.xml.bind:jaxb-api:2.3.0"

compile "com.google.protobuf:protobuf-java-util:$protocVersion"
compile "org.eclipse.jgit:org.eclipse.jgit:$jgitVersion"
}

dev("org.springframework.boot:spring-boot-devtools")

}

task backend(dependsOn: bootRun)
74 changes: 74 additions & 0 deletions backend/src/main/java/castro/backend/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package castro.backend;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.protobuf.ProtobufJsonFormatHttpMessageConverter;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;

@SpringBootApplication
//@EnableSwagger2
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

// @Bean
// public Docket repositoryApi() {
// return new Docket(DocumentationType.SWAGGER_2)
// .groupName("repository-api")
// .apiInfo(apiInfo())
// .select()
// .paths(PathSelectors.ant("/api/repository/*"))
// .build();
// }
//
// @Bean
// public Docket api() {
// return new Docket(DocumentationType.SWAGGER_2)
// .select()
// .apis(RequestHandlerSelectors.basePackage("castro.backend.controllers"))
// .paths(PathSelectors.ant("/api/*"))
// .build()
// .apiInfo(apiInfo());
// }
//
// private ApiInfo apiInfo() {
// return new ApiInfoBuilder()
// .title("Backend API")
// .description("Hello world")
// .termsOfServiceUrl("http://springfox.io")
//// .license("Apache License Version 2.0")
//// .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
//// .version("2.0")
// .build();
// }

@Bean
ProtobufJsonFormatHttpMessageConverter protobufHttpMessageConverter() {
return new ProtobufJsonFormatHttpMessageConverter();
}

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}

}
12 changes: 0 additions & 12 deletions backend/src/main/java/castro/backend/Main.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package castro.backend.controllers;

public class AbstractContorller {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package castro.backend.controllers;

import castro.repository.Repository;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

// The pattern is a workaround to make implementations methods to inherit annotations
// https://stackoverflow.com/questions/8002514/spring-mvc-annotated-controller-interface-with-pathvariable
// https://jira.spring.io/browse/SPR-11055

@RequestMapping(value = "/api/repository", produces = MediaType.APPLICATION_JSON_VALUE)
public interface RepositoryApi {
@RequestMapping(value = "/{id}")
default Repository repository(@PathVariable String id) {
return repositoryImpl(id);
}
Repository repositoryImpl(String id);

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
default void repository(@PathVariable String id, @RequestBody Repository repo) {
repositoryImpl(id, repo);
}
void repositoryImpl(String id, Repository repo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package castro.backend.controllers;

import castro.repository.Repository;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RepositoryApiController implements RepositoryApi {
private Logger logger = LoggerFactory.getLogger(getClass());

@Override
public Repository repositoryImpl(String id) {
return Repository.newBuilder().setDomain("github.com").setMainBranch("master").setRepositoryId(id).build();
}

@Override
public void repositoryImpl(String id, Repository repo) {
try {
logger.info("update {}", JsonFormat.printer().print(repo));
} catch (InvalidProtocolBufferException e) {
// e.printStackTrace();
}
}
}
5 changes: 5 additions & 0 deletions scripts/tmux_session
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd $(dirname $0)/..

tmuxp load scripts/tmux_session.yaml
26 changes: 26 additions & 0 deletions scripts/tmux_session.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# download: pip install --user tmuxp
# usage: tmuxp load tmux_session.yaml
# see: https://github.com/tmux-python/tmuxp
session_name: castro-dev
windows:
- window_name: elk
layout: even-horizontal
panes:
- shell_command:
- ./gradlew startKibana
- shell_command:
- ./gradlew startDeps
- window_name: backend
layout: even-horizontal
panes:
- shell_command:
- ./gradlew bootRun
- shell_command:
- ./gradlew -t build
- window_name: others
layout: even-horizontal
panes:
- shell_command:
-
- shell_command:
-
2 changes: 2 additions & 0 deletions util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ plugins {

dependencies {
compile 'ch.qos.logback:logback-classic:1.2.3'
compile 'com.ibm.icu:icu4j:61.1'
compile 'commons-io:commons-io:2.6'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package castro.hash;
package castro.util;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
Expand Down
Loading

0 comments on commit b7e9103

Please sign in to comment.