Skip to content
Snippets Groups Projects
Commit 11c9b98c authored by heikkkk's avatar heikkkk
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://gitlab.stud.idi.ntnu.no/idatt2106-2024-07/backend into feat/model-classes

 Conflicts:
	.gitlab-ci.yml
parents d7a05d42 7d2ba308
Branches feat/model-classes
No related tags found
1 merge request!6Feat/model classes
Pipeline #274082 passed
image: maven:3.8.5-openjdk-17 image: maven:3.8.5-openjdk-17
variables: variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true" MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true" MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
SPRING_PROFILES_ACTIVE: gitlab-ci SPRING_PROFILES_ACTIVE: gitlab-ci
DATABASE_URL: "jdbc:mysql://mysql-service:3306/sparesti"
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
services: services:
- name: mysql:8.0.36 - name: mysql:latest
alias: mysql-service alias: mysql
variables:
MYSQL_ROOT_PASSWORD: "root" # TODO Set this in GitLab's CI/CD environment variables for security in production
MYSQL_DATABASE: "sparesti"
stages: stages:
- test - compile_and_test
- generate_site_reports
- modify_generated_site_reports
- publish_pages
cache: cache:
key: "${CI_JOB_NAME}" # To keep cache across branches
paths: paths:
- .m2/repository - .m2/repository
key: "$CI_BUILD_REF_NAME" # Separate cache for each branch or tag
compile_and_test:
stage: compile_and_test
script:
- mvn clean test # Cleans the previous build and runs tests
when: always
generate_site_reports:
stage: generate_site_reports
script:
- mvn site # Generates a website containing project documentation (including checkstyle report)
artifacts:
paths:
- target/site/
only:
- master
modify_generated_site_reports: # Modify the generated website containing project documentation to also link to JaCoCo coverage file
image: python:3.8-slim
stage: modify_generated_site_reports
script:
- pip install beautifulsoup4 # Used to parse contents of HTML files
- python scripts/add_jacoco_coverage_link_to_html.py # Script that modifies the HTML file to include a link to JaCoCo coverage file
artifacts:
paths:
- target/site/
dependencies:
- generate_site_reports
only:
- master
test:jdk17: # We move the code coverage reports generated by jacoco and mvn site to be served by Gitlab Pages (Settings -> Pages)
stage: test publish_pages:
image: alpine:latest
stage: publish_pages
dependencies:
- modify_generated_site_reports
script: script:
- docker run --publish 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.36 - mkdir public
- mvn clean test # Cleans the previous build and runs tests. - cp -r target/site/* public/
when: always artifacts:
\ No newline at end of file paths:
- public
only:
- master
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
<version>3.2.5</version> <version>3.2.5</version>
</plugin> </plugin>
<!-- Jacoco --> <!-- Produce code coverage reports -->
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
...@@ -137,9 +137,10 @@ ...@@ -137,9 +137,10 @@
<goal>prepare-agent</goal> <goal>prepare-agent</goal>
</goals> </goals>
</execution> </execution>
<!-- Attached to Maven test phase -->
<execution> <execution>
<id>report</id> <id>report</id>
<phase>prepare-package</phase> <phase>test</phase>
<goals> <goals>
<goal>report</goal> <goal>report</goal>
</goals> </goals>
...@@ -151,6 +152,51 @@ ...@@ -151,6 +152,51 @@
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
<!-- Plugin that generates a site for the current project -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M13</version>
</plugin>
<!-- Plugin allow execution of system and Java programs -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>update-html-report</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>python</executable>
<workingDirectory>${project.basedir}/scripts</workingDirectory>
<arguments>
<argument>add_jacoco_coverage_link_to_html.py</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
<reporting>
<plugins>
<!-- Generate Checkstyle Report -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project> </project>
# Function is used to modify target/site/project-reports.html to include
# a link to the JaCoCo generated coverage files at target/site/jacoco/index.html.
def add_jacoco_coverage_link_to_html(file_path):
import bs4
# Open and read the HTML file at file_path
with open(file_path, 'r', encoding='utf-8') as file:
original_html = file.read()
# Parse the content of the HTML file using Beautiful Soup (bs4)
soup = bs4.BeautifulSoup(original_html, features='html.parser')
# Find the <ul> element that contains the Checkstyle link inside the Project Reports navigation section
# This is where we wanna add a list item for the JaCoCo coverage report
nav_list = soup.find("li", class_="active").find("ul", class_="nav nav-list")
# Create the new list item for JaCoCo
new_li = soup.new_tag("li")
new_a = soup.new_tag("a", href="jacoco/index.html")
new_a.string = "Jacoco Coverage"
new_li.append(new_a)
# Add the new list item to the navigation list
nav_list.append(new_li)
# Find the table that contains the Checkstyle link
# This is where we wanna add a table that contains a link for the JaCoCo report
table = soup.find("table", class_="table table-striped")
# Create the new table row for JaCoCo
new_tr = soup.new_tag("tr", **{"class": "a"})
new_td1 = soup.new_tag("td")
new_a2 = soup.new_tag("a", href="jacoco/index.html")
new_a2.string = "Jacoco Coverage"
new_td2 = soup.new_tag("td")
new_td2.string = "Code coverage report generated by JaCoCo."
new_td1.append(new_a2)
new_tr.append(new_td1)
new_tr.append(new_td2)
# Add the new table row to the table
table.append(new_tr)
# Write the modified HTML content back to the original file
with open(file_path, 'w', encoding='utf-8') as file:
file.write(str(soup.prettify()))
file_path = 'target/site/project-reports.html'
add_jacoco_coverage_link_to_html(file_path)
...@@ -32,7 +32,7 @@ import org.springframework.security.core.userdetails.UserDetails; ...@@ -32,7 +32,7 @@ import org.springframework.security.core.userdetails.UserDetails;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Entity @Entity
@Table(name = "user") @Table(name = "`user`")
public class User implements UserDetails{ public class User implements UserDetails{
@Id @Id
......
server.port: 8080
spring:
datasource:
url: jdbc:mysql://mysql:3306/sparesti
username: root
password: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
defer-datasource-initialization: true
sql:
init:
mode: always
continue-on-error: true
springdoc:
swagger-ui:
path: /swagger/index.html
api-docs:
path: /swagger/api-docs
...@@ -13,13 +13,4 @@ class DemoApplicationTests { ...@@ -13,13 +13,4 @@ class DemoApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {
} }
@Autowired
private TestRestTemplate restTemplate;
@Test
void homeResponse() {
String body = this.restTemplate.getForObject("/", String.class);
assertEquals("Spring is here!", body);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment