Skip to content

Commit

Permalink
라이브러리 버전 정리 및 실습 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-hyungu committed Aug 28, 2023
1 parent 10a03b3 commit b16924a
Show file tree
Hide file tree
Showing 76 changed files with 1,887 additions and 59 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: SonarCloud
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'corretto' # Alternative distribution options are available
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
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 sonar --info -x :study:build
33 changes: 15 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id 'java'
id 'idea'
id "java"
id "idea"
id "jacoco"
}

group 'org.example'
version '1.0-SNAPSHOT'
group "org.example"
version "1.0-SNAPSHOT"

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand All @@ -14,21 +15,17 @@ repositories {
}

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

implementation 'org.apache.tomcat.embed:tomcat-embed-core:10.1.0-M16'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.1.0-M16'
implementation 'ch.qos.logback:logback-classic:1.2.10'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation "org.apache.tomcat.embed:tomcat-embed-core:10.1.13"
implementation "org.apache.tomcat.embed:tomcat-embed-jasper:10.1.13"
implementation "ch.qos.logback:logback-classic:1.2.12"
implementation "org.apache.commons:commons-lang3:3.13.0"

testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.mockito:mockito-core:3.+'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
useJUnitPlatform()
testImplementation "org.assertj:assertj-core:3.24.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.2"
testImplementation "org.mockito:mockito-core:5.4.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.2"
}

idea {
Expand All @@ -40,6 +37,6 @@ idea {

sourceSets {
main {
java.destinationDirectory.set(file('src/main/webapp/WEB-INF/classes'))
java.destinationDirectory.set(file("src/main/webapp/WEB-INF/classes"))
}
}
50 changes: 50 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id "java"
id "jacoco"
id "org.sonarqube" version "4.2.1.3168"
}

subprojects {
apply plugin: 'org.sonarqube'
sonar {
properties {
property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
}
}

tasks.withType(Test).configureEach {
maxParallelForks 3
useJUnitPlatform()
}
}

apply from: "$project.rootDir/sonar.gradle"

// $ ./gradlew test codeCoverageReport
tasks.register("codeCoverageReport", JacocoReport) {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
subprojects { subproject ->
subproject.plugins.withType(JacocoPlugin).configureEach {
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask ->
//the jacoco extension may be disabled for some projects
if (testTask.extensions.getByType(JacocoTaskExtension).isEnabled()) {
sourceSets subproject.sourceSets.main
executionData(testTask)
} else {
logger.warn('Jacoco extension is disabled for test task \'{}\' in project \'{}\'. this test task will be excluded from jacoco report.',testTask.getName(),subproject.getName())
}
}

subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach {
rootProject.tasks.codeCoverageReport.dependsOn(it)
}
}
}

// enable the different report types (html, xml, csv)
reports {
xml.required = true
html.required = true
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}
33 changes: 15 additions & 18 deletions mvc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id "java"
id "jacoco"
}

sourceCompatibility = JavaVersion.VERSION_11
Expand All @@ -10,25 +11,21 @@ repositories {
}

