jvanzyl 02/04/19 07:50:09
Modified: src/java/org/apache/maven MavenUtils.java
Log:
Adding a workspace mapper. Used in the workspace mapper test and in the
reactor.
Revision Changes Path
1.11 +57 -1 jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
Index: MavenUtils.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MavenUtils.java 16 Apr 2002 21:15:19 -0000 1.10
+++ MavenUtils.java 19 Apr 2002 14:50:09 -0000 1.11
@@ -55,11 +55,14 @@
*/
import java.io.File;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.Strings;
import org.apache.maven.project.Project;
+import org.apache.maven.project.Profile;
+import org.apache.maven.project.Workspace;
import org.apache.commons.xo.Mapper;
@@ -71,7 +74,7 @@
* the project.
*
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: MavenUtils.java,v 1.10 2002/04/16 21:15:19 jvanzyl Exp $
+ * @version $Id: MavenUtils.java,v 1.11 2002/04/19 14:50:09 jvanzyl Exp $
*/
public class MavenUtils
{
@@ -105,6 +108,59 @@
return project;
}
+ /**
+ * Create a Workspace object given a workspace and profile
+ * descriptor.
+ *
+ * @throws Exception
+ */
+ public static Workspace getWorkspace(String workspaceDescriptor,
+ String profileDescriptor,
+ String mavenLocalRepo)
+ throws Exception
+ {
+ return getWorkspace(new File(workspaceDescriptor),
+ new File(profileDescriptor),
+ new File(mavenLocalRepo));
+ }
+
+ /**
+ * Create a Project object given a file descriptor.
+ *
+ * @throws Exception
+ */
+ public static Workspace getWorkspace(File workspaceDescriptor,
+ File profileDescriptor,
+ File mavenLocalRepo)
+ throws Exception
+ {
+ // Create our workspace
+ Mapper workspaceMapper = new Mapper();
+ Workspace workspace = (Workspace) workspaceMapper.map(workspaceDescriptor,
Workspace.class.getName());
+
+ // Create our profile
+ Mapper profileMapper = new Mapper();
+ Profile profile = (Profile) profileMapper.map(profileDescriptor,
Profile.class.getName());
+ workspace.setProfile(profile);
+
+ // Create our set of project.
+ for (Iterator i = profile.getProjectIds().iterator(); i.hasNext();)
+ {
+ String projectId = (String) i.next();
+ // This should take care of any trailing slashes, or the directory
+ // formatted in any arbitrary fashion. I don't want to expect a
+ // particular format because people do everything different.
+ File baseDir = new File(new File(mavenLocalRepo, "project"), projectId);
+ File projectDescriptor = new File(baseDir, "project.xml");
+
+ // Map the project descriptors and add them to the profile.
+ Mapper projectMapper = new Mapper();
+ Project project = (Project) projectMapper.map(projectDescriptor,
Project.class.getName());
+ profile.addProject(project);
+ }
+
+ return workspace;
+ }
/**
* Get a set of files from a specifed directory with a set of includes.