Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-hyungu committed Sep 16, 2021
0 parents commit eef22fd
Show file tree
Hide file tree
Showing 115 changed files with 14,763 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonarqube --info
126 changes: 126 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
### Windows template
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Example user template template
### Example user template

# IntelliJ project files
.idea
*.iml
out
gen
### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Example user template template
### Example user template

# IntelliJ project files
.idea
*.iml
out
gen

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

/tomcat.8080/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# jwp-dashboard-jdbc
59 changes: 59 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
plugins {
id 'application'
id 'org.sonarqube' version '3.3'
id 'idea'
}

application {
mainClass = 'com.techcourse.JwpApplication'
}

idea {
module {
inheritOutputDirs = false
outputDir file("webapp/WEB-INF/classes")
}
}

group = 'nextstep.jwp'
version = '1.0'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

dependencies {
implementation project(':mvc')
implementation project(':jdbc')

implementation 'ch.qos.logback:logback-classic:1.2.3'
implementation 'com.google.guava:guava:29.0-jre'

implementation 'org.apache.tomcat.embed:tomcat-embed-core:10.0.10'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.0.10'

implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.5'

implementation 'com.h2database:h2:1.4.200'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.3'
testImplementation 'org.mockito:mockito-core:3.12.3'
testImplementation 'org.assertj:assertj-core:3.20.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

tasks.named('test') {
useJUnitPlatform()
}

sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "woowacourse_jwp-dashboard-jdbc"
property "sonar.organization", "woowacourse"
property "sonar.host.url", "https://sonarcloud.io"
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/techcourse/AppWebApplicationInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.techcourse;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRegistration;
import nextstep.mvc.DispatcherServlet;
import nextstep.mvc.controller.asis.ControllerHandlerAdapter;
import nextstep.mvc.controller.tobe.AnnotationHandlerMapping;
import nextstep.mvc.controller.tobe.HandlerExecutionHandlerAdapter;
import nextstep.web.WebApplicationInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AppWebApplicationInitializer implements WebApplicationInitializer {

private static final Logger log = LoggerFactory.getLogger(AppWebApplicationInitializer.class);

@Override
public void onStartup(ServletContext servletContext) {
final DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.addHandlerMapping(new ManualHandlerMapping());
dispatcherServlet.addHandlerMapping(new AnnotationHandlerMapping("com.techcourse.controller"));

dispatcherServlet.addHandlerAdapter(new ControllerHandlerAdapter());
dispatcherServlet.addHandlerAdapter(new HandlerExecutionHandlerAdapter());

final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");

log.info("Start AppWebApplication Initializer");
}
}
50 changes: 50 additions & 0 deletions app/src/main/java/com/techcourse/JwpApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.techcourse;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.stream.Stream;

public class JwpApplication {

private static final Logger log = LoggerFactory.getLogger(JwpApplication.class);

private static final int DEFAULT_PORT = 8080;

public static void main(String[] args) throws Exception {
final int port = defaultPortIfNull(args);

final Tomcat tomcat = new Tomcat();
tomcat.setPort(port);

addWebapp(tomcat);

// 불필요한 설정은 skip
skipBindOnInit(tomcat);

tomcat.start();
}

private static int defaultPortIfNull(String[] args) {
return Stream.of(args)
.findFirst()
.map(Integer::parseInt)
.orElse(DEFAULT_PORT);
}

private static Context addWebapp(Tomcat tomcat) {
final String docBase = new File("app/webapp/").getAbsolutePath();
final Context context = tomcat.addWebapp("/", docBase);
log.info("configuring app with basedir: {}", docBase);
return context;
}

private static void skipBindOnInit(Tomcat tomcat) {
final Connector connector = tomcat.getConnector();
connector.setProperty("bindOnInit", "false");
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/techcourse/ManualHandlerMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.techcourse;

import com.techcourse.controller.*;
import jakarta.servlet.http.HttpServletRequest;
import nextstep.mvc.HandlerMapping;
import nextstep.mvc.controller.asis.Controller;
import nextstep.mvc.controller.asis.ForwardController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class ManualHandlerMapping implements HandlerMapping {

private static final Logger log = LoggerFactory.getLogger(ManualHandlerMapping.class);

private static final Map<String, Controller> controllers = new HashMap<>();

@Override
public void initialize() {
controllers.put("/", new ForwardController("/index.jsp"));
controllers.put("/logout", new LogoutController());

log.info("Initialized Handler Mapping!");
controllers.keySet().forEach(path -> log.info("Path : {}, Controller : {}", path, controllers.get(path).getClass()));
}

@Override
public Controller getHandler(HttpServletRequest request) {
final String requestURI = request.getRequestURI();
log.debug("Request Mapping Uri : {}", requestURI);
return controllers.get(requestURI);
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/techcourse/config/DataSourceConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.techcourse.config;

import org.h2.jdbcx.JdbcDataSource;

import java.util.Objects;

public class DataSourceConfig {

private static javax.sql.DataSource INSTANCE;

public static javax.sql.DataSource getInstance() {
if (Objects.isNull(INSTANCE)) {
INSTANCE = createJdbcDataSource();
}
return INSTANCE;
}

private static JdbcDataSource createJdbcDataSource() {
final JdbcDataSource jdbcDataSource = new JdbcDataSource();
jdbcDataSource.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;");
jdbcDataSource.setUser("");
jdbcDataSource.setPassword("");
return jdbcDataSource;
}

private DataSourceConfig() {}
}
Loading

0 comments on commit eef22fd

Please sign in to comment.