Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Tutorial: Creating JDeveloper Audit Rules - Part 4

Bob Rhubart-OracleFeb 13 2015 — edited Apr 27 2015

By Oracle ACE Director Wilfred van der Deijl and Oracle ACE Richard Orlichs

Continued from Part 3

7. Distribute the Extension

Now that you know how to create rules in your extension project, it's time to share your extension project with the rest of the world. However, you don't want to spam everyone every time there is an update. Luckily, we can automate by creating an Update Center.

7.1 Creating a bundle.xml

The first thing we're going to do is to create a bundle.xml with the information about this extension. We're going to create an XML file in the Extension project:

vanderdeijl-auditrule-fig123.jpg

Select XML and then XML Document:

vanderdeijl-auditrule-fig124.jpg

Call it bundle.xml and click OK:

vanderdeijl-auditrule-fig125.png

This bundle contains certain information about your project. It starts with properties like name, version, author, and description. You can add information about yourself and the extension in this section. As a starting point, you can use this source code:

<update-bundle version="1.0"
xmlns="http://xmlns.oracle.com/jdeveloper/updatebundle"
xmlns:u="http://xmlns.oracle.com/jdeveloper/update">
<u:update id="org.example.ruletutorial">
<u:name>Rule Tutorial</u:name>
<u:version>1.1.0</u:version>
<u:author>Richard Olrichs</u:author>
<u:author-url>http://www.olrichs.nl</u:author-url>
<u:description>Creating an Extension project with Rules as a tutorial Exercise.</u:description>
<u:post-startup-hook></u:post-startup-hook>
<u:requirements>
<u:requires-extension id="oracle.ide.audit" minVersion="12.1.2.00.00" maxVersion="12.1.3.99.99"/>
</u:requirements>
</u:update>
</update-bundle>

This results in a bundle.xml as shown below:

vanderdeijl-auditrule-fig126.jpg

After that, you see a section called “requirements”–extensions required by your extension. Here you will see most of the bundles you entered in the extension.xml dependencies tab.

After this, the creation of your bundle.xml is done.

7.2 Creating a deployment profile

Next, we need a deployment profile. Go to your project properties:

vanderdeijl-auditrule-fig127.png

And then to the Deployment tab:

vanderdeijl-auditrule-fig128.jpg

Here you see an existing Deployment Profile named “Extension (Extension JAR).” We will keep that and use it in the new profile we're going to create. Click the ‘New' button on the right side of the window.

Choose JAR file and enter a Deployment Profile Name. Click OK.

vanderdeijl-auditrule-fig129.png

In the next window, edit the JAR file to include a version number, and change the extension to .zip:

vanderdeijl-auditrule-fig130.jpg

Now go to Profile Dependencies and select the Extension project:

vanderdeijl-auditrule-fig131.jpg

Select Project Output and click Delete:

vanderdeijl-auditrule-fig132.jpg

Now select File Groups again and click New:

vanderdeijl-auditrule-fig133.jpg

Enter “Extension Jar” in the File Group Name field, and choose Libraries as Type of file group. Click OK:

vanderdeijl-auditrule-fig134.png

vanderdeijl-auditrule-fig135.jpg

Go to Contributors and make sure the JAR file is selected:

vanderdeijl-auditrule-fig136.jpg

Select File Groups once more and click New again:

vanderdeijl-auditrule-fig137.jpg

Enter "bundle.xml" as File Group Name, select Packaging, and click OK:

vanderdeijl-auditrule-fig138.png

For the Target Directory, enter "META-INF" then click OK:

vanderdeijl-auditrule-fig139.jpg

Leave the Contributors as default. Go to Filters and unselect everything except the bundle.xml, and click OK:

vanderdeijl-auditrule-fig140.jpg

Now go to Deploy and select RuleTutorial :

vanderdeijl-auditrule-fig141.png

Accept all defaults and click Finish:

vanderdeijl-auditrule-fig142.jpg

In the log window you can see that first the JAR file is recreated and then the zip file is generated:

vanderdeijl-auditrule-fig143.jpg

7.3 Cleaning JDevs extensions and cache

Since we're constantly deploying our project to the target platform, JDeveloper may get confused about caching your extension. It's best to know how to clean the JDeveloper cache in case you have any problems running your extension.

This is not something that concerns your end user, but, if you develop extensions, you will run into this situation every now and then. So, before installing the zip file of the extension (just like a user of your extension would), we will show you how to clean the deployments to the target platform.

