ROASTER: Using the formatter (feedback)
by forge-users@lists.jboss.org
I have tried to use the Formatter with a custom format (modifications introduced with ROASTER-37 (https://issues.jboss.org/browse/ROASTER-37)):
Formatter.format(Properties, JavaClassSource)
Here some findings / information:
h2. 1/ Obtain the Properties object
When you export the Java Formatter format from Eclipse (see screenshot), you obtain an xml file. The settings contained in the file are correct (setting tag: id attribute & value attribute) but I think that the format is not suitable.
Alternative is to check the /.settings/org.eclipse.jdt.core.prefs of your java project (if you have checked the “Enabled project specific settings” in the project preferences, the current formatter settings will also be stored there).
I my opinion this file contains too much entries (non jdt-formatter stuff), but the format is suitable and it can be loaded into a java.util.Properties object.
Here is how (based on google guava):
//imports: com.google.common.io.Files, com.google.common.base.Charsets
//propFile is a java.io.File
BufferedReader inputStream = Files.+newReader+(propFile, Charsets.+UTF_8+);
Properties prop = *new* Properties();
1. prop.load(inputStream);
If you want to do some cleanup, you can extract the lines from the org.eclipse.jdt.core.prefs file into a roaster_formatter.properties file. Basically you will need the lines starting with org.eclipse.jdt.core.formatter. The keys are defined in this Javadoc: DefaultCodeFormatterConstants (http://help.eclipse.org/luna/topic/org.eclipse.jdt.doc.isv/reference/api/...).
h2. 2/ Make the formatter working: set the version of the java source
I noticed that my formatter was not working with all my JavaClassSource classes.
After a long debug session, I found out why it was not working.
A breakpoint in RecordedParsingInformation.updateRecordedParsingInformation(CompilationResult) shows that is some cases, compilationResult.problems is not null:
Pb(596) Syntax error, annotations are only available if source level is 1.5 or greater
The JDT cannot compile a file that cannot be parsed. It took me a while to understand how to set the source level. If you do nothing, the method DefaultCodeFormatter.getDefaultCompilerOptions() sets the version to "1.3". Here the corresponding code snippet:
Object sourceOption = *this*.options.get(CompilerOptions.OPTION_Source);
*if* (sourceOption != *null*) {
*this*.defaultCompilerOptions.put(CompilerOptions.OPTION_Source, sourceOption);
} *else* {
*this*.defaultCompilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
}
To set the version to another version (1.7 for example), just add the line in your properties file:
org.jboss.forge.roaster._shade.org.eclipse.jdt.core.compiler.source=1.7
I am not sure why this org.jboss..._shade prefix is necessary, but without this prefix, it is not working. This might be related with ROASTER-12 (https://issues.jboss.org/browse/ROASTER-12).
h2. 3/ Side-note: Formatter.format(Properties, JavaClassSource) calls the formatter twice.
The current implementation of org.jboss.forge.roaster.model.util.Formatter.format(Properties, JavaClassSource) calls the JDT Formatter twice.
The implementation looks like this:
/**
* Format the given {@link JavaClassSource}, using the given Eclipse code format {@link Properties}.
*/
*public* *static* String format(Properties prefs, JavaClassSource javaClass)
{
*return* +format+(prefs, javaClass.toString());
}
A break point at the beginning of the private method: Formatter._format(String, CodeFormatter) shows why:
- First call: because of the AbstractJavaSource#toString() implementation. The class gets formatted with the default settings.
- Second call: the expected one.
I hope this feedback is useful for other developers using roaster.
Posted by forums
Original post: https://developer.jboss.org/message/908059#908059
10 years, 1 month
wildfly plugin not working ?
by forge-users@lists.jboss.org
Hi,
I've installed the Wildfly plugin from
http://forge.jboss.org/addon/org.jboss.forge.addon:as
into JBoss Dev Studio 8.1, running embedded Forge 2.12.1 final. The install worked fine.
The as-setup command appears to work fine too.
But as-deploy returns an error of;
***ERROR*** No running JBoss Application Server could be found at 'localhost:9990'.
when there is in fact a running JBoss - I checked that I can connect with telnet
Tested with Wildfly 8.1 - same result.
What is the best approach to debug this ?
Thanks,
Posted by forums
Original post: https://developer.jboss.org/message/908518#908518
10 years, 1 month
@Option explanations please
by forge-users@lists.jboss.org
Hi,
I'm currently writing an article about Forge addons.
I'm beginning to write an addon, with @Command to start slowly and get the reader hooked.
I'm a bit puzzled with the behaviour of @Option .
Attribute "value" is mandatory, OK but if I define a value, it is not displayed. Why ??
The defaultValue has to be defined so it is displayed.
What are value and defaultValue for ?
How do they interact together ?
About the 'type' attribute. Is there other types than String supported ?
Integer and Long seem not to be recognized (or enforced).
Thank you
Jérôme
Posted by forums
Original post: https://developer.jboss.org/message/908979#908979
10 years, 1 month