KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > build > JdtApt


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * jgarms@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12 package org.eclipse.jdt.apt.core.build;
13
14 import java.io.File JavaDoc;
15
16 import org.apache.tools.ant.BuildException;
17 import org.apache.tools.ant.taskdefs.Java;
18 import org.apache.tools.ant.types.Path;
19 import org.eclipse.jdt.apt.core.internal.build.Messages;
20
21 /**
22  * Ant task for invoking the commandline apt builder
23  *
24  * Sample build.xml:
25  *
26  * <project name="test_eclipse" default="build" basedir=".">
27  *
28  * <taskdef name="apt" classname="org.eclipse.jdt.apt.core.build.JdtApt"/>
29  *
30  * <target name="build">
31  * <apt workspace="C:\my_workspace" eclipseHome="C:\eclipse"/>
32  * </target>
33  * </project>
34  */

35 public class JdtApt extends Java {
36
37     private static final String JavaDoc APP_CLASSNAME = "org.eclipse.core.launcher.Main"; //$NON-NLS-1$
38
private static final String JavaDoc APP_PLUGIN = "org.eclipse.jdt.apt.core.aptBuild"; //$NON-NLS-1$
39

40     private File JavaDoc workspace;
41     private File JavaDoc startupJar;
42     
43     public void setWorkspace(File JavaDoc file) {
44         if(!file.exists()) {
45             throw new BuildException(Messages.JdtApt_noWorkspace + file);
46         }
47         workspace = file;
48     }
49
50     public void setEclipseHome(File JavaDoc file) {
51         if(!file.exists()) {
52             throw new BuildException(Messages.JdtApt_noEclipse + file);
53         }
54         startupJar = new File JavaDoc(file, "startup.jar"); //$NON-NLS-1$
55
if(!startupJar.exists()) {
56             throw new BuildException(Messages.JdtApt_noStartupJar + file);
57         }
58     }
59     
60     public void execute() throws BuildException {
61         if(workspace == null) {
62             throw new BuildException("Must set a workspace"); //$NON-NLS-1$
63
}
64         if(startupJar == null) {
65             throw new BuildException("Must set eclipse home"); //$NON-NLS-1$
66
}
67         
68         setFork(true);
69         setLogError(true);
70         setClasspath(new Path(null, startupJar.getAbsolutePath()));
71         setClassname(APP_CLASSNAME);
72         createArg().setValue("-noupdate"); //$NON-NLS-1$
73
createArg().setValue("-application"); //$NON-NLS-1$
74
createArg().setValue(APP_PLUGIN);
75         createArg().setValue("-data"); //$NON-NLS-1$
76
createArg().setValue(workspace.getAbsolutePath());
77         super.execute();
78     }
79
80
81 }
82
Popular Tags