Roaster - Missing or improving ?
by Antonio Goncalves
Hi,
Still playing with Roaster so I could fix
https://issues.jboss.org/browse/FORGE-1618 (Command
constraint-new-validator to create a new validator implementation). I don't
know how to do two things (nicely) :
*# Parameterize interface*
For a constraint, I need to implement a parametrize interface like this :
public class MaxValidatorForString implements ConstraintValidator<Max,
Number> {
The only way I could find is passing a String :
final JavaClassSource javaClass = Roaster.*create*(JavaClassSource.class);
javaClass.setName("MaxValidatorForString");
javaClass.addImport(ConstraintValidator.class);
javaClass.addInterface("ConstraintValidator<Max, Number>");
It's a shame because with addInterface(Class), it does the import
automatically and things are more typed. But I cannot add types :
final JavaClassSource javaClass = Roaster.*create*(JavaClassSource.class);
javaClass.setName("MaxValidatorForString");
javaClass.addInterface(ConstraintValidator.class);
It would be good to have something like :
javaClass.addInterface(ConstraintValidator.class).
addType(Max.class).addType(Number.class);
*# Typed parameters*
My isValid method takes two parameters. And the only way to add two
parameters seems to be by a String
javaClass.addMethod().setPublic().setName("isValid").setReturnType("boolean"
).setParameters("Number value, ConstraintValidatorContext
context").setBody("return
false;").addAnnotation(Override.class);
Again, it would be nice to have typed parameters so the import is implicit,
and things are a bit more typed :
javaClass.addMethod().setPublic().setName("isValid").setReturnType("boolean"
).addParameter(Number.class,
"value").addParameter(ConstraintValidatorContext.class,
"context").setBody("return
false;").addAnnotation(Override.class);
So I'm just wondering if I'm missing something or this is not implemented
yet on Roaster
--
Antonio Goncalves
Software architect and Java Champion
Web site <http://www.antoniogoncalves.org/> |
Twitter<http://twitter.com/agoncal>
| LinkedIn <http://www.linkedin.com/in/agoncal> | Paris
JUG<http://www.parisjug.org/>
| Devoxx France <http://www.devoxx.fr/>
10 years, 6 months
[Roaster] Don't know how to add an annotation inside another one
by Antonio Goncalves
Hi,
This is a Roaster question. I've been trying to create a Bean Validation
constraint properly... in vain. What I want to achieve is the following
(notice the @List annotation) :
@Target({*METHOD*, *FIELD*, *ANNOTATION_TYPE*, *CONSTRUCTOR*, *PARAMETER*})
@Retention(*RUNTIME*)
@Documented
@Constraint(validatedBy = {})
*public *@*interface *Email {
String message() *default **"wrong email address"*;
Class<?>[] groups() *default *{};
Class<? *extends *Payload>[] payload() *default *{};
@Target({*METHOD*, *FIELD*, *ANNOTATION_TYPE*, *CONSTRUCTOR*, *PARAMETER*
})
@Retention(*RUNTIME*)
@*interface **List* {
Email[] value();
}
}
This is the code I've written. Both annotation are generated separately...
but I don't know how to add listAnnotation inside emailAnnotation. Any idea
?
Thanks
public class Main {
public static void main(String[] args) {
// This is the inner annotation List
final JavaAnnotationSource listAnnotation =
Roaster.create(JavaAnnotationSource.class);
listAnnotation.setName("List");
listAnnotation.addAnnotation(Retention.class).setEnumValue(RUNTIME);
listAnnotation.addAnnotation(Target.class).setEnumValue(METHOD,
FIELD, PARAMETER, TYPE);
listAnnotation.addAnnotationElement("Email[] value()");
System.out.println(listAnnotation);
// This is the annotation @Email
final JavaAnnotationSource emailAnnotation =
Roaster.create(JavaAnnotationSource.class);
emailAnnotation.setPackage("org.agoncal.proj.constraints").setName("Email");
emailAnnotation.addImport(Payload.class);
emailAnnotation.addAnnotation(Documented.class);
emailAnnotation.addAnnotation(Retention.class).setEnumValue(RUNTIME);
emailAnnotation.addAnnotation(Target.class).setEnumValue(METHOD,
FIELD, PARAMETER, TYPE);
emailAnnotation.addAnnotation(Constraint.class).setLiteralValue("validatedBy",
"{}");
emailAnnotation.addAnnotationElement("String message() default
\"wrong email address\"");
emailAnnotation.addAnnotationElement("Class<?>[] groups() default {}");
emailAnnotation.addAnnotationElement("Class<? extends
Payload>[] payload() default {}");
// I was expecting to have a method like that so I
could add annotation inside another one
// emailAnnotation.addAnnotationElement(emailAnnotation);
System.out.println(emailAnnotation);
}
}
--
Antonio Goncalves
Software architect and Java Champion
Web site <http://www.antoniogoncalves.org/> |
Twitter<http://twitter.com/agoncal>
| LinkedIn <http://www.linkedin.com/in/agoncal> | Paris
JUG<http://www.parisjug.org/>
| Devoxx France <http://www.devoxx.fr/>
10 years, 8 months
Converting a Forge 1.4.x plugin to Forge 2.3.+
by Lennart Jörelid
Good morning, all.
It seems that the Forge community has been hard at work to refactor the
Forge 1.x structure to Forge 2. Well done.
I would simply like to migrate a decently complex add-on to Forge 2,
implying I would want to find a solid step-by-step tutorial on how I should
proceed. However, all of the documentation I have been able to find so far
pertains to Forge1. While I feel I'm most likely missing something
fundamental here, there may be other folks in the same position. So...
1. Where can I find a step-by-step tutorial on how to develop and test a
Forge2 plugin which accesses Maven libraries and Forge libraries?
2. Where can I find a cookbook on what functionality different APIs
provide? For example:
1. My *new-nazgul-project *add-on needs to create or use an existing
project structure, implying that it must detect if a project
exists and has
the correct Maven GAV structure, some internal structure details and the
correct parent. I used to do this with a mix of Maven and Forge 1.x
functionality, but I wonder how I can find out how to do this under Forge
2.x
So ... I used to use the following resources to create directories, analyze
POMs and generate resources. Of course, all is doable using raw JDK and
Maven APIs, but likely much simpler with Forge APIs.
// Internal state
protected Shell shell;
protected ProjectFactory projectFactory;
protected ResourceFactory resourceFactory;
--
--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: lj(a)jguru.se
| URL: www.jguru.se
| Phone
| (skype): jgurueurope
| (intl): +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+
10 years, 9 months
GSoC project idea: Create Tattletale plugin for Eclipse
by Dejan Simeonov
Hi Forge team, Hi George,
Let me briefly introduce myself:
My name is Dejan Simeonov, and I am final-year student of Faculty of
Organizational Sciences, University of Belgrade, Serbia.
I have experience with Java, PHP, HTML and CSS, SVN, GIT... I am familiar
with Eclipse and several open-source tools for Statistic Code analysis as
Eclipse and Hudson plugins.
Currently I am learning about Maven and Eclipse Plugins implementation.
And I would like to participate as a student in Google Summer Of Code 2014.
Several days ago I proposed my ideas for GSoC to Jonathan, JBoss's GSoC
mentor. We talked about them and he advised me to review one of them with
you, Forge team, hopefully to help me with the concrete details and
specification.
One of tools I used is Tattletale. I found it very useful for
investigating dependencies inside the project and to discovering unused
jars.
I used it as command line and Maven plugin, but I think it could be even
more useful as Eclipse plugin. So, idea is:
Create Tattletale plugin for Eclipse
Lot of tools have plugin for Eclipse. (Findbugs, PMD...). Tattletale plugin
for Eclipse still does not exist, but this way it should be easier to use
comparing to usage trough console . Tattletale tool could be used as engine
for this plugin. The basic plugin implementation could display standard
Tattletale HTML report inside the Eclipse, but some sub reports like
"Unused Jar" or "Multiple Jar files" could "mark" some referenced libraries
displayed in the Eclipse controls and highlight them for the removal.
I investigate a little and I found that developers like to periodically
use the Tattletale tool to review dependencies inside the project, to
remove unused ones and this way, to keep projects 'fit'.
This option could be one of the main feature of the future plugin.
Other things this plugin should be able to do are (several ideas):
- Tattletale tool requires that all dependencies should be placed in the
same folder. Tattletale Eclipse plugin should be able to automatically
recognize all libraries referenced by the Eclipse project, like jars
inside the project, external jars and Maven dependencies.
- This plugin should include compiled classes of current Eclipse project
into report. Dependent eclipse project should be included, too. This way,
developer does not have to create build(all jars) to create the valid
Tattletale report.
- Mark Duplicated class in the Project Explorer(Multiple Locations
report should be used). This is possible, Eclipse API supports this,
Findbugs plugin can do it.
- Mark Unused JAR files in the Project Explorer's Referenced Libraries
node(Unused Jars report should be used). Currently, I do not know is this
possible.
- This plugin should be able to create and open default HTML report in
Eclipse plugin. This report could allow to navigate to particular class
listed in it using CTRL+LeftClick. Currently Tattletale does not support
this.
- Graphical dependencies report should work "out of the box"
- We could add options like "Remove unused dependencies", "Eliminate Jar
files with different versions", but this should be discussed. This tool
could have only "advisory" nature and could manage class-path for Maven and
Eclipse Java projects. I am not sure should we provide potentially risky
options which are managing eclipse project class-path?
- This plugin could be displayed in the new "Tattletale Eclipse
perspective".
I should ask you if someone is interested to become a GSoC mentor for this
project, to finish it together?
In this case, I could try implement prototype of this plugin with basic
options as part of the GSoC proposal evaluation process.
I think I can finish this plugin, and this project seems as great
opportunity to me, first, to create an useful tool which will be widely
used as part of Eclipse and to gain more experience in lot of open-source
tools.
Please, feel free to ask if you have any questions, Any comment or
suggestions is appriciated.
Best Regards,
Dejan Simeonov
10 years, 9 months
Integrated F2 Console on Windows
by Koen Aers
Guys,
Setting the terminal to a POSIXTerminal in the ShellImpl constructor did the trick. I also had to update the Aesh dependency to 0.51-SNAPSHOT on the shell add-on to include a necessary fix in POSIXTerminal to make it all work.
So I guess Stale needs to do a new Aesh release as well before Forge 2.2.1.Final can be released with all the stuff needed for JBT 4.2.0.Beta1.
See you tomorrow!
Cheers,
Koen
10 years, 9 months
JBoss modules doesn't load CORBA (lol)
by Ivan St. Ivanov
Hi folks,
This is more a JBoss Modules question, but I decided to start here first ;)
A colleague of mine is writing a Forge 1 plugin that uses SAP's APIs to
deploy ear files to the NetWeaver server. And he gets a weird
ClassNotFoundException for the class javax.rmi.CORBA.Tie. It is used by our
APIs for performing remote connections.
We rewrote his plugin to Forge 2 addon and we got the same exception again.
Here is the JBoss Modules specific part of the exception trace, although I
don't think it is quite useful:
Caused by: java.lang.ClassNotFoundException: javax.rmi.CORBA.Tie from
[Module
"com.sap.nw.deploy.forge.nwdeploy:1.0.0-SNAPSHOT_d5a54a79-5d83-4f31-bc98-1d6384c4df1c"
from AddonModuleLoader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
at
org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443)
at
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431)
at
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373)
at
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118)
... 83 more
I de-compiled the SAP code that blows up and at the row where the exception
is thrown, I see the following:
this.out = new MarshalOutputStream(new ByteArrayOutput(this.offset));
The MarshalOutputStream class is from SAP APIs as well and it has in its
imports javax.rmi.CORBA.Tie.
Can you think of a reason why JBoss Modules would have a problem loading a
class that is part of the standard JDK?
Thanks,
Ivan
10 years, 9 months