notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1403 - in development/main/magic: . spells/eclipse spells/eclipse/etc spells/eclipse/etc/deliverables spells/eclipse/etc/deliverables/templates spells/eclipse/src spells/eclipse/src/main spells/eclipse/src/main/net spells/eclipse/src/main/net/dpml spells/eclipse/src/main/net/dpml/magic spells/eclipse/src/main/net/dpml/magic/eclipse
- From: andreas.ronge AT jayway.se
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1403 - in development/main/magic: . spells/eclipse spells/eclipse/etc spells/eclipse/etc/deliverables spells/eclipse/etc/deliverables/templates spells/eclipse/src spells/eclipse/src/main spells/eclipse/src/main/net spells/eclipse/src/main/net/dpml spells/eclipse/src/main/net/dpml/magic spells/eclipse/src/main/net/dpml/magic/eclipse
- Date: Fri, 07 Jan 2005 15:30:34 +0100
Author: andreas.ronge AT jayway.se
Date: Fri Jan 7 15:30:34 2005
New Revision: 1403
Added:
development/main/magic/spells/eclipse/
development/main/magic/spells/eclipse/build.xml (contents, props changed)
development/main/magic/spells/eclipse/etc/
development/main/magic/spells/eclipse/etc/deliverables/
development/main/magic/spells/eclipse/etc/deliverables/templates/
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
development/main/magic/spells/eclipse/src/
development/main/magic/spells/eclipse/src/main/
development/main/magic/spells/eclipse/src/main/net/
development/main/magic/spells/eclipse/src/main/net/dpml/
development/main/magic/spells/eclipse/src/main/net/dpml/magic/
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
(contents, props changed)
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/antlib.xml
(contents, props changed)
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/package.html
(contents, props changed)
Modified:
development/main/magic/index.xml
development/main/magic/module.xml
Log:
Moved eclipse spell from laboratory to main.
Some minor refactoring and cleanup of the code
Fixed bug - duplicated resource in .classpath
Added a template for the spell, like the checkstyle spell
Modified: development/main/magic/index.xml
==============================================================================
--- development/main/magic/index.xml (original)
+++ development/main/magic/index.xml Fri Jan 7 15:30:34 2005
@@ -41,6 +41,7 @@
</dependencies>
<plugins>
<include key="dpml-magic-checkstyle"/>
+ <include key="dpml-magic-eclipse"/>
</plugins>
</project>
@@ -117,6 +118,20 @@
</dependencies>
</project>
+<project basedir="spells/eclipse">
+ <info>
+ <group>dpml/magic</group>
+ <name>dpml-magic-eclipse</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="dpml-magic-core"/>
+ </dependencies>
+ </project>
+
+
<project basedir="spells/style">
<info>
<group>dpml/magic</group>
@@ -340,4 +355,5 @@
</info>
</resource>
+
</index>
Modified: development/main/magic/module.xml
==============================================================================
--- development/main/magic/module.xml (original)
+++ development/main/magic/module.xml Fri Jan 7 15:30:34 2005
@@ -24,6 +24,7 @@
<magic:import uri="artifact:template:dpml/magic/standard"/>
<magic:import uri="artifact:template:dpml/magic/checkstyle"/>
+ <magic:import uri="artifact:template:dpml/magic/eclipse"/>
<target name="build" depends="standard.build">
<x:module index="index.xml">
@@ -59,6 +60,7 @@
<package name="net.dpml.magic.publish"/>
<package name="net.dpml.magic.upload"/>
<package name="net.dpml.magic.checkstyle"/>
+ <package name="net.dpml.magic.eclipse"/>
<package name="net.dpml.magic.style"/>
</group>
</x:javadoc>
Added: development/main/magic/spells/eclipse/build.xml
==============================================================================
--- (empty file)
+++ development/main/magic/spells/eclipse/build.xml Fri Jan 7 15:30:34
2005
@@ -0,0 +1,21 @@
+<project name="dpml-magic-eclipse" default="install" basedir="."
+ xmlns:magic="antlib:net.dpml.magic"
xmlns:x="plugin:dpml/magic/dpml-magic-core" >
+
+ <magic:import uri="artifact:template:dpml/magic/standard"/>
+
+ <!-- example of usage
+ <magic:import uri="artifact:template:dpml/magic/eclipse"/>
+ -->
+
+ <target name="init" depends="standard.init">
+ <x:filter feature="plugin" token="PLUGIN-URI"/>
+ </target>
+
+ <target name="build" depends="standard.build">
+ <x:export class="net.dpml.magic.eclipse.EclipseTask">
+ <antlib resource="net/dpml/magic/eclipse/antlib.xml"
+ urn="plugin:dpml/magic/dpml-magic-eclipse"/>
+ </x:export>
+ </target>
+
+</project>
Added:
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
==============================================================================
--- (empty file)
+++
development/main/magic/spells/eclipse/etc/deliverables/templates/eclipse.template
Fri Jan 7 15:30:34 2005
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright 2004 Stephen J McConnell
+ Copyright 2004 Niclas Hedhman
+
+ 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.
+-->
+
+<project name="eclipse"
+ xmlns:magic="antlib:net.dpml.magic" >
+
+ <target name="eclipse" depends="prepare" unless="project.eclipse.disable" >
+ <magic:plugin uri="@PLUGIN-URI@"/>
+ <mkdir dir="target/eclipse"/>
+ <eclipse xmlns="plugin:dpml/magic/dpml-magic-eclipse"/>
+ </target>
+
+</project>
Added:
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
==============================================================================
--- (empty file)
+++
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/EclipseTask.java
Fri Jan 7 15:30:34 2005
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2004 Cameron Taggart Copyright 2004 Dwango Wireless
+ *
+ * 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 net.dpml.magic.eclipse;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import net.dpml.magic.Index;
+import net.dpml.magic.model.Definition;
+import net.dpml.magic.model.Info;
+import net.dpml.magic.model.Resource;
+import net.dpml.magic.model.ResourceRef;
+import net.dpml.magic.project.Context;
+import net.dpml.magic.tasks.ContextualTask;
+
+import org.apache.tools.ant.BuildException;
+
+/**
+ * Creates Eclipse project files.
+ *
+ * @author Andreas Ronge
+ * @author Cameron Taggart
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta
+ * Library </a>
+ */
+public class EclipseTask extends ContextualTask
+{
+
+ public static final String PROJECT_FILENAME = ".project";
+
+ public static final String CLASSPATH_FILENAME = ".classpath";
+
+ /**
+ * the location of the created eclipse project files
+ */
+ public static final String TARGET_DIR = "target/eclipse";
+
+ /**
+ * The eclipse classpath variable pointing to the magic cache dir
+ */
+ public static final String ECLIPSE_MAGIC_VARIABLE = "MAGIC_CACHE";
+
+ /**
+ * Creates the two eclipse project files
+ *
+ * @see org.apache.tools.ant.Task#execute()
+ * @see #PROJECT_FILENAME
+ * @see #CLASSPATH_FILENAME
+ */
+ public void execute() throws BuildException
+ {
+ OutputStream projectOutput = getOutputStream( PROJECT_FILENAME );
+ OutputStream classpathOutput = getOutputStream( CLASSPATH_FILENAME );
+
+ try
+ {
+ createProject( projectOutput );
+ createClasspath( classpathOutput );
+ }
+ catch ( IOException e )
+ {
+ throw new BuildException( "Can't write to eclipse project files",
+ e );
+ }
+ finally
+ {
+ closeStream( projectOutput );
+ closeStream( classpathOutput );
+ }
+ }
+
+ protected void createProject( OutputStream projectOutput )
+ throws IOException
+ {
+ Definition projectDef = getProjectDefinition();
+
+ Writer writer = new OutputStreamWriter( projectOutput );
+
+ 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 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" );
+
+ Definition projectDef = getProjectDefinition();
+ ResourceRef[] resourceRefs = projectDef.getResourceRefs();
+ Collection resources = getResources( resourceRefs );
+ Iterator iter = resources.iterator();
+ while ( iter.hasNext() )
+ {
+ Resource resource = ( Resource ) iter.next();
+ writer.write( " " + getEclipseClasspath( resource ) + "\n" );
+ }
+
+ writer.write( "</classpath>\n" );
+ writer.flush();
+ }
+
+ protected Definition getProjectDefinition()
+ {
+ Context ctx = getContext();
+ String key = ctx.getKey();
+ Index index = getIndex();
+ return index.getDefinition( key );
+ }
+
+ /**
+ * Recursiv search of all resources dependencies this resource ref has.
+ *
+ * @param resourceRefs the resourceRef for which the dependencies we
want to
+ * find
+ * @return collection of Resource objects
+ */
+ private Collection getResources( ResourceRef[] resourceRefs )
+ {
+ Set resources = new HashSet();
+
+ for ( int i = 0; i < resourceRefs.length; i++ )
+ {
+ Resource r = getIndex().getResource( resourceRefs[i] );
+ resources.add( r );
+ resources.addAll( getResources( r.getResourceRefs() ) );
+ }
+ return resources;
+ }
+
+ private String getEclipseClasspath( Resource r )
+ {
+ Info info = r.getInfo();
+ StringBuffer sb = new StringBuffer();
+ sb.append( "<classpathentry kind=\"var\" path=\""
+ + ECLIPSE_MAGIC_VARIABLE + "/" );
+ sb.append( info.getGroup() );
+ sb.append( "/jars/" );
+ sb.append( info.getName() );
+ if ( info.getVersion() != null )
+ {
+ sb.append( "-" );
+ sb.append( info.getVersion() );
+ }
+ sb.append( "." );
+ sb.append( info.getType() );
+ sb.append( "\"/>" );
+ return sb.toString();
+ }
+
+ private OutputStream getOutputStream( String filename )
+ {
+ String targetFile = TARGET_DIR + "/" + filename;
+ File projectFile = getProject().resolveFile( targetFile );
+ OutputStream out;
+ try
+ {
+ out = new FileOutputStream( projectFile );
+ }
+ catch ( FileNotFoundException e )
+ {
+ String fileLocation = projectFile.getAbsolutePath();
+ throw new BuildException( "Can't create file '" + fileLocation
+ + "'", e );
+ }
+ return out;
+ }
+
+ private void closeStream( OutputStream output )
+ {
+ if ( null != output )
+ {
+ try
+ {
+ output.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+
+}
\ No newline at end of file
Added:
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/antlib.xml
==============================================================================
--- (empty file)
+++
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/antlib.xml
Fri Jan 7 15:30:34 2005
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<antlib>
+
+ <!-- taskdefs -->
+ <taskdef name="eclipse"
classname="net.dpml.magic.eclipse.EclipseTask"/>
+
+</antlib>
Added:
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/package.html
==============================================================================
--- (empty file)
+++
development/main/magic/spells/eclipse/src/main/net/dpml/magic/eclipse/package.html
Fri Jan 7 15:30:34 2005
@@ -0,0 +1,7 @@
+
+<body>
+<p>
+Task supporting the creation of eclipse project files.
+</p>
+</body>
+
- svn commit: r1403 - in development/main/magic: . spells/eclipse spells/eclipse/etc spells/eclipse/etc/deliverables spells/eclipse/etc/deliverables/templates spells/eclipse/src spells/eclipse/src/main spells/eclipse/src/main/net spells/eclipse/src/main/net/dpml spells/eclipse/src/main/net/dpml/magic spells/eclipse/src/main/net/dpml/magic/eclipse, andreas . ronge, 01/07/2005
Archive powered by MHonArc 2.6.24.