avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject svn commit: rev 45972 - in avalon/trunk/central/laboratory/studio/magic: . src src/main src/main/org src/main/org/apache src/main/org/apache/metro src/main/org/apache/metro/studio src/main/org/apache/metro/studio/magic
Date Mon, 13 Sep 2004 12:12:11 GMT
Author: niclas
Date: Mon Sep 13 05:12:11 2004
New Revision: 45972

Added:
   avalon/trunk/central/laboratory/studio/magic/
   avalon/trunk/central/laboratory/studio/magic/build.xml   (contents, props changed)
   avalon/trunk/central/laboratory/studio/magic/project.properties   (contents, props changed)
   avalon/trunk/central/laboratory/studio/magic/src/
   avalon/trunk/central/laboratory/studio/magic/src/main/
   avalon/trunk/central/laboratory/studio/magic/src/main/org/
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/EclipseBuildListener.java
  (contents, props changed)
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/EclipseTask.java
  (contents, props changed)
   avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/package.html
  (contents, props changed)
Log:
Added a Magic Plugin that generates Eclipse Plugins.

Added: avalon/trunk/central/laboratory/studio/magic/build.xml
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/magic/build.xml	Mon Sep 13 05:12:11 2004
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<project name="metro-studio-magic" default="install" basedir="." 
+    xmlns:x="antlib:org.apache.avalon.tools"
+>
+
+  <property file="project.properties" />
+  
+  <x:home index="../index.xml"/>
+  <import file="${project.system}/default/standard.xml"/>
+  
+  <target name="build" depends="standard.build">
+    <x:declare/>
+  </target>
+
+  
+</project>

Added: avalon/trunk/central/laboratory/studio/magic/project.properties
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/magic/project.properties	Mon Sep 13 05:12:11 2004
@@ -0,0 +1,5 @@
+
+project.name = metro-studio-magic
+
+project.system = ../../../system/build
+

Added: avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/EclipseBuildListener.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/EclipseBuildListener.java
Mon Sep 13 05:12:11 2004
@@ -0,0 +1,186 @@
+/* 
+ * 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.metro.studio.magic;
+
+import java.io.File;
+
+import org.apache.avalon.tools.model.MagicPath;
+import org.apache.avalon.tools.model.Policy;
+
+import org.apache.avalon.tools.tasks.ReplicateTask;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+
+/**
+ * An abstract build listener. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Id: MetaBuildListener.java 30977 2004-07-30 08:57:54Z niclas $
+ */
+public class EclipseBuildListener 
+    implements BuildListener
+{
+    private static final String PREPARE_TASK_KEY = 
+      "antlib:org.apache.avalon.tools:prepare";
+
+    private static final String META_TASK_KEY = 
+      "plugin:metro/studio/metro-studio-magic:studio";
+
+    private final String m_uri;
+
+    private boolean m_executed;
+
+    public EclipseBuildListener( String uri )
+    {
+        m_uri = uri;
+        m_executed = false;
+    }
+
+    /**
+     * Signals that a build has started. This event
+     * is fired before any targets have started.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     */
+    public void buildStarted( BuildEvent event )
+    {
+        // will not happen
+    }
+
+    /**
+     * Signals that the last target has finished. This event
+     * will still be fired if an error occurred during the build.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getException()
+     */
+    public void buildFinished( BuildEvent event )
+    {
+    }
+
+    /**
+     * Signals that a target is starting.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getTarget()
+     */
+    public void targetStarted( BuildEvent event )
+    {
+    }
+
+    /**
+     * Signals that a target has finished. This event will
+     * still be fired if an error occurred during the build.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getException()
+     */
+    public void targetFinished( BuildEvent event )
+    {
+    }
+
+    /**
+     * Signals that a task is starting.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getTask()
+     */
+    public void taskStarted( BuildEvent event )
+    {
+    }
+
+    /**
+     * Signals that a task has finished. This event will still
+     * be fired if an error occurred during the build.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getException()
+     */
+    public void taskFinished( BuildEvent event )
+    {
+        if( m_executed ) 
+            return;
+
+        String type = event.getTask().getTaskType();
+        if( PREPARE_TASK_KEY.equals( type ) )
+        {
+            Project project = event.getProject();
+            generatePluginXML( project );
+            m_executed = true;
+        }
+    }
+
+    private void generatePluginXML( Project project )
+    {
+        File basedir = project.getBaseDir();
+        File pluginSpec = new File( basedir, "target/build/etc/plugin-spec.xml" );
+        if( pluginSpec.exists() )
+        {
+            File dest = new File( basedir, "target/deliverables/" );
+            dest.mkdirs();
+            
+            MagicPath path = new MagicPath( project );
+            path.setMode( "RUNTIME" );
+            
+            ReplicateTask repl = new ReplicateTask();
+            repl.setProject( project );
+            repl.setTaskName( "replicate" );
+            repl.init();
+            File f = new File( basedir, "target/deliverables/lib" );
+            f.mkdirs();
+            repl.setTodir( f );
+            repl.setRefid( path );
+            repl.execute();
+            
+            EclipseTask task = new EclipseTask();
+            task.setProject( project );
+            task.setTaskName( "eclipse" );
+            task.init();
+            
+            task.setDestDir( dest );
+            task.setPluginSpec( pluginSpec );
+            task.execute();
+        }
+    }
+
+    /**
+     * Signals a message logging event.
+     *
+     * @param event An event with any relevant extra information.
+     *              Must not be <code>null</code>.
+     *
+     * @see BuildEvent#getMessage()
+     * @see BuildEvent#getPriority()
+     */
+    public void messageLogged( BuildEvent event )
+    {
+    }   
+}

Added: avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/EclipseTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/EclipseTask.java
Mon Sep 13 05:12:11 2004
@@ -0,0 +1,243 @@
+/* 
+ * 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.metro.studio.magic;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.ArrayList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+
+import javax.xml.transform.dom.DOMSource;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.avalon.tools.model.Context;
+import org.apache.avalon.tools.model.Definition;
+import org.apache.avalon.tools.model.Home;
+import org.apache.avalon.tools.model.Info;
+import org.apache.avalon.tools.model.Policy;
+import org.apache.avalon.tools.model.Resource;
+import org.apache.avalon.tools.model.ResourceRef;
+
+import org.apache.avalon.tools.tasks.SystemTask;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+import org.apache.tools.ant.types.Path;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Generate a eclipse plugin XML.
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ */
+public class EclipseTask extends SystemTask
+{
+    /**
+     * The file containing the specification for the plugin.xml
+     */
+    private File m_PluginSpec;
+
+    /**
+     * The destination directory for plugin.xml
+     */
+    private File m_DestDir;
+
+
+    /**
+     * Set the desitation directory to generate output files to.
+     *
+     * @param destDir The destination directory
+     */
+    public void setDestDir( final File destDir )
+    {
+        m_DestDir = destDir;
+    }
+
+    /**
+     * Return the destination directory in which files are generated.
+     *
+     * @return the destination directory in which files are generated.
+     */
+    public File getDestDir()
+    {
+        return m_DestDir;
+    }
+    
+    /**
+     * Set the file containing the specification for the plugin.xml.
+     *
+     * @param destDir the file containing the specification for 
+     *                the plugin.xml.
+     */
+    public void setPluginSpec( File pluginSpec )
+    {
+        m_PluginSpec = pluginSpec;
+    }
+
+    /**
+     * Return the file containing the specification for the plugin.xml.
+     *
+     * @return the file containing the specification for the plugin.xml.
+     */
+    public File getPluginSpec()
+    {
+        return m_PluginSpec;
+    }
+
+    /**
+     * Execute generator task.
+     * @exception BuildException if a build error occurs
+     */
+    public void execute()
+        throws BuildException
+    {
+        try
+        {
+            Document doc = parseSpecification();
+            addVersionAttribute( doc );
+            addRuntimeElement( doc );
+            writePluginXml( doc );
+        } catch( ParserConfigurationException e )
+        {
+            String message = "JAXP is not properly setup. Missing Parser.";
+            throw new BuildException( message, e );
+        } catch( TransformerConfigurationException e )
+        {
+            String message = "JAXP is not properly setup. Missing Transformer.";
+            throw new BuildException( message, e );
+        } catch( SAXException e )
+        {
+            String message = "";
+            throw new BuildException( message, e );
+        } catch( IOException e )
+        {
+            String message = "";
+            throw new BuildException( message, e );
+        } catch( TransformerException e )
+        {
+            String message = "";
+            throw new BuildException( message, e );
+        }
+    }
+    
+    private Document parseSpecification()
+        throws ParserConfigurationException, SAXException, IOException
+    {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        Document doc = builder.parse( m_PluginSpec );
+        return doc;
+    }
+    
+    private void addVersionAttribute( Document doc )
+    {
+        Element root = doc.getDocumentElement();
+        Home home = getHome();
+        String name = getProject().getName();
+        Definition def = home.getDefinition( name );
+        Info info = def.getInfo();
+        String version = info.getVersion();
+        root.setAttribute( "version", version );
+    }
+    
+    private void addRuntimeElement( Document doc )
+    {
+        Element root = doc.getDocumentElement();
+        Element runtimeElement = doc.createElement( "runtime" );
+        Text padding = doc.createTextNode( "\n  " );
+        root.appendChild( padding );
+        root.appendChild( runtimeElement );
+        padding = doc.createTextNode( "\n" );
+        root.appendChild( padding );
+        
+        Project project = getProject();
+        String projectName = project.getName();
+        Home home = getHome();
+        Definition def = home.getDefinition( projectName );
+        processDefinition( doc, runtimeElement, def );
+    }
+    
+    private void processDefinition( Document doc, Element runtime, Definition def )
+    {
+        Element selfNode = appendLibraryChild( doc, runtime, def );
+        Element export = doc.createElement( "export" );
+        export.setAttribute( "name", "*" );
+        Text padding = doc.createTextNode( "\n      " );
+        selfNode.appendChild( padding );
+        selfNode.appendChild( export );
+        padding = doc.createTextNode( "\n    " );
+        selfNode.appendChild( padding );
+        
+        final ResourceRef[] refs = 
+            def.getResourceRefs( getProject(), Policy.RUNTIME, ResourceRef.ANY, true );
+        Home home = getHome();
+        for( int i=0 ; i < refs.length ; i++ )
+        {
+            Resource resource = home.getResource( refs[i] );
+            appendLibraryChild( doc, runtime, resource );
+        }
+        padding = doc.createTextNode( "\n  " );
+        runtime.appendChild( padding );
+    }
+
+    private Element appendLibraryChild( Document doc, Node node, Resource resource )
+    {
+        final String name = resource.getFilename();
+        final String group = resource.getInfo().getGroup();
+        
+        final String filename = "lib/" + group + "/" + name;
+        
+        final Element library = doc.createElement( "library" );
+        library.setAttribute( "name", filename );
+        Text padding = doc.createTextNode( "\n    " );
+        node.appendChild( padding );
+        node.appendChild( library );
+        return library;
+    }
+        
+    private void writePluginXml( Document doc )
+        throws TransformerConfigurationException, TransformerException
+    {
+        TransformerFactory factory = TransformerFactory.newInstance();
+        Transformer transformer = factory.newTransformer();
+        
+        File output = new File( m_DestDir, "plugin.xml" );
+        
+        DOMSource source = new DOMSource( doc );
+        StreamResult result = new StreamResult( output );
+        transformer.transform( source, result );
+    }
+}

Added: avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/package.html
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/magic/src/main/org/apache/metro/studio/magic/package.html
Mon Sep 13 05:12:11 2004
@@ -0,0 +1,5 @@
+<html><body>
+<p>Plugin for Magic that creates Eclipse Plugins.</p>
+</body></html>
+
+

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


Mime
View raw message