001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2008 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.build.ant;
025:
026: import java.io.File;
027: import java.util.Enumeration;
028: import java.util.List;
029: import java.util.Vector;
030:
031: import org.apache.tools.ant.BuildException;
032: import org.apache.tools.ant.Task;
033: import org.apache.tools.ant.TaskContainer;
034: import org.apache.tools.ant.taskdefs.CallTarget;
035: import org.apache.tools.ant.taskdefs.Property;
036: import org.apache.tools.ant.types.Path;
037:
038: import com.bostechcorp.cbesb.build.ant.util.EclipseClasspathFile;
039: import com.bostechcorp.cbesb.build.ant.util.EclipseClasspathFile.ClassPathEntry;
040:
041: public class GetEclipseClasspathTask extends Task {
042:
043: private String workspace;
044: private String projectName;
045: private String pathProperty;
046: private String deployDir;
047:
048: public GetEclipseClasspathTask() {
049: workspace = null;
050: projectName = null;
051:
052: }
053:
054: public void setProjectName(String projectName) {
055: this .projectName = projectName;
056: }
057:
058: public void setWorkspace(String workspace) {
059: this .workspace = workspace;
060: }
061:
062: public void setPathProperty(String pathProperty) {
063: this .pathProperty = pathProperty;
064: }
065:
066: public void setDeployDir(String deployDir) {
067: this .deployDir = deployDir;
068: }
069:
070: public void execute() throws BuildException {
071: if (workspace == null) {
072: throw new BuildException("Missing workspace attribute.");
073: }
074: if (projectName == null) {
075: throw new BuildException("Missing projectName attribute.");
076: }
077:
078: File workspaceFile = new File(workspace);
079: File classpathFile = new File(workspaceFile, projectName
080: + File.separator + ".classpath");
081: if (!classpathFile.exists()) {
082: throw new BuildException(
083: "Could not find project classpath file: "
084: + classpathFile.getAbsolutePath());
085: }
086:
087: EclipseClasspathFile eclClasspathFile = new EclipseClasspathFile();
088: try {
089: eclClasspathFile.load(classpathFile);
090: } catch (Exception e) {
091: getProject().log(e.getLocalizedMessage());
092: throw new BuildException(
093: "Exception loading .classpath file:"
094: + classpathFile.getAbsolutePath(), e);
095: }
096:
097: StringBuffer sb = new StringBuffer();
098: List<ClassPathEntry> entryList = eclClasspathFile.getEntries();
099: File deployDirFile = new File(deployDir);
100: for (int i = 0; i < entryList.size(); i++) {
101: ClassPathEntry entry = entryList.get(i);
102: if (entry.isProjectReference()) {
103: String projectEntry = entry.getPath().substring(1);
104: File pathFile = new File(deployDirFile, projectEntry
105: + ".jar");
106: Path pathEntry = new Path(getProject(), pathFile
107: .getAbsolutePath());
108: if (sb.length() > 0) {
109: sb.append(";");
110: }
111: sb.append(pathEntry);
112: } else if (entry.isJarFile()) {
113: File pathFile = new File(workspaceFile, entry.getPath()
114: .substring(1));
115: Path pathEntry = new Path(getProject(), pathFile
116: .getAbsolutePath());
117: if (sb.length() > 0) {
118: sb.append(";");
119: }
120: sb.append(pathEntry);
121: }
122: }
123:
124: getProject().setProperty(pathProperty, sb.toString());
125: }
126:
127: }
|