Программный экспорт XML профиля профиля eclipse в .prefs - PullRequest
0 голосов
/ 29 мая 2018

Моя команда использует соглашения о форматировании кода, определенные в XML-файле профиля затмения, который выглядит примерно так:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="This Team's Formatting Convention"  version="12">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
...

Я использую eclipse в качестве средства форматирования командной строки, используя следующую команду:

eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
    -config ${JAVA_FORMATTER_CONFIG_FILE} ${*}

Работает только в том случае, если ${JAVA_FORMATTER_CONFIG_FILE} - это файл настроек затмения с именем файла, таким как org.eclipse.jdt.core.prefs и содержимым:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

Как программно получить файл .prefs безвручную импортировать профиль XML из пользовательского интерфейса eclipse?

1 Ответ

0 голосов
/ 30 мая 2018

Из рабочей среды Eclipse Oxygen,

  • Экспорт текущих настроек: Файл -> Экспорт -> Настройки
  • Выбрать "Java CodeНастройки стиля "
  • Выберите имя и место назначения и сохраните (кажется, необходимо использовать расширение .epf)

Файл будет содержать (среди прочего) пользовательскую конфигурацию fomatter

/instance/org.eclipse.jdt.ui/formatter_profile=_my-java-formatter
/instance/org.eclipse.jdt.ui/formatter_settings_version=13
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.formatterprofiles=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<profiles version\="13">\n<profile kind\="CodeFormatterProfile" name\="my-java-formatter" version\="13">\n...
...

Затем вы можете запустить Formatter как

eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -config eclipse-formatter.epf Test.java

Вывод:

org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized.  Will retry after the state location is initialized.
org.eclipse.m2e.logback.configuration: Logback config file: /home/luis/eclipse-workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.8.3.20180227-2137.xml
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundleresource://496.fwk1538849250:1/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundleresource://496.fwk1538849250:2/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
org.eclipse.m2e.logback.configuration: Initializing logback
Configuration Name: eclipse-formatter.epf
Starting format job ...
Done.

Экспорт настроек выполняется один раз, после чего вы можете поделиться eclipse-formatter.epf файлом,Надеюсь, это поможет.

...