svn commit: rev 21441 - in avalon/trunk: central/system tools/magic/src/main/org/apache/avalon/tools/home tools/magic/src/main/org/apache/avalon/tools/project tools/magic/src/main/org/apache/avalon/tools/tasks
[email protected] 19 Jun 2004 04:50:28 -0000
Newsgroups
gmane.comp.jakarta.avalon.cvs
Message-ID
<[email protected] >
Author: mcconnell
Date: Fri Jun 18 21:50:27 2004
New Revision: 21441
Modified:
avalon/trunk/central/system/index.xml
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/ResourceRef.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java
Log:
update javadoc task to handle nested link declarations (see planet/tutorials/hello for an example of usage)
Modified: avalon/trunk/central/system/index.xml
==============================================================================
--- avalon/trunk/central/system/index.xml (original)
+++ avalon/trunk/central/system/index.xml Fri Jun 18 21:50:27 2004
@@ -774,8 +774,6 @@
</dependencies>
</project>
-
- <!--
<project basedir="../../runtime/main" key="avalon-runtime">
<info>
<group>avalon</group>
@@ -802,6 +800,7 @@
</dependencies>
</project>
+ <!--
<project basedir="../../runtime/merlin/unit">
<info>
<group>avalon/merlin</group>
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/home/Home.java Fri Jun 18 21:50:27 2004
@@ -213,6 +213,13 @@
return (Definition[]) list.toArray( new Definition[0] );
}
+ public Resource getResource( String key )
+ throws BuildException
+ {
+ ResourceRef ref = new ResourceRef( key );
+ return getResource( ref );
+ }
+
public Resource getResource( ResourceRef ref )
throws BuildException
{
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/ResourceRef.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/ResourceRef.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/project/ResourceRef.java Fri Jun 18 21:50:27 2004
@@ -54,6 +54,22 @@
}
}
+ public static String getCategoryName( int category )
+ {
+ if( category == API )
+ {
+ return "api";
+ }
+ else if( category == SPI )
+ {
+ return "spi";
+ }
+ else
+ {
+ return "impl";
+ }
+ }
+
public ResourceRef( String key )
{
this( key, new Policy(), ANY );
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java Fri Jun 18 21:50:27 2004
@@ -47,34 +47,104 @@
private static final Link J2SE =
new Link( "http://java.sun.com/j2se/1.4/docs/api/" );
- private static class Link
+ public static class Link
{
- final String m_href;
+ private String m_href;
+ private File m_dir;
+ private int m_tag = ResourceRef.ANY;
+ private String m_key;
+
+ public Link()
+ {
+ m_href = null;
+ }
public Link( String href )
{
+ this( href, null );
+ }
+
+ public Link( String href, File dir )
+ {
m_href = href;
+ m_dir = dir;
+ }
+
+ public void setHref( String href )
+ {
+ m_href = href;
+ }
+
+ public void setTag( String tag )
+ {
+ m_tag = ResourceRef.getCategory( tag );
}
public String getHref()
{
return m_href;
}
- }
- private static class LocalLink extends Link
- {
- final File m_dir;
+ public void setKey( String key )
+ {
+ m_key = key;
+ }
- public LocalLink( String href, File dir )
+ public void setDir( File dir )
{
- super( href );
m_dir = dir;
}
- public File getDir()
+ public File getDir( Home home )
+ {
+ if( null == m_key )
+ {
+ return m_dir;
+ }
+ else
+ {
+ Resource resource = home.getResource( m_key );
+ File cache = home.getDocsRepository().getCacheDirectory();
+ File group = new File( cache, resource.getInfo().getGroup() );
+ File docs = new File( group, resource.getInfo().getName() );
+ String category = ResourceRef.getCategoryName( m_tag );
+ String version = resource.getInfo().getVersion();
+ if(( null == version ) || "".equals( version ))
+ {
+ return new File( docs, category );
+ }
+ else
+ {
+ File vDir = new File( docs, version );
+ return new File( vDir, category );
+ }
+ }
+ }
+
+ public boolean matches( int category )
{
- return m_dir;
+ if( ResourceRef.ANY == category ) return true;
+ if( ResourceRef.ANY == m_tag ) return true;
+ return ( m_tag == category );
+ }
+
+ public String toString()
+ {
+ if( null == m_dir )
+ {
+ if( null == m_key )
+ {
+ return "link: " + m_href;
+ }
+ else
+ {
+ return "link: " + m_href + " from [" + m_key + "]";
+ }
+ }
+ else
+ {
+ return "link: " + m_href + " at " + m_dir;
+ }
}
}
@@ -86,6 +156,7 @@
private String m_root;
private String m_id;
private String m_title;
+ private List m_links = new ArrayList();
public void setRoot( String root )
{
@@ -102,38 +173,44 @@
m_title = title;
}
+ public Link createLink()
+ {
+ Link link = new Link();
+ m_links.add( link );
+ return link;
+ }
+
public void execute() throws BuildException
{
Definition def = getReferenceDefinition();
File root = getJavadocRootDirectory( def );
Path classpath = def.getPath( getProject(), Policy.RUNTIME );
- Link[] links = new Link[]{ J2SE };
File api = new File( root, "api" );
File spi = new File( root, "spi" );
File imp = new File( root, "impl" );
- setup( def, classpath, ResourceRef.API, api, links, "API", false );
- setup( def, classpath, ResourceRef.SPI, spi, links, "SPI", false );
- setup( def, classpath, ResourceRef.IMPL, imp, links, "IMPL", true );
+ setup( def, classpath, ResourceRef.API, api, false );
+ setup( def, classpath, ResourceRef.SPI, spi, false );
+ setup( def, classpath, ResourceRef.IMPL, imp, true );
}
private void setup(
- Definition def, Path classpath, int category, File root,
- Link[] links, String message, boolean flag )
+ Definition def, Path classpath, int category, File root, boolean flag )
{
ResourceRef[] refs =
def.getResourceRefs( Policy.RUNTIME, category, true );
if( refs.length > 0 )
{
+ String message = ResourceRef.getCategoryName( category );
log( "Javadoc " + message + " generation." );
- generate( def, classpath, refs, root, links, message, flag );
+ generate( def, classpath, refs, category, root, flag );
}
}
private void generate(
Definition definition, Path classpath, ResourceRef[] refs,
- File root, Link[] links, String group, boolean flag )
+ int category, File root, boolean flag )
{
Javadoc javadoc = (Javadoc) getProject().createTask( "javadoc" );
@@ -141,7 +218,37 @@
javadoc.setDestdir( root );
Path source = javadoc.createSourcepath();
javadoc.createClasspath().add( classpath );
- javadoc.setDoctitle( getTitle( definition, group ) );
+ javadoc.setDoctitle( getTitle( definition, category ) );
+
+ for( int i=0; i<m_links.size(); i++ )
+ {
+ Link link = (Link) m_links.get( i );
+ if( link.matches( category ) )
+ {
+ Javadoc.LinkArgument arg = javadoc.createLink();
+ arg.setHref( link.getHref() );
+ File dir = link.getDir( getHome() );
+ if( null != dir )
+ {
+ if( dir.exists() )
+ {
+ log( link.toString() );
+ arg.setOffline( true );
+ arg.setPackagelistLoc( dir );
+ }
+ else
+ {
+ final String warning =
+ link + ": warning - unresolved directory";
+ log( warning, Project.MSG_WARN );
+ }
+ }
+ else
+ {
+ log( link.toString() );
+ }
+ }
+ }
for( int i=0; i<refs.length; i++ )
{
@@ -163,24 +270,11 @@
}
else
{
- log( "Ignoring src path: " + src );
+ log( "Ignoring src path: " + src, Project.MSG_WARN );
}
}
}
- for( int i=0; i<links.length; i++ )
- {
- Link link = links[i];
- Javadoc.LinkArgument arg = javadoc.createLink();
- arg.setHref( link.getHref() );
- if( link instanceof LocalLink )
- {
- LocalLink local = (LocalLink) link;
- arg.setOffline( true );
- arg.setPackagelistLoc( local.getDir() );
- }
- }
-
if( flag )
{
File basedir = definition.getBasedir();
@@ -226,9 +320,9 @@
}
}
- private String getTitle( Definition def, String group )
+ private String getTitle( Definition def, int category )
{
- String extra = getTitleSuppliment( def, group );
+ String extra = getTitleSuppliment( def, category );
if( null == m_title )
{
return def.getInfo().getName() + extra;
@@ -236,16 +330,17 @@
return m_title + extra;
}
- private String getTitleSuppliment( Definition def, String group )
+ private String getTitleSuppliment( Definition def, int cat )
{
+ String category = ResourceRef.getCategoryName( cat ).toUpperCase();
String version = def.getInfo().getVersion();
if( null == version )
{
- return " : " + group;
+ return " : " + category;
}
else
{
- return ", Version " + version + " : " + group;
+ return ", Version " + version + " : " + category;
}
}