avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject svn commit: rev 20241 - in avalon/trunk/tools/project/src: main/org/apache/avalon/tools main/org/apache/avalon/tools/tasks test/projects/gizmo
Date Sun, 23 May 2004 09:14:31 GMT
Author: mcconnell
Date: Sun May 23 02:14:30 2004
New Revision: 20241

Added:
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java
Modified:
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java
   avalon/trunk/tools/project/src/test/projects/gizmo/build.xml
Log:
add jar creation plus improvement to directory resolution approach

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/antlib.xml	Sun May 23 02:14:30
2004
@@ -4,4 +4,5 @@
   <typedef name="home" classname="org.apache.avalon.tools.home.Home"/> 
   <taskdef name="prepare" classname="org.apache.avalon.tools.tasks.PrepareTask"/> 
   <taskdef name="javac" classname="org.apache.avalon.tools.tasks.JavacTask"/> 
+  <taskdef name="jar" classname="org.apache.avalon.tools.tasks.JarTask"/> 
 </antlib> 

Added: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java	Sun May
23 02:14:30 2004
@@ -0,0 +1,75 @@
+/* 
+ * 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 java.io.File;
+import java.io.IOException;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Jar;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+
+/**
+ * Load a goal. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class JarTask extends HomeTask
+{
+    public void execute() throws BuildException 
+    {
+        File classes = 
+          JavacTask.getTargetClassesDirectory( getProject() );
+        File jarFile = getJarFile();
+        if( classes.exists() )
+        {
+            jar( classes, jarFile );
+        }
+    }
+
+    private File getJarFile()
+    {
+        File target = PrepareTask.getTargetDirectory( getProject() );
+        Definition def = getDefinition();
+        String name = def.getInfo().getName();
+        if( null != def.getInfo().getVersion() )
+        {
+            return new File( target, name + "-" + def.getInfo().getVersion() + ".jar" );
+        } 
+        else
+        {
+            return new File( target, name + ".jar" );
+        }
+    }
+
+    private void jar( File classes, File jarFile )
+    {
+        Jar jar = (Jar) getProject().createTask( "jar" );
+        jar.setDestFile( jarFile );
+        jar.setBasedir( classes );
+        jar.init();
+        jar.execute();
+    }
+}

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JavacTask.java	Sun May
23 02:14:30 2004
@@ -21,6 +21,7 @@
 import java.io.IOException;
 
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Copy;
 import org.apache.tools.ant.taskdefs.Javac;
@@ -47,6 +48,13 @@
     public static final String FORK_KEY = "java.compile.fork";
     public static final boolean FORK_FLAG = false;
 
+    public static File getTargetClassesDirectory( Project project )
+    {
+        File target = PrepareTask.getTargetDirectory( project );
+        String classes = project.getProperty( CLASSES_KEY );
+        return new File( target, classes );
+    }
+
     public void init() throws BuildException 
     {
         super.init();
@@ -81,10 +89,7 @@
 
     private File getTargetClassesDirectory()
     {
-        String path = getProject().getProperty( "avalon.target" );
-        File target = new File( getProject().getBaseDir(), path );
-        String classes = getProject().getProperty( "avalon.target.classes" );
-        return new File( target, classes );
+        return getTargetClassesDirectory( getProject() );
     }
 
     private void compile( File sources, File classes, Path classpath )

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PrepareTask.java	Sun
May 23 02:14:30 2004
@@ -21,6 +21,7 @@
 import java.io.IOException;
 
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Copy;
 import org.apache.tools.ant.taskdefs.Property;
@@ -43,6 +44,14 @@
     public static String TARGET_SRC = TARGET + "/src";
     public static String TARGET_SRC_MAIN = TARGET_SRC + "/main";
 
+    public static final String TARGET_KEY = "avalon.target";
+
+    public static File getTargetDirectory( Project project )
+    {
+        String target = project.getProperty( TARGET_KEY );
+        return new File( project.getBaseDir(), target );
+    }
+
     public void init() throws BuildException 
     {
         setProjectProperty( "avalon.src", SRC );
@@ -75,8 +84,7 @@
 
     private File getTargetDirectory()
     {
-        String target = getProject().getProperty( "avalon.target" );
-        return new File( getProject().getBaseDir(), target );
+        return getTargetDirectory( getProject() );
     }
 
     private void copySrcToBuildWithFiltering( File target )

Modified: avalon/trunk/tools/project/src/test/projects/gizmo/build.xml
==============================================================================
--- avalon/trunk/tools/project/src/test/projects/gizmo/build.xml	(original)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/build.xml	Sun May 23 02:14:30 2004
@@ -6,6 +6,7 @@
 
   <x:prepare/>
   <x:javac/>
+  <x:jar/>
 
 
 </project>

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message