Revision: 3494 http://vexi.svn.sourceforge.net/vexi/?rev=3494&view=rev Author: mkpg2 Date: 2009-05-02 18:05:42 +0000 (Sat, 02 May 2009)
Log Message: ----------- Feature. 'Source Types' - TEST,DEV,NORMAL. Depending on the location of a template file/package (the source type of folder it is under) detirmines the path that is generated. So that test and development files are only included when needed. Modified Paths: -------------- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexiProject.java trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexidevUtils.java trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchPathEditor.java trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchShortcut.java trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchTab.java trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/navigator/VexiModelProvider.java trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/ui/projectprops/SourceFoldersEditor.java Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexiProject.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexiProject.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexiProject.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -22,7 +22,7 @@ } private List<PathItem> sourceList; - private List<IFolder> folderList; + private List<PathItem<IFolder>> folderList; private List<IProject> projectList; final public IVexiPathList<PathItem> sources = new IVexiPathList<PathItem>(){ @@ -47,20 +47,31 @@ } }; - public List<IFolder> getSourceFolders(){ + public List<PathItem<IFolder>> getSourceFolders(){ loadIfNecessary(); return folderList; } + public Set<IFolder> getSourceFolderSet(){ + List<PathItem<IFolder>> folders = getSourceFolders(); + HashSet<IFolder> r = new HashSet(); + for(PathItem<IFolder> pi: folders) + r.add(pi.resource); + return r; + } + + // Recurse on all referenced projects adding sourcepath of each one - synchronized public List getFullPath() { + synchronized public List getFullPath(SourceType sourceType) { List path = new ArrayList(); + if(sourceType==SourceType.TEST) + path.add("VUNIT"); Set<VexiProject> visited = new HashSet<VexiProject>(); - getFullPath(visited, path); + getFullPath(visited, path, sourceType); return path; } - private void getFullPath(Set<VexiProject> visited , List path ) { + private void getFullPath(Set<VexiProject> visited , List path, SourceType type) { if(visited.contains(this)) return; visited.add(this); @@ -69,16 +80,17 @@ // Add projects paths first (precedence) for(IProject p: projectList){ VexiProject vp = (VexiProject)p.getAdapter(VexiProject.class); - vp.getFullPath(visited, path); + vp.getFullPath(visited, path, type); } for(PathItem pi: sourceList){ - if(!path.contains(pi.resource)) - path.add(pi.resource); + if(!path.contains(pi.resource)){ + if(pi.type.ordinal() <= type.ordinal()){ + path.add(pi.resource); + } + } } - - } private List<IProject> dynamicToProjList(List projects_) throws DefinitionException { @@ -109,7 +121,7 @@ for(Object res: resList){ if(res instanceof IFolder){ IFolder f = (IFolder)res; - sfList.add(new PathItem(f)); + sfList.add(PathItem.forFolder(f)); }else sfList.add(new PathItem(res,SourceType.NORMAL)); } @@ -152,7 +164,7 @@ folderList = new ArrayList(sourceList.size()); for(PathItem pi: sourceList){ if(pi.resource instanceof IFolder) - folderList.add((IFolder)pi.resource); + folderList.add(pi); } } } @@ -177,15 +189,15 @@ } } - static public class PathItem { - final public Object resource; + static public class PathItem<X> { + final public X resource; final public SourceType type; - public PathItem(Object resource, SourceType type){ + public PathItem(X resource, SourceType type){ this.resource = resource; this.type = type; } - public PathItem(IFolder f) { - resource = f; + static public PathItem<IFolder> forFolder(IFolder f) { + SourceType type; if(f.getName().endsWith("test") || f.getName().endsWith("vunit")){ type = SourceType.TEST; @@ -193,7 +205,35 @@ type = SourceType.DEV; }else type = SourceType.NORMAL; - + return new PathItem<IFolder>(f,type); } } + + public PathItem<IFolder> getSourceFolder(String mainTemplate) { + List<PathItem<IFolder>> sourcePath = getSourceFolders(); + String pathStr = mainTemplate.replace('.', '/'); + Path path = new Path(pathStr); + for(PathItem<IFolder> pi: sourcePath){ + if(pi.resource instanceof IFolder){ + IFolder f = pi.resource; + if(f.exists(path)) return pi; + } + } + return null; + } + + public PathItem<IFolder> getSourceFolder(IResource resource) { + List<PathItem<IFolder>> sourcePath = getSourceFolders(); + for(PathItem<IFolder> dir: sourcePath){ + IFolder folder = dir.resource; + IContainer parent = resource.getParent(); + while(parent!=null){ + if(parent.equals(folder)) + return dir; + parent = parent.getParent(); + } + } + return null; + } + } Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexidevUtils.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexidevUtils.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/VexidevUtils.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -139,7 +139,7 @@ } return null; } - + /* static public IFolder getSourceFolder(IResource resource){ IProject proj = resource.getProject(); VexiProject vproj = (VexiProject) proj.getAdapter(VexiProject.class); @@ -155,26 +155,17 @@ } } return null; - } + }*/ - static public String getVexiPathOfFile(IResource resource){ + static public PathItem<IFolder> getSourceFolder(IResource resource){ IProject proj = resource.getProject(); VexiProject vproj = (VexiProject) proj.getAdapter(VexiProject.class); - - List<IFolder> sourcePath = vproj.getSourceFolders(); - for(IFolder dir: sourcePath){ - IFolder folder = (IFolder)dir; - IContainer parent = resource.getParent(); - while(parent!=null){ - if(parent.equals(folder)) - return getVexiPath(folder.getFullPath(), resource.getFullPath()); - parent = parent.getParent(); - } - } - return ""; + if(vproj==null) return null; + return vproj.getSourceFolder(resource); + } - + // getVexiPath(folder.getFullPath(), resource.getFullPath()); static public String getVexiPath(IPath folder, IPath file){ IPath relative = file.removeFirstSegments(folder.segmentCount()); String vexipath = relative.toString().replaceAll("/", "."); Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchPathEditor.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchPathEditor.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchPathEditor.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -14,9 +14,8 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; -import org.vexi.vexidev.IConstants; -import org.vexi.vexidev.VexiProject; -import org.vexi.vexidev.VexidevUtils; +import org.vexi.vexidev.*; +import org.vexi.vexidev.VexiProject.PathItem; import org.vexi.vexidev.ui.SourcePathEditor; // Dubious inheritance here (probably should be reimplementing and inherit directly from @@ -50,7 +49,9 @@ public void widgetSelected(SelectionEvent e) { IProject project = launchTab.getProject(); VexiProject vproject = (VexiProject)project.getAdapter(VexiProject.class); - List<IResource> resources = vproject.getFullPath(); + PathItem folder = vproject.getSourceFolder(launchTab.getMainTemplate()); + SourceType sourceType = folder==null?SourceType.TEST:folder.type; + List<IResource> resources = vproject.getFullPath(sourceType); init(resources); refresh(); } Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchShortcut.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchShortcut.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchShortcut.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -1,7 +1,5 @@ package org.vexi.vexidev.debug.ui; -import static org.vexi.vexidev.VexidevUtils.getVexiPathOfFile; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchTab.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchTab.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/debug/ui/LaunchTab.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -6,15 +6,11 @@ package org.vexi.vexidev.debug.ui; //Needed to parse file[] from file list string -import static org.vexi.vexidev.VexidevUtils.getVexiPathOfFile; import static org.vexi.vexidev.VexidevUtils.pathListToString; import java.util.List; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; @@ -40,9 +36,8 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.dialogs.ElementListSelectionDialog; -import org.vexi.vexidev.IConstants; -import org.vexi.vexidev.VexiProject; -import org.vexi.vexidev.VexidevPlugin; +import org.vexi.vexidev.*; +import org.vexi.vexidev.VexiProject.PathItem; import org.vexi.vexidev.debug.VexiRunnerConfig; import org.vexi.vexidev.navigator.elements.VexiPackage; import org.vexi.vexidev.ui.PathObjectLabelProvider; @@ -220,36 +215,38 @@ ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager(); IProject project = resource.getProject(); + VexiProject vproject = (VexiProject)project.getAdapter(VexiProject.class); String projectName = project.getName(); workingCopy.setAttribute(IConstants.P_LAUNCH_PROJ, projectName); StringBuffer buffer = new StringBuffer(projectName); + SourceType sourceType = SourceType.TEST; if(resource!=null){ buffer.append(" "); - String mainTemplate = getVexiPathOfFile(resource); - buffer.append(mainTemplate); - workingCopy.setAttribute(IConstants.P_LAUNCH_MAINTEMPLATE, mainTemplate); + PathItem<IFolder> pathItem = vproject.getSourceFolder(resource); + if(pathItem!=null){ + String mainTemplate = VexidevUtils.getVexiPath(pathItem.resource.getFullPath(), resource.getFullPath()); + buffer.append(mainTemplate); + workingCopy.setAttribute(IConstants.P_LAUNCH_MAINTEMPLATE, mainTemplate); + sourceType = pathItem.type; + } + } String name = buffer.toString().trim(); name= manager.generateUniqueLaunchConfigurationNameFrom(name); workingCopy.rename(name); - - VexiProject vproject = (VexiProject)project.getAdapter(VexiProject.class); - List path = defaultPath(vproject,vunit); + List path = vproject.getFullPath(sourceType); String pathStr = pathListToString(path); workingCopy.setAttribute(IConstants.P_LAUNCH_PATH, pathStr); + + } + - static public List defaultPath(VexiProject vproject, boolean vunit){ - List path = vproject.getFullPath(); - if(vunit) path.add(0,"VUNIT"); - return path; - } - /** * The original AbstractLaunchConfigurationTab does refresh in reverse * (updateMessage, then buttons) This does not work well (Message uses ol @@ -408,6 +405,11 @@ return r; } + + String getMainTemplate() { + return mainTemplateField.getText().trim(); + } + IProject getProject() { String projectName = fProjText.getText().trim(); if (projectName.length() < 1) { Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/navigator/VexiModelProvider.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/navigator/VexiModelProvider.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/navigator/VexiModelProvider.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -75,7 +75,7 @@ if(parent instanceof IProject){ VexiProject vproject = (VexiProject)((IProject)parent).getAdapter(VexiProject.class); - Set<IFolder> srcPath = new HashSet(vproject.getSourceFolders()); + Set<IFolder> srcPath = vproject.getSourceFolderSet(); //getSourcePath List elements = new ArrayList(currentElements); currentElements.clear(); @@ -181,7 +181,7 @@ // The folder is a vexi src folder, it just does not // know it yet!! VexiProject vproject = (VexiProject)((IProject)p).getAdapter(VexiProject.class); - Set<IFolder> srcPath = new HashSet(vproject.getSourceFolders()); + Set<IFolder> srcPath = vproject.getSourceFolderSet(); if(srcPath.contains(res)){ newtargets.add(getVexiSourceFolder(p, (IFolder) res)); } Modified: trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/ui/projectprops/SourceFoldersEditor.java =================================================================== --- trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/ui/projectprops/SourceFoldersEditor.java 2009-05-02 01:19:53 UTC (rev 3493) +++ trunk/tools/org.vexi.vexidev/src/org/vexi/vexidev/ui/projectprops/SourceFoldersEditor.java 2009-05-02 18:05:42 UTC (rev 3494) @@ -50,7 +50,7 @@ for(int i=0; i<elements.length; i++){ Object e = elements[i]; if(e instanceof IFolder) - r[i] = new PathItem((IFolder)e); + r[i] = PathItem.forFolder((IFolder)e); else r[i] = new PathItem(e,SourceType.NORMAL); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn