Skip to main content

ADF Maven : A little bit of mojo Model project

I was testing the much improved maven stuff in Jdev for my ADF project and found a couple of differences in my produced jar and the ADF ojdeploy produced one.

First I needed to include the xml, jpx and properties stuff in my jar in the build\resources tag:


<resource>     <directory>src/</directory>      <includes>       <include>**/*.xml</include>        <include>**/*.jpx</include>       <include>**/*.xcfg</include>       <include>**/*.properties</include>     </includes> </resource>
Then I needed the adfm.xml and oracle.adf.common.services.ResourceService.sva files all the other files where just text files so I am ignoring them for now.

So for this I created a mojo plugin and included it in my build step

 

      <plugin>         <groupId>za.co.test.plugins</groupId>
        <artifactId>my-plugins</artifactId>
       <version>1.0-SNAPSHOT</version>
        <executions>
          <execution>
            <phase>compile</phase>             <goals>               <goal>adfJarMetadataGenerator</goal>             </goals>           </execution>         </executions>       </plugin>



Onto the plugin:
Create a new maven project in Jdev and make surte the packaging is of type maven-plugin.

Then create a java class (your mojo) and extend org.apache.maven.plugin.AbstractMojo
The @goal sudo annotation denotes the name of your plugin that you will use in the calling project.

/**
 * This should generate the extra meta data for adf jar projects.
 * @goal adfJarMetadataGenerator
 * @phase compile
 */
public class ADFClassMetaDataGenerator extends AbstractMojo {

The @parameter annotation denotes and xml tag that you can pass data to your mojo from the calling project.http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

/**
 * @parameter
 */
private String adfmFileName = "classes/adfm.xml";
/**
 * @parameter  expression="${project.build.sourceDirectory}"
 */
private File srcDirectory = new File("src/");
 /**
 * @parameter
 */
private String svaFileName = "classes/oracle.adf.common.services.ResourceService.sva";


You then need an   public void execute() throws MojoExecutionException { method.
This will go though your project and find the location of your Model.jpx file and your bc4j.xcfg this will allow you to generate the adfm.xml.

adfm.xml
      StringBuilder adfmBuilder =
        new StringBuilder("\n").append("\n").append("  
          bc4jFormatName).append("\"/>\n").append("
          "\"/>\n").append("
\n");


Then parse the Model.jpx to find all the application modules for the ResourceService.sva.

oracle.adf.common.services.ResourceService.sva
StringBuilder svaBuilder =  new StringBuilder("#:__PROLOG__:ADF_LibraryDependencies:!;ADF_DataControl:ADF_BusComps\n");
      //for each data control
for(DataControl dc : dcs) {
svaBuilder.append("#:ADF_DataControl:oracle.adf.library.rc.appmodules.AppModuleURLDescriptor:0,").append(dc.getAmName()).append(",").append(dc.getDataContolName()).append(",").append(dc.getFormattedJpxFileName()).append("\n");
      }
      svaBuilder.append("#:__EPILOG__:\n").append("oracle.adf.library.rc.dependencies.LibDepsServiceStrategy ADF_LibraryDependencies\n").append("oracle.adf.library.rc.dcxdatacontrols.DataControlServiceStrategy ADF_DataControl\n").append("oracle.adf.library.rc.buscomp.BusCompServiceStrategy ADF_BusComps\n");

Then just create these files and you are done.

Do a clean install and you can now use the generator in any of your projects.

Note: This is still a work in progress hopefully I get time to finish it off and I will publish the plugin. But it should give you a good idea of what to do.

Comments

  1. Great post!
    BTW, does your mojo have any dependency to Oracle ADF library?
    Have you made any progress after this post? If so, is there any chance you could make it available?
    Thanks a lot.

    ReplyDelete
    Replies
    1. Sorry I did not get any further - project timelines did not allow and I am on a different project now.

      Hopefully I will get back to this at some stage though then I will let you know.

      Delete
    2. Not a problem.
      Would you mind making make the current code available anyway? I would like to see how you've obtained the data control objects via API.
      Any help will be appreaciated.

      Regards.

      Delete
    3. Email me at the email address on my profile and I will see what I can do.

      Delete

Post a Comment

Popular posts from this blog

ADF sort of generic screen for tables with the same structure

We have a couple (about a hundred) of tables with the same structure (Code, Description, Create Date, Update Date). So I wanted to do something simple so that I did not have to create all these screens 1) EO   I created the EO based on one of the tables I had that had the above columns. I then Added a transient attribute called table name to my EO based on a groovy expression. (the expression needs to change as I am reading web tier stuff from the model layer but I will fix this later) I then generated a java class for my EO. And added the following overriden method to my newly created java class. protected StringBuffer buildDMLStatement(int i, AttributeDefImpl[] attributeDefImpl,   AttributeDefImpl[] attributeDefImpl2, AttributeDefImpl[] attributeDefImpl3, boolean b) {   StringBuffer statement = super.buildDMLStatement(   i, attributeDefImpl, attributeDefImpl2, attributeDefImpl3, b); return new StringBuffer(StringUtils.replace(statement.to...

Util code

public static MethodExpression getMethodExpression( String expr, Class returnType, Class[] argTypes){ FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); ExpressionFactory elFactory = fc.getApplication().getExpressionFactory(); return elFactory.createMethodExpression( elctx, expr, returnType, argTypes); } public static javax.faces.el.MethodBinding getMethodBinding( String expr, Class[] argTypes){ FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); return fc.getApplication().createMethodBinding(expr, argTypes); } SetPropertyListener listener = new SetPropertyListener( ActionEvent.class.getName()); listener.setFrom(link.getRoute()); listener.setValueExpression("to", JSFUtils.getValueExpression("#{pageFlowScope.route}", String.class)); action.addActionListener(listener); AdfFacesContext.getCurrentInstance().getPageFlowScope() .put("route", lin...

MANIFEST.MF merge JDeveloper for an executable jar

Goto your project > properties. Then click on deployment in the menu. Edit or add a jar deployment profile. Fill in the details under jar options (select Include manifest and give it a main class name) Also remember that the merge functionality only works with a BLANK line at the end of the merge file. REALLY this caught me. My merge file contents: Class-Path: commons-codec-1.3.jar [...empty line here CRLF...]