Here are the two files for the eclipse working set generator.

-=EclipseWorkingSetGenerator.java=-
{CODE()}
/
* 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=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>");
out.println("<workingSetManager>");
// out.println("");
for(EclipseWorkingSet workingSet : workingSets) {
workingSet.outputWorkingSet(proj,out,workspaceRootPath);
}

// <mruList name=&quot;Hibernate stuff&quot;/>
// <mruList name=&quot;TEST&quot;/>

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>();
}
{CODE}

-=EclipseWorkingSet.java=-
{CODE()}
/

* 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=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;"+ workingSetName +"&quot;");
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 &quot;"+ fullPath +"&quot; doesn't start with the project root path &quot;"+ workspaceRootPath +"&quot;.");
String projectRelativePath = fullPath.substring( workspaceRootPath.length() );

// if(projectRelativePath.endsWith("
.java")) {
// // is java file
// } else {
// is resource file
out.print("<item");
out.print(" factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;");
out.print(projectRelativePath);
out.print("&quot; type=&quot;1&quot;/>");
out.println();
// }


// out.print("<item elementID=&quot;=");
// KnowList/src&lt;
// com.knowlist.list.edit{ShowUserPage.java
// out.println("&quot; factoryID=&quot;org.eclipse.jdt.ui.PersistableJavaElementFactory&quot;/>");
}
}

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=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;Object Page&quot;>
<item elementID=&quot;=KnowList/src&lt;com.knowlist.list.edit{ShowUserPage.java&quot; factoryID=&quot;org.eclipse.jdt.ui.PersistableJavaElementFactory&quot;/>
<item elementID=&quot;=KnowList/src&lt;com.knowlist.list.edit{ShowList.java&quot; factoryID=&quot;org.eclipse.jdt.ui.PersistableJavaElementFactory&quot;/>
<item elementID=&quot;=KnowList/src&lt;com.knowlist.list.external&quot; factoryID=&quot;org.eclipse.jdt.ui.PersistableJavaElementFactory&quot;/>
</workingSet>


<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;EditCustomObj&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;EditCustomView, ShowCustomViewToUse&quot;>
<item elementID=&quot;=KnowForum&quot; factoryID=&quot;org.eclipse.jdt.ui.PersistableJavaElementFactory&quot;/>
</workingSet>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;EditUserObjProf&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;Hibernate stuff&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;Login, Registration, Userpage&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;Object Page&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;taglibs&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;templates&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;TEST&quot;/>
<workingSet editPageId=&quot;org.eclipse.jdt.ui.JavaWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;web config&quot;/>

*/
}
{CODE}
Version 1.1 last modified by Geoff Fortytwo on 12/05/2008 at 01:18

Attachments 0

No attachments for this document
Website Top
Send Me Mail!:
   g42website4 AT g42.org
My Encyclopaedia Blog

Creator: Geoff Fortytwo on 2008/05/12 01:18
Copyright 2004-2007 (c) XPertNet and Contributing Authors
1.3.2.9174