Class KeySetGeneratorMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
com.easydesk.localization.maven.KeySetGeneratorMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="generate", defaultPhase=GENERATE_SOURCES, threadSafe=true) public class KeySetGeneratorMojo extends org.apache.maven.plugin.AbstractMojo
resource bundle(.properties) 의 key 들로 enum (예: L10NKey) 을 만든다.

한 번 실행(execution)에 enum 하나를 만든다. key 를 고르는 방법:

  • defaultLocaleFile / defaultLocaleFiles : key 를 읽을 기본 locale bundle 파일(들)
  • includes : (선택) key 이름 정규식. 예: Email.*
  • keysFile : (선택) key 목록 파일 (한 줄에 하나, # 주석). 있으면 이 목록의 key 만, 이 순서대로 쓴다. bundle 에 없는 key 는 경고를 남기고 건너뛴다.
keysFile 이 없으면 key 이름순으로 쓴다.

template(src/main/template/L10NKey.java) 의 표시를 채운다:

  • @@PACKAGE@@, @@CLASS@@ : className 의 package / class 이름
  • @@SOURCE@@ : key 를 읽은 bundle 파일 이름 (설명용)
  • @@CONSTANTS@@ : key 마다 enum 상수 (이름은 key 를 대문자 + '_' 로 바꾼 것, 예: MovedFromItemDescription -> MOVED_FROM_ITEM_DESCRIPTION)
  • @@KEYS@@ : 상수 순서대로 실제 bundle key 문자열 (enum 의 toString() 이 이 값을 돌려준다)
결과는 target/generated-sources/l10n 에 쓰고 그 폴더를 compile source root 로 추가한다 (source tree 에는 쓰지 않는다). 내용이 같으면 파일을 다시 쓰지 않는다.

Java identifier 로 쓸 수 없는 key (예: AcceptMemberShip.vm.Title) 는 경고를 남기고 건너뛴다. 바꾼 상수 이름이 앞의 key 와 겹치면 (예: FRI 와 Fri) 뒤의 key 는 key 이름을 그대로 상수 이름으로 쓴다 (L10NKey.Fri).

Author:
YounghoCho
  • Field Summary

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KeySetGeneratorMojo

      public KeySetGeneratorMojo()
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException