diff -pruN my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/plugin.xml my_epf.changed_1_0_2/org.eclipse.epf.rcp/plugin.xml --- my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/plugin.xml 2007-01-14 09:17:49.000000000 +0100 +++ my_epf.changed_1_0_2/org.eclipse.epf.rcp/plugin.xml 2007-04-12 03:54:00.000000000 +0200 @@ -26,6 +26,7 @@ + diff -pruN my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/MainApplication.java my_epf.changed_1_0_2/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/MainApplication.java --- my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/MainApplication.java 2006-07-25 19:45:45.000000000 +0200 +++ my_epf.changed_1_0_2/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/MainApplication.java 2007-04-21 17:57:33.000000000 +0200 @@ -10,18 +10,36 @@ //------------------------------------------------------------------------------ package org.eclipse.epf.rcp; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.runtime.IPlatformRunnable; import org.eclipse.core.runtime.Platform; +import org.eclipse.epf.library.ILibraryService; +import org.eclipse.epf.library.LibraryService; +import org.eclipse.epf.library.LibraryServiceUtil; +import org.eclipse.epf.library.xmi.XMILibraryManager; +import org.eclipse.epf.publishing.services.AbstractPublishManager; +import org.eclipse.epf.publishing.services.PublishManager; +import org.eclipse.epf.publishing.services.PublishOptions; +import org.eclipse.epf.uma.MethodConfiguration; +import org.eclipse.epf.uma.MethodLibrary; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; + + /** * This class controls all aspects of the application's execution. * @@ -30,36 +48,237 @@ import org.eclipse.ui.PlatformUI; */ public class MainApplication implements IPlatformRunnable { + + private static final String BUNDLE_NAME = "org.eclipse.epf.publishing.cmdline.Messages"; //$NON-NLS-1$ + + public static String badConfig; + public static String internalError; + public static String invalidAboutPath; + public static String invalidBannerPath; + public static String invalidLibraryPath; + public static String missingRequiredParameter; + public static String startingTask; + public static String unknownArg; + public static Object usage; + + private static final String PUBLISH_CONSOLE = "-publishConsole"; //$NON-NLS-1$ + private static final String ABOUT = "-about"; //$NON-NLS-1$ + private static final String BANNER = "-banner"; //$NON-NLS-1$ + private static final String CHECK_LINKS = "-checkLinks"; //$NON-NLS-1$ + private static final String CONFIG = "-config"; //$NON-NLS-1$ + private static final String FEEDBACK = "-feedback"; //$NON-NLS-1$ + private static final String GLOSSARY = "-glossary"; //$NON-NLS-1$ + private static final String INDEX = "-index"; //$NON-NLS-1$ + private static final String LIBRARY_PATH = "-libraryPath"; //$NON-NLS-1$ + private static final String PUBLISH_PATH = "-publishPath"; //$NON-NLS-1$ + private static final String PUBLISH_UNVERIFIED_DIAGRAMS = "-publishUnverifiedDiagrams"; //$NON-NLS-1$ + private static final String PUBLISH_UNMODIFIED_DIAGRAMS = "-publishUnmodifiedDiagrams"; //$NON-NLS-1$ + private static final String CONVERT_BROKEN_LINKS = "-convertBrokenLinks"; //$NON-NLS-1$ + private static final String DESCRIPTOR_EXTRA_INFO = "-DescriptorExtraInfo"; //$NON-NLS-1$ + private static final String LIGHT_WEIGHT_TREE = "-LightWeightTree"; //$NON-NLS-1$ + private static final String TITLE = "-title"; //$NON-NLS-1$ + + private static final String PUBLISH = "-publish"; //$NON-NLS-1$ + + private static final String LIBRARY_XMI = "/library.xmi"; //$NON-NLS-1$ + + private String libraryPath; + private boolean done; + + public Object CL_run(final Object args) throws Exception { + final PublishOptions publishDataModel = parseArgs((String[])args); + + if (publishDataModel==null) { + return(null); + } + + final Object[] object = new Object[1]; + + ILibraryService libService = LibraryService.getInstance(); + Map params = new HashMap(); + params.put(XMILibraryManager.ARG_LIBRARY_PATH, libraryPath); + libService.openMethodLibrary(XMILibraryManager.LIBRARY_TYPE, params); + + try { + object[0] = MainApplication.this.CL_run(args, publishDataModel); + } catch (Exception e) { + object[0] = e; + } + + if(object[0] instanceof Exception) { + throw (Exception)object[0]; + } + return object[0]; + } + + public Object CL_run(Object args, PublishOptions publishDataModel) throws Exception { + try { + + String selectedConfigName = publishDataModel.getSelectedConfig(); + String publishDestFolder = publishDataModel.getPublicationPath(); + ILibraryService lp = LibraryService.getInstance(); + MethodLibrary library = lp.getCurrentMethodLibrary(); + + try { + AbstractPublishManager publishMgr = null; + try { + String selecedConfigName = publishDataModel.getSelectedConfig(); + MethodConfiguration config = LibraryServiceUtil + .getMethodConfiguration(LibraryService.getInstance() + .getCurrentMethodLibrary(), selecedConfigName); + + publishMgr = new PublishManager(); + System.err.println("begin"); + publishMgr.init(publishDestFolder, config, publishDataModel); + System.err.println("init done"); + publishMgr.publish(new TextProgressMonitor()); + System.err.println("publish done done"); + System.err.println(publishMgr.getPublishedUrl()); + System.err.println(publishMgr.getPublishReportUrl()); + } finally { + if (publishMgr != null) { + publishMgr.dispose(); + } + } + + } finally { + done = true; + lp.closeCurrentMethodLibrary(); + System.err.println("finito"); + } + } catch(Exception ex) { + System.err.println(ex.getMessage()); + System.err.println(usage); + return new Integer(1); + } catch(Throwable ex) { + ex.printStackTrace(); + System.err.println(internalError); + return new Integer(2); + } + + return EXIT_OK; + } + + private PublishOptions parseArgs(String[] args) throws Exception { + PublishOptions options = new PublishOptions(); + int doit = 0; + + for(int i = 0; i < args.length; i++) { + if(args[i].charAt(0) == '-') { + if(args[i].equals(LIBRARY_PATH)) { + File path = new File(args[++i]); + if(!path.isAbsolute()) { + path = path.getAbsoluteFile(); + } + if(!new File(path, LIBRARY_XMI).exists()) { + System.err.println(invalidLibraryPath); + } + libraryPath = path.getAbsolutePath(); + System.err.println(libraryPath); + } else if(args[i].equals(PUBLISH_PATH)) { + options.setPublicationPath(args[++i]); + } else if(args[i].equals(CONFIG)) { + options.setSelectedConfig(args[++i]); + } else if(args[i].equals(BANNER)) { + options.setBannerImage(args[++i]); + if(!new File(args[i]).exists()) { + System.err.println(invalidBannerPath); + } + } else if(args[i].equals(FEEDBACK)) { + options.setFeedbackURL(args[++i]); + } else if(args[i].equals(TITLE)) { + options.setTitle(args[++i]); + } else if(args[i].equals(ABOUT)) { + options.setAboutHTML(args[++i]); + if(!new File(args[i]).exists()) { + System.err.println(invalidAboutPath); + } + } else if(args[i].equals(GLOSSARY)) { + options.setGenerateGlossary(true); + } else if(args[i].equals(INDEX)) { + options.setGenerateIndex(true); + + } else if(args[i].equals(CHECK_LINKS)) { + options.setCheckExtLinks(true); + } else if(args[i].equals(CONVERT_BROKEN_LINKS)) { + options.setConvertBrokenLinks(true); + + } else if(args[i].equals(PUBLISH_UNMODIFIED_DIAGRAMS)) { + options.setAutoGenerateActivityDiagrams(true); + } else if(args[i].equals(PUBLISH_UNVERIFIED_DIAGRAMS)) { + options.setUnopenExtendedActivityDiagram(true); + } else if(args[i].equals(DESCRIPTOR_EXTRA_INFO)) { + options.setShowExtraDescriptorInfo(true); + } else if(args[i].equals(LIGHT_WEIGHT_TREE)) { + options.setGenerateLightWeightTree(true); + + } else if(args[i].equals(PUBLISH_CONSOLE)) { + FileOutputStream fos = new FileOutputStream(args[++i]); + PrintStream ps = new PrintStream(fos); + System.err.println("redirecting output."); + System.setErr(ps); + } else if(args[i].equals(PUBLISH)) { + System.err.println(usage); + doit=1; + } + } + } + + if (doit==1) { + if(libraryPath == null) { + System.err.println(missingRequiredParameter+LIBRARY_PATH); + System.err.println(usage); + } + if(options.getPublicationPath() == null) { + System.err.println(missingRequiredParameter+PUBLISH_PATH); + System.err.println(usage); + } + if(options.getSelectedConfig() == null) { + System.err.println(missingRequiredParameter+CONFIG); + System.err.println(usage); + } + } else { + options=null; + } + + return options; + } + /* * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object) */ public Object run(Object args) throws Exception { - Display display = PlatformUI.createDisplay(); - Shell shell = new Shell(display, SWT.ON_TOP); - try { - boolean noLock = false; - String[] rmcArgs = Platform.getApplicationArgs(); - for (int i = 0; i < rmcArgs.length; i++) { - if (rmcArgs[i].equalsIgnoreCase("-nolock")) { //$NON-NLS-1$ - noLock = true; + + if (CL_run(args)==null) { + Display display = PlatformUI.createDisplay(); + Shell shell = new Shell(display, SWT.ON_TOP); + try { + boolean noLock = false; + String[] rmcArgs = Platform.getApplicationArgs(); + for (int i = 0; i < rmcArgs.length; i++) { + if (rmcArgs[i].equalsIgnoreCase("-nolock")) { //$NON-NLS-1$ + noLock = true; + } + } + + if (!noLock && !checkWorkspaceLock(shell)) { + Platform.endSplash(); + return EXIT_OK; } + + int returnCode = PlatformUI.createAndRunWorkbench(display, + new MainWorkbenchAdvisor()); + if (returnCode == PlatformUI.RETURN_RESTART) { + return IPlatformRunnable.EXIT_RESTART; + } + return IPlatformRunnable.EXIT_OK; + } finally { + if (shell != null) + shell.dispose(); + display.dispose(); } - - if (!noLock && !checkWorkspaceLock(shell)) { - Platform.endSplash(); + } else { return EXIT_OK; - } - - int returnCode = PlatformUI.createAndRunWorkbench(display, - new MainWorkbenchAdvisor()); - if (returnCode == PlatformUI.RETURN_RESTART) { - return IPlatformRunnable.EXIT_RESTART; - } - return IPlatformRunnable.EXIT_OK; - } finally { - if (shell != null) - shell.dispose(); - display.dispose(); } } diff -pruN my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/Messages.properties my_epf.changed_1_0_2/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/Messages.properties --- my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/Messages.properties 1970-01-01 01:00:00.000000000 +0100 +++ my_epf.changed_1_0_2/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/Messages.properties 2007-04-21 17:55:13.000000000 +0200 @@ -0,0 +1,27 @@ +badConfig=Couldn't find configuration {0} in the library at {1} +internalError=Internal Error +invalidAboutPath=Invalid path for about html file: {0} +invalidBannerPath=Invalid path for banner image: {0} +invalidLibraryPath=Invalid library path: {0} +missingRequiredParameter=Missing required parameter: {0} +startingTask=Starting task {0} +unknownArg=Unknown option {0} +usage=Usage:\n\ +Required:\n\ +\t-libraryPath \n\ +\t-publishPath \n\ +\t-config \n\ +Optional:\n\ +\t-about \n\ +\t-banner \n\ +\t-title \n\ +\t-feedback <feedback url>\n\n\ +\t-glossary\n\ +\t-index\n\n\ +\t-checkLinks\n\ +\t-convertBrokenLinks\n\n\ +\t-publishUnverifiedDiagrams\n\ +\t-publishUnmodifiedDiagrams\n\ +\t-DescriptorExtraInfo\n\n\ +\t-LightWeightTree\n\ +\t-publishConsole <file> \ No newline at end of file diff -pruN my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/TextProgressMonitor.java my_epf.changed_1_0_2/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/TextProgressMonitor.java --- my_epf.org_1_0_2/org.eclipse.epf/plugins/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/TextProgressMonitor.java 1970-01-01 01:00:00.000000000 +0100 +++ my_epf.changed_1_0_2/org.eclipse.epf.rcp/src/org/eclipse/epf/rcp/TextProgressMonitor.java 2007-04-12 05:03:05.000000000 +0200 @@ -0,0 +1,40 @@ +package org.eclipse.epf.rcp; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.osgi.util.NLS; + +public class TextProgressMonitor + extends NullProgressMonitor { + + private boolean needNewline; + + public void beginTask(String name, int totalWork) { + System.err.println("Starting task: "+name); + } + + public void done() { + println(); + } + + public void setTaskName(String name) { + println(); + System.err.println("Starting task: "+name); + } + + public void subTask(String name) { + println(); + System.err.println('\t' + name); + } + + public void worked(int work) { + needNewline = true; + System.err.print('.'); + } + + private void println() { + if(needNewline) { + System.err.println(); + needNewline = false; + } + } +}