notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1462 - in development/main/magic/spells/eclipse: . etc/deliverables/eclipses etc/deliverables/templates src/main/net/dpml/magic/eclipse
- From: andreas.ronge AT jayway.se
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1462 - in development/main/magic/spells/eclipse: . etc/deliverables/eclipses etc/deliverables/templates src/main/net/dpml/magic/eclipse
- Date: Tue, 11 Jan 2005 18:52:18 +0100
Author: andreas.ronge AT jayway.se
Date: Tue Jan 11 18:52:18 2005
New Revision: 1462
Added:
development/main/magic/spells/eclipse/etc/deliverables/eclipses/
development/main/magic/spells/eclipse/etc/deliverables/eclipses/classpath.eclipse
development/main/magic/spells/eclipse/etc/deliverables/eclipses/project.eclipse
Modified:
development/main/magic/spells/eclipse/build.xml
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
Log:
added configuration for eclipse task by using artifacts
only include jar files in eclipse classpath
Modified: development/main/magic/spells/eclipse/build.xml
==============================================================================
--- development/main/magic/spells/eclipse/build.xml (original)
+++ development/main/magic/spells/eclipse/build.xml Tue Jan 11 18:52:18
2005
@@ -3,7 +3,7 @@
<magic:import uri="artifact:template:dpml/magic/standard"/>
- <!-- example of usage
+ <!-- example of usage
<magic:import uri="artifact:template:dpml/magic/eclipse"/>
-->
Added:
development/main/magic/spells/eclipse/etc/deliverables/eclipses/classpath.eclipse
==============================================================================
--- (empty file)
+++
development/main/magic/spells/eclipse/etc/deliverables/eclipses/classpath.eclipse
Tue Jan 11 18:52:18 2005
@@ -0,0 +1,4 @@
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="src" path="src/main"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="src" path="src/test" output="target/test-classes"/>
Added:
development/main/magic/spells/eclipse/etc/deliverables/eclipses/project.eclipse
==============================================================================
--- (empty file)
+++
development/main/magic/spells/eclipse/etc/deliverables/eclipses/project.eclipse
Tue Jan 11 18:52:18 2005
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<projectDescription>
+ <name>@PROJECT_NAME@</name>
+ <comment></comment>
+ <projects></projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments></arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Modified:
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
==============================================================================
---
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
(original)
+++
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
Tue Jan 11 18:52:18 2005
@@ -22,9 +22,15 @@
xmlns:magic="antlib:net.dpml.magic" >
<target name="eclipse" depends="prepare" unless="project.eclipse.disable" >
+
+ <property name="project.eclipse.project.uri"
value="artifact:eclipse:dpml/magic/project"/>
+ <property name="project.eclipse.classpath.uri"
value="artifact:eclipse:dpml/magic/classpath"/>
+
<magic:plugin uri="@PLUGIN-URI@"/>
<mkdir dir="target/eclipse"/>
- <eclipse xmlns="plugin:dpml/magic/dpml-magic-eclipse"/>
+ <eclipse xmlns="plugin:dpml/magic/dpml-magic-eclipse"
+ projectUri="${project.eclipse.project.uri}"
+ classpathUri="${project.eclipse.classpath.uri}"/>
</target>
</project>
Modified:
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
==============================================================================
---
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
(original)
+++
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
Tue Jan 11 18:52:18 2005
@@ -17,13 +17,18 @@
package net.dpml.magic.eclipse;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -36,8 +41,11 @@
import net.dpml.magic.model.ResourceRef;
import net.dpml.magic.project.Context;
import net.dpml.magic.tasks.ContextualTask;
+import net.dpml.transit.artifact.Handler;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.types.FilterSet;
/**
* Creates Eclipse project files.
@@ -50,6 +58,11 @@
public class EclipseTask extends ContextualTask
{
+ /**
+ * The ant filter for the classpath.eclipse artifact
+ */
+ public static final String PROJECT_NAME = "PROJECT_NAME";
+
public static final String PROJECT_FILENAME = ".project";
public static final String CLASSPATH_FILENAME = ".classpath";
@@ -64,6 +77,10 @@
*/
public static final String ECLIPSE_MAGIC_VARIABLE = "MAGIC_CACHE";
+ private File m_projectFile;
+
+ private File m_classpathFile;
+
/**
* Creates the two eclipse project files
*
@@ -73,12 +90,12 @@
*/
public void execute() throws BuildException
{
- OutputStream projectOutput = getOutputStream( PROJECT_FILENAME );
+ createProject();
+
OutputStream classpathOutput = getOutputStream( CLASSPATH_FILENAME );
try
{
- createProject( projectOutput );
createClasspath( classpathOutput );
}
catch ( IOException e )
@@ -88,51 +105,96 @@
}
finally
{
- closeStream( projectOutput );
closeStream( classpathOutput );
}
}
- protected void createProject( OutputStream projectOutput )
- throws IOException
+ /**
+ *
+ * @param projectUri the artifact uri for the eclipse project file
+ */
+ public void setProjectUri( String projectUri )
{
- Definition projectDef = getProjectDefinition();
+ try
+ {
+ URL url = new URL( null, projectUri, new Handler() );
+ m_projectFile = ( File ) url
+ .getContent( new Class[] { File.class } );
+ }
+ catch ( Throwable e )
+ {
+ final String error = "Could not resolve the project uri ["
+ + projectUri + "]";
+ throw new BuildException( error, e );
+ }
+ }
+
+ /**
+ *
+ * @param classpathUri the artifact uri for the eclipse classpath
fragment
+ */
+ public void setClasspathUri( String classpathUri )
+ {
+ try
+ {
+ URL url = new URL( null, classpathUri, new Handler() );
+ m_classpathFile = ( File ) url
+ .getContent( new Class[] { File.class } );
+ }
+ catch ( Throwable e )
+ {
+ final String error = "Could not resolve the classpath uri ["
+ + classpathUri + "]";
+ throw new BuildException( error, e );
+ }
+ }
- Writer writer = new OutputStreamWriter( projectOutput );
+ //
-------------------------------------------------------------------------
+ // protected methods
+ //
-------------------------------------------------------------------------
- writer.write( "<?xml version=\"1.0\"?>\n" );
- writer.write( "<projectDescription>\n" );
- writer.write( " <name>" + projectDef.getKey() + "</name>\n" );
- writer.write( " <comment></comment>\n" );
- writer.write( " <projects></projects>\n" );
- writer.write( " <buildSpec>\n" );
- writer.write( " <buildCommand>\n" );
- writer.write( " <name>org.eclipse.jdt.core.javabuilder</name>\n"
);
- writer.write( " <arguments></arguments>\n" );
- writer.write( " </buildCommand>\n" );
- writer.write( " </buildSpec>\n" );
- writer.write( " <natures>\n" );
- writer
- .write( "
<nature>org.eclipse.jdt.core.javanature</nature>\n" );
- writer.write( " </natures>\n" );
- writer.write( "</projectDescription>\n" );
- writer.flush();
+ protected void createProject()
+ {
+ if ( m_projectFile == null )
+ throw new BuildException( "Missing projectUri property for task"
);
+
+ if ( !m_projectFile.canRead() )
+ throw new BuildException( "Can't read from resource '"
+ + m_projectFile.getAbsolutePath() );
+
+ String targetLocation = TARGET_DIR + "/" + PROJECT_FILENAME;
+ File targetFile = getProject().resolveFile( targetLocation );
+
+ Copy copy = new Copy();
+ copy.setProject( getProject() );
+ copy.setFile( m_projectFile );
+ copy.setTofile( targetFile );
+ copy.setOverwrite( true );
+ copy.setFiltering( true );
+
+ FilterSet filterSet = copy.createFilterSet();
+ Definition projectDef = getProjectDefinition();
+ filterSet.addFilter( PROJECT_NAME, projectDef.getKey() );
+
+ copy.execute();
}
+ /**
+ * Adds jar files and classpath header to the outputstream.
+ *
+ * @param classpathOutput
+ * @throws IOException
+ */
protected void createClasspath( OutputStream classpathOutput )
throws IOException
{
+
Writer writer = new OutputStreamWriter( classpathOutput );
writer.write( "<?xml version=\"1.0\"?>\n" );
writer.write( "<classpath>\n" );
- writer
- .write( " <classpathentry kind=\"con\"
path=\"org.eclipse.jdt.launching.JRE_CONTAINER\"/>\n" );
- writer.write( " <classpathentry kind=\"src\" path=\"src/main\"/>\n"
);
- writer
- .write( " <classpathentry kind=\"output\"
path=\"target/classes\"/>\n" );
- writer
- .write( " <classpathentry kind=\"src\" path=\"src/test\"
output=\"target/test-classes\"/>\n" );
+
+ appendClasspathHeader( writer );
Definition projectDef = getProjectDefinition();
ResourceRef[] resourceRefs = projectDef.getResourceRefs();
@@ -141,6 +203,10 @@
while ( iter.hasNext() )
{
Resource resource = ( Resource ) iter.next();
+ Info info = resource.getInfo();
+ String type = info.getType();
+ if ( !"jar".equalsIgnoreCase( type ) )
+ continue;
writer.write( " " + getEclipseClasspath( resource ) + "\n" );
}
@@ -156,6 +222,52 @@
return index.getDefinition( key );
}
+ //
-------------------------------------------------------------------------
+ // private methods
+ //
-------------------------------------------------------------------------
+
+ private void appendClasspathHeader( Writer writer )
+ throws FileNotFoundException, IOException
+ {
+ if ( m_classpathFile == null )
+ throw new BuildException( "Missing classpathUri property for
task" );
+ if ( !m_classpathFile.canRead() )
+ throw new BuildException( "Can't read from resource '"
+ + m_classpathFile.getAbsolutePath() );
+
+ InputStream in = new FileInputStream( m_classpathFile );
+ String inString = readInputStream( in );
+ writer.write( inString );
+ }
+
+ private String readInputStream( InputStream iInStream )
+ {
+ InputStreamReader tInputReader = new InputStreamReader( iInStream );
+ BufferedReader tReader = new BufferedReader( tInputReader );
+ StringBuffer readData = new StringBuffer();
+
+ try
+ {
+ int tTemp = tReader.read();
+ while ( tTemp != -1 )
+ {
+ readData.append( ( char ) tTemp );
+ tTemp = tReader.read();
+ }
+ String tFileData = readData.toString();
+
+ return tFileData;
+ }
+ catch ( IOException e )
+ {
+ throw new BuildException( "Can't read file", e );
+ }
+ finally
+ {
+ closeStream(iInStream);
+ }
+ }
+
/**
* Recursiv search of all resources dependencies this resource ref has.
*
@@ -229,4 +341,19 @@
}
}
+ private void closeStream( InputStream input )
+ {
+ if ( null != input )
+ {
+ try
+ {
+ input.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+
}
\ No newline at end of file
- svn commit: r1462 - in development/main/magic/spells/eclipse: . etc/deliverables/eclipses etc/deliverables/templates src/main/net/dpml/magic/eclipse, andreas . ronge, 01/11/2005
Archive powered by MHonArc 2.6.24.