You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ob...@apache.org on 2004/08/14 14:04:11 UTC
svn commit: rev 36385 - in avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro: . studio studio/eclipse studio/eclipse/core studio/eclipse/core/nature studio/eclipse/core/templateengine studio/eclipse/core/tools studio/eclipse/ui studio/eclipse/ui/controller
Author: oberhack
Date: Sat Aug 14 05:04:11 2004
New Revision: 36385
Added:
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/MetroStudioCore.java
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/
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/package.html
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/
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/ProjectManager.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
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/ClassNameAnalyzer.java
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/DynProjectParam.java
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/SystemTool.java
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/ui/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/ui/controller/
avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/ui/controller/CreateNewProjectWizardController.java
Log:
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/MetroStudioCore.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/MetroStudioCore.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,156 @@
+/*
+
+ 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;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ *
+ * The main plugin class to be used in the desktop.
+ */
+public class MetroStudioCore extends AbstractUIPlugin
+{
+ //The shared instance.
+ private static MetroStudioCore plugin;
+ //Resource bundle.
+ private ResourceBundle resourceBundle;
+
+ public static final String PLUGIN_ID = "org.apache.avalon.MerlinDeveloperCore";
+
+ /**
+ * The constructor.
+ */
+ public MetroStudioCore()
+ {
+ super();
+ plugin = this;
+ try
+ {
+ resourceBundle =
+ ResourceBundle.getBundle(
+ "org.apache.avalon.ide.eclipse.merlin.core.MerlinDeveloperCoreResources");
+ } catch (MissingResourceException x)
+ {
+ resourceBundle = null;
+ }
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static MetroStudioCore getDefault()
+ {
+ return plugin;
+ }
+
+ /**
+ * Returns the workspace instance.
+ */
+ public static IWorkspace getWorkspace()
+ {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle, or 'key' if not
+ * found.
+ */
+ public static String getResourceString(String key)
+ {
+ ResourceBundle bundle = MetroStudioCore.getDefault().getResourceBundle();
+ try
+ {
+ return (bundle != null ? bundle.getString(key) : key);
+ } catch (MissingResourceException e)
+ {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle, @uml property=resourceBundle
+ */
+ public ResourceBundle getResourceBundle()
+ {
+ return resourceBundle;
+ }
+
+ public static void log(IStatus status)
+ {
+ getDefault().getLog().log(status);
+ }
+
+ public static void log(Throwable e, String message)
+ {
+ boolean isDebugging = true; // change to false for production
+ IStatus status =
+ new Status(
+ IStatus.ERROR,
+ ResourcesPlugin.getPlugin().getBundle().getSymbolicName(),
+ IStatus.ERROR,
+ message,
+ e);
+
+ log(status);
+ if (isDebugging)
+ {
+ System.out.println(message + ": " + e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+ public Path getPluginLocation(){
+
+ try
+ {
+ URL installURL =
+ getDefault().getBundle().getEntry("/");
+ return new Path(Platform.resolve(installURL).getFile());
+ } catch (IOException e)
+ {
+ log(e, "unable to resulve plugin location");
+ }
+ return null;
+ }
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/MetroBlockNature.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/nature/MetroBlockNature.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,95 @@
+/*
+
+ 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.nature;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaProject;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ *
+ */
+public class MetroBlockNature implements IProjectNature
+{
+
+ private IProject project;
+ private IJavaProject javaProject;
+
+ /**
+ * Normaly, the whole initialization stuff (creating directory structure,
+ * initial files etc. ) is done here. But because we need greater
+ * flexibility, this is done in the wizards operastions classes.
+ *
+ * @see org.eclipse.core.resources.IProjectNature#configure()
+ */
+ public void configure() throws CoreException
+ {
+
+ }
+
+ public void deconfigure() throws CoreException
+ {
+ // Remove the nature-specific information here.
+ }
+
+ public String getDocumentBase()
+ {
+ return this.getProject().getLocation().toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#getProject()
+ */
+ public IProject getProject()
+ {
+ return project;
+ }
+
+ /**
+ * This method is automatically called by eclipse during project creation
+ * before the configure() method is called
+ *
+ * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
+ */
+ public void setProject(IProject project)
+ {
+ this.project = project;
+ }
+
+ /**
+ * @param pJavaProject
+ */
+ private void setJavaProject(IJavaProject pJavaProject)
+ {
+ javaProject = pJavaProject;
+
+ }
+
+ /**
+ * @return Returns the javaProject.
+ */
+ public IJavaProject getJavaProject()
+ {
+ return javaProject;
+ }
+
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/package.html
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/package.html Sat Aug 14 05:04:11 2004
@@ -0,0 +1,17 @@
+<html>
+
+<head>
+<meta http-equiv="Content-Language" content="de">
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
+<meta name="ProgId" content="FrontPage.Editor.Document">
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<title>Resource package</title>
+</head>
+
+<body>
+
+<p>core package</p>
+
+</body>
+
+</html>
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Directory.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Directory.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,226 @@
+/*
+
+ 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.templateengine;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+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;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team </a>
+ * 11.08.2004 last change:
+ *
+ */
+public class Directory
+{
+
+ private String name;
+ private boolean isSource = false;
+ private List libraries = new ArrayList();
+ private transient IFolder eclipseFolder;
+
+ /**
+ *
+ */
+ public Directory()
+ {
+ super();
+ }
+
+ /**
+ * @return Returns the isSource.
+ */
+ public boolean isSource()
+ {
+ return isSource;
+ }
+
+ /**
+ * @param isSource
+ * The isSource to set.
+ */
+ public void setSource(boolean isSource)
+ {
+ this.isSource = isSource;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name
+ * The name to set.
+ */
+ public void setName(String name)
+ {
+ 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.
+ *
+ * @param project
+ */
+ public void create(IProject project)
+ {
+
+ IFolder folder = null;
+
+ try
+ {
+ // if we like to create folder / subfolders, each folder has to be
+ // created by its own. The ClassNameAnalyzer splits a filePath into
+ // its segments
+ ClassNameAnalyzer cna = new ClassNameAnalyzer();
+ cna.setPath(name);
+ Iterator it = cna.getSegments().iterator();
+
+ while (it.hasNext())
+ {
+ // Now get the folder
+ if (folder == null)
+ {
+ // first segment
+ folder = project.getFolder((String) it.next());
+ } else
+ {
+ folder = folder.getFolder((String) it.next());
+ }
+
+ // ... and create it
+ if (!folder.exists())
+ {
+ folder.create(false, true, null);
+ eclipseFolder = folder;
+ }
+ }
+
+ } catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+
+ /**
+ * append a directory.
+ *
+ * @param project
+ */
+ public Directory appendPackage(String packageName)
+ {
+
+ IFolder folder = null;
+
+ try
+ {
+ // if we like to create folder / subfolders, each folder has to be
+ // created by its own. The ClassNameAnalyzer splits a filePath into
+ // its segments
+ ClassNameAnalyzer cna = new ClassNameAnalyzer();
+ cna.setPackageName(packageName);
+ Iterator it = cna.getSegments().iterator();
+
+ while (it.hasNext())
+ {
+ if(folder == null)
+ {
+ folder = getEclipseFolder().getFolder((String) it.next());
+ } else
+ {
+ folder = folder.getFolder((String) it.next());
+ }
+ // ... and create it
+ if (!folder.exists())
+ {
+ folder.create(false, true, null);
+ }
+ }
+
+ } catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+ Directory dir = new Directory();
+ dir.setEclipseFolder(folder);
+ dir.setName(folder.getLocation().toString());
+ return dir;
+
+ }
+
+ /**
+ * @return Returns the eclipseFolder.
+ */
+ public IFolder getEclipseFolder()
+ {
+ return eclipseFolder;
+ }
+ /**
+ * @param eclipseFolder The eclipseFolder to set.
+ */
+ public void setEclipseFolder(IFolder eclipseFolder)
+ {
+ this.eclipseFolder = eclipseFolder;
+ }
+}
\ No newline at end of file
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplate.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplate.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,130 @@
+/*
+
+ 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.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.eclipse.core.resources.IProject;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
+ * 11.08.2004
+ * last change:
+ *
+ */
+public class DirectoryTemplate
+{
+
+ private String id;
+ private List directories = new ArrayList();
+ /**
+ *
+ */
+ public DirectoryTemplate()
+ {
+ super();
+ }
+
+ /**
+ * 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
+ */
+ public void create(IProject project){
+
+ Iterator it = getDirectories().iterator();
+ while(it.hasNext()){
+ ((Directory)it.next()).create(project);
+ }
+ }
+
+ public void addDirectory(Directory directory){
+
+ directories.add(directory);
+ }
+
+ public List getDirectories(){
+
+ return directories;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public String getId()
+ {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+ public Directory getDirectory(String directoryName)
+ {
+
+ Iterator it = getDirectories().iterator();
+ while(it.hasNext())
+ {
+ Directory dir = (Directory)it.next();
+ if(directoryName.equals(dir.getName()))
+ {
+ return dir;
+ }
+ }
+ MetroStudioCore.log(null, "can't find rootsegment resource " + directoryName);
+ return null;
+
+ }
+ /**
+ * @return
+ */
+ public Vector getSourceFolderNames()
+ {
+
+ Vector libraries = new Vector();
+ Iterator it = directories.iterator();
+ while(it.hasNext()){
+ Directory dir = (Directory)it.next();
+ if(dir.isSource())
+ {
+ libraries.add(dir.getName());
+ }
+ }
+ return libraries;
+ }
+
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplateManager.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/DirectoryTemplateManager.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,232 @@
+/*
+
+ 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.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;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team </a>
+ * 11.08.2004 last change:
+ *
+ */
+public class DirectoryTemplateManager
+{
+
+ private Hashtable directoryTemplates = new Hashtable();
+
+ /**
+ *
+ */
+ public DirectoryTemplateManager()
+ {
+ super();
+ }
+
+ public void addDirectoryTemplate(DirectoryTemplate template)
+ {
+
+ directoryTemplates.put(template.getId(), template);
+ }
+
+ public Set getDirectoryTemplates()
+ {
+
+ return directoryTemplates.entrySet();
+ }
+
+ public DirectoryTemplate getTemplate(String key)
+ {
+
+ return (DirectoryTemplate)directoryTemplates.get(key);
+ }
+
+ /**
+ * 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()
+ {
+ IPath repositoryPath = MetroStudioCore.getDefault()
+ .getPluginLocation(); //$NON-NLS-1$
+ repositoryPath = repositoryPath.append("lib/avalon-framework");
+ return repositoryPath;
+ }
+
+ /**
+ * @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)
+ {
+
+ DirectoryTemplate template = (DirectoryTemplate) directoryTemplates
+ .get(templateId);
+ if (template != null)
+ {
+ template.create(project);
+ addLibraries(template, project);
+ }
+ }
+
+ /**
+ * Load DirectoryStructureTemplates from file
+ *
+ * @param filePathName
+ * @return
+ */
+ public static DirectoryTemplateManager load(String filePathName)
+ {
+
+ XStream xstream = new XStream(new DomDriver());
+ initXStream(xstream);
+
+ FileReader reader = null;
+ try
+ {
+ reader = new FileReader(filePathName);
+
+ } catch (FileNotFoundException e)
+ {
+ MetroStudioCore.log(e,
+ "can't open Directory Template configuration file");
+ return null;
+ }
+ return (DirectoryTemplateManager) xstream.fromXML(reader);
+ }
+
+ public static void initXStream(XStream xstream)
+ {
+ xstream.alias("DirectoryTemplates", DirectoryTemplateManager.class);
+ xstream.alias("DirectoryTemplate", DirectoryTemplate.class);
+ xstream.alias("Directory", Directory.class);
+ xstream.alias("Library", Library.class);
+
+ }
+ /**
+ * @param xstream
+ */
+ public void addXStreamAliases(XStream xstream)
+ {
+ initXStream(xstream);
+ }
+}
\ No newline at end of file
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Library.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Library.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,67 @@
+/*
+
+ 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.templateengine;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
+ * 11.08.2004
+ * last change:
+ *
+ */
+public class Library
+{
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+ /**
+ * @return Returns the version.
+ */
+ public String getVersion()
+ {
+ return version;
+ }
+ /**
+ * @param version The version to set.
+ */
+ public void setVersion(String version)
+ {
+ this.version = version;
+ }
+ private String name;
+ private String version;
+ /**
+ *
+ */
+ public Library()
+ {
+ super();
+ }
+
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ProjectManager.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ProjectManager.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,152 @@
+/*
+
+ 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.templateengine;
+
+import java.util.List;
+
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team </a>
+ * 11.08.2004 last change:
+ *
+ */
+public class ProjectManager
+{
+ final static String BASE = "org.apache.metro.studio.core";
+
+ final static String BLOCK_NATURE_ID = BASE + ".blockNature";
+
+ final static String FACILITY_NATURE_ID = BASE + ".facilityNature";
+
+ final static String KERNEL_NATURE_ID = BASE + ".kernelNature";
+
+ /**
+ *
+ */
+ public ProjectManager()
+ {
+ super();
+ }
+
+ /**
+ * get a list of wizard pages, which are needed for a specific
+ * ResourceTemplate.
+ *
+ * @param resourceTemplateName
+ * @return
+ */
+ public static List getWizards(String resourceTemplateName)
+ {
+
+ return null;
+ }
+
+ /**
+ * This method is called from the "project new wizard" to create a new
+ * project with all values entered in all wizard pages.
+ *
+ * @param valueObject
+ * @return
+ */
+ public static IProject createBlockProject(Object valueObject)
+ {
+
+ return null;
+ }
+
+ /**
+ * This method is called to show all available template in the wizard so
+ * that the user can choose one of them.
+ */
+ public List getResourceTemplateNames()
+ {
+ return null;
+ }
+
+ /**
+ * Create a block project
+ *
+ * @param name
+ * @return
+ */
+ public static IProject createBlockProject(String name)
+ {
+ return createProject(name, BLOCK_NATURE_ID);
+ }
+
+ /**
+ * Create a facility project
+ *
+ * @param name
+ * @return
+ */
+ public static IProject createFacilityProject(String name)
+ {
+ return createProject(name, FACILITY_NATURE_ID);
+ }
+
+ private static IProject createProject(String name, String nature)
+ {
+ IProject project = null;
+ try
+ {
+ IWorkspaceRoot root = MetroStudioCore.getWorkspace().getRoot();
+ // create the project in workspace.
+ project = root.getProject(name);
+
+ if (!project.exists())
+ {
+ project.create(null);
+ }
+
+ if (!project.isOpen())
+ {
+ project.open(null);
+ }
+ IProjectDescription description = project.getDescription();
+
+ String[] natureIds = new String[] { JavaCore.NATURE_ID, nature };
+ description.setLocation(null);
+ description.setNatureIds(natureIds);
+ project.setDescription(description, null);
+
+ } catch (CoreException e)
+ {
+ MetroStudioCore.log(e, "can't create project");
+ }
+
+ return project;
+ }
+
+ public static void delete(IProject project)
+ {
+ try
+ {
+ project.delete(true, true, null);
+ } catch (CoreException e)
+ {
+ MetroStudioCore.log(e, "can't delete project");
+ }
+ }
+}
\ No newline at end of file
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Resource.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/Resource.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,251 @@
+/*
+
+ 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.templateengine;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.Iterator;
+
+import org.apache.metro.studio.eclipse.core.tools.ClassNameAnalyzer;
+import org.apache.metro.studio.eclipse.core.tools.DynProjectParam;
+import org.apache.metro.studio.eclipse.core.tools.SystemTool;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team </a>
+ * 11.08.2004 last change:
+ *
+ */
+public class Resource
+{
+ /**
+ * This is the name of the root segment (one of the folders directly under
+ * the projects name)
+ */
+ private String rootSegment;
+
+ /**
+ * This is the pointer to the templates source
+ */
+ private String sourceFilePathName;
+
+ /**
+ * The packagename, where the output should be stored
+ */
+ private String packageName;
+
+ /**
+ * the parameter object which hold all dynamic parameters
+ */
+ private transient DynProjectParam dynParam;
+
+ /**
+ *
+ */
+ public Resource()
+ {
+ super();
+ }
+
+ /**
+ * @return Returns the rootSegment.
+ */
+ public String getRootSegment()
+ {
+ return rootSegment;
+ }
+
+ /**
+ * @param rootSegment
+ * The rootSegment to set.
+ */
+ public void setRootSegment(String rootSegment)
+ {
+ this.rootSegment = rootSegment;
+ }
+
+ /**
+ * @return Returns the sourceFilePathName.
+ */
+ public String getSourceFilePathName()
+ {
+ return sourceFilePathName;
+ }
+
+ /**
+ * @param sourceFilePathName
+ * The sourceFilePathName to set.
+ */
+ public void setSourceFilePathName(String sourceFilePathName)
+ {
+ this.sourceFilePathName = sourceFilePathName;
+ }
+
+ /**
+ * opens the templatefile and replaces all occurencies of the parameters
+ * contained in the map. Output is writen to <folder>
+ *
+ * @param templateName
+ * @param map
+ * @param folder
+ */
+ private void createFromTemplate(String templateName, DynProjectParam map,
+ String destinationPath)
+ {
+
+ try
+ {
+ InputStream input = new FileInputStream(new File(templateName));
+ InputStreamReader file = new InputStreamReader(input);
+ BufferedReader reader = new BufferedReader(file);
+
+ String outPath = destinationPath;
+ FileOutputStream ostream = new FileOutputStream(outPath);
+ OutputStreamWriter out = new OutputStreamWriter(ostream);
+
+ String line;
+ Iterator it = map.keySet().iterator();
+ String key;
+
+ while ((line = reader.readLine()) != null)
+ {
+ while (it.hasNext())
+ {
+ if ((key = (String) it.next()).startsWith("%"))
+ {
+ if ((line.indexOf(key)) != -1)
+ {
+ /*
+ * to retain 1.3.1 compatibiliy (WSAD) dont use
+ * "replace" line = line.replaceAll(key, (String)
+ * map.get(key));
+ */
+ line = SystemTool.replaceAll(line, key,
+ (String) map.get(key));
+
+ }
+ }
+ }
+ out.write(line);
+ out.write("\n");
+ it = map.keySet().iterator();
+ }
+ out.close();
+ file.close();
+ } catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ }
+
+ private String replaceParam(String line, DynProjectParam map)
+ {
+
+ Iterator it = map.keySet().iterator();
+ String key;
+
+ while (it.hasNext())
+ {
+ if ((key = (String) it.next()).startsWith("%"))
+ {
+ if ((line.indexOf(key)) != -1)
+ {
+ /*
+ * to retain 1.3.1 compatibiliy (WSAD) dont use "replace"
+ * line = line.replaceAll(key, (String) map.get(key));
+ */
+ line = SystemTool.replaceAll(line, key, (String) map
+ .get(key));
+
+ }
+ }
+ }
+ return line;
+
+ }
+
+ private String getFileName()
+ {
+
+ ClassNameAnalyzer analyzer = new ClassNameAnalyzer();
+ analyzer.setPath(sourceFilePathName);
+ return replaceParam(analyzer.getFileName(), getDynParam());
+
+ }
+
+ /**
+ * @param directory.
+ * Destination directory template
+ * @param templateName
+ */
+ public void create(DirectoryTemplate directoryTemplate,
+ DynProjectParam param)
+ {
+ setDynParam(param);
+ String destinationFilePathName = null;
+ Directory dir = directoryTemplate.getDirectory(rootSegment);
+ if (dir == null)
+ return;
+ dir = dir.appendPackage(getPackageName());
+
+ destinationFilePathName = dir.getEclipseFolder().getLocation()
+ .toString();
+ destinationFilePathName = destinationFilePathName + "/" + getFileName();
+ createFromTemplate(sourceFilePathName, param, destinationFilePathName);
+
+ }
+
+ /**
+ * @return Returns the packageName.
+ */
+ public String getPackageName()
+ {
+ return replaceParam(packageName, getDynParam());
+
+ }
+
+ /**
+ * @param packageName
+ * The packageName to set.
+ */
+ public void setPackageName(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+ /**
+ * @return Returns the dynParam.
+ */
+ public DynProjectParam getDynParam()
+ {
+ return dynParam;
+ }
+
+ /**
+ * @param dynParam
+ * The dynParam to set.
+ */
+ public void setDynParam(DynProjectParam dynParam)
+ {
+ this.dynParam = dynParam;
+ }
+}
\ No newline at end of file
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplate.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplate.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,126 @@
+/*
+
+ 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.templateengine;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
+import org.apache.metro.studio.eclipse.core.tools.DynProjectParam;
+import org.eclipse.core.resources.IProject;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
+ * 11.08.2004
+ * last change:
+ *
+ */
+public class ResourceTemplate
+{
+
+ private String directoryType;
+ private String templateId;
+ private List wizardPages = new ArrayList();
+ private List resources = new ArrayList();
+ private List libraries = new ArrayList();
+
+ /**
+ * Constructor
+ */
+ public ResourceTemplate()
+ {
+ super();
+ }
+ /**
+ * Creates the directorystructure and all Resources of
+ * the template project
+ *
+ * @param project
+ *
+ */
+ 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);
+
+ // 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
+
+ }
+
+ /**
+ * @return Returns the directoryType.
+ */
+ public String getDirectoryType()
+ {
+ return directoryType;
+ }
+ /**
+ * @param directoryType The directoryType to set.
+ */
+ public void setDirectoryType(String directoryType)
+ {
+ this.directoryType = directoryType;
+ }
+ /**
+ * @return Returns the resources.
+ */
+ public List getResources()
+ {
+ return resources;
+ }
+ /**
+ * @param resources The resources to set.
+ */
+ public void setResources(List resources)
+ {
+ this.resources = resources;
+ }
+ /**
+ * @return Returns the templateId.
+ */
+ public String getTemplateId()
+ {
+ return templateId;
+ }
+ /**
+ * @param templateId The templateId to set.
+ */
+ public void setTemplateId(String templateId)
+ {
+ this.templateId = templateId;
+ }
+
+ public void addResource(Resource resource)
+ {
+ resources.add(resource);
+ }
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplateManager.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/templateengine/ResourceTemplateManager.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,117 @@
+/*
+
+ 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.templateengine;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.Hashtable;
+
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
+import org.apache.metro.studio.eclipse.core.tools.DynProjectParam;
+import org.eclipse.core.resources.IProject;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
+ * 11.08.2004
+ * last change:
+ *
+ */
+public class ResourceTemplateManager
+{
+
+ private Hashtable resourceTemplates = new Hashtable();
+ private DirectoryTemplateManager directoryManager;
+ /**
+ *
+ */
+ public ResourceTemplateManager()
+ {
+ super();
+ }
+
+ public static ResourceTemplateManager load(String resourceFilePathName)
+ {
+ XStream xstream = new XStream(new DomDriver());
+ initXStream(xstream);
+
+ new DirectoryTemplateManager().addXStreamAliases(xstream);
+ FileReader reader = null;
+ try
+ {
+ reader = new FileReader(resourceFilePathName);
+
+ } catch (FileNotFoundException e)
+ {
+ MetroStudioCore.log(e,
+ "can't open Resource Template configuration file");
+ return null;
+ }
+
+ ResourceTemplateManager rm = (ResourceTemplateManager) xstream.fromXML(reader);
+ return rm;
+
+ }
+ /**
+ * @param xstream
+ */
+ public static void initXStream(XStream xstream)
+ {
+ xstream.alias("ResourceTemplates", ResourceTemplateManager.class);
+ xstream.alias("ResourceTemplate", ResourceTemplate.class);
+ xstream.alias("Resource", Resource.class);
+ }
+
+ public void addResourceTemplate(ResourceTemplate resource)
+ {
+ resourceTemplates.put(resource.getTemplateId(), resource);
+ }
+ /**
+ * @param string
+ * @return
+ */
+ public ResourceTemplate getTemplate(String key)
+ {
+ return (ResourceTemplate)resourceTemplates.get(key);
+ }
+
+ /**
+ * @param dm
+ */
+ public void importDirectoryTemplates(DirectoryTemplateManager dm)
+ {
+ directoryManager = dm;
+ }
+
+ /**
+ * Create a directorystrucure and all required resources in a project
+ */
+ public void create(IProject project, String resourceName, DynProjectParam param)
+ {
+ ResourceTemplate template = getTemplate(resourceName);
+ if(template == null)
+ {
+ MetroStudioCore.log(null, "cant find resource template <" + resourceName +">");
+ return;
+ }
+ template.create(project, directoryManager, param);
+ }
+
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/ClassNameAnalyzer.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/ClassNameAnalyzer.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,104 @@
+/*
+
+ 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.tools;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>*
+ */
+public class ClassNameAnalyzer
+{
+
+ /**
+ * @uml property=segments associationEnd={multiplicity={(0 -1)}
+ * elementType=java.lang.String}
+ *
+ */
+ private List segments = new ArrayList();
+
+ public void setPackageName(String name)
+ {
+
+ setFullClassName(name);
+ }
+
+ public void setFullClassName(String name)
+ {
+
+ while (name.indexOf(".") != -1)
+ {
+ segments.add(name.substring(0, name.indexOf(".")));
+ name = name.substring(name.indexOf(".") + 1, name.length());
+ }
+ segments.add(name);
+ }
+
+ public String getPath()
+ {
+
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; segments.size() > i + 2; i++)
+ {
+ buff.append((String) segments.get(i));
+ buff.append("/");
+ }
+ return buff.toString();
+ }
+
+ /**
+ * @return
+ */
+ public String getFileName()
+ {
+
+ StringBuffer buff = new StringBuffer();
+ int size = segments.size();
+ for (int i = size - 1; size > i; i++)
+ {
+ buff.append((String) segments.get(i));
+ if (i < size - 1)
+ buff.append(".");
+ }
+ return buff.toString();
+ }
+
+ /**
+ * @param directory
+ */
+ public void setPath(String directory)
+ {
+
+ while (directory.indexOf("/") != -1)
+ {
+ segments.add(directory.substring(0, directory.indexOf("/")));
+ directory = directory.substring(directory.indexOf("/") + 1, directory.length());
+ }
+ segments.add(directory);
+ }
+
+ /**
+ * @return Returns the segments. @uml property=segments
+ */
+ public List getSegments()
+ {
+ return segments;
+ }
+
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/DynProjectParam.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/DynProjectParam.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,158 @@
+/*
+
+ 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.tools;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ *
+ */
+public class DynProjectParam
+{
+
+ /**
+ * @uml property=param associationEnd={multiplicity={(0 1)}
+ * qualifier=(constant:java.lang.String string:java.lang.String)}
+ */
+ Map param = new HashMap();
+
+ public void setFullImplementationClassName(String fullClassName)
+ {
+
+ param.put("%implementationpackage%", extractPackage(fullClassName));
+ param.put("%implementationclass%", extractClassName(fullClassName));
+ param.put("%full_implementationclass%", fullClassName);
+
+ }
+ public void setFullServiceClassName(String fullClassName)
+ {
+
+ param.put("%servicepackage%", extractPackage(fullClassName));
+ param.put("%serviceclass%", extractClassName(fullClassName));
+ param.put("%full_serviceclass%", fullClassName);
+
+ }
+ public void setContainerName(String containerName)
+ {
+
+ param.put("%containername%", containerName);
+
+ }
+
+ /**
+ * @param fullClassName
+ * @return the package part of the fully qualified className
+ */
+ private String extractPackage(String fullClassName)
+ {
+ if (fullClassName.trim().length() > 0)
+ {
+ return fullClassName.substring(0, fullClassName.lastIndexOf('.'));
+ } else
+ {
+ return "";
+ }
+ }
+
+ /**
+ * @param fullClassName
+ * @return className part of the fully qualified className
+ */
+ private String extractClassName(String fullClassName)
+ {
+ if (fullClassName.trim().length() > 0)
+ {
+ return fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
+ } else
+ {
+ return "";
+ }
+ }
+ /**
+ * @param string
+ */
+ public void setProjectName(String string)
+ {
+
+ param.put("%projectname%", string);
+ }
+ /**
+ *
+ */
+ public String getProjectName()
+ {
+
+ return (String) param.get("%projectname%");
+ }
+ /**
+ * @param string
+ */
+ public void setVirtualServiceName(String string)
+ {
+
+ param.put("%virtualservicename%", string);
+
+ }
+ /**
+ * @param string
+ */
+ public void setVersion(String string)
+ {
+
+ param.put("%version%", string);
+
+ }
+ /**
+ * @param string
+ * @return Object
+ */
+ public Object get(String string)
+ {
+
+ return param.get(string);
+ }
+ /**
+ * @return Set
+ */
+ public Set keySet()
+ {
+ return param.keySet();
+ }
+ /**
+ * @return (String) package of the service
+ */
+ public String getServicePackage()
+ {
+ return (String) param.get("%servicepackage%");
+ }
+ public String getImplementationClass()
+ {
+ return (String) param.get("%implementationclass%");
+ }
+ /**
+ * @return (String) package of the implementation class
+ */
+ public String getImplementationPackage()
+ {
+ return (String) param.get("%implementationpackage%");
+ }
+
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/SystemTool.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/core/tools/SystemTool.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,187 @@
+/*
+
+ 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.tools;
+
+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 org.apache.metro.studio.eclipse.core.MetroStudioCore;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ *
+ */
+public class SystemTool
+{
+
+ /**
+ *
+ */
+ public SystemTool()
+ {
+ super();
+ }
+ /*
+ * java 1.4 version to retain 1.3.1 compatibility (WSAD!) dont use it now
+ *
+ * public static void copyFile(File in, File out) throws Exception {
+ * FileChannel sourceChannel = new FileInputStream(in).getChannel();
+ * FileChannel destinationChannel = new FileOutputStream(out).getChannel();
+ * sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
+ * sourceChannel.close(); destinationChannel.close(); }
+ */
+ /*
+ * This method makes a copy of a file.
+ *
+ * java CopyFile source.dat copy.dat
+ *
+ * This command will fail if a file named copy.dat already exists. To force
+ * the command to succede, add the -f command line option:
+ *
+ * java CopyFile -f source.dat copy.dat
+ *
+ * Either command will fail if the source file does not exist.
+ */
+
+ public static void copyFile(File in, File out) throws Exception
+ {
+ InputStream source; // Stream for reading from the source file.
+ OutputStream copy; // Stream for writing the copy.
+ boolean force = true; // This is set to true if the "-f" option is
+ // specified.
+ int byteCount; // The number of bytes copied from the source file.
+
+ /* Create the input stream. If an error occurs, end the program. */
+
+ try
+ {
+ source = new FileInputStream(in);
+ } catch (FileNotFoundException e)
+ {
+ MetroStudioCore.log(e, "Can't find file \"" + in.getName() + "\".");
+ return;
+ }
+
+ /*
+ * If the output file alrady exists and the -f option was not
+ * specified,
+ */
+
+ File file = out;
+ if (file.exists() && force == false)
+ {
+ MetroStudioCore.log(null, "Output file exists. Use the -f option to replace it.");
+ return;
+ }
+
+ /* Create the output stream. If an error occurs, end the program. */
+
+ try
+ {
+ copy = new FileOutputStream(out);
+ } catch (IOException e)
+ {
+ System.out.println("Can't open output file \"" + out.getName() + "\".");
+ return;
+ }
+
+ /*
+ * Copy one byte at a time from the input stream to the out put stream,
+ * ending when the read() method returns -1 (which is the signal that
+ * the end of the stream has been reached. If any error occurs, print
+ * an error message. Also print a message if the file has bee copied
+ */
+
+ byteCount = 0;
+
+ try
+ {
+ while (true)
+ {
+ int data = source.read();
+ if (data < 0)
+ break;
+ copy.write(data);
+ byteCount++;
+ }
+ source.close();
+ copy.close();
+
+ } catch (Exception e)
+ {
+ MetroStudioCore.log(
+ e,
+ "Error occured while copying. " + byteCount + " bytes copied.");
+ }
+
+ } // end copyFile()
+
+ public static String getFileContents(String fileName)
+ {
+
+ StringBuffer buf = new StringBuffer();
+ try
+ {
+ FileInputStream in = new FileInputStream(fileName);
+ InputStreamReader file = new InputStreamReader(in);
+ BufferedReader reader = new BufferedReader(file);
+
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ buf.append(line);
+ }
+ file.close();
+ } catch (FileNotFoundException e)
+ {
+ MetroStudioCore.log(e, "");
+ } catch (IOException e)
+ {
+ MetroStudioCore.log(e, "");
+ }
+ return buf.toString();
+ }
+ /**
+ * @param pLine
+ * @param pKey
+ * @param pString
+ * @return
+ */
+ public static String replaceAll(String source, String pKey, String pReplacement)
+ {
+ int start = 0;
+ int next;
+ StringBuffer in = new StringBuffer(source);
+ StringBuffer out = new StringBuffer();
+ while((next = in.indexOf(pKey, start)) != -1){
+ out.append(source.substring(start, next));
+ out.append(pReplacement);
+ start = next + pKey.length();
+ };
+ out.append(source.substring(start, source.length()));
+
+ return out.toString();
+ }
+}
Added: avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/ui/controller/CreateNewProjectWizardController.java
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/studio/eclipse/core/src/org/apache/metro/studio/eclipse/ui/controller/CreateNewProjectWizardController.java Sat Aug 14 05:04:11 2004
@@ -0,0 +1,102 @@
+/*
+
+ 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.ui.controller;
+
+import java.rmi.RemoteException;
+
+import org.apache.metro.facility.presentationservice.api.ControllerEventService;
+import org.apache.metro.facility.presentationservice.api.ValueObjectEventListener;
+import org.apache.metro.facility.presentationservice.impl.PresentationEvent;
+import org.apache.metro.facility.presentationservice.impl.PresentationServiceFactory;
+import org.apache.metro.studio.eclipse.core.MetroStudioCore;
+import org.apache.metro.studio.eclipse.core.templateengine.ProjectManager;
+import org.apache.metro.studio.eclipse.core.templateengine.ResourceTemplateManager;
+import org.apache.metro.studio.eclipse.core.tools.DynProjectParam;
+import org.eclipse.core.resources.IProject;
+
+/**
+ * @author <a href="mailto:dev@avalon.apache.org">Metro Development Team</a>
+ * 14.08.2004
+ * last change:
+ *
+ */
+public class CreateNewProjectWizardController
+{
+ final static String baseDir = MetroStudioCore.getDefault()
+ .getPluginLocation().toString();
+
+ final static String resourcesLocation = baseDir
+ + "config/resources.test_cfg";
+
+ private String selectedTemplate;
+ /**
+ *
+ */
+ public CreateNewProjectWizardController()
+ {
+ super();
+ initializeListeners();
+ }
+
+ public void initializeListeners()
+ {
+ ControllerEventService service = null;
+
+ try
+ {
+ service = PresentationServiceFactory.getControllerEventService();
+
+ // create project when apply button is pressed
+ service.addClickedListener(
+ "CreateNewProjectWizard.applyButton",
+ new ValueObjectEventListener()
+ {
+ public PresentationEvent notify(PresentationEvent evt)
+ throws RemoteException
+ {
+ String projectName = (String)evt.getData().get("selectedTemplate");
+ IProject project = ProjectManager.createBlockProject("HelloWorld Tutorial");
+ ResourceTemplateManager rm = ResourceTemplateManager
+ .load(resourcesLocation);
+ rm.create(project, selectedTemplate, new DynProjectParam());
+
+ return evt;
+
+ }
+ });
+
+ service.addClickedListener(
+ "CreateNewProjectWizard.exampleProjectList",
+ new ValueObjectEventListener()
+ {
+ public PresentationEvent notify(PresentationEvent evt)
+ throws RemoteException
+ {
+ selectedTemplate = (String)evt.getData().get("selectedTemplate");
+ return evt;
+
+ }
+ });
+ } catch (Exception e)
+ {
+ MetroStudioCore.log(e, "Can't initialize PresentationService");
+ }
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org