-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eef22fd
Showing
115 changed files
with
14,763 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# jwp-dashboard-jdbc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
app/src/main/java/com/techcourse/AppWebApplicationInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
app/src/main/java/com/techcourse/config/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
Oops, something went wrong.