001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.ideaplugin.bean;
020:
021: import java.io.File;
022: import java.io.FileNotFoundException;
023: import java.io.FileWriter;
024: import java.io.IOException;
025: import java.util.ArrayList;
026: import java.util.Calendar;
027:
028: /**
029: * Author: Deepal Jayasinghe
030: * Date: Sep 17, 2005
031: * Time: 11:40:40 PM
032: */
033: public class ArchiveBean {
034:
035: private boolean singleService = false;
036: private boolean generetServiceDesc = false;
037: private ArrayList classLocation = new ArrayList();
038: private File classLoc;
039: private ClassLoader classLoader;
040: private String ServiceXML;
041: public String fileSeparator = System.getProperty("file.separator");
042: private ArrayList libs = new ArrayList();
043: private ArrayList tempLibs = new ArrayList();
044: private ArrayList tempWsdls = new ArrayList();
045: private ArrayList wsdls = new ArrayList();
046: private String outPath;
047: private String archiveName;
048: private ArrayList servicelsit = new ArrayList();
049: private boolean includeClass = false;
050:
051: public ArrayList getTempWsdls() {
052: return tempWsdls;
053: }
054:
055: public void setTempWsdls(ArrayList tempWsdls) {
056: this .tempWsdls = tempWsdls;
057: }
058:
059: public ArrayList getTempLibs() {
060: return tempLibs;
061: }
062:
063: public void setTempLibs(ArrayList tempLibs) {
064: this .tempLibs = tempLibs;
065: }
066:
067: public File getClassLoc() {
068: return classLoc;
069: }
070:
071: public void setClassLoc(File classLoc) {
072: this .classLoc = classLoc;
073: }
074:
075: public ArrayList getServicelsit() {
076: return servicelsit;
077: }
078:
079: public void addToServicelsit(ServiceObj service) {
080: for (int count = 0; count < servicelsit.size(); count++) {
081: if (((ServiceObj) servicelsit.get(count)).getServiceName()
082: .equalsIgnoreCase(service.getServiceName())) {
083: servicelsit.remove(count);
084: servicelsit.add(service);
085: return;
086: }
087:
088: }
089: servicelsit.add(service);
090: }
091:
092: public boolean isSingleService() {
093: return singleService;
094: }
095:
096: public void setSingleService(boolean singleService) {
097: this .singleService = singleService;
098: }
099:
100: public boolean isGeneretServiceDesc() {
101: return generetServiceDesc;
102: }
103:
104: public void setGeneretServiceDesc(boolean generetServiceDesc) {
105: this .generetServiceDesc = generetServiceDesc;
106: }
107:
108: public ArrayList getClassLocation() {
109: return classLocation;
110: }
111:
112: public void addClassLocation(File classLocation) {
113: this .classLocation.add(classLocation);
114: }
115:
116: public String getServiceXML() {
117: return ServiceXML;
118: }
119:
120: public void setServiceXML(String serviceXML) {
121: ServiceXML = serviceXML;
122: }
123:
124: public ArrayList getLibs() {
125: return libs;
126: }
127:
128: public void addLibs(ArrayList libs) {
129: this .libs.addAll(libs);
130: }
131:
132: public ArrayList getWsdls() {
133: return wsdls;
134: }
135:
136: public void addWsdls(File wsdl) {
137: this .wsdls.add(wsdl);
138: }
139:
140: public String getOutPath() {
141: return outPath;
142: }
143:
144: public void setOutPath(String outPath) {
145: this .outPath = outPath;
146: }
147:
148: public String getArchiveName() {
149: return archiveName;
150: }
151:
152: public void setArchiveName(String archiveName) {
153: this .archiveName = archiveName;
154: }
155:
156: public void setIncludeClass(boolean includeClass) {
157: this .includeClass = includeClass;
158: }
159:
160: public boolean getIncludeClass() {
161: return this .includeClass;
162: }
163:
164: public void finsh() throws Exception {
165: //Creating out File
166: try {
167: File outFile = new File(getOutPath());
168: String time = Calendar.getInstance().getTime().toString()
169: .replace(':', '-');
170: File tempfile = new File(outFile, "temp-" + time);
171: tempfile.mkdir();
172: //creating META-INF
173: File metainf = new File(tempfile, "META-INF");
174: if (!metainf.exists()) {
175: metainf.mkdir();
176: }
177:
178: // Writing services.xml
179: File servicexml = new File(metainf, "services.xml");
180: FileWriter writer = new FileWriter(servicexml);
181: writer.write(getServiceXML());
182: writer.flush();
183: writer.close();
184:
185: //Coping class files
186: FileCopier fc = new FileCopier();
187: if (includeClass) {
188: for (int count = 0; count < classLocation.size(); count++)
189: fc.copyFiles((File) classLocation.get(count),
190: tempfile, ".class");
191: } else {
192: for (int count = 0; count < classLocation.size(); count++)
193: fc.copyFiles((File) classLocation.get(count),
194: tempfile, null);
195: }
196: // Coping wsdl files
197: File lib = new File(tempfile, "lib");
198: if (!lib.exists()) {
199: lib.mkdir();
200: }
201: if (libs != null) {
202: for (int i = 0; i < libs.size(); i++) {
203: String libname = (String) libs.get(i);
204: fc.copyFiles(new File(libname), lib, null);
205: }
206: }
207:
208: //coping wsdl files
209: if (wsdls != null)
210: for (int i = 0; i < wsdls.size(); i++) {
211: File libname = (File) wsdls.get(i);
212: fc.copyFiles(libname, metainf, null);
213: }
214:
215: String arcivename = getArchiveName();
216: if (arcivename.indexOf(".aar") < 0) {
217: arcivename = arcivename + ".aar";
218: }
219: JarFileWriter jwriter = new JarFileWriter();
220: jwriter.writeJarFile(outFile, arcivename, tempfile);
221: //craeting the jar file
222: deleteDir(tempfile);
223:
224: } catch (Exception e) {
225: throw e;
226: }
227: }
228:
229: private boolean deleteDir(File dir) {
230: if (dir.isDirectory()) {
231: String[] children = dir.list();
232: for (int i = 0; i < children.length; i++) {
233: boolean success = deleteDir(new File(dir, children[i]));
234: if (!success) {
235: return false;
236: }
237: }
238: }
239:
240: // The directory is now empty so delete it
241: return dir.delete();
242: }
243:
244: public ClassLoader getClassLoader() {
245: return classLoader;
246: }
247:
248: public void setClassLoader(ClassLoader classLoader) {
249: this.classLoader = classLoader;
250: }
251:
252: }
|