GithubHelp home page GithubHelp logo

forge-formatter-plugin's Introduction

Forge Formatter Plugin

Build Status

As much as Forge is a great tool - the code it generates is usually not in your preferred code styling. This plugin is intended to help you getting source code nice and readable after generation, in the way you want it.

The formatter plugin currently supports only Java source formatting. Other file formats might be added in a later version.

Installation

The formatter plugin is currently installable from this github repository. Start Forge and run

forge git-plugin git://github.com/thomashug/forge-formatter-plugin.git

Usage

Once you have the plugin installed you can simply execute

formatter ${path_to_file}.java

This will format your Java file based on the Sun coding conventions. You can also format a complete folder with

formatter ${path_to_parent_folder}

Or even more, format a folder recursively with

formatter ${path_to_parent_folder} --recursive

Formatting Options

The Forge formatter plugin supports several predefined formatter settings. To use one of them, execute the formatter command with the following option:

formatter ${path_to_file}.java --configName [Sun|Eclipse|JBoss]

Using this option each time you want to format a file is quite inconvenient. You can configure your project to use a specific formatter profile every time you format a file with the following setup command:

formatter setup --configName [Sun|Eclipse|JBoss]

Custom Formatter Settings

You can also use customer formatter settings by exporting a configuration from Eclipse. Save the XML under your project and use the following command to set it as default for your project:

formatter setup ${path_to_config}.xml

All following formattings will use the custom formatter config file.

Comments

Sometimes you spend a while formatting JavaDoc to reflect the HTML output. Then the formatter comes and screws it all up - something we want to spare you from. Disable comment formatting with the following flag:

formatter setup ... --skipComments # persist the setting
formatter --skipComments           # one time skip on the formatter command

Sample

Create a new project:

[no project] projects $ new-project --named test

Create an Eclipse formatting file with your preferred coding style and copy it into your project root (or similar location):

[test] test $ ls
eclipse-formatter.xml    pom.xml                  src/                     
[test] test $ formatter setup eclipse-formatter.xml
Wrote test/src/main/resources/META-INF/forge.xml

Your formatter settings get stored in the forge.xml config file. Create now e.g. a JPA entity and use the formatter:

[test] test $ persistence setup --provider HIBERNATE --container JBOSS_AS7
...
[test] test $ entity --named Test --package org.jboss.forge.model

Check the generated code:

[test] Test.java $ less .

And now format it:

[test] Test.java $ formatter .

This should match now with the formatting conditions you've put into the Eclipse formatter file.

forge-formatter-plugin's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

luiz158

forge-formatter-plugin's Issues

Allow excluding comments from formatting

Formatting comments can sometimes be very annoying. There should be a flag in the format command, as well as an option in the setup command that stores the flag persistently in the config.

Enable Autoformatting

Would require receiving ResourceEvents, seems not to be working for plugins (yet).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.