MBG with maven : merging java generated files

492 views
Skip to first unread message

Yoel Benharrous

unread,
Dec 2, 2011, 8:54:53 AM12/2/11
to mybatis-user
Dear All,

For My project I use MyBatisGenerator.
I create a profil to generate source in src/main/java and not generate-source phase
because I want to modify Java generated object.
(if only partial class as in C# existed ... ;) )

But, with maven Java object are not merged.

There is someone who has an implementation of  : org.mybatis.generator.api.ShellCallback doing the stuff?

before coding something...

If no implementation exist, community is interresting to have this kind of features.

Thanks for feed back

 




Jeff Butler

unread,
Dec 2, 2011, 9:37:55 AM12/2/11
to mybati...@googlegroups.com
Java merge only happens when using the Eclipse plugin - not maven.

This is, hopefully, well documented.

Jeff Butler

Yoel Benharrous

unread,
Dec 2, 2011, 9:41:51 AM12/2/11
to mybati...@googlegroups.com
Is it possible to extend the maven plugin for merging?



2011/12/2 Jeff Butler <jeffg...@gmail.com>

Jeff Butler

unread,
Dec 2, 2011, 9:48:46 AM12/2/11
to mybati...@googlegroups.com
Sure - anything's possible given enough time and money :) But it is a
big job. You'll need to write a Java parser and AST generator.

On Fri, Dec 2, 2011 at 9:41 AM, Yoel Benharrous

Iwao AVE!

unread,
Dec 2, 2011, 11:56:32 AM12/2/11
to mybati...@googlegroups.com
Hi,

Actually, I was just trying to make the java merge functionality
available in non-Eclipse environment.The AST parser used in generator
eclipse plugin can be used outside Eclipse with appropriate
dependencies added.
I just did a few simple test, but it seems to be working.

Here's what I did:
1. Build modified version of generator binary.
1-1. Copy merge-related files from generator eclipse plugin project.
You will need the three files in the following directory.
http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/org.mybatis.generator.eclipse.core/src/org/mybatis/generator/eclipse/core/merge/
1-2. Edit the DefaultShellCallback as follows
* change #isMergeSupported() to return true.
* change #mergeJavaFile() method: instead of throwing
UnsupportedOperationException, add the following lines (copied from
EclipseShellCallback.java).  JavaFileMerger merger = new
JavaFileMerger(newFileSource, existingFileFullPath, javadocTags,
fileEncoding);  return merger.getMergedSource();
1-3. Add the following dependency to the pom.xml (other dependencies
seems to be automatically loaded).<dependency>
<groupId>org.eclipse.jdt</groupId>  <artifactId>core</artifactId>
<version>3.3.0-v_771</version></dependency>
1-4. Build generator jar with 'mvn clean package'.
2. Run generator with dependencies. I executed the following command.
You will find the eclipse-related jars somewhere under the
$M2_REPO/org/eclipse/ directory.
java -cp mybatis-generator-core-1.3.2-SNAPSHOT.jar:core-3.3.0-v_771.jar:text-3.3.0-v20070606-0010.jar:runtime-3.3.100-v20070530.jar:common-3.3.0-v20070426.jar:osgi-3.3.0-v20070530.jar:resources-3.3.0-v20070604.jar:jobs-3.3.0-v20070423.jar:contenttype-3.2.100-v20070319.jar:preferences-3.2.100-v20070522.jar
org.mybatis.generator.api.ShellRunner -configfile GeneratorConfig.xml
As I am a happy Eclipse user myself, it would be great if you test
these steps and give us a feedback.

Regards,Iwao
2011/12/2 Jeff Butler <jeffg...@gmail.com>:

Iwao AVE!

unread,
Dec 2, 2011, 12:04:50 PM12/2/11
to mybati...@googlegroups.com
Sorry about the line wrapping.
Let me try again.

1. Build modified version of generator binary.

1-1. Copy merge-related files from generator eclipse plugin project.
You will need the three files in the following directory.
http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/org.mybatis.generator.eclipse.core/src/org/mybatis/generator/eclipse/core/merge/

1-2. Edit the DefaultShellCallback as follows

* change #isMergeSupported() to return true.

* change #mergeJavaFile() method: instead of throwing
UnsupportedOperationException, add the following lines (copied from
EclipseShellCallback.java).  JavaFileMerger merger = new
JavaFileMerger(newFileSource, existingFileFullPath, javadocTags,
fileEncoding);  return merger.getMergedSource();

1-3. Add the following dependency to the pom.xml (other dependencies
seems to be automatically loaded).

<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>core</artifactId>
  <version>3.3.0-v_771</version>
</dependency>

1-4. Build generator jar with 'mvn clean package'.

2. Run generator with dependencies. I executed the following command.

You will find these jars somewhere under the $M2_REPO/org/eclipse/

Jeff Butler

unread,
Dec 2, 2011, 12:33:27 PM12/2/11
to mybati...@googlegroups.com
That is super cool. My only concern about doing this in the committed
code is that the versions of Eclipse in maven are over 4 years old.
Do you happen to know if Eclipse has any formal statement about
putting their artifacts in Maven?

Jeff Butler

Iwao AVE!

unread,
Dec 2, 2011, 1:08:05 PM12/2/11
to mybati...@googlegroups.com
Jeff,

2011/12/3 Jeff Butler <jeffg...@gmail.com>:


> That is super cool.  My only concern about doing this in the committed
> code is that the versions of Eclipse in maven are over 4 years old.

Yes, it's a shame.
I am looking for some information as someone must have asked or
requested it before.

> Do you happen to know if Eclipse has any formal statement about
> putting their artifacts in Maven?

I think EPL permits it, but it needs to be clarified.
I'll search about it too, but if anyone on this list knows about the
stuff, please share it with us.

Regards,
Iwao

Jeff Butler

unread,
Dec 2, 2011, 1:10:34 PM12/2/11
to mybati...@googlegroups.com
I did some reading here:

http://wiki.eclipse.org/Maven

and in the associated bugzilla tickets. It seems that Eclipse has
been working on doing a Maven push of their artifacts for a couple
years. The technical issues seem to be related to converting their
OSGi based component structure into something that is Maven compliant.

Once they have this working it will make it possible for us to make
the Java code merge more widely available. That would be a good
thing!

Jeff Butler

Iwao AVE!

unread,
Dec 2, 2011, 2:11:23 PM12/2/11
to mybati...@googlegroups.com
Jeff,

Thanks for the link.
Let's hope they make it work soon!

And for those who are willing to try the steps I wrote, I found that
their testing repository contains newer version.
So in the step 1-3, add the following 'repositories' entry and the
dependency to the pom.xml.

<repositories>
<repository>
<id>eclipse-testing</id>
<name>Eclipse Testing Repository</name>
<url>http://maven.eclipse.org/nexus/content/repositories/testing/</url>
</repository>
</repositories>

<dependency>
    <groupId>org.eclipse.jdt</groupId>
    <artifactId>org.eclipse.jdt.core</artifactId>
    <version>3.6.2</version>
</dependency>

Regards,
Iwao

2011/12/3 Jeff Butler <jeffg...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages