Lines 7-25
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Phil Loats/Erxiang Liu (IBM Corp.) - fix to only use Foundation APIs |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.update.internal.configurator; |
12 |
package org.eclipse.update.internal.configurator; |
12 |
|
13 |
|
13 |
import java.io.*; |
14 |
import java.io.*; |
14 |
import java.lang.reflect.*; |
15 |
import java.lang.reflect.*; |
15 |
import java.net.*; |
16 |
import java.net.*; |
16 |
import java.nio.channels.*; |
17 |
//import java.nio.channels.*; |
17 |
import java.util.*; |
18 |
import java.util.*; |
18 |
|
19 |
|
19 |
import javax.xml.parsers.*; |
20 |
import javax.xml.parsers.*; |
20 |
import javax.xml.transform.*; |
21 |
//import javax.xml.transform.*; |
21 |
import javax.xml.transform.dom.*; |
22 |
//import javax.xml.transform.dom.*; |
22 |
import javax.xml.transform.stream.*; |
23 |
//import javax.xml.transform.stream.*; |
23 |
|
24 |
|
24 |
import org.eclipse.core.runtime.*; |
25 |
import org.eclipse.core.runtime.*; |
25 |
import org.eclipse.osgi.service.datalocation.*; |
26 |
import org.eclipse.osgi.service.datalocation.*; |
Lines 40-48
Link Here
|
40 |
*/ |
41 |
*/ |
41 |
public class PlatformConfiguration implements IPlatformConfiguration, IConfigurationConstants { |
42 |
public class PlatformConfiguration implements IPlatformConfiguration, IConfigurationConstants { |
42 |
|
43 |
|
|
|
44 |
private static final String XML_ENCODING = "UTF-8"; |
43 |
private static PlatformConfiguration currentPlatformConfiguration = null; |
45 |
private static PlatformConfiguration currentPlatformConfiguration = null; |
44 |
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); |
46 |
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); |
45 |
private static final TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
47 |
//private static final TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
46 |
|
48 |
|
47 |
private Configuration config; |
49 |
private Configuration config; |
48 |
private URL configLocation; |
50 |
private URL configLocation; |
Lines 52-58
Link Here
|
52 |
private boolean featuresChangeStampIsValid; |
54 |
private boolean featuresChangeStampIsValid; |
53 |
private long pluginsChangeStamp; |
55 |
private long pluginsChangeStamp; |
54 |
private boolean pluginsChangeStampIsValid; |
56 |
private boolean pluginsChangeStampIsValid; |
55 |
private FileLock lock; |
57 |
//private FileLock lock; |
56 |
|
58 |
|
57 |
private static final String ECLIPSE = "eclipse"; //$NON-NLS-1$ |
59 |
private static final String ECLIPSE = "eclipse"; //$NON-NLS-1$ |
58 |
private static final String CONFIG_HISTORY = "history"; //$NON-NLS-1$ |
60 |
private static final String CONFIG_HISTORY = "history"; //$NON-NLS-1$ |
Lines 214-224
Link Here
|
214 |
|
216 |
|
215 |
SiteEntry result = config.getSiteEntry(key); |
217 |
SiteEntry result = config.getSiteEntry(key); |
216 |
if (result == null) { // retry with decoded URL string |
218 |
if (result == null) { // retry with decoded URL string |
217 |
try { |
219 |
// try { |
218 |
key = URLDecoder.decode(key, "UTF-8"); //$NON-NLS-1$ |
220 |
// key = URLDecoder.decode(key, "UTF-8"); //$NON-NLS-1$ |
219 |
} catch (UnsupportedEncodingException e) { |
221 |
key = URLDecoder.decode(key); |
220 |
// ignore |
222 |
// } catch (UnsupportedEncodingException e) { |
221 |
} |
223 |
// // ignore |
|
|
224 |
// } |
222 |
result = config.getSiteEntry(key); |
225 |
result = config.getSiteEntry(key); |
223 |
} |
226 |
} |
224 |
|
227 |
|
Lines 746-771
Link Here
|
746 |
* @param url configuration directory |
749 |
* @param url configuration directory |
747 |
*/ |
750 |
*/ |
748 |
private void getConfigurationLock(URL url) { |
751 |
private void getConfigurationLock(URL url) { |
749 |
if (!url.getProtocol().equals("file")) //$NON-NLS-1$ |
752 |
// if (!url.getProtocol().equals("file")) //$NON-NLS-1$ |
750 |
return; |
753 |
// return; |
751 |
|
754 |
|
752 |
File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE+ File.separator+CONFIG_FILE_LOCK_SUFFIX); |
755 |
// File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE+ File.separator+CONFIG_FILE_LOCK_SUFFIX); |
753 |
verifyPath(url); |
756 |
// verifyPath(url); |
754 |
try { |
757 |
// try { |
755 |
RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$ |
758 |
// RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$ |
756 |
lock = raf.getChannel().lock(); |
759 |
// lock = raf.getChannel().lock(); |
757 |
} catch (IOException ioe) { |
760 |
// } catch (IOException ioe) { |
758 |
lock = null; |
761 |
// lock = null; |
759 |
} |
762 |
// } |
760 |
} |
763 |
} |
761 |
|
764 |
|
762 |
private void clearConfigurationLock() { |
765 |
private void clearConfigurationLock() { |
763 |
if (lock != null) { |
766 |
// if (lock != null) { |
764 |
try { |
767 |
// try { |
765 |
lock.channel().close(); |
768 |
// lock.channel().close(); |
766 |
} catch (IOException ioe) { |
769 |
// } catch (IOException ioe) { |
767 |
} |
770 |
// } |
768 |
} |
771 |
// } |
769 |
} |
772 |
} |
770 |
|
773 |
|
771 |
|
774 |
|
Lines 1073-1084
Link Here
|
1073 |
return installURL; |
1076 |
return installURL; |
1074 |
} |
1077 |
} |
1075 |
|
1078 |
|
|
|
1079 |
//Old saveASXML, has to use standard XML parser and use javax.tranform.* package. |
1080 |
/* |
1076 |
private void saveAsXML(OutputStream stream) throws CoreException { |
1081 |
private void saveAsXML(OutputStream stream) throws CoreException { |
1077 |
StreamResult result = null; |
1082 |
StreamResult result = null; |
1078 |
try { |
1083 |
try { |
1079 |
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); |
1084 |
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); |
1080 |
Document doc = docBuilder.newDocument(); |
1085 |
Document doc = docBuilder.newDocument(); |
1081 |
|
1086 |
|
1082 |
if (config == null) |
1087 |
if (config == null) |
1083 |
throw Utils.newCoreException(Messages.getString("PlatformConfiguration.cannotSaveNonExistingConfig"),null); //$NON-NLS-1$ |
1088 |
throw Utils.newCoreException(Messages.getString("PlatformConfiguration.cannotSaveNonExistingConfig"),null); //$NON-NLS-1$ |
1084 |
|
1089 |
|
Lines 1086-1093
Link Here
|
1086 |
doc.appendChild(doc.createComment("Created on " + config.getDate().toString())); //$NON-NLS-1$ |
1091 |
doc.appendChild(doc.createComment("Created on " + config.getDate().toString())); //$NON-NLS-1$ |
1087 |
Element configElement = config.toXML(doc); |
1092 |
Element configElement = config.toXML(doc); |
1088 |
doc.appendChild(configElement); |
1093 |
doc.appendChild(configElement); |
1089 |
|
1094 |
|
1090 |
// Write out to a file |
1095 |
// Write out to a file . |
1091 |
|
1096 |
|
1092 |
Transformer transformer=transformerFactory.newTransformer(); |
1097 |
Transformer transformer=transformerFactory.newTransformer(); |
1093 |
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ |
1098 |
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ |
Lines 1105-1111
Link Here
|
1105 |
result.setOutputStream(null); |
1110 |
result.setOutputStream(null); |
1106 |
result = null; |
1111 |
result = null; |
1107 |
} |
1112 |
} |
1108 |
} |
1113 |
} |
|
|
1114 |
*/ |
1115 |
|
1116 |
private void saveAsXML(OutputStream stream) throws CoreException,IOException { |
1117 |
OutputStreamWriter xmlWriter = new OutputStreamWriter(stream,XML_ENCODING); |
1118 |
try { |
1119 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
1120 |
factory.setExpandEntityReferences(false); |
1121 |
factory.setValidating(false); |
1122 |
factory.setIgnoringComments(true); |
1123 |
DocumentBuilder docBuilder = factory.newDocumentBuilder(); |
1124 |
Document doc = docBuilder.newDocument(); |
1125 |
|
1126 |
if (config == null) |
1127 |
throw Utils.newCoreException(Messages.getString("PlatformConfiguration.cannotSaveNonExistingConfig"),null); //$NON-NLS-1$ |
1128 |
|
1129 |
config.setDate(new Date()); |
1130 |
Element configElement = config.toXML(doc); |
1131 |
doc.appendChild(configElement); |
1132 |
|
1133 |
XMLPrintHandler.printComment(xmlWriter,"Created on " + config.getDate().toString()); |
1134 |
XMLPrintHandler.printNode(xmlWriter,doc,XML_ENCODING); |
1135 |
|
1136 |
} catch (Exception e) { |
1137 |
throw Utils.newCoreException("", e); //$NON-NLS-1$ |
1138 |
} finally { |
1139 |
xmlWriter.close(); |
1140 |
xmlWriter = null; |
1141 |
} |
1142 |
} |
1109 |
|
1143 |
|
1110 |
private void reconcile() throws CoreException { |
1144 |
private void reconcile() throws CoreException { |
1111 |
long lastChange = config.getDate().getTime(); |
1145 |
long lastChange = config.getDate().getTime(); |