001: /*
002:
003: Derby - Class org.apache.derbyBuild.eclipse.DerbyEclipsePlugin
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyBuild.eclipse;
023:
024: import java.util.*;
025: import java.io.File;
026: import java.io.FileOutputStream;
027: import java.io.FileWriter;
028: import java.io.InputStream;
029: import org.apache.derby.iapi.services.info.ProductGenusNames;
030: import org.apache.derby.iapi.services.info.PropertyNames;
031:
032: /**
033: * This class provides the functionality to create the build related
034: * related properties, which are used for creating the Derby plug-in
035: * for Eclipse by the ANT script.
036: *
037: * - The Eclipse plugin will be called 'Apache Derby Core Plug-in for Eclipse'
038: *
039: * - The plugin can be build from the main build.xml using 'ant' with the 'plugin'
040: * argument.
041: *
042: * - The package name for the Derby plug-in will
043: * be: org.apache.derby.core_<major>.<minor>.<interim> (example: org.apache.derby.core_10.1.0).
044: *
045: * - The plugin.xml in the Derby plug-in will show the actual version of the
046: * the Derby build (example: 10.1.0.0 (111545M) ). This can be viewed from
047: * Help - About Eclipse Platform - Plug-in Details of Eclipse of the Eclipse IDE
048: *
049: * - The zip file created for the DerbyEclipse under the jars directory will have the name:
050: * derby_core_plugin_<major>.<minor>.<interim>.zip (example:derby_core_plugin_10.1.0.zip)
051: *
052: * - The current packaging includes derby.jar, derbynet.jar and
053: * derbytools.jar. The locale jars for Derby are not included yet.
054: *
055: * @author Rajesh Kartha
056: */
057: public class DerbyEclipsePlugin {
058: /*
059: * Derby plug-in package property and name
060: */
061: private static String PLUGIN_PKG = "plugin.derby.core";
062: private static String PLUGIN_PKG_NAME = "org.apache.derby.core";
063: /*
064: * Derby plug-in zip file property and name
065: */
066: private static String PLUGIN_ZIP_FILE = "plugin.derby.core.zipfile";
067: private static String PLUGIN_ZIP_FILE_NAME = "derby_core_plugin";
068: /*
069: * Derby plug-in build properties and name
070: */
071: private static String PLUGIN_VERSION = "plugin.derby.version";
072: private static String PLUGIN_VERSION_BUILD_NUMBER = "plugin.derby.version.build.number";
073: private static int MAINT_DIV = 1000000;
074:
075: /*
076: * plugin.xml file information, split into three parts
077: */
078: private static String part_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
079: + "<?eclipse version=\"3.0\"?> \n"
080: + "<plugin \n"
081: + "\t id=\"org.apache.derby.core\" \n"
082: + "\t name=\"Apache Derby Core Plug-in for Eclipse\" \n"
083: + "\t version=\"";
084:
085: private static String part_2 = "\n\t provider-name=\"";
086: private static String part_3 = "\n\t <runtime> \n"
087: + "\t\t <library name=\"derby.jar\"> \n"
088: + "\t\t\t <export name=\"*\"/> \n" + "\t\t </library> \n"
089: + "\t\t <library name=\"derbyclient.jar\"> \n"
090: + "\t\t\t <export name=\"*\"/> \n" + "\t\t </library> \n"
091: + "\t\t <library name=\"derbytools.jar\"> \n"
092: + "\t\t\t <export name=\"*\"/> \n" + "\t\t </library> \n"
093: + "\t\t <library name=\"derbynet.jar\"> \n"
094: + "\t\t\t <export name=\"*\"/> \n" + "\t\t </library> \n"
095: + "\t </runtime> \n" + "\t <requires> \n"
096: + "\t </requires> \n" + "</plugin>";
097:
098: private String version = "";
099: private String tmpPropFile = "plugintmp.properties";
100: private static File tmpFileLocation = null;
101: private static Properties tmpProp = new Properties();
102: private String pluginXMLFile = "plugin.xml";
103:
104: /*
105: * The public main() method to test the working of this class. A valid destination
106: * String is all that is needed as an argument for running this class.
107: * <p>
108: * example: java DerbyEclipsePlugin <destination>
109: * <p>
110: */
111:
112: public static void main(String[] args) {
113: if (args.length <= 0) {
114: System.out.println("Incorrect number of arguments.");
115: return;
116: }
117: try {
118: tmpFileLocation = new File(args[0]);
119: DerbyEclipsePlugin dep = new DerbyEclipsePlugin();
120: dep.getProps();
121: dep.createTmpFiles();
122: } catch (Exception e) {
123: e.printStackTrace();
124: }
125:
126: }
127:
128: /*
129: * For internal use only.
130: * getProps() generates the required Properties from the DBMS.properties file.
131: *
132: * @exception Exception if there is an error
133: */
134: private void getProps() throws Exception {
135: InputStream versionStream = getClass().getResourceAsStream(
136: ProductGenusNames.DBMS_INFO);
137: Properties prop = new Properties();
138: prop.load(versionStream);
139:
140: //create the tmp Prop file
141: tmpProp.put(PLUGIN_PKG, PLUGIN_PKG_NAME); //package name
142: tmpProp.put(PLUGIN_ZIP_FILE, PLUGIN_ZIP_FILE_NAME); //zip file name
143: tmpProp.put(PropertyNames.PRODUCT_VENDOR_NAME, prop
144: .getProperty(PropertyNames.PRODUCT_VENDOR_NAME));
145: int maint = Integer.parseInt(prop
146: .getProperty(PropertyNames.PRODUCT_MAINT_VERSION));
147: version = prop.getProperty(PropertyNames.PRODUCT_MAJOR_VERSION)
148: + "."
149: + prop.getProperty(PropertyNames.PRODUCT_MINOR_VERSION)
150: + "." + maint / MAINT_DIV;
151: tmpProp.put(PLUGIN_VERSION, version);
152:
153: //With Eclipse 3.1M5a release, adding '(PRODUCT_BUILD_NUMBER)' to the 'version' info in
154: //the plugin.xml creates some issues while loading. It has been removed and only the
155: //MAJOR.Minor.interim.point has been added to the plugin.xml.
156: //The actual Derby build version can be obtained using the 'sysinfo' tool.
157:
158: version += "." + maint % MAINT_DIV;
159: tmpProp.put(PLUGIN_VERSION_BUILD_NUMBER, version + " ("
160: + prop.getProperty(PropertyNames.PRODUCT_BUILD_NUMBER)
161: + ")");
162:
163: //add info to plugin.xml strings
164: part_1 += version + "\"";
165: part_2 += tmpProp
166: .getProperty(PropertyNames.PRODUCT_VENDOR_NAME)
167: + "\">\n";
168:
169: }
170:
171: /*
172: * For internal use only.
173: * createTmpFiles() create the temporary files with the build properties at the specified location.
174: *
175: * @exception Exception if there is an error
176: */
177: private void createTmpFiles() throws Exception {
178: File file = new File(tmpFileLocation.getAbsolutePath()
179: + File.separator + tmpPropFile);
180: FileOutputStream fo = new FileOutputStream(file);
181: tmpProp.store(fo, null);
182: fo.close();
183: file = new File(tmpFileLocation.getAbsolutePath()
184: + File.separator + pluginXMLFile);
185: FileWriter fw = new FileWriter(file);
186: fw.write(part_1 + part_2 + part_3);
187: fw.close();
188:
189: }
190: }
|