diff options
Diffstat (limited to 'examples/org.eclipse.swt.examples.launcher/org/eclipse/swt/examples/launcher/ImportProjectTask.java')
-rwxr-xr-x | examples/org.eclipse.swt.examples.launcher/org/eclipse/swt/examples/launcher/ImportProjectTask.java | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/examples/org.eclipse.swt.examples.launcher/org/eclipse/swt/examples/launcher/ImportProjectTask.java b/examples/org.eclipse.swt.examples.launcher/org/eclipse/swt/examples/launcher/ImportProjectTask.java index 57aa38d608..8ab81820f7 100755 --- a/examples/org.eclipse.swt.examples.launcher/org/eclipse/swt/examples/launcher/ImportProjectTask.java +++ b/examples/org.eclipse.swt.examples.launcher/org/eclipse/swt/examples/launcher/ImportProjectTask.java @@ -226,7 +226,7 @@ public class ImportProjectTask {
// Support for externalized project properties /* Add builders */
ICommand[] buildSpecs = projectDesc.getBuildSpec();
- final String buildersList = properties.getProperty(PROPERTYKEY_BUILDERS);
if (buildersList != null) {
StringTokenizer entries = new StringTokenizer(buildersList, "; \t\n\r\f");
while (entries.hasMoreTokens()) {
buildSpecs = addUniqueCommand(buildSpecs, entries.nextToken(), new HashMap());
}
projectDesc.setBuildSpec(buildSpecs);
}
}
/**
* Updates the Classpath Variables.
*
* @param properties a Properties file containing entries of the form
* var.<varname> = [<string>|<substitution string>]
* @param progressMonitor an IProgressMonitor to use while setting things up
*/
private void updateClasspathVariables(Properties properties, IProgressMonitor progressMonitor) {
Enumeration it = properties.propertyNames();
while (it.hasMoreElements()) {
final String name = (String) it.nextElement();
if (name.startsWith(PROPERTYKEY_VARIABLES_PREFIX)) {
final String varName = name.substring(PROPERTYKEY_VARIABLES_PREFIX.length());
final String path = properties.getProperty(name);
if (path == null || path.length() == 0) continue;
IPath oldValue = JavaCore.getClasspathVariable(varName);
if (oldValue != null) continue; // silently ignore if set
// Variable does not exist, set it.
try {
final IPath varPath = new Path(expandSubstitutionKeywords(path));
varPath.makeAbsolute();
JavaCore.setClasspathVariable(varName, varPath, progressMonitor);
continue;
} catch (Exception e) {
}
MessageDialog.openInformation(parentShell,
LauncherPlugin.getResourceString("dialog.ImportProgramProblems.title"),
LauncherPlugin.getResourceString("dialog.UnableToSetClasspathVariable.message",
new Object[] { varName, path } ));
}
}
}
/**
* Updates the Program and VM Arguments.
*
* @param properties a Properties file containing entries of the form
* args.<class> = [<string>|<substitution string>]
* vmargs.<class> = [<string>|<substitution string>]
*/
private void updateProgramAndVMArguments(Properties properties) {
Enumeration it = properties.propertyNames();
while (it.hasMoreElements()) {
final String name = (String) it.nextElement();
final String resource;
final int argId; // 0 is program, 1 is VM
if (name.startsWith(PROPERTYKEY_ARGS_PREFIX)) {
resource = name.substring(PROPERTYKEY_ARGS_PREFIX.length());
argId = 0;
} else if (name.startsWith(PROPERTYKEY_VMARGS_PREFIX)) {
resource = name.substring(PROPERTYKEY_VMARGS_PREFIX.length());
argId = 1;
} else continue;
String value = properties.getProperty(name);
if (value == null) continue;
value = expandSubstitutionKeywords(value);
MessageDialog.openInformation(parentShell,
LauncherPlugin.getResourceString("dialog.ImportProgramProblems.title"),
LauncherPlugin.getResourceString((argId == 0) ?
"dialog.UnableToProgramArguments.message" : "dialog.UnableToVMArguments.message",
new Object[] { resource, value } ));
}
}
/**
* Replaces any substitution keywords with their values.
*
* @param string the string to work on
* @return the expanded string
*/
private String expandSubstitutionKeywords(String string) {
int endIndex = 0;
for (;;) {
int index = string.indexOf(SUBST_KEYWORD_INTRO, endIndex);
if (index == -1) return string;
endIndex = string.indexOf(SUBST_KEYWORD_EXTRO, index);
if (endIndex == -1) return string;
endIndex += SUBST_KEYWORD_EXTRO.length();
final String keyword = string.substring(index, endIndex);
String value = null;
for (int i = 0; i < substitutionKeywords.length; ++i) {
final SubstitutionKeyword subst = substitutionKeywords[i];
if (subst.isMatch(keyword)) {
value = subst.getValue();
break;
}
}
if (value == null) {
MessageDialog.openInformation(parentShell,
LauncherPlugin.getResourceString("dialog.ImportProgramProblems.title"),
LauncherPlugin.getResourceString("dialog.UnableExpandSubstitutionKeyword.message",
new Object[] { keyword, string } ));
} else {
string = string.substring(0, index) + value + string.substring(endIndex);
}
}
}
/** Data for subsitution keywords **/
static abstract class SubstitutionKeyword {
public abstract boolean isMatch(String keyword);
public abstract String getValue();
}
static final SubstitutionKeyword[] substitutionKeywords = new SubstitutionKeyword[] {
new SubstitutionKeyword() {
public boolean isMatch(String keyword) {
return keyword.equalsIgnoreCase(SUBST_ECLIPSE_PLUGINS);
}
public String getValue() {
try {
// Guess at primary plugins directory location
// get the platform's public plugin registry
IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
// retrieve plugin descriptor for org.eclipse.core
IPluginDescriptor pd = pluginRegistry.getPluginDescriptor("org.eclipse.core.runtime");
// getInstallUrl() returns the path of the directory with the plugin manifest file(s)
// for a specific plugin, find the parent directory
final URL installUrl = Platform.resolve(pd.getInstallURL());
if (! installUrl.getProtocol().equals("file")) return null;
String pluginPath = installUrl.getPath();
pluginPath = pluginPath.substring(0, pluginPath.lastIndexOf('/'));
// eliminate terminal '/' on directory
pluginPath = pluginPath.substring(0, 1 + pluginPath.lastIndexOf('/'));
// locate parent directory
return pluginPath;
} catch (Exception e) {
return null;
}
}
},
new SubstitutionKeyword() {
public boolean isMatch(String keyword) {
return keyword.equalsIgnoreCase(SUBST_ECLIPSE_LIBRARY_PATH);
}
public String getValue() {
return System.getProperty("java.library.path");
}
}
};
/**
+ final String buildersList = properties.getProperty(PROPERTYKEY_BUILDERS);
if (buildersList != null) {
StringTokenizer entries = new StringTokenizer(buildersList, "; \t\n\r\f");
while (entries.hasMoreTokens()) {
buildSpecs = addUniqueCommand(buildSpecs, entries.nextToken(), new HashMap());
}
projectDesc.setBuildSpec(buildSpecs);
}
}
/**
* Updates the Classpath Variables.
*
* @param properties a Properties file containing entries of the form
* var.<varname> = [<string>|<substitution string>]
* @param progressMonitor an IProgressMonitor to use while setting things up
*/
private void updateClasspathVariables(Properties properties, IProgressMonitor progressMonitor) {
Enumeration it = properties.propertyNames();
while (it.hasMoreElements()) {
final String name = (String) it.nextElement();
if (name.startsWith(PROPERTYKEY_VARIABLES_PREFIX)) {
final String varName = name.substring(PROPERTYKEY_VARIABLES_PREFIX.length());
final String path = properties.getProperty(name);
if (path == null || path.length() == 0) continue;
IPath oldValue = JavaCore.getClasspathVariable(varName);
if (oldValue != null) continue; // silently ignore if set
// Variable does not exist, set it.
try {
final IPath varPath = new Path(expandSubstitutionKeywords(path));
varPath.makeAbsolute();
JavaCore.setClasspathVariable(varName, varPath, progressMonitor);
continue;
} catch (Exception e) {
}
MessageDialog.openInformation(parentShell,
LauncherPlugin.getResourceString("dialog.ImportProgramProblems.title"),
LauncherPlugin.getResourceString("dialog.UnableToSetClasspathVariable.message",
new Object[] { varName, path } ));
}
}
}
/**
* Updates the Program and VM Arguments.
*
* @param properties a Properties file containing entries of the form
* args.<class> = [<string>|<substitution string>]
* vmargs.<class> = [<string>|<substitution string>]
*/
private void updateProgramAndVMArguments(Properties properties) {
Enumeration it = properties.propertyNames();
while (it.hasMoreElements()) {
final String name = (String) it.nextElement();
final String resource;
final int argId; // 0 is program, 1 is VM
if (name.startsWith(PROPERTYKEY_ARGS_PREFIX)) {
resource = name.substring(PROPERTYKEY_ARGS_PREFIX.length());
argId = 0;
} else if (name.startsWith(PROPERTYKEY_VMARGS_PREFIX)) {
resource = name.substring(PROPERTYKEY_VMARGS_PREFIX.length());
argId = 1;
} else continue;
String value = properties.getProperty(name);
if (value == null) continue;
value = expandSubstitutionKeywords(value);
MessageDialog.openInformation(parentShell,
LauncherPlugin.getResourceString("dialog.ImportProgramProblems.title"),
LauncherPlugin.getResourceString((argId == 0) ?
"dialog.UnableToProgramArguments.message" : "dialog.UnableToVMArguments.message",
new Object[] { resource, value } ));
}
}
/**
* Replaces any substitution keywords with their values.
*
* @param string the string to work on
* @return the expanded string
*/
private String expandSubstitutionKeywords(String string) {
int endIndex = 0;
for (;;) {
int index = string.indexOf(SUBST_KEYWORD_INTRO, endIndex);
if (index == -1) return string;
endIndex = string.indexOf(SUBST_KEYWORD_EXTRO, index);
if (endIndex == -1) return string;
endIndex += SUBST_KEYWORD_EXTRO.length();
final String keyword = string.substring(index, endIndex);
String value = null;
for (int i = 0; i < substitutionKeywords.length; ++i) {
final SubstitutionKeyword subst = substitutionKeywords[i];
if (subst.isMatch(keyword)) {
value = subst.getValue();
break;
}
}
if (value == null) {
MessageDialog.openInformation(parentShell,
LauncherPlugin.getResourceString("dialog.ImportProgramProblems.title"),
LauncherPlugin.getResourceString("dialog.UnableExpandSubstitutionKeyword.message",
new Object[] { keyword, string } ));
} else {
string = string.substring(0, index) + value + string.substring(endIndex);
}
}
}
/** Data for subsitution keywords **/
static abstract class SubstitutionKeyword {
public abstract boolean isMatch(String keyword);
public abstract String getValue();
}
static final SubstitutionKeyword[] substitutionKeywords = new SubstitutionKeyword[] {
new SubstitutionKeyword() {
public boolean isMatch(String keyword) {
return keyword.equalsIgnoreCase(SUBST_ECLIPSE_PLUGINS);
}
public String getValue() {
try {
// Guess at primary plugins directory location
// get the platform's public plugin registry
IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
// retrieve plugin descriptor for org.eclipse.core
IPluginDescriptor pd = pluginRegistry.getPluginDescriptor("org.eclipse.core.runtime");
// getInstallUrl() returns the path of the directory with the plugin manifest file(s)
// for a specific plugin, find the parent directory
final URL installUrl = Platform.resolve(pd.getInstallURL());
if (! installUrl.getProtocol().equals("file")) return null;
String pluginPath = installUrl.getFile();
pluginPath = pluginPath.substring(0, pluginPath.lastIndexOf('/'));
// eliminate terminal '/' on directory
pluginPath = pluginPath.substring(0, 1 + pluginPath.lastIndexOf('/'));
// locate parent directory
return pluginPath;
} catch (Exception e) {
return null;
}
}
},
new SubstitutionKeyword() {
public boolean isMatch(String keyword) {
return keyword.equalsIgnoreCase(SUBST_ECLIPSE_LIBRARY_PATH);
}
public String getValue() {
return System.getProperty("java.library.path");
}
}
};
/**
* Validates the target project path
*
* @param projectPath the project path to verify
|