xref: /AOO41X/main/scripting/workben/installer/IdeUpdater.java (revision cd519653a6b6a9e2ff38774da567b1ae7cbeddbb)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package installer;
23 
24 import java.io.*;
25 import java.util.*;
26 import java.util.jar.*;
27 //import org.xml.sax.*;
28 //import org.w3c.dom.*;
29 //import javax.xml.parsers.*;
30 import java.net.URL;
31 import java.net.JarURLConnection;
32 //import javax.xml.parsers.*;
33 import javax.swing.*;
34 
35 /**
36  *  The <code>XmlUpdater</code> pulls a META-INF/converter.xml
37  *  file out of a jar file and parses it, providing access to this
38  *  information in a <code>Vector</code> of <code>ConverterInfo</code>
39  *  objects.
40  *
41  *  @author  Aidan Butler
42  */
43 public class IdeUpdater extends Thread {
44 
45     private String classesPath = null;
46     private String jarfilename;
47     private String installPath;
48 
49     private JLabel statusLabel;
50 
51     private Vector listeners;
52     private Thread internalThread;
53     private boolean threadSuspended;
54     private JProgressBar progressBar;
55 
56     private boolean isNetbeansPath = false;
57 
58 
IdeUpdater(String installPath, JLabel statusLabel, JProgressBar pBar)59     public IdeUpdater(String installPath, JLabel statusLabel, JProgressBar pBar) {
60 
61         if (installPath.endsWith(File.separator) == false)
62             installPath += File.separator;
63 
64     //File jeditLauncher = new File( installPath + "jedit.jar" );
65     File netbeansLauncher = new File( installPath + "bin" );
66 
67     if( netbeansLauncher.isDirectory() ) {
68         isNetbeansPath = true;
69         installPath = installPath +"modules" + File.separator;
70     }
71     /*
72     else if( jeditLauncher.isFile() ){
73         isNetbeansPath =  false;
74         installPath = installPath + "jars" + File.separator;
75     }
76     */
77 
78     System.out.println( "IdeUpdater installPath is " + installPath + " isNetbeansPath is " + isNetbeansPath );
79         this.installPath = installPath;
80         this.statusLabel = statusLabel;
81     listeners = new Vector();
82     threadSuspended = false;
83     progressBar=pBar;
84     progressBar.setStringPainted(true);
85     }// XmlUpdater
86 
87 
checkStop()88     public boolean checkStop()
89     {
90             if (internalThread == Thread.currentThread())
91                 return false;
92             return true;
93     }// checkStop
94 
95 
checkSuspend()96     public void checkSuspend()
97     {
98             if (threadSuspended)
99             {
100         synchronized(this)
101         {
102                     while (threadSuspended)
103                     {
104                         try {
105                             wait();
106                         } catch (InterruptedException eInt) {
107                             //...
108                         }
109                     }
110         }
111             }
112     }// checkSuspend
113 
114 
setSuspend()115     public void setSuspend()
116     {
117             threadSuspended = true;
118     }// setSuspend
119 
120 
setResume()121     public void setResume()
122     {
123             threadSuspended = false;
124             notify();
125     }// setResume
126 
127 
setStop()128     public void setStop()
129     {
130             internalThread = null;
131     }// setStop
132 
133 
run()134     public void run() {
135 
136         //InputStream istream;
137         //URL url;
138         //String fileName = null;
139 
140     internalThread = Thread.currentThread();
141 
142     progressBar.setString("Unzipping Required Files");
143         ZipData zd = new ZipData("SFrameworkInstall.jar");
144 
145     // Adding IDE support
146     if( isNetbeansPath ) {
147         if (!zd.extractEntry("ide/office.jar",installPath, statusLabel))
148             {
149             onInstallComplete();
150             return;
151         }
152     }
153     else {
154         if (!zd.extractEntry("ide/idesupport.jar",installPath, statusLabel))
155             {
156             onInstallComplete();
157             return;
158         }
159         if (!zd.extractEntry("ide/OfficeScripting.jar",installPath, statusLabel))
160             {
161             onInstallComplete();
162             return;
163         }
164     }
165 
166         //System.out.println("About to call register");
167     //Register.register(installPath+File.separator, statusLabel, progressBar);
168 
169     statusLabel.setText("Installation Complete");
170     progressBar.setString("Installation Complete");
171     progressBar.setValue(10);
172     onInstallComplete();
173 
174     }// run
175 
176 
addInstallListener(InstallListener listener)177     public void addInstallListener(InstallListener listener)
178     {
179         listeners.addElement(listener);
180     }// addInstallListener
181 
182 
onInstallComplete()183     private void onInstallComplete()
184     {
185         Enumeration e = listeners.elements();
186         while (e.hasMoreElements())
187         {
188             InstallListener listener = (InstallListener)e.nextElement();
189             listener.installationComplete(null);
190         }
191     }// onInstallComplete
192 
193 }// XmlUpdater class
194