System.out.println("Server not found!");
return;
}
System.out.println("Server type found, ID is: " + serverType.getId());
final IRuntimeType runtimeType = serverType.getRuntimeType();
System.out.println("Associated runtime type: " + runtimeType.getName());
System.out.println("Runtime type ID is: " + runtimeType.getId());
final ServerRuntime serverRuntime = CorePlugin.getDefault().getServerTypeDefinitionManager().getServerRuntimeDefinition(serverType.getId(), runtimeType.getId(), null);
System.out.println("ServerRuntime found: " + serverRuntime.getName());
final List serverRuntimeProperties = serverRuntime.getProperty();
final HashMap runtimeProperties = new HashMap();
final HashMap serverProperties = new HashMap();
for (int i = 0; i < serverRuntimeProperties.size(); i++)
{
final Property property = (Property) serverRuntimeProperties.get(i);
Map values = null;
if (property.getContext().equals(Property.CONTEXT_RUNTIME))
{
System.out.print("\tServer runtime property: ");
values = runtimeProperties;
}
else
{
System.out.print("\tServer property: ");
values = serverProperties;
}
System.out.println(property.getId() + ", default value is: " + property.getDefault());
final String svalue = pf.getProperty(property.getId());
if (svalue == null)
{
System.out.println("ERROR: No value associated for " + property.getId() + " in " + propertiesFile);
return;
}
Object value = null;
if (property.getType().equals(Property.TYPE_DIRECTORY))
{
final File f = new File(svalue);
if (!f.exists() || !f.isDirectory())
{
System.out.println("ERROR: directory property " + property.getId() + " value does not exist or not a directory: " + svalue);
}
value = svalue;
}
else if (property.getType().equals(Property.TYPE_FILE))
{
final File f = new File(svalue);
if (!f.exists() || !f.isFile())
{
System.out.println("ERROR: file property " + property.getId() + " value does not exist or not a regular file: " + svalue);
}
value = svalue;
}
else
{
value = svalue;
}
values.put(property.getId(), value);
}
System.out.println("Creating server runtime...");
final RuntimeWorkingCopy rwc = (RuntimeWorkingCopy) runtimeType.createRuntime(runtimeType.getName() + " GENERATED", monitor);
if (!pf.containsKey("location"))
{
System.out.println("ERROR: no location property in properties file: " + propertiesFile);
return;
}
rwc.setLocation(new Path(pf.getProperty("location")));
rwc.setName(runtimeType.getName() + " GENERATED");
rwc.setStub(false);
final Iterator it = runtimeProperties.entrySet().iterator();
while (it.hasNext())
{
final Map.Entry e = (Entry) it.next();
rwc.setAttribute((String) e.getKey(), (String) e.getValue());
}
Map m = rwc.getAttribute("generic_server_instance_properties", (Map) null);
m.put("key", "generic_server_instance_properties");
m.putAll(runtimeProperties);
rwc.setAttribute("generic_server_instance_properties", m);
rwc.setAttribute("runtime-type-id", runtimeType.getId());
rwc.setAttribute("server_definition_id", serverRuntime.getId());
final IRuntime runtime = rwc.save(true, monitor);
System.out.println("Server runtime created: " + runtime.getName());