KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyBuild > eclipse > DerbyEclipsePlugin


1 /*
2
3    Derby - Class org.apache.derbyBuild.eclipse.DerbyEclipsePlugin
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyBuild.eclipse;
23
24 import java.util.*;
25 import java.io.File JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.FileWriter JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import org.apache.derby.iapi.services.info.ProductGenusNames;
30 import org.apache.derby.iapi.services.info.PropertyNames;
31
32 /**
33  * This class provides the functionality to create the build related
34  * related properties, which are used for creating the Derby plug-in
35  * for Eclipse by the ANT script.
36  *
37  * - The Eclipse plugin will be called 'Apache Derby Core Plug-in for Eclipse'
38  *
39  * - The plugin can be build from the main build.xml using 'ant' with the 'plugin'
40  * argument.
41  *
42  * - The package name for the Derby plug-in will
43  * be: org.apache.derby.core_<major>.<minor>.<interim> (example: org.apache.derby.core_10.1.0).
44  *
45  * - The plugin.xml in the Derby plug-in will show the actual version of the
46  * the Derby build (example: 10.1.0.0 (111545M) ). This can be viewed from
47  * Help - About Eclipse Platform - Plug-in Details of Eclipse of the Eclipse IDE
48  *
49  * - The zip file created for the DerbyEclipse under the jars directory will have the name:
50  * derby_core_plugin_<major>.<minor>.<interim>.zip (example:derby_core_plugin_10.1.0.zip)
51  *
52  * - The current packaging includes derby.jar, derbynet.jar and
53  * derbytools.jar. The locale jars for Derby are not included yet.
54  *
55  * @author Rajesh Kartha
56  */

