jhipster / jhipster-core

JHipster Domain Language, used by JHipster UML and JDL-Studio to generate entities
Apache License 2.0
346 stars 116 forks source link

entities in JDL without javadoc are regenerated by import-jdl even if no changes #341

Closed kaidohallik closed 5 years ago

kaidohallik commented 5 years ago
Overview of the issue

If entity has no javadoc in JDL and command jhipster import-jdl is executed multiple times without changes in JDL then this entity without javadoc is regenerated each time import-jdl is executed.

Motivation for or Use Case

It confuses if import-jdl claims that there are changes but actually no changes.
And this is not optimal to regenerate if no changes.
And without changes in PR #340 this is causing generating new liquibase changelogs for every unchanged entity which has no javadoc in JDL.

Reproduce the error

Generate application with jhipster
Compose JDL where exists entities without javadoc
Import entities from JDL by jhipster import-jdl
Re-execute jhipster import-jdl without any change in JDL.

Re-executing jhipster import-jdl regenerates entities which has no javadoc in JDL.

Related issues

jhipster/generator-jhipster#9837
jhipster/generator-jhipster#9996

Suggest a Fix

If entity javadoc is missing in JDL then entity configuration parsed from JDL contains key javadoc with value undefined.
But in entity configuration read from disk this key javadoc is missing.
By this reason Object.keys(firstEntity).length !== Object.keys(secondEntity).length is true here: https://github.com/jhipster/jhipster-core/blob/master/lib/utils/object_utils.js#L53 and entity is counted as changed entity.

Possible fix:

add (removes keys which value is undefined before comparison):

  Object.keys(firstEntity).forEach(key => firstEntity[key] === undefined && delete firstEntity[key]);
  Object.keys(secondEntity).forEach(key => secondEntity[key] === undefined && delete secondEntity[key]);

after this line: https://github.com/jhipster/jhipster-core/blob/master/lib/utils/object_utils.js#L47

JHipster Version(s)
jhipster@0.0.0 C:\projects\teest\jhipster-error
`-- generator-jhipster@6.1.2  -> C:\projects\kaido-github\generator-jhipster
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.mycompany.myapp",
      "nativeLanguage": "et"
    },
    "jhipsterVersion": "6.1.2",
    "applicationType": "monolith",
    "baseName": "jhipster",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "gradle",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": true,
    "nativeLanguage": "et",
    "languages": ["et"]
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
/**
 * not an ignored comment
 */
entity Location {
  streetAddress String,
  postalCode String,
  city String,
  stateProvince String
}
/**
 * Task entity.
 * @author The JHipster team.
 */
entity Task {
  title String,
  description String
}
/**
 * The Employee entity.
 */
entity Employee {
  /**
   * The firstname attribute.
   */
  firstName String,
  lastName String,
  email String,
  phoneNumber String,
  hireDate Instant,
  salary Long,
  commissionPct Long
}
entity Region {
  regionName String
}
entity Country {
  countryName String
}
entity Department {
  departmentName String required,
  departmentDescription String
}
entity Job {
  jobTitle String,
  minSalary Long,
  maxSalary Long
}
entity JobHistory {
  startDate Instant,
  endDate Instant,
  language Language
}
enum Language {
  FRENCH,
  ENGLISH,
  SPANISH
}

relationship OneToOne {
  Location{country} to Country,
  Country{region} to Region,
  Department{location} to Location,
  JobHistory{job} to Job,
  JobHistory{department} to Department,
  JobHistory{employee} to Employee
}
relationship OneToMany {
  /**
   * A relationship
   */
  Department{employee} to Employee{department},
  Employee{job} to Job{employee}
}
relationship ManyToOne {
  Employee{manager} to Employee
}
relationship ManyToMany {
  Job{task(title)} to Task{job}
}

service Location, Task, Region, Country, Department, JobHistory with serviceImpl
paginate Employee, JobHistory with infinite-scroll
paginate Job with pagination

Environment and Tools

java version "1.8.0_211" Java(TM) SE Runtime Environment (build 1.8.0_211-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

git version 2.21.0.windows.1

node: v10.15.3

npm: 6.9.0

yeoman: 2.0.6

yarn: 1.15.2

Docker version 18.09.2, build 6247962

docker-compose version 1.23.2, build 1110ad01

Browsers and Operating System

Windows 10