Skip to content

Commit

Permalink
build: process JavaScript components with Babel.
Browse files Browse the repository at this point in the history
As "frontend" plugin gets activated before executing any goals, this
leads to a non obvious outcome that "mvn clean <some goal>" command
doesn't regenerate JS-files. It happens because "frontent" plugin
doesn't get activated as the target/classes/js/components directory
exists in the begginning and hasn't been removed yet.

As a workaround you might use:
- mvn -Pfrontend clean <some goal>
- mvn clean; mvn <some goal>

Addressed to #1060 and (a little bit to) #1057
  • Loading branch information
php-coder committed Jul 10, 2019
1 parent b65cc49 commit 1dc70fd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ if File.file?(validator_output)
print_errors_summary 'html5validator', errors_count
end

# @todo #1060 Danger: handle Babel errors from frontend-maven-plugin

# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
# Handle `mvn org.codehaus.gmavenplus:gmavenplus-plugin:testCompile` output
Expand Down Expand Up @@ -696,8 +698,9 @@ if github.branch_for_head !~ /^gh[0-9]+_/
end

js_file = %r{^src/main/javascript/.*\.js$}
component_file = %r{^src/main/frontend/src/.*\.js$}
css_file = %r{^src/main/webapp/.*\.css$}
modified_resources = git.modified_files.any? { |file| file =~ js_file || file =~ css_file }
modified_resources = git.modified_files.any? { |file| file =~ js_file || file =~ component_file || file =~ css_file }
updated_url = git.modified_files.include? 'src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java'
if modified_resources && !updated_url
warn("danger check: looks like you forgot to update `ResourceUrl.RESOURCES_VERSION` after modifying JS/CSS file(s)")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you are programmer/sysadmin or you just feeling that you are able to run a lo

* *At the heart of*: Spring Framework (and especially Spring Boot)
* *Template engine*: Thymeleaf
* *UI*: HTML, Bootstrap and a bit of JavaScript with JQuery
* *UI*: HTML, Bootstrap and JavaScript (React, JQuery)
* *Security*: Spring Security
* *Databases*: H2, MySQL or PostgreSQL
* *Database access*: Spring's `JdbcTemplate`
Expand Down
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,15 @@
</profile>
<profile>
<id>frontend</id>
<activation>
<file>
<!-- Should be in sync with Babel configuration from src/main/frontend/package.json -->
<missing>target/classes/js/components</missing>
</file>
</activation>
<build>
<plugins>
<!-- @todo #1060 Document usage of frontend-maven-plugin -->
<!--
We assume that most of the time we develop backend rather frontend.
So, we cache and skip the frontend-related things by default. This
Expand Down Expand Up @@ -1257,6 +1264,16 @@
<arguments>ci</arguments>
</configuration>
</execution>
<execution>
<id>npm-run-build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"babel-preset-react": "^6.24.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "babel src --out-dir ../../../target/classes/js",
"watch": "babel src --out-dir ../../../target/classes/js --watch"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions src/main/frontend/src/components/SeriesSaleImportForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// IMPORTANT:
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
//

4 changes: 2 additions & 2 deletions src/main/scripts/ci/check-build-and-verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
print_status "$ENFORCER_STATUS" 'Run maven-enforcer-plugin'

if [ "$TEST_STATUS" != 'skip' ]; then
mvn --batch-mode test -Denforcer.skip=true -Dmaven.resources.skip=true -DskipMinify=true -DdisableXmlReport=false \
mvn --batch-mode test -Denforcer.skip=true -Dmaven.resources.skip=true -DskipMinify=true -DdisableXmlReport=false -Dskip.npm -Dskip.installnodenpm \
>test.log 2>&1 || TEST_STATUS=fail
fi
print_status "$TEST_STATUS" 'Run unit tests'
Expand All @@ -220,7 +220,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
print_status "$SPOTBUGS_STATUS" 'Run SpotBugs'
fi

mvn --batch-mode verify -Denforcer.skip=true -DskipUnitTests=true \
mvn --batch-mode --activate-profiles frontend verify -Denforcer.skip=true -DskipUnitTests=true \
>verify-raw.log 2>&1 || VERIFY_STATUS=fail
# Workaround for #538
"$(dirname "$0")/filter-out-htmlunit-messages.pl" <verify-raw.log >verify.log
Expand Down
2 changes: 1 addition & 1 deletion src/main/scripts/ci/publish-code-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set -o pipefail

JACOCO_FAIL=

mvn --batch-mode jacoco:prepare-agent test jacoco:report -Denforcer.skip=true -DskipMinify=true >jacoco.log 2>&1 || JACOCO_FAIL=yes
mvn --batch-mode jacoco:prepare-agent test jacoco:report -Denforcer.skip=true -DskipMinify=true -Dskip.npm -Dskip.installnodenpm >jacoco.log 2>&1 || JACOCO_FAIL=yes

# -Z Exit with 1 if not successful. Default will Exit with 0
bash <(curl -s https://codecov.io/bash) -Z >>jacoco.log 2>&1 || JACOCO_FAIL=yes
Expand Down

2 comments on commit 1dc70fd

@0pdd
Copy link

@0pdd 0pdd commented on 1dc70fd Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1060-542e4feb discovered in pom.xml and submitted as #1070. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 1dc70fd Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1060-a747d278 discovered in Dangerfile and submitted as #1071. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.