57 public class DerbyEclipsePlugin{
58     /*
59      * Derby plug-in package property and name
60      */

61     private static String JavaDoc PLUGIN_PKG="plugin.derby.core";
62     private static String JavaDoc PLUGIN_PKG_NAME="org.apache.derby.core";
63     /*
64      * Derby plug-in zip file property and name
65      */

66     private static String JavaDoc PLUGIN_ZIP_FILE="plugin.derby.core.zipfile";
67     private static String JavaDoc PLUGIN_ZIP_FILE_NAME="derby_core_plugin";
68     /*
69      * Derby plug-in build properties and name
70      */

71     private static String JavaDoc PLUGIN_VERSION="plugin.derby.version";
72     private static String JavaDoc PLUGIN_VERSION_BUILD_NUMBER="plugin.derby.version.build.number";
73     private static int MAINT_DIV=1000000;
74
75     /*
76      * plugin.xml file information, split into three parts
77      */

78     private static String JavaDoc part_1="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
79                       "<?eclipse version=\"3.0\"?> \n"+
80                       "<plugin \n" +
81                       "\t id=\"org.apache.derby.core\" \n" +
82                       "\t name=\"Apache Derby Core Plug-in for Eclipse\" \n" +
83                       "\t version=\"";
84
85     private static String JavaDoc part_2="\n\t provider-name=\"";
86     private static String JavaDoc part_3="\n\t <runtime> \n" +
87                           "\t\t <library name=\"derby.jar\"> \n" +
88                           "\t\t\t <export name=\"*\"/> \n" +
89                           "\t\t </library> \n" +
90                                       "\t\t <library name=\"derbyclient.jar\"> \n" +
91                                       "\t\t\t <export name=\"*\"/> \n" +
92                                       "\t\t </library> \n" +
93                           "\t\t <library name=\"derbytools.jar\"> \n" +
94                           "\t\t\t <export name=\"*\"/> \n"+
95                           "\t\t </library> \n"+
96                           "\t\t <library name=\"derbynet.jar\"> \n"+
97                           "\t\t\t <export name=\"*\"/> \n"+
98                           "\t\t </library> \n"+
99                       "\t </runtime> \n"+
100                       "\t <requires> \n"+
101                       "\t </requires> \n"+
102                       "</plugin>";
103
104     private String JavaDoc version="";
105     private String JavaDoc tmpPropFile="plugintmp.properties";
106     private static File JavaDoc tmpFileLocation=null;
107     private static Properties tmpProp=new Properties();
108     private String JavaDoc pluginXMLFile="plugin.xml";
109
110     /*
111      * The public main() method to test the working of this class. A valid destination
112      * String is all that is needed as an argument for running this class.
113      * <p>
114      * example: java DerbyEclipsePlugin <destination>
115      * <p>
116      */

117
118     public static void main(String JavaDoc [] args){
119         if(args.length<=0){
120             System.out.println("Incorrect number of arguments.");
121             return;
122         }
123         try{
124             tmpFileLocation=new File JavaDoc(args[0]);
125             DerbyEclipsePlugin dep = new DerbyEclipsePlugin();
126             dep.getProps();
127             dep.createTmpFiles();
128         }catch(Exception JavaDoc e)
129         {
130             e.printStackTrace();
131         }
132
133
134
135
136     }
137     /*
138      * For internal use only.
139      * getProps() generates the required Properties from the DBMS.properties file.
140      *
141      * @exception Exception if there is an error
142      */

143     private void getProps() throws Exception JavaDoc{
144         InputStream JavaDoc versionStream = getClass().getResourceAsStream(ProductGenusNames.DBMS_INFO);
145         Properties prop=new Properties();
146         prop.load(versionStream);
147
148         //create the tmp Prop file
149
tmpProp.put(PLUGIN_PKG,PLUGIN_PKG_NAME); //package name
150
tmpProp.put(PLUGIN_ZIP_FILE,PLUGIN_ZIP_FILE_NAME); //zip file name
151
tmpProp.put(PropertyNames.PRODUCT_VENDOR_NAME,prop.getProperty(PropertyNames.PRODUCT_VENDOR_NAME));
152         int maint=Integer.parseInt(prop.getProperty(PropertyNames.PRODUCT_MAINT_VERSION));
153         version=prop.getProperty(PropertyNames.PRODUCT_MAJOR_VERSION)+"."+prop.getProperty(PropertyNames.PRODUCT_MINOR_VERSION)+"."+maint/MAINT_DIV;
154         tmpProp.put(PLUGIN_VERSION,version);
155
156         //With Eclipse 3.1M5a release, adding '(PRODUCT_BUILD_NUMBER)' to the 'version' info in
157
//the plugin.xml creates some issues while loading. It has been removed and only the
158
//MAJOR.Minor.interim.point has been added to the plugin.xml.
159
//The actual Derby build version can be obtained using the 'sysinfo' tool.
160

161         version+="."+maint%MAINT_DIV;
162         tmpProp.put(PLUGIN_VERSION_BUILD_NUMBER,version+" ("+prop.getProperty(PropertyNames.PRODUCT_BUILD_NUMBER)+")");
163
164         //add info to plugin.xml strings
165
part_1+=version+"\"";
166         part_2+=tmpProp.getProperty(PropertyNames.PRODUCT_VENDOR_NAME)+"\">\n";
167
168     }
169     /*
170      * For internal use only.
171      * createTmpFiles() create the temporary files with the build properties at the specified location.
172      *
173      * @exception Exception if there is an error
174      */

175     private void createTmpFiles() throws Exception JavaDoc{
176         File JavaDoc file=new File JavaDoc(tmpFileLocation.getAbsolutePath()+File.separator+tmpPropFile);
177         FileOutputStream JavaDoc fo=new FileOutputStream JavaDoc(file);
178         tmpProp.store(fo,null);
179         fo.close();
180         file=new File JavaDoc(tmpFileLocation.getAbsolutePath()+File.separator+pluginXMLFile);
181         FileWriter JavaDoc fw=new FileWriter JavaDoc(file);
182         fw.write(part_1+part_2+part_3);
183         fw.close();
184
185     }
186 }
187
188
Popular Tags