Here are the two files for the eclipse working set generator.
EclipseWorkingSetGenerator.java
/* * Created on Mar 17, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package com.knowlist.ant; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.LinkedList; import java.util.List; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; /** * @author main * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class EclipseWorkingSetGenerator extends Task { public void execute() throws BuildException { Project proj = getProject(); StringWriter sout = new StringWriter(); PrintWriter out = new PrintWriter(sout); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<workingSetManager>"); // out.println(""); for(EclipseWorkingSet workingSet : workingSets) { workingSet.outputWorkingSet(proj,out,workspaceRootPath); } // <mruList name=\"Hibernate stuff\"/> // <mruList name=\"TEST\"/> out.println("</workingSetManager>"); out.flush(); if(workingSetFile==null || "".equals(workingSetFile)) { System.out.println( sout.toString() ); } else { try { FileWriter fout = new FileWriter(workingSetFile); fout.write( sout.toString() ); fout.close(); } catch(IOException e) { throw new BuildException(e); } } } public void setOutputFile(String workingSetFile) {this.workingSetFile=workingSetFile;} public void setWorkspaceRootPath(String workspaceRootPath) { if(workspaceRootPath==null) { this.workspaceRootPath=null; return; } // replace all backslashes with forward slashes workspaceRootPath = workspaceRootPath.replace('','/'); // // add trailing slash if necessary. // if(!workspaceRootPath.endsWith("/")) // workspaceRootPath += "/"; // remove trailing slash if necessary. if(workspaceRootPath.endsWith("/")) workspaceRootPath = workspaceRootPath.substring(0,workspaceRootPath.length()-1); this.workspaceRootPath=workspaceRootPath; } public void addConfiguredWorkingset(EclipseWorkingSet workingSet) { workingSets.add(workingSet); } private String workingSetFile; private String workspaceRootPath; private List<EclipseWorkingSet> workingSets = new LinkedList<EclipseWorkingSet>(); }
EclipseWorkingSet.java
/* * Created on Mar 17, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package com.knowlist.ant; import java.io.File; import java.io.PrintWriter; import java.util.LinkedList; import java.util.List; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path.PathElement; /** * @author main * * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates */ public class EclipseWorkingSet // extends Task { public void outputWorkingSet(Project proj, PrintWriter out, String workspaceRootPath) throws BuildException { assert workingSetName!=null; out.print("<workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\""+ workingSetName +"\""); if(filesets.isEmpty()) { out.println("/>"); return; } else { out.println(">"); } for(FileSet fileset : filesets) { File dir = fileset.getDir(proj); DirectoryScanner directoryScanner = fileset.getDirectoryScanner(proj); String[] includedFiles = directoryScanner.getIncludedFiles(); for(String includedFile : includedFiles) { //TODO: The path seperator should be checked if it's right or left. String fullPath = dir.getAbsolutePath() +"/"+ includedFile; fullPath = fullPath.replace('','/'); if(fullPath.length() < workspaceRootPath.length() || !fullPath.substring(0,workspaceRootPath.length()).equals(workspaceRootPath)) throw new BuildException("The path \""+ fullPath +"\" doesn't start with the project root path \""+ workspaceRootPath +"\"."); String projectRelativePath = fullPath.substring( workspaceRootPath.length() ); // if(projectRelativePath.endsWith(".java")) { // // is java file // } else { // is resource file out.print("<item"); out.print(" factoryID=\"org.eclipse.ui.internal.model.ResourceFactory\" path=\""); out.print(projectRelativePath); out.print("\" type=\"1\"/>"); out.println(); // } // out.print("<item elementID=\"="); // KnowList/src< // com.knowlist.list.edit{ShowUserPage.java // out.println("\" factoryID=\"org.eclipse.jdt.ui.PersistableJavaElementFactory\"/>"); } } out.println("</workingSet>"); } public void setName(String workingSetName) {this.workingSetName=workingSetName;} public void addConfiguredFileset(FileSet fileset) { filesets.add(fileset); } public void addConfiguredPathelement(PathElement pathElement) { pathElements.add(pathElement); } private String workingSetName; private List<FileSet> filesets = new LinkedList<FileSet>(); private List<PathElement> pathElements = new LinkedList<PathElement>(); /* <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"Object Page\"> <item elementID=\"=KnowList/src<com.knowlist.list.edit{ShowUserPage.java\" factoryID=\"org.eclipse.jdt.ui.PersistableJavaElementFactory\"/> <item elementID=\"=KnowList/src<com.knowlist.list.edit{ShowList.java\" factoryID=\"org.eclipse.jdt.ui.PersistableJavaElementFactory\"/> <item elementID=\"=KnowList/src<com.knowlist.list.external\" factoryID=\"org.eclipse.jdt.ui.PersistableJavaElementFactory\"/> </workingSet> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"EditCustomObj\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"EditCustomView, ShowCustomViewToUse\"> <item elementID=\"=KnowForum\" factoryID=\"org.eclipse.jdt.ui.PersistableJavaElementFactory\"/> </workingSet> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"EditUserObjProf\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"Hibernate stuff\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"Login, Registration, Userpage\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"Object Page\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"taglibs\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"templates\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"TEST\"/> <workingSet editPageId=\"org.eclipse.jdt.ui.JavaWorkingSetPage\" factoryID=\"org.eclipse.ui.internal.WorkingSetFactory\" name=\"web config\"/> */ }
Version 5.1 last modified by Geoff Fortytwo on 25/05/2008 at 15:23
Document data
Attachments:
No attachments for this document