Skip to content

Commit

Permalink
o.c.util.product: Add "-workbench_xmi" command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed Dec 7, 2015
1 parent a1d710a commit 34cd22c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public class StartupParameters implements StartupParametersExtPoint
/** Parameter tag defines the shared link. The value is stored in the returned map. */
public static final String SHARE_LINK_PARAM = "css.shareLink"; //$NON-NLS-1$

/** Command-line switch to install workbench.xmi */
private static final String WORKBENCH_XMI = "-workbench_xmi"; //$NON-NLS-1$

/** Parameter tag for WORKBENCH_XMI. Map value contains path to workbench.xmi. */
public static final String WORKBENCH_XMI_PARAM = "css.workbench.xmi"; //$NON-NLS-1$

/** {@inheritDoc} */
@SuppressWarnings("nls")
@Override
Expand Down Expand Up @@ -122,6 +128,29 @@ else if (arg.equalsIgnoreCase(WORKSPACE_PROMPT))
}
}
}
else if (arg.equalsIgnoreCase(WORKBENCH_XMI))
{
String template = null;
if ((i + 1) < args.length)
{
final String next = args[i+1];
if (!next.startsWith("-")) //$NON-NLS-1$
{
template = next;
++i;
}
}
if (template != null)
parameters.put(WORKBENCH_XMI_PARAM, template);
else
{
System.out.println("Error: Missing /path/to/workspace.xmi"); //$NON-NLS-1$
showHelp();
// Exit ASAP, see comment below.
parameters.put(EXIT_CODE, IApplication.EXIT_OK);
System.exit(0);
}
}
else if (arg.equalsIgnoreCase(SHARE_LINK))
{
if ((i + 1) < args.length)
Expand Down Expand Up @@ -240,6 +269,8 @@ private void showHelp()
WORKSPACE_PROMPT);
System.out.format(" %-40s : Present workspace dialog with given default\n",
WORKSPACE_PROMPT + " /some/workspace");
System.out.format(" %-40s : Initialize workbench.xmi with a given template\n",
WORKBENCH_XMI + " /path/to/workbench.xmi");
System.out.format(" %-40s : Log all messages to the console\n",
"-consoleLog");
System.out.format(" %-40s : Select workspace on command-line, no prompt\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.csstudio.platform.workspace.WorkspaceIndependentStore;
import org.csstudio.platform.workspace.WorkspaceInfo;
Expand Down Expand Up @@ -68,6 +72,29 @@ public Object promptForWorkspace(Display display,
//Platform.endSplash();
return IApplication.EXIT_OK;
}

o = parameters.get(StartupParameters.WORKBENCH_XMI_PARAM);
if (o != null)
{ // Install predefined workbench.xmi
final File template = new File((String)o);
try
{ // Another way to get the workbench.xmi location,
// but depends on hardcoded knowledge of ".metadata/.plugins":
// ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi");
final URL uri = Platform.getInstanceLocation().getDataArea("org.eclipse.e4.workbench/workbench.xmi");
final File file = new File(uri.getFile());
if (! file.isAbsolute())
throw new Exception("Cannot obtain absolute workbench.xmi location, got " + file);
Files.createDirectories(file.toPath().getParent());
Files.copy(template.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
catch (Exception ex)
{
Logger.getLogger(getClass().getName())
.log(Level.SEVERE, "Cannot install workbench.xmi template " + template, ex);
}
}

return null;
}

Expand Down

0 comments on commit 34cd22c

Please sign in to comment.