Return-Path: Delivered-To: apmail-avalon-cvs-archive@www.apache.org Received: (qmail 77343 invoked from network); 30 Jun 2004 10:11:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 30 Jun 2004 10:11:13 -0000 Received: (qmail 70162 invoked by uid 500); 30 Jun 2004 10:11:33 -0000 Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 69662 invoked by uid 500); 30 Jun 2004 10:11:22 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 69181 invoked by uid 99); 30 Jun 2004 10:11:15 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Wed, 30 Jun 2004 03:11:15 -0700 Received: (qmail 77097 invoked by uid 65534); 30 Jun 2004 10:10:43 -0000 Date: 30 Jun 2004 10:10:43 -0000 Message-ID: <20040630101043.77090.qmail@minotaur.apache.org> From: mcconnell@apache.org To: cvs@avalon.apache.org Subject: svn commit: rev 22313 - in avalon/trunk/tools/magic/src/main/org/apache/avalon/tools: . model tasks X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: mcconnell Date: Wed Jun 30 03:10:42 2004 New Revision: 22313 Added: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java Log: Addition of a block task (does automatic creation of the block defintion for standalon and embedded scenarios). Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/antlib.xml Wed Jun 30 03:10:42 2004 @@ -21,6 +21,7 @@ + Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Context.java Wed Jun 30 03:10:42 2004 @@ -43,6 +43,8 @@ public static final String TARGET = "target"; public static final String BUILD = "build"; + public static final String CLASSES = "classes"; + public static final String TEST_CLASSES = "test-classes"; public static final String TEMP = "temp"; public static final String TEST = "test"; public static final String DELIVERABLES = "deliverables"; @@ -51,7 +53,6 @@ private static final String USER_PROPERTIES = "user.properties"; private static final String BUILD_PROPERTIES = "build.properties"; - public static final String SRC_KEY = "project.src"; public static final String SRC_VALUE = "src"; @@ -97,6 +98,8 @@ private File m_target; private File m_build; private File m_deliverables; + private File m_classes; + private File m_testClasses; private File m_temp; private File m_docs; private File m_test; @@ -137,8 +140,10 @@ m_target = new File( basedir, TARGET ); m_build = setBuildPath( BUILD ); m_deliverables = setBuildPath( DELIVERABLES ); + m_classes = setBuildPath( CLASSES ); m_temp = setBuildPath( TEMP ); m_test = setBuildPath( TEST ); + m_testClasses = setBuildPath( TEST_CLASSES ); m_docs = setBuildPath( DOCS ); project.addReference( KEY, this ); @@ -201,6 +206,16 @@ public File getDeliverablesDirectory() { return m_deliverables; + } + + public File getClassesDirectory() + { + return m_classes; + } + + public File getTestClassesDirectory() + { + return m_testClasses; } public File getTempDirectory() Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java Wed Jun 30 03:10:42 2004 @@ -64,9 +64,10 @@ } final String gpg = getProject().getProperty( GPG_EXE_KEY ); + if(( null != gpg ) && !"".equals( gpg ) ) { - log( "Creating asc signature using '" + gpg + "']" ); + log( "Creating asc signature using '" + gpg + "'." ); final ExecTask execute = (ExecTask) getProject().createTask( "exec" ); execute.setExecutable( gpg ); Added: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java ============================================================================== --- (empty file) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java Wed Jun 30 03:10:42 2004 @@ -0,0 +1,194 @@ +/* + * Copyright 2004 Apache Software Foundation + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.avalon.tools.tasks; + +import org.apache.avalon.tools.model.Definition; +import org.apache.avalon.tools.model.ResourceRef; +import org.apache.avalon.tools.model.Info; +import org.apache.avalon.tools.model.Resource; +import org.apache.tools.ant.BuildException; +import org.apache.avalon.tools.model.Plugin.ListenerDef; +import org.apache.avalon.tools.model.Plugin.TaskDef; +import org.apache.avalon.tools.model.Plugin; +import org.apache.avalon.tools.model.Policy; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.FileOutputStream; +import java.io.File; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.List; +import java.util.ArrayList; + +/** + * Create meta-data for a block. + * + * @author Avalon Development Team + * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $ + */ +public class BlockTask extends DeclareTask +{ + private static final String BLOCK = "block"; + private static final String MAIN = "main"; + private static final String TEST = "test"; + + public static class Component + { + private String m_name; + private String m_classname; + + public Component() + { + } + + public void setName( final String name ) + { + m_name = name; + } + + public void setClass( final String classname ) + { + m_classname = classname; + } + + public String getName() + { + return m_name; + } + + public String getClassname() + { + return m_classname; + } + } + + private String m_target; + private String m_container; + private List m_components = new ArrayList(); + + public void setName( final String name ) + { + m_container = name; + } + + /** + * Optional attribute indicating that the block is to be generated + * as an embedded BLOCK-INF/block.xml into either the MAIN or TEST + * classes directory as indicated by the target parameter. + */ + public void setEmbed( final String target ) + { + if( MAIN.equalsIgnoreCase( target ) ) + { + m_target = MAIN; + } + else if( TEST.equalsIgnoreCase( target ) ) + { + m_target = TEST; + } + else + { + final String error = + "Embed policy not recognized (use MAIN or TEST)"; + throw new BuildException( error ); + } + } + + private String getName( Definition def ) + { + if( null == m_container ) + { + return def.getInfo().getName(); + } + else + { + return m_container; + } + } + + protected File getPluginFile() + { + if( null == m_target ) + { + return super.getPluginFile(); + } + else + { + File root = getEmbeddedRoot( m_target ); + File blockinf = new File( root, "BLOCK-INF" ); + return new File( blockinf, "block.xml" ); + } + } + + private File getEmbeddedRoot( String target ) + { + if( MAIN.equals( m_target ) ) + { + return getContext().getClassesDirectory(); + } + else + { + return getContext().getTestClassesDirectory(); + } + } + + public Component createComponent() + { + final Component component = new Component(); + m_components.add( component ); + return component; + } + + public void init() + { + super.init(); + super.setType( BLOCK ); + } + + protected void writePlugin( final Writer writer, final Definition def ) + throws IOException + { + final Info info = def.getInfo(); + + writer.write( "\n\n" ); + writer.write( "\n\n " ); + boolean standalone = (null == m_target); + writeClasspath( writer, def, " ", standalone ); + writer.write( "\n " ); + writer.write( "\n" ); + + Component[] components = + (Component[]) m_components.toArray( new Component[0] ); + for( int i=0; i\n" ); + } + + private void writeComponent( final Writer writer, final Component component ) + throws IOException + { + writer.write( + "\n \n" ); + } +} Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java Wed Jun 30 03:10:42 2004 @@ -33,19 +33,25 @@ import java.io.File; import java.io.OutputStreamWriter; import java.io.Writer; - - - +import java.util.List; +import java.util.ArrayList; /** - * Load a plugin. + * Create meta-data for a plugin. * * @author Avalon Development Team * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $ */ public class DeclareTask extends SystemTask { - private static final String TYPE = "plugin"; + private static final String PLUGIN = "plugin"; + + private String m_type = PLUGIN; + + protected void setType( String type ) + { + m_type = type; + } public void execute() throws BuildException { @@ -55,6 +61,7 @@ try { final File file = getPluginFile(); + file.getParentFile().mkdirs(); file.createNewFile(); final OutputStream output = new FileOutputStream( file ); @@ -73,32 +80,17 @@ } } - private File getPluginFile() + protected File getPluginFile() { final File dir = getContext().getDeliverablesDirectory(); - final File ants = new File( dir, TYPE + "s" ); - mkDir( ants ); - + final File ants = new File( dir, m_type + "s" ); final Definition def = getHome().getDefinition( getKey() ); final Info info = def.getInfo(); - final String filename = getFilename( info ); + final String filename = info.getShortFilename() + "." + m_type; return new File( ants, filename ); } - private String getFilename( final Info info ) - { - final String version = info.getVersion(); - if( null == version ) - { - return info.getName() + "." + TYPE; - } - else - { - return info.getName() + "-" + version + "." + TYPE; - } - } - - public void writePluginDef( final OutputStream output, final Definition def ) + private void writePluginDef( final OutputStream output, final Definition def ) throws IOException { final Writer writer = new OutputStreamWriter( output ); @@ -107,18 +99,7 @@ writer.flush(); } - /** - * Write the XML header. - * @param writer the writer - * @throws IOException if unable to write xml - */ - private void writeHeader( final Writer writer ) - throws IOException - { - writer.write( "" ); - } - - private void writePlugin( final Writer writer, final Definition def ) + protected void writePlugin( final Writer writer, final Definition def ) throws IOException { final Info info = def.getInfo(); @@ -131,10 +112,21 @@ writeTaskDefs( writer, plugin ); writeListenerDefs( writer, plugin ); } - writeClasspath( writer, def ); + writeClasspath( writer, def, " ", true ); writer.write( "\n\n" ); } + /** + * Write the XML header. + * @param writer the writer + * @throws IOException if unable to write xml + */ + private void writeHeader( final Writer writer ) + throws IOException + { + writer.write( "" ); + } + private void writeTaskDefs( final Writer writer, final Plugin plugin ) throws IOException { @@ -185,20 +177,28 @@ { writer.write( "\n " + version + "" ); } - writer.write( "\n " + TYPE + "" ); + writer.write( "\n " + m_type + "" ); writer.write( "\n " ); } - private void writeClasspath( final Writer writer, final Definition def ) + /** + * Write the classpath. If the fag is true, then include this defintion + * in the claspath. + */ + protected void writeClasspath( + final Writer writer, final Definition def, String padding, boolean flag ) throws IOException { - writer.write( "\n " ); - final String pad = " "; + writer.write( "\n" + padding + "" ); + final String pad = padding + " "; final ResourceRef[] resources = def.getResourceRefs( Policy.RUNTIME, ResourceRef.ANY, true ); writeResourceRefs( writer, pad, resources ); - writeResource( writer, pad, def ); - writer.write( "\n " ); + if( flag ) + { + writeResource( writer, pad, def ); + } + writer.write( "\n" + padding + "" ); } private void writeResourceRefs( Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java Wed Jun 30 03:10:42 2004 @@ -107,7 +107,7 @@ if( src.exists() ) { - final File classes = new File( m_test, "classes" ); + final File classes = getContext().getTestClassesDirectory(); mkDir( classes ); final Definition definition = getHome().getDefinition( getKey() ); Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java Wed Jun 30 03:10:42 2004 @@ -41,7 +41,7 @@ public void execute() throws BuildException { final File classes = - getContext().getBuildPath( JavacTask.BUILD_CLASSES_KEY ); + getContext().getClassesDirectory(); final File deliverables = getContext().getDeliverablesDirectory(); Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavacTask.java Wed Jun 30 03:10:42 2004 @@ -38,8 +38,6 @@ */ public class JavacTask extends SystemTask { - public static final String BUILD_CLASSES_KEY = "classes"; - public static final String BUILD_CLASSES_PATH = "classes"; public static final String DEBUG_KEY = "java.compile.debug"; public static final boolean DEBUG_VALUE = false; @@ -55,9 +53,6 @@ final Project project = getProject(); project.setNewProperty( DEBUG_KEY, "" + DEBUG_VALUE ); project.setNewProperty( FORK_KEY, "" + FORK_VALUE ); - getContext().setBuildPath( - BUILD_CLASSES_KEY, - BUILD_CLASSES_PATH ); } } @@ -69,7 +64,7 @@ if( main.exists() ) { - final File classes = getContext().getBuildPath( BUILD_CLASSES_KEY ); + final File classes = getContext().getClassesDirectory(); mkDir( classes ); final ResourceRef ref = new ResourceRef( getKey() ); --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org