This involves a few steps.

Go to $JDEV_HOME and navigate to the \jdev\extensions directory:

vanderdeijl-auditrule-fig144.jpg

Among the JAR files listed, select org.example.ruletutorial.jar and delete it.

Go to your JDeveloper system folder, find the system_cache folder, and delete it:

vanderdeijl-auditrule-fig145.jpg

(Note: If JDeveloper is open, you might get an error, so close JDeveloper before deleting this folder.)

7.4 Create an Update Center

Start JDeveloper again.

Create a new XML file called RuleTutorialUC.xml:

vanderdeijl-auditrule-fig146.png

The first part is pretty much the same as the bundle.xml:

vanderdeijl-auditrule-fig147.jpg

However, you need to add the bundle-url. Normally, this would typically be a network share or via an online URL. But for now it's pointing to the zip in the Deploy directory.

After creating this XML, we need to add a new Update Center to JDeveloper. Go to Help > Check for Updates:

vanderdeijl-auditrule-fig148.png

Click the Add button:

vanderdeijl-auditrule-fig149.jpg

Enter a name, browse to the XML, then click OK:

vanderdeijl-auditrule-fig150.png

You'll see that the Update Center is added:

vanderdeijl-auditrule-fig151.jpg

Click Next.

Select the available update and click Next:

vanderdeijl-auditrule-fig152.jpg

Click Finish on the last page:

vanderdeijl-auditrule-fig153.jpg

JDeveloper will ask if you want to restart. Click Yes:

vanderdeijl-auditrule-fig154.png

After JDeveloper is restarted, we'll take a look at the power of this update center as an alternative to sharing your zip file with everyone.

Imagine more work has been done on your Extension and you're going to release version 2.0.

Update the bundle.xml to 2.0:

vanderdeijl-auditrule-fig155.jpg

Update to 2.0 the RuleTutorial Deployment Profile that creates the zip file:

vanderdeijl-auditrule-fig156.jpg

Deploy the RuleTutorial:

vanderdeijl-auditrule-fig157.png

In your log you'll see that the 2.0 version has been created:

vanderdeijl-auditrule-fig158.jpg

Now open the RuleTutorialUC.xml. This version has to be in sync, so change the version number to 2.0 here as well:

vanderdeijl-auditrule-fig159.jpg

Go back to the Check for Updates menu.

Select the Update Center and unselect the others.

Click Next:

vanderdeijl-auditrule-fig160.jpg

Now, without distributing the zip file, anyone who has installed the Update Center will be able to get the 2.0 version of your Extension project.

And if the automatic check for update is checked, on start up from JDeveloper, they will even see an alert like this:

vanderdeijl-auditrule-fig161.png

8. Conclusion

During this tutorial you have seen the power of developing rules for Java and XML classes: with relatively little effort, you can code your company or project code guidelines in a rule, compelling developers to think about the quality of their code while writing it.

Apart from the basics of writing audit rules, you've built a custom fix to transform the source code with a violation. You have built and distributed a JDeveloper extension and learned how to create an update center for your development team.

All that's left is to put your newly gained knowledge into action.

Don't forget to check out the community effort named ADF EMG Audit Rules, in which the Oracle Code Guidelines are coded into audit rules. It presents a good example of how to implement different rules.

About the Authors

Oracle ACE Director Wilfred van der Deijl has been working with Oracle's development tools and database ever since getting his degree in Computer Science in 1995. An active member of the Oracle community, Wilfred is a blogger, author, Oracle customer advisory board member, and a frequent presenter at international conferences, including ODTUG and Oracle OpenWorld.

Oracle ACE Richard Olrichs is an Oracle Developer at MN, a techology company based in the Netherlands. Richard has extensive expertise in Oracle Fusion Middleware with deep specialization in the Oracle Application Development Framework. Richard initiated an open source project creating an ADF EMG Audit Rules extension for both JDeveloper 11g and JDeveloper12c, and was also one of the initiators of ADF EMG XML DataControl, an open source project for both JDeveloper ADF 11g and JDeveloper ADF 12c. Richard is has spoken at TECH13, Tech 14, and Oracle Open World 2014.

Note: This article has been reviewed by the relevant Oracle product team and found to be in compliance with standards and practices for the use of Oracle products.

Comments
Post Details
Added on Feb 13 2015
0 comments
1,118 views