dependencies {
implementation 'jakarta.servlet:jakarta.servlet-api:5.0.0'
implementation 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.3'
implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0'
implementation 'jakarta.annotation:jakarta.annotation-api:2.0.0'
annotationProcessor 'jakarta.annotation:jakarta.annotation-api:2.0.0'
implementation "jakarta.servlet:jakarta.servlet-api:5.0.0"
implementation "javax.servlet.jsp:javax.servlet.jsp-api:2.3.3"
implementation "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0"
implementation "jakarta.annotation:jakarta.annotation-api:2.0.0"
annotationProcessor "jakarta.annotation:jakarta.annotation-api:2.0.0"

implementation 'org.reflections:reflections:0.10.2'
implementation "org.reflections:reflections:0.10.2"

implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.2"

implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'ch.qos.logback:logback-classic:1.2.10'
implementation "org.apache.commons:commons-lang3:3.13.0"
implementation "ch.qos.logback:logback-classic:1.2.12"

testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.mockito:mockito-core:3.+'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
useJUnitPlatform()
testImplementation "org.assertj:assertj-core:3.24.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.2"
testImplementation "org.mockito:mockito-core:5.4.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.2"
}
27 changes: 5 additions & 22 deletions mvc/src/main/java/nextstep/mvc/DispatcherServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,28 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class DispatcherServlet extends HttpServlet {

private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(DispatcherServlet.class);

private final List<HandlerMapping> handlerMappings;
private HandlerMapping handlerMappings;

public DispatcherServlet() {
this.handlerMappings = new ArrayList<>();
public void addHandlerMapping(final HandlerMapping handlerMapping) {
this.handlerMappings = handlerMapping;
}

@Override
public void init() {
handlerMappings.forEach(HandlerMapping::initialize);
}

public void addHandlerMapping(final HandlerMapping handlerMapping) {
handlerMappings.add(handlerMapping);
this.handlerMappings.initialize();
}

@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
log.debug("Method : {}, Request URI : {}", request.getMethod(), request.getRequestURI());

try {
final var controller = getController(request);
final var controller = (Controller) handlerMappings.getHandler(request);
final var viewName = controller.execute(request, response);
move(viewName, request, response);
} catch (Throwable e) {
Expand All @@ -47,15 +39,6 @@ protected void service(final HttpServletRequest request, final HttpServletRespon
}
}

private Controller getController(final HttpServletRequest request) {
return handlerMappings.stream()
.map(handlerMapping -> handlerMapping.getHandler(request))
.filter(Objects::nonNull)
.map(Controller.class::cast)
.findFirst()
.orElseThrow();
}

private void move(final String viewName, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (viewName.startsWith(JspView.REDIRECT_PREFIX)) {
response.sendRedirect(viewName.substring(JspView.REDIRECT_PREFIX.length()));
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = 'jwp-dashboard-mvc'

include 'mvc'
include 'app'
include 'study'
11 changes: 11 additions & 0 deletions sonar.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apply plugin: "org.sonarqube"

sonar {
properties {
property "sonar.projectKey", "woowacourse_jwp-dashboard-mvc"
property "sonar.organization", "woowacourse"
property "sonar.host.url", "https://sonarcloud.io"

property "sonar.exclusions", "study/**"
}
}
48 changes: 48 additions & 0 deletions study/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id "java"
id "idea"
}

group "nextstep"
version "1.0-SNAPSHOT"

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

dependencies {
implementation "org.reflections:reflections:0.10.2"
implementation "org.apache.tomcat.embed:tomcat-embed-core:10.1.13"
implementation "org.apache.tomcat.embed:tomcat-embed-jasper:10.1.13"
implementation "ch.qos.logback:logback-classic:1.2.12"
implementation "org.apache.commons:commons-lang3:3.13.0"

implementation "org.springframework:spring-context:5.3.29"

testImplementation "org.assertj:assertj-core:3.24.2"
testImplementation "org.mockito:mockito-core:5.4.0"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.7.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.2"
testImplementation 'com.h2database:h2:2.2.220'
}

test {
maxParallelForks 3
useJUnitPlatform()
}

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

sourceSets {
main {
java.outputDir = file('src/main/webapp/WEB-INF/classes')
}
}
34 changes: 34 additions & 0 deletions study/src/main/java/ioc/IocApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ioc;

import ioc.decoupled.ExchangeRateConfiguration;
import ioc.decoupled.ExchangeRateRenderer;
import ioc.decoupled.ExchangeRateSupportFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class IocApplication {
public static void main(String[] args) {
myIocContainer();
xmlApplicationContext();
annotationApplicationContext();
}

private static void myIocContainer() {
final ExchangeRateSupportFactory factory = ExchangeRateSupportFactory.getInstance();
final ExchangeRateRenderer renderer = factory.getExchangeRateRenderer();
renderer.render();
}

private static void xmlApplicationContext() {
final ApplicationContext context = new ClassPathXmlApplicationContext("exchange-rate-context.xml");
final ExchangeRateRenderer renderer = context.getBean("exchangeRateRenderer", ExchangeRateRenderer.class);
renderer.render();
}

private static void annotationApplicationContext() {
final ApplicationContext context = new AnnotationConfigApplicationContext(ExchangeRateConfiguration.class);
final ExchangeRateRenderer renderer = context.getBean("exchangeRateRenderer", ExchangeRateRenderer.class);
renderer.render();
}
}
Loading

0 comments on commit b16924a

Please sign in to comment.