avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oberh...@apache.org
Subject svn commit: rev 37234 - in avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse: core/environment core/nature core/templateengine ui
Date Tue, 31 Aug 2004 04:42:08 GMT
Author: oberhack
Date: Mon Aug 30 21:42:07 2004
New Revision: 37234

Added:
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/KernelManager.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ModelObject.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/BlockProjectManager.java
      - copied, changed from rev 36643, avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ProjectManager.java
Removed:
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ProjectManager.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/ui/
Modified:
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/MetroEnvironment.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ServerEnvironment.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/MetroBlockNature.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Directory.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplate.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplateManager.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Library.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Resource.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplate.java
   avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplateManager.java
Log:


Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/KernelManager.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/KernelManager.java
Mon Aug 30 21:42:07 2004
@@ -0,0 +1,419 @@
+/* 
+ * 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.eclipse.core.environment;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.avalon.repository.Artifact;
+import org.apache.avalon.repository.main.DefaultBuilder;
+import org.apache.avalon.repository.main.DefaultInitialContextFactory;
+import org.apache.avalon.repository.provider.Builder;
+import org.apache.avalon.repository.provider.Factory;
+import org.apache.avalon.repository.provider.InitialContext;
+import org.apache.avalon.repository.provider.InitialContextFactory;
+import org.apache.avalon.util.env.Env;
+import org.apache.avalon.util.exception.ExceptionHelper;
+import org.apache.avalon.util.i18n.ResourceManager;
+import org.apache.avalon.util.i18n.Resources;
+
+/**
+ * Merlin command line handler.
+ * 
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team </a>
+ * @version $Id: Main.java 30977 2004-07-30 08:57:54Z niclas $
+ */
+public class KernelManager
+{
+    //----------------------------------------------------------
+    // static
+    //----------------------------------------------------------
+
+    private static Resources REZ = ResourceManager
+            .getPackageResources(KernelManager.class);
+
+    private static final File USER_HOME = new File(System
+            .getProperty("user.home"));
+
+    private static final String MERLIN_PROPERTIES = "merlin.properties";
+
+    private static final String IMPLEMENTATION_KEY = "merlin.implementation";
+
+    private static KernelManager MAIN = null;
+
+    /**
+     * Main command line enty point.
+     * 
+     * @param args
+     *            the command line arguments
+     */
+    public static void main(String[] args)
+    {
+        boolean debug = false;
+        try
+        {
+
+            ModelObject line = new ModelObject();
+            line.put("impl", "merlin-cli-3.3.0.jar");
+            
+            File dir = getWorkingDirectory(line);
+            File cache = getMerlinSystemRepository(line);
+            Artifact artifact = getDefaultImplementation(dir, line);
+
+            InitialContextFactory factory = new DefaultInitialContextFactory(
+                    "merlin", dir);
+            factory.setCacheDirectory(cache);
+            factory.setOnlineMode(!line.hasOption("offline"));
+            InitialContext context = factory.createInitialContext();
+            
+            KernelManager kernel = new KernelManager( context, artifact, line );
+            
+        } catch (Exception exception)
+        {
+            String msg = ExceptionHelper.packException(exception, debug);
+            System.err.println(msg);
+            System.exit(-1);
+        } catch (Throwable throwable)
+        {
+            String msg = ExceptionHelper.packException(throwable, true);
+            System.err.println(msg);
+            System.exit(-1);
+        }
+    }
+
+    //----------------------------------------------------------
+    // constructor
+    //----------------------------------------------------------
+
+    /**
+     * Creation of a new kernel cli handler.
+     * 
+     * @param context
+     *            the repository inital context
+     * @param artifact
+     *            the merlin implementation artifact
+     * @param line
+     *            the command line construct
+     * @exception Exception
+     *                if an error occurs
+     */
+    public KernelManager(InitialContext context, Artifact artifact,
+            ModelObject line) throws Exception
+    {
+        Builder builder = context.newBuilder(artifact);
+        Factory factory = builder.getFactory();
+        Map criteria = factory.createDefaultCriteria();
+
+        //
+        // update the criteria using the command line information
+        //
+
+        handleCommandLine(criteria, line);
+
+    }
+
+    //----------------------------------------------------------
+    // implementation
+    //----------------------------------------------------------
+
+    private void handleCommandLine(Map criteria, ModelObject line)
+    {
+        setLanguage(criteria, line);
+        setInfoPolicy(criteria, line);
+        setDebugPolicy(criteria, line);
+        setAuditPolicy(criteria, line);
+        setProxyPolicy(criteria, line);
+        setServerPolicy(criteria, line);
+        setSecurityPolicy(criteria, line);
+        setAnchorDirectory(criteria, line);
+        setContextDirectory(criteria, line);
+        setRepositoryDirectory(criteria, line);
+        setKernelURL(criteria, line);
+        setOverridePath(criteria, line);
+        setDeploymentPath(criteria, line);
+    }
+
+    private void setLanguage(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("lang"))
+        {
+            String language = line.getOptionValue("lang");
+            criteria.put("merlin.lang", language);
+        }
+    }
+
+    private void setKernelURL(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("kernel"))
+        {
+            String kernel = line.getOptionValue("kernel");
+            criteria.put("merlin.kernel", kernel);
+        }
+    }
+
+    private void setOverridePath(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("config"))
+        {
+            String config = line.getOptionValue("config");
+            criteria.put("merlin.override", config);
+        }
+    }
+
+    private void setWorkingDirectory(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("home"))
+        {
+            String home = line.getOptionValue("home");
+            criteria.put("merlin.dir", home);
+        }
+    }
+
+    private void setAnchorDirectory(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("anchor"))
+        {
+            String anchor = line.getOptionValue("anchor");
+            criteria.put("merlin.anchor", anchor);
+        }
+    }
+
+    private void setContextDirectory(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("context"))
+        {
+            String context = line.getOptionValue("context");
+            criteria.put("merlin.context", context);
+        }
+    }
+
+    private void setRepositoryDirectory(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("repository"))
+        {
+            String repository = line.getOptionValue("repository");
+            criteria.put("merlin.repository", repository);
+        }
+    }
+
+    private void setDebugPolicy(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("debug"))
+        {
+            criteria.put("merlin.debug", new Boolean(true));
+        }
+    }
+
+    private void setAuditPolicy(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("audit"))
+        {
+            criteria.put("merlin.audit", new Boolean(true));
+        }
+    }
+
+    private void setProxyPolicy(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("noproxy"))
+        {
+            criteria.put("merlin.proxy", new Boolean(false));
+        }
+    }
+
+    private void setInfoPolicy(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("info"))
+        {
+            criteria.put("merlin.info", new Boolean(true));
+        }
+    }
+
+    private void setServerPolicy(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("execute"))
+        {
+            criteria.put("merlin.server", new Boolean(false));
+        }
+    }
+
+    private void setSecurityPolicy(Map criteria, ModelObject line)
+    {
+        if (line.hasOption("secure"))
+        {
+            criteria.put("merlin.code.security.enabled", new Boolean(true));
+        }
+    }
+
+    private void setDeploymentPath(Map criteria, ModelObject line)
+    {
+        String[] arguments = line.getArgs();
+        if (arguments.length > 0)
+        {
+            criteria.put("merlin.deployment", arguments);
+        }
+    }
+
+    /**
+     * Resolve the merlin.dir value.
+     * 
+     * @param line
+     *            the command line construct
+     * @return the working directory
+     */
+    private static File getWorkingDirectory(ModelObject line) throws Exception
+    {
+        if (line.hasOption("home"))
+        {
+            String dir = line.getOptionValue("home");
+            return new File(dir).getCanonicalFile();
+        } else
+        {
+            return getBaseDirectory();
+        }
+    }
+
+    /**
+     * Resolve the default implementation taking into account command line
+     * arguments, local and hom properties, and application defaults.
+     * 
+     * @param line
+     *            the command line construct
+     * @return the artifact reference
+     */
+    private static Artifact getDefaultImplementation(File base, ModelObject line)
+            throws Exception
+    {
+        if (line.hasOption("impl"))
+        {
+            String spec = line.getOptionValue("impl");
+            return Artifact.createArtifact(spec);
+        } else
+        {
+            return DefaultBuilder.createImplementationArtifact(
+                    KernelManager.class.getClassLoader(), getMerlinHome(),
+                    getBaseDirectory(), MERLIN_PROPERTIES, IMPLEMENTATION_KEY);
+        }
+    }
+
+    /**
+     * Return the merlin system repository root directory taking into account
+     * the supplied command-line, and merlin.properties files in the current and
+     * home directories.
+     * 
+     * @param line
+     *            the command line construct
+     * @return the merlin system root repository directory
+     */
+    private static File getMerlinSystemRepository(ModelObject line)
+    {
+        if (line.hasOption("system"))
+        {
+            String system = line.getOptionValue("system");
+            return new File(system);
+        } else
+        {
+            return new File(getMerlinHome(), "system");
+        }
+    }
+
+    /**
+     * Return the merlin home directory.
+     * 
+     * @return the merlin installation directory
+     */
+    private static File getMerlinHome()
+    {
+        return new File(getMerlinHomePath());
+    }
+
+    /**
+     * Return the merlin home directory path.
+     * 
+     * @return the merlin installation directory path
+     */
+    private static String getMerlinHomePath()
+    {
+        try
+        {
+            String merlin = System.getProperty("merlin.home", Env
+                    .getEnvVariable("MERLIN_HOME"));
+            if (null != merlin)
+                return merlin;
+            return System.getProperty("user.home") + File.separator + ".merlin";
+        } catch (Throwable e)
+        {
+            final String error = "Internal error while attempting to access MERLIN_HOME environment.";
+            final String message = ExceptionHelper
+                    .packException(error, e, true);
+            throw new RuntimeException(message);
+        }
+    }
+
+    /**
+     * Return the functional base directory. The implementation looks for the
+     * ${merlin.dir} system property and if not found, looks for the ${basedir}
+     * system property, and as a last resort, returns the JVM ${user.dir} value.
+     * 
+     * @return the base directory
+     */
+    private static File getBaseDirectory()
+    {
+        final String merlin = System.getProperty("merlin.dir");
+        if (null != merlin)
+        {
+            return new File(merlin);
+        }
+        final String base = System.getProperty("basedir");
+        if (null != base)
+        {
+            return new File(base);
+        }
+        return new File(System.getProperty("user.dir"));
+    }
+
+    /**
+     * Return a property file from a fir with a supplied filename.
+     * 
+     * @param dir
+     *            the directory
+     * @param filename
+     *            the filename
+     * @return a possibly empty properties instance
+     */
+    private static Properties getLocalProperties(File dir, String filename)
+    {
+        Properties properties = new Properties();
+        if (null == dir)
+            return properties;
+        File file = new File(dir, filename);
+        if (!file.exists())
+            return properties;
+        try
+        {
+            properties.load(new FileInputStream(file));
+            return properties;
+        } catch (Throwable e)
+        {
+            final String error = "Unexpected exception while attempting to read properties
from: "
+                    + file + ". Cause: " + e.toString();
+            throw new IllegalStateException(error);
+        }
+    }
+}
\ No newline at end of file

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/MetroEnvironment.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/MetroEnvironment.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/MetroEnvironment.java
Mon Aug 30 21:42:07 2004
@@ -18,7 +18,6 @@
 package org.apache.metro.studio.eclipse.core.environment;
 
 import java.io.IOException;
-import java.util.Properties;
 
 import org.apache.avalon.util.defaults.DefaultsBuilder;
 import org.apache.metro.studio.eclipse.core.MetroStudioCore;
@@ -60,10 +59,6 @@
         String path;
         try
         {
-            Properties prop = merlinBuilder.getUserProperties();
-            prop = merlinBuilder.getDirProperties();
-            prop = merlinBuilder.getHomeProperties();
-
             path = merlinBuilder.getHomeDirectory().getCanonicalPath();
         } catch (IOException e)
         {

Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ModelObject.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ModelObject.java
Mon Aug 30 21:42:07 2004
@@ -0,0 +1,60 @@
+/*
+
+   Copyright 2004. The 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.eclipse.core.environment;
+
+import java.util.Hashtable;
+
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
+ * 20.08.2004
+ * last change:
+ * 
+ */
+public class ModelObject
+{
+
+    Hashtable table = new Hashtable();
+    /**
+     * 
+     */
+    public ModelObject()
+    {
+        super();
+    }
+    
+    public void put(Object key, Object value)
+    {
+        table.put(key, value);
+    }
+    public boolean hasOption(String option)
+    {
+        return table.containsKey(option);
+    }
+    
+    public String getOptionValue(String option)
+    {
+        return (String)table.get(option);
+    }
+    
+    public String[] getArgs()
+    {
+        return null;
+    }
+
+}

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ServerEnvironment.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ServerEnvironment.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/environment/ServerEnvironment.java
Mon Aug 30 21:42:07 2004
@@ -26,6 +26,12 @@
 public class ServerEnvironment
 {
 
+    public static final String DEFAULT_LANG = "de";
+    public static final boolean DEFAULT_DEBUG = true;
+    public static final boolean DEFAULT_DEPLOY = false;
+    public static final boolean DEFAULT_SERVER = false;
+    public static final boolean DEFAULT_SECURITY = true;
+    
     /**
      * 
      */

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/MetroBlockNature.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/MetroBlockNature.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/MetroBlockNature.java
Mon Aug 30 21:42:07 2004
@@ -17,7 +17,10 @@
  */
 package org.apache.metro.studio.eclipse.core.nature;
 
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
+import org.eclipse.core.resources.ICommand;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.IProjectNature;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jdt.core.IJavaProject;
@@ -41,6 +44,41 @@
 	 */
     public void configure() throws CoreException
     {
+        addBuilder("org.apache.metro.studio.launch.merlinBuilder");
+    }
+    /**
+     * @param pString
+     */
+    public void addBuilder(String builderID)
+    {
+        try
+        {
+            IProjectDescription desc = getProject().getDescription();
+            ICommand[] commands = desc.getBuildSpec();
+            boolean found = false;
+
+            for (int i = 0; i < commands.length; ++i) {
+                if (commands[i].getBuilderName().equals(builderID)) {
+                    found = true;
+                    break;
+                }
+            }
+            if (!found) { 
+                //add builder to project
+                ICommand command = desc.newCommand();
+                command.setBuilderName(builderID);
+                ICommand[] newCommands = new ICommand[commands.length + 1];
+
+                // Add it before other builders.
+                System.arraycopy(commands, 0, newCommands, 1, commands.length);
+                newCommands[0] = command;
+                desc.setBuildSpec(newCommands);
+                getProject().setDescription(desc, null);
+            }
+        } catch (CoreException e)
+        {
+            MetroStudioCore.log(e, "Error while setting the builder commands");
+        }
 
     }
 

Copied: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/BlockProjectManager.java
(from rev 36643, avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ProjectManager.java)
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ProjectManager.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/BlockProjectManager.java
Mon Aug 30 21:42:07 2004
@@ -19,6 +19,7 @@
 
 import java.util.List;
 
+import org.apache.metro.facility.presentationservice.impl.ChannelEvent;
 import org.apache.metro.studio.eclipse.core.MetroStudioCore;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
@@ -32,7 +33,7 @@
  *         11.08.2004 last change:
  *  
  */
-public class ProjectManager
+public class BlockProjectManager
 {
     final public static String BASE = "org.apache.metro.studio.core";
 
@@ -41,13 +42,31 @@
     final public static String FACILITY_NATURE_ID = BASE + ".facilityNature";
 
     final public static String KERNEL_NATURE_ID = BASE + ".kernelNature";
+    
+    private static ResourceTemplateManager resourceTemplateManager = null;
 
     /**
      *  
      */
-    public ProjectManager()
+    public BlockProjectManager()
     {
         super();
+
+    }
+
+    /**
+     * get a list of wizard pages, which are needed for a specific
+     * ResourceTemplate.
+     * 
+     * @param resourceTemplateName
+     * @return
+     */
+    public static String getResourceHelp(String resourceTemplateName)
+    {
+
+        ResourceTemplate template = resourceTemplateManager.getTemplate(resourceTemplateName);
+        if(template==null) return "";
+        return template.getDescription();
     }
 
     /**
@@ -70,7 +89,7 @@
      * @param valueObject
      * @return
      */
-    public static IProject createBlockProject(Object valueObject)
+    public static IProject create(ChannelEvent event)
     {
 
         return null;
@@ -80,9 +99,10 @@
      * This method is called to show all available template in the wizard so
      * that the user can choose one of them.
      */
-    public List getResourceTemplateNames()
+    public static String[] listTemplateNames()
     {
-        return null;
+        initialize();
+        return resourceTemplateManager.listTemplateNames();
     }
 
     /**
@@ -91,22 +111,31 @@
      * @param name
      * @return
      */
-    public static IProject createBlockProject(String name)
+    public static IProject create(String projectName, String templateName)
     {
-        return createProject(name, BLOCK_NATURE_ID);
+        initialize();
+        IProject project = createProject(projectName, BLOCK_NATURE_ID);
+        //if no template name is given, create the project only
+        if(templateName==null)
+        {
+            return project;
+        }
+        // create the resources of a given templateName
+        resourceTemplateManager.create(project, templateName, null);
+        return project;
     }
 
     /**
-     * Create a facility project
      * 
-     * @param name
-     * @return
      */
-    public static IProject createFacilityProject(String name)
+    private static void initialize()
     {
-        return createProject(name, FACILITY_NATURE_ID);
+        if(resourceTemplateManager==null)
+        {
+            resourceTemplateManager = ResourceTemplateManager.load(null);
+        }
+        
     }
-
     private static IProject createProject(String name, String nature)
     {
         IProject project = null;
@@ -160,7 +189,7 @@
         IProjectNature nature = null;
         try
         {
-            nature = project.getNature(ProjectManager.BLOCK_NATURE_ID);
+            nature = project.getNature(BlockProjectManager.BLOCK_NATURE_ID);
             // TODO: check for other valid Metro natures
             
         } catch (CoreException e)
@@ -173,4 +202,15 @@
         }
         return nature;
     }
+
+    /**
+     * Only used for testing purpose
+     * @param name
+     * @return
+     */
+    public static IProject testCreateProject(String name)
+    {
+        return createProject(name, BLOCK_NATURE_ID);
+    }
+
 }

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Directory.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Directory.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Directory.java
Mon Aug 30 21:42:07 2004
@@ -17,15 +17,18 @@
  */
 package org.apache.metro.studio.eclipse.core.templateengine;
 
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Vector;
 
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
 import org.apache.metro.studio.eclipse.core.tools.ClassNameAnalyzer;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
 
 /**
  * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team </a>
@@ -37,7 +40,6 @@
 
     private String name;
     private boolean isSource = false;
-    private List libraries = new ArrayList();
     private transient IFolder eclipseFolder;
 
     /**
@@ -82,40 +84,6 @@
         this.name = name;
     }
 
-    public void addLibrary(Library library)
-    {
-
-        libraries.add(library);
-    }
-
-    public List getLibraries()
-    {
-
-        return libraries;
-    }
-
-    /**
-     * Collect all library names
-     * @return
-     */
-    public Vector getLibraryNames()
-    {
-
-        Vector libraries = new Vector();
-        Iterator it = getLibraries().iterator();
-        while (it.hasNext())
-        {
-            Library lib = (Library)it.next();
-            String name;
-            name = lib.getName();
-            if(lib.getVersion() != null){
-                name = name + "-"+lib.getVersion();
-            }
-            libraries.add(name+".jar");
-        }
-        return libraries;
-    }
-
     /**
      * Create a directory under the given project.
      * 
@@ -153,6 +121,11 @@
                     folder.create(false, true, null);
                     eclipseFolder = folder;
                 }
+                if(isSource())
+                {
+                    IClasspathEntry entry = JavaCore.newSourceEntry(project.getFullPath().append(folder.getName()));
+                    addClasspath(project, entry);
+                }
             }
 
         } catch (CoreException e)
@@ -162,6 +135,39 @@
 
     }
     
+
+    /**
+     * @param project
+     */
+    private void addClasspath(IProject project, IClasspathEntry entry)
+    {
+        try
+        {
+            Vector libraries = new Vector();
+            
+            IJavaProject javaProject = JavaCore.create(project);
+            IClasspathEntry[] current = javaProject.getResolvedClasspath(true);
+
+            for(int i=0; i<current.length; i++)
+            {
+                // don't add the project to the classpath!
+                if( ! current[i].getPath().toString().equals(project.getFullPath().toString()))
+                {
+                libraries.add(current[i]);  
+                }
+            }
+            libraries.add(entry);
+            
+            javaProject.setRawClasspath((IClasspathEntry[]) libraries
+                    .toArray(new IClasspathEntry[libraries.size()]),
+                    javaProject.getOutputLocation(), null);
+
+
+        } catch (JavaModelException e)
+        {
+            MetroStudioCore.log(e, "could not add libraries to project");
+        }
+    }
 
     /**
      * append a directory.

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplate.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplate.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplate.java
Mon Aug 30 21:42:07 2004
@@ -45,19 +45,6 @@
     }
     
     /**
-     * Collect all LibraryNames
-     * @return
-     */
-    public Vector getLibraryNames(){
-        
-        Vector libraries = new Vector();
-        Iterator it = directories.iterator();
-        while(it.hasNext()){
-            libraries.addAll(((Directory)it.next()).getLibraryNames());
-        }
-        return libraries;
-    }
-    /**
      * Create all directories in Project
      * @param project
      */

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplateManager.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplateManager.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplateManager.java
Mon Aug 30 21:42:07 2004
@@ -17,23 +17,14 @@
  */
 package org.apache.metro.studio.eclipse.core.templateengine;
 
-import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.Set;
-import java.util.Vector;
 
 import org.apache.metro.studio.eclipse.core.MetroStudioCore;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.launching.JavaRuntime;
 
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.io.xml.DomDriver;
@@ -75,37 +66,6 @@
     }
 
     /**
-     * Add standard libraries to the project.
-     * 
-     * @param template
-     * @param project
-     */
-    public void addLibraries(DirectoryTemplate template, IProject project)
-    {
-        Vector libraries = new Vector();
-        Vector libraryNames;
-
-        IPath repositoryPath = getRepositoryPath();
-
-        libraries.addAll(collectLibraries(template, repositoryPath));
-        libraries.addAll(collectSourceFolders(template, project));
-
-        // add all Libraries to project.
-        try
-        {
-            IJavaProject javaProject = JavaCore.create(project);
-            javaProject.setRawClasspath((IClasspathEntry[]) libraries
-                    .toArray(new IClasspathEntry[libraries.size()]),
-                    javaProject.getOutputLocation(), null);
-
-        } catch (JavaModelException e)
-        {
-            MetroStudioCore.log(e, "could not add libraries to project");
-        }
-
-    }
-
-    /**
      * @return
      */
     public IPath getRepositoryPath()
@@ -117,66 +77,13 @@
     }
 
     /**
-     * @param template
-     * @param libraries
-     * @param repositoryPath
-     */
-    public Vector collectLibraries(DirectoryTemplate template,
-            IPath repositoryPath)
-    {
-        Vector libraryNames;
-        Vector libraries = new Vector();
-
-        // first add the java standard library
-        libraries.add(JavaRuntime.getJREVariableEntry());
-
-        // Now collect libraries from template.
-        libraryNames = template.getLibraryNames();
-        Iterator it = libraryNames.iterator();
-
-        while (it.hasNext())
-        {
-            String lib = (String) it.next();
-            if (new File(lib).exists())
-            {
-                libraries.add(JavaCore.newLibraryEntry(repositoryPath
-                        .append(lib), null, null));
-            }
-        }
-        return libraries;
-    }
-
-    /**
-     * @param template
-     * @param libraries
-     * @param repositoryPath
-     */
-    public Vector collectSourceFolders(DirectoryTemplate template,
-            IProject project)
-    {
-        Vector folderNames;
-        Vector libraries = new Vector();
-
-        // Now collect libraries from template.
-        folderNames = template.getSourceFolderNames();
-        Iterator it = folderNames.iterator();
-
-        while (it.hasNext())
-        {
-            IPath folder = new Path((String)it.next());
-            libraries.add(JavaCore.newSourceEntry(project.getFullPath().append(folder)));
-        }
-        return libraries;
-    }
-
-    /**
      * Create a directory structure under a given project. Use the template with
      * id 'templateId' Add all requiered Libraries.
      * 
      * @param templateId
      * @param project
      */
-    public void create(String templateId, IProject project)
+    public DirectoryTemplate create(String templateId, IProject project)
     {
 
         DirectoryTemplate template = (DirectoryTemplate) directoryTemplates
@@ -184,8 +91,9 @@
         if (template != null)
         {
             template.create(project);
-            addLibraries(template, project);
+
         }
+        return template;
     }
 
     /**

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Library.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Library.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Library.java
Mon Aug 30 21:42:07 2004
@@ -17,6 +17,9 @@
 */
 package org.apache.metro.studio.eclipse.core.templateengine;
 
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
+import org.eclipse.core.runtime.IPath;
+
 /**
  * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
  * 11.08.2004
@@ -25,8 +28,25 @@
  */
 public class Library
 {
+    private String name;
+    private String version;
+    private String repositoryPath;
 
     /**
+     * @return Returns the repositoryPath.
+     */
+    public String getRepositoryPath()
+    {
+        return "lib/avalon-framework";
+    }
+    /**
+     * @param repositoryPath The repositoryPath to set.
+     */
+    public void setRepositoryPath(String repositoryPath)
+    {
+        this.repositoryPath = repositoryPath;
+    }
+    /**
      * @return Returns the name.
      */
     public String getName()
@@ -54,14 +74,35 @@
     {
         this.version = version;
     }
-    private String name;
-    private String version;
     /**
      * 
      */
     public Library()
     {
         super();
+    }
+    /**
+     * @return
+     */
+    public IPath getPath()
+    {
+        // TODO: has to be changed to metro repository
+        IPath pluginPath = MetroStudioCore.getDefault().getPluginLocation();
+        
+        pluginPath = pluginPath.append(getRepositoryPath());
+        return pluginPath.append(getFullName());
+    }
+    /**
+     * @return
+     */
+    private String getFullName()
+    {
+
+        StringBuffer buf = new StringBuffer(name);
+        buf.append("-");
+        buf.append(version);
+        buf.append(".jar");
+        return buf.toString();
     }
 
 }

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Resource.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Resource.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Resource.java
Mon Aug 30 21:42:07 2004
@@ -114,6 +114,10 @@
 
         try
         {
+            if(map==null)
+            {
+                map = new DynProjectParam();
+            }
             InputStream input = new FileInputStream(new File(templateName));
             InputStreamReader file = new InputStreamReader(input);
             BufferedReader reader = new BufferedReader(file);
@@ -159,7 +163,7 @@
 
     private String replaceParam(String line, DynProjectParam map)
     {
-
+        if(map==null)return line;
         Iterator it = map.keySet().iterator();
         String key;
 

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplate.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplate.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplate.java
Mon Aug 30 21:42:07 2004
@@ -20,10 +20,15 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Vector;
 
-import org.apache.metro.studio.eclipse.core.MetroStudioCore;
 import org.apache.metro.studio.eclipse.core.tools.DynProjectParam;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.launching.JavaRuntime;
 
 /**
  * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
@@ -39,7 +44,7 @@
     private String description;
     private List wizardPages = new ArrayList();
     private List resources = new ArrayList();
-    private List libraries = new ArrayList();
+    private Vector libraries = new Vector();
     
     /**
      * Constructor
@@ -58,25 +63,80 @@
     public void create(IProject project, DirectoryTemplateManager manager, DynProjectParam
param)
     {
         // load directoryType and create the directory structure
-        DirectoryTemplate template = manager.getTemplate(directoryType);
-        if(template == null)
-        {
-            MetroStudioCore.log(null, "unknown directory type in resource " + getTemplateId());
-            return;
-        }
-        template.create(project);
+        DirectoryTemplate template = manager.create(directoryType, project);
         
         // add all needed resources to created directory structure
         Iterator it = getResources().iterator();
+       
         while(it.hasNext())
         {
             ((Resource)it.next()).create(template, param);
         }
-        
+ 
         // add all needed libraries
+        addLibraries(project);
         
     }
 
+    /**
+     * @param project
+     */
+    private void addLibraries(IProject project)
+    {
+
+        try
+        {
+            Vector libs = new Vector();
+            
+            IJavaProject javaProject = JavaCore.create(project);
+            
+            // first retain already created libs
+            IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
+            for(int i=0; i<entries.length; i++)
+            {
+                libs.add(entries[i]);
+            }
+            
+            // allways add the java library
+            libs.add(JavaRuntime.getJREVariableEntry());
+
+            // now add custom libraries
+            libs.addAll(getLibraryEntries());
+            javaProject.setRawClasspath(
+                    (IClasspathEntry[]) libs.toArray(
+                        new IClasspathEntry[libraries.size()]),
+                    javaProject.getOutputLocation(),
+                    null);
+        } catch (JavaModelException e)
+        {
+            e.printStackTrace();
+        }
+
+    }
+    /**
+     * @return
+     */
+    public void addLibrary(Library library)
+    {
+        libraries.add(library);
+    }
+    
+    private Vector getLibraryEntries()
+    {
+        Vector libs = new Vector();
+        
+        Iterator it = libraries.iterator();
+        
+        while(it.hasNext())
+        {
+            Library library = (Library)it.next();
+            libs.add(JavaCore.newLibraryEntry(
+                    		library.getPath(),
+                            null,
+                            null));
+        }
+        return libs;
+    }
     /**
      * @return Returns the directoryType.
      */

Modified: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplateManager.java
==============================================================================
--- avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplateManager.java
(original)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplateManager.java
Mon Aug 30 21:42:07 2004
@@ -20,6 +20,8 @@
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
 
 import org.apache.metro.studio.eclipse.core.MetroStudioCore;
 import org.apache.metro.studio.eclipse.core.tools.DynProjectParam;
@@ -39,6 +41,11 @@
 
     private Hashtable resourceTemplates = new Hashtable();
     private DirectoryTemplateManager directoryManager;
+    
+    final static String baseDir = MetroStudioCore.getDefault()
+    .getPluginLocation().toString();
+    public static final String DEFAULT_CONFIG_PATH = baseDir + "config/resources.test_cfg";
+    
     /**
      * 
      */
@@ -49,6 +56,11 @@
 
     public static ResourceTemplateManager load(String resourceFilePathName)
     {
+        if(resourceFilePathName == null)
+        {
+            resourceFilePathName = getDefaultFilePathName();
+        }
+        
         XStream xstream = new XStream(new DomDriver()); 
         initXStream(xstream);
 
@@ -70,6 +82,15 @@
 
     }
     /**
+     * @return
+     */
+    private static String getDefaultFilePathName()
+    {
+
+        return ResourceTemplateManager.DEFAULT_CONFIG_PATH;
+    }
+
+    /**
      * @param xstream
      */
     public static void initXStream(XStream xstream)
@@ -77,12 +98,29 @@
         xstream.alias("ResourceTemplates", ResourceTemplateManager.class);
         xstream.alias("ResourceTemplate", ResourceTemplate.class);
         xstream.alias("Resource", Resource.class);
+        xstream.alias("Library", Library.class);
     }
 
     public void addResourceTemplate(ResourceTemplate resource)
     {
         resourceTemplates.put(resource.getTemplateId(), resource);
     }
+
+    /**
+     * @return String[]. An array of all keys
+     */
+    public String[] listTemplateNames()
+    {
+        Set set = resourceTemplates.keySet();
+        String[] keyList = new String[set.size()];
+        Iterator it = set.iterator();
+        for (int i=0; i<set.size(); i++)
+        {
+            keyList[i] = (String)it.next();
+        }
+        return keyList;
+    }
+
     /**
      * @param string
      * @return
@@ -112,6 +150,14 @@
             return;
         }
         template.create(project, directoryManager, param);
+    }
+
+    /**
+     * 
+     */
+    public Hashtable getResourceTemplates()
+    {
+        return resourceTemplates;
     }
 
 }

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


Mime
View raw message