Update of /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12316/modules/jdo/src/xdoclet/modules/jdo
Modified Files:
JdoXmlMetadataSubTask.java JdoTagsHandler.java
Added Files:
GenerateClassCounter.java
Log Message:
delete empty package.jdo files (found no possibility to prevent creation, hence
I delete them after package processing)
--- NEW FILE: GenerateClassCounter.java ---
/*
* Copyright (c) 2001, 2002 The XDoclet team
* All rights reserved.
*/
package xdoclet.modules.jdo;
/**
* @author Marco Schulze - marco at nightlabs dot de
* @created July 20, 2005
*/
public class GenerateClassCounter
{
private static GenerateClassCounter _sharedInstance = null;
private int count = 0;
protected GenerateClassCounter()
{
}
public static GenerateClassCounter sharedInstance()
{
if (_sharedInstance == null)
_sharedInstance = new GenerateClassCounter();
return _sharedInstance;
}
/**
* @return Returns the count.
*/
public int getCount()
{
return count;
}
/**
* Sets the count to 0.
*/
public void clearCount()
{
count = 0;
}
/**
* Increments the count by 1.
*/
public void incCount()
{
++count;
}
}
Index: JdoXmlMetadataSubTask.java
===================================================================
RCS file:
/cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo/JdoXmlMetadataSubTask.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** JdoXmlMetadataSubTask.java 20 Jul 2005 13:17:16 -0000 1.13
--- JdoXmlMetadataSubTask.java 20 Jul 2005 14:43:48 -0000 1.14
***************
*** 139,143 ****
Log log = LogUtil.getLog(JdoXmlMetadataSubTask.class, "execute");
! log.info("Using jdospec \"" + jdoSpec + "\".");
if (JdoSpecVersion.JDO_2_0.equals(jdoSpec)) {
--- 139,143 ----
Log log = LogUtil.getLog(JdoXmlMetadataSubTask.class, "execute");
! log.info("Using jdoSpec \"" + jdoSpec + "\".");
if (JdoSpecVersion.JDO_2_0.equals(jdoSpec)) {
***************
*** 277,281 ****
Log log = LogUtil.getLog(getClass(), "generateForClass");
String generatedFileName = getGeneratedFileName(pkg);
! File file = new File(getDestDir().toString(), generatedFileName);
if (log.isDebugEnabled()) {
--- 277,284 ----
Log log = LogUtil.getLog(getClass(), "generateForClass");
String generatedFileName = getGeneratedFileName(pkg);
! // File file = new File(getDestDir().toString(), generatedFileName);
! File file = new File(getDestDir(), generatedFileName);
!
! GenerateClassCounter.sharedInstance().clearCount();
if (log.isDebugEnabled()) {
***************
*** 303,307 ****
try {
setCurrentPackage(pkg);
! startEngine(getTemplateURL(), new File(getDestDir(),
generatedFileName));
}
catch (TemplateException e) {
--- 306,311 ----
try {
setCurrentPackage(pkg);
! // startEngine(getTemplateURL(), new File(getDestDir(),
generatedFileName));
! startEngine(getTemplateURL(), file);
}
catch (TemplateException e) {
***************
*** 314,317 ****
--- 318,336 ----
}
}
+
+ if (log.isDebugEnabled()) {
+ log.debug("GenerateClassCounter.sharedInstance().getCount()=" +
GenerateClassCounter.sharedInstance().getCount());
+ }
+
+ if (GenerateClassCounter.sharedInstance().getCount() == 0) {
+ // No class has been generated - remove the file which is
unfortunately
+ // always created.
+ if (file.delete()) {
+ log.info("Deleted \"" + generatedFileName + "\", because no
class-meta-data for this package has been generated.");
+ }
+ else {
+ log.warn("File \"" + file.getAbsolutePath() + "\" should have
been deleted, because no class-meta-data has been generated, but deleting
failed!");
+ }
+ }
}
Index: JdoTagsHandler.java
===================================================================
RCS file:
/cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo/JdoTagsHandler.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** JdoTagsHandler.java 10 Oct 2004 22:10:10 -0000 1.10
--- JdoTagsHandler.java 20 Jul 2005 14:43:48 -0000 1.11
***************
*** 32,36 ****
/**
* The <code>forAllPackages</code> iterates through all packages, and
generates the template if the
! * jdo.persistence-capable tag is present in at least one class in the
package.
*
* @param template a <code>String</code> value
--- 32,40 ----
/**
* The <code>forAllPackages</code> iterates through all packages, and
generates the template if the
! * jdo.persistence-capable tag is present in at least one class in the
package. <p>
! *
! * If generation is done per package, the package.jdo is generated
already before and it seems, there's no way to
! * prevent the file from being generated (at least I - Marco - didn't
find one). Hence, I count the generated
! * classes (see [EMAIL PROTECTED] GenerateClassCounter}) and delete the
file, if no class has been generated.
*
* @param template a <code>String</code> value
***************
*** 94,102 ****
for (Iterator i = classes.iterator(); i.hasNext(); ) {
setCurrentClass((XClass) i.next());
! generate(template);
}
}
else {
! generate(template);
}
--- 98,113 ----
for (Iterator i = classes.iterator(); i.hasNext(); ) {
setCurrentClass((XClass) i.next());
!
! if
(getCurrentClass().getDoc().hasTag("jdo.persistence-capable")) {
! GenerateClassCounter.sharedInstance().incCount();
! generate(template);
! }
}
}
else {
! if (getCurrentClass().getDoc().hasTag("jdo.persistence-capable"))
{
! GenerateClassCounter.sharedInstance().incCount();
! generate(template);
! }
}
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
xdoclet-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel