PhpProjectBuildDriver.java Sample

This topic inludes the source code for the PhpProjectBuildDriver.java Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/IdeDevKit/CustomProject/src/ideExtensions/customProject/

Sample Source Code


01 package ideExtensions.customProject; 
02 
03 import com.bea.ide.core.ResourceSvc;
04 import com.bea.ide.util.IOUtil;
05 import com.bea.ide.workspace.IProject;
06 import com.bea.ide.workspace.project.DefaultBuildDriver;
07 import java.io.File;
08 import java.util.regex.Pattern;
09 
10 /**
11  * A simple build driver for PHP projects. The getAntScript method,
12  * which is not implemented in class that this class extends, 
13  * assembles an Ant build.xml file using a template in this 
14  * projects and values provided primarily by WebLogic Workshop.
15  */
16 public class PhpProjectBuildDriver extends DefaultBuildDriver
17 
18     /**
19      * Constructs a new driver instance with an instance
20      * of the PHP project that will use the driver. This
21      * implementation merely calls the super's, which
22      * uses the IProject to extract information need to 
23      * create the build.xml file.
24      */
25     public PhpProjectBuildDriver(IProject project)
26     {
27         super(project);
28     }
29     
30     /**
31      * Called by the IDE to retrieve default Ant build
32      * file contents when the user clicks "Export to Ant file"
33      * in the Build panel of the project properties dialog.
34      
35      * Note that the build target in the file created merely
36      * zips the projects contents and puts the generated ZIP
37      * file at the project's root.
38      
39      @return XML that comprises an Ant build file's contents.
40      */
41     public String getAntScript()
42     {
43         /**
44          * Create the ZIP file's name from the project name.
45          * Note that the _project variable is inherited from
46          * DefaultBuildDriver.
47          */ 
48         String zipFileName = _project.getName() ".zip";
49 
50         /**
51          * Use a utility API to read the contents of the template
52          * XML into a string.
53          */
54         String source = IOUtil.read(
55             ResourceSvc.get().getReader("xml/defaultPhpBuild.xml"));
56         
57         if (source == null)
58             return null;        
59 
60         /**
61          * Call an inherited method to translate the placeholders that
62          * correspond to beahome.local.directory, platformhome.local.directory,
63          * app.local.directory, and project.local.directory. 
64          */
65         source = expandLocalDirs(source);
66         /**
67          * Translate the placeholder corresponding to output.filename,
68          * replacing it with the name of the project + .zip.
69          */
70         source = OUTPUT_FILENAME.matcher(source).replaceFirst(zipFileName);
71         
72         // Return the template with useful values instead of placeholders.
73         return source;
74     }
75