Skip to content

Latest commit

 

History

History
287 lines (223 loc) · 6.52 KB

dev.md

File metadata and controls

287 lines (223 loc) · 6.52 KB

Start develop environment

(cd docker; docker-compose up -d)

Install maven wrapper

mvn -N io.takari:maven:wrapper

Run tests and generate report

./mvnw clean package site

Building (with doc)

./mvnw clean package

Building with frontend and without tests using default goal

./mvnw -Pfrontend -DskipTests

Documentation

Execute frontend plugin goal

./mvnw -pl frontend frontend:install-node-and-npm

Build only frontend with maven

./mvnw -pl frontend -P frontend  generate-resources

For get cli analogs of any <configuration> property see its Expression (Ctrl + Q in IntelliJ IDEA) and pass it with -D:

./mvnw -Dfrontend.npm.arguments=version -pl frontend frontend:npm
./mvnw -Dfrontend.npm.arguments='run dev' -pl frontend frontend:npm

Docker-compose

docker-compose -f docker-compose.yml -f docker-compose.demo.yml up -d
- "./mvnw -Dkarma.browsers=Firefox -Dcustom.selenium.browser=FIREFOX -P frontend clean package"
- "./mvnw -Dkarma.browsers=Chrome -Dcustom.selenium.browser=CHROME -P frontend clean package"

Jest

You should clear jest cache after change .babelrc See here.

To see where is jest cache you can

jest --showConfig  | grep -i cache

Show goals on phase

mvn help:describe -Dcmd=compile

https://stackoverflow.com/questions/1709625/maven-command-to-list-lifecycle-phases-along-with-bound-goals/35610377#35610377

./mvnw fr.jcgay.maven.plugins:buildplan-maven-plugin:list-phase

Take dump

docker exec $(docker inspect --format "{{.Status.ContainerStatus.ContainerID}}" $(docker service ps BLOGSTACK_postgresql --filter desired-state=running -q)) pg_dump -U blog -b --create --column-inserts --serializable-deferrable > /tmp/dump.sql```

Restore dump

cat <(echo -n "drop database blog;") ~/blog/$(ls ~/blog | grep backup- | sort | tail -n 1)/blog.sql | docker exec -i postgresql-blog-dev psql -U postgres

Install

./mvnw -DskipTests clean install

Java 9

https://dou.ua/lenta/articles/problems-with-java-9/ https://stackoverflow.com/questions/43258796/hibernate-support-for-java-9

Pull up exists database

Add in docker yml command: ["--spring.flyway.baselineOnMigrate=true"] command: ["--spring.flyway.baselineOnMigrate=true", "--spring.flyway.baselineVersion=32767"] if demo profile enabled

Building with frontend and build docker image

There is highly recommends to shut down your application on 8080, although tests uses 9080, some of them can fails, with websocket for example.

./mvnw -P frontend -P docker clean package

As you can see, there is switches via maven profiles.

This will run tests on Chrome. See .travis.yml for Firefox and Chrome test examples

Building without frontend and without webdriver tests

./mvnw clean package

Build and start docker image for development

cd docker
docker-compose -f docker-compose.yml -f docker-compose.nginx.yml -f docker-compose.dev.yml up -d --build

Run

# By default
java -jar frontend/target/frontend-1.0.3-SNAPSHOT-exec.jar
# .. or with pre-generated content
java -jar frontend/target/frontend-1.0.3-SNAPSHOT-exec.jar --spring.profiles.active=demo

Test user credentials can be found in backend/src/main/resources/db/demo/V32000__demo.sql:4

Development

Changing version

./mvnw -DnewVersion=1.0.0 versions:set versions:commit

Check for update maven dependency versions

./mvnw -DlogOutput=false -DprocessDependencyManagement=false versions:display-dependency-updates | less
./mvnw -DlogOutput=false versions:display-property-updates | less

./mvnw -DlogOutput=false versions:display-plugin-updates | less

Update with careful

shedlock
hibernate-types-52
selenide
webdrivermanager

Run boot-run

./mvnw clean spring-boot:run

Frontend development

Run webpack

cd frontend
npm run dev

Run Jest

cd frontend
npm run test

clean Jest cache

# where is it
npm run test -- --showConfig | grep cache
rm -rf /var/tmp/jest_rs

Update js dependencies

https://www.npmjs.com/package/npm-check-updates

ncu -u
rm package-lock.json
npm install

Debug js tests

youtube video ndb

# globally seems not working
cd frontend
npm i ndb

node_modules/ndb/ndb.js .

FAQ

Q: I suddenly get http 403 error in JUnit mockMvc tests.

A: Add .with(csrf()) to MockMvcRequestBuilder chain

Code coverage

  1. Add profile jacoco ./mvnw -Pjacoco clean package
  2. See coverage HTML report in ./jacoco/target/site/jacoco-aggregate/index.html directory.

Elasticsearch

curl -X GET    -H "Content-Type:application/json"    -d '{
  "query": {
        "prefix": {
          "text": "почт"
        }
  }
}'  'http://127.0.0.1:19200/blog/_search' | jq
curl -X GET    -H "Content-Type:application/json"    -d '{
  "query": {
    "bool":{
      "should": [
         {"match_phrase_prefix": { "text": "почт" }},
         {"match_phrase_prefix": { "title": "почт" }}
      ]
    }
  },
  "_source": ["_"],
  "highlight" : {
        "fields" : {
            "text" : { "fragment_size" : 150, "pre_tags" : ["<em>"], "post_tags" : ["</em>"], "number_of_fragments" : 5 },
            "title" : { "fragment_size" : 150, "pre_tags" : ["<em>"], "post_tags" : ["</em>"], "number_of_fragments" : 5 }
        }
  }
}'  'http://127.0.0.1:19200/blog/_search' | jq
curl -X GET    -H "Content-Type:application/json"    -d '{
  "query": {
    "bool":{
      "should": [
         {"match_phrase_prefix": { "text": "рыбами" }},
         {"match_phrase_prefix": { "title": "рыбами" }}
      ]
    }
  },
  "highlight" : {
        "fields" : {
            "text" : { "fragment_size" : 150, "pre_tags" : ["<em>"], "post_tags" : ["</em>"], "number_of_fragments" : 5 },
            "title" : { "fragment_size" : 150, "pre_tags" : ["<em>"], "post_tags" : ["</em>"], "number_of_fragments" : 1 }
        }
  },
     "sort" : [
        {"id" : {"order" : "desc"}}
     ]
}'  'http://127.0.0.1:19200/post/_search' | jq

Install dependency

./mvnw -pl common-test clean install