Author: tchemit Date: 2009-10-08 18:48:27 +0200 (Thu, 08 Oct 2009) New Revision: 1568 Added: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUI.java branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUIHandler.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java Removed: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpUI.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxGeneratorMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxHelpGeneratorMojo.java Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/JAXXContext.java branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerValidatorTest.java branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DecoratorTest.java branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Evolution74Test.java branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/I18nTest.java branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java Log: evolution #78 : rendre le syst?\195?\168me d'aide multi-langue + JAXXContext is returned to jaxx.runtime package Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java =================================================================== --- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -14,7 +14,7 @@ /** * - * @return the class loader to use by compilers + * @return the class loader used by compilers */ ClassLoader getClassLoader(); @@ -51,36 +51,6 @@ /** * - * @return the name of the help set to generate - */ - String getHelpSetName(); - - /** - * - * @return the prefix of i18n keys to use in help system - */ - String getHelpsetI18nPrefix(); - - /** - * - * @return the suffix of i18n keys to use in index of help system - */ - String getHelpsetIndexI18nSuffix(); - - /** - * - * @return the suffix of i18n keys to use in title of the help system - */ - String getHelpsetTitleI18nSuffix(); - - /** - * - * @return the suffix of i18n keys to use in toc of the help system - */ - String getHelpsetTocI18nSuffix(); - - /** - * * @return the type of context to use in each generated jaxx object */ Class<? extends JAXXContext> getJaxxContextClass(); Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java =================================================================== --- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -13,24 +13,20 @@ */ public class DefaultCompilerConfiguration implements CompilerConfiguration { -// private File javacTargetDirectory; -// private String classPath; -// private String javacOpts; -// private boolean keepJavaFiles; /** - * + * where to generate */ private File targetDirectory; /** - * + * flag to optimize generated code */ private boolean optimize; /** - * + * verbose flag */ private boolean verbose; /** - * + * to do a profile pass after generation */ private boolean profile; /** @@ -59,11 +55,11 @@ */ private Class<?> defaultErrorUI; /** - * + * class loader to use in compiler */ private ClassLoader classLoader; /** - * + * the compiler class to use */ private Class<? extends JAXXCompiler> compilerClass; /** @@ -90,36 +86,6 @@ * since this class should be in sources (so not yet compiled) */ private String helpBrokerFQN; - /** - * The prefix to add to i18n key for any help i18n key. - * - * @since 1.3 - */ - protected String helpsetI18nPrefix; - /** - * The suffix to add to i18n key for an help Id. - * - * @since 1.3 - */ - protected String helpsetTitleI18nSuffix; - /** - * The suffix to add to i18n key for an toc Id. - * - * @since 1.3 - */ - protected String helpsetTocI18nSuffix; - /** - * The suffix to add to i18n key for an toc Id. - * - * @since 1.3 - */ - protected String helpsetIndexI18nSuffix; - /** - * The helpset name - * - * @since 1.3 - */ - protected String helpSetName; @Override public File getTargetDirectory() { @@ -211,31 +177,6 @@ } @Override - public String getHelpsetIndexI18nSuffix() { - return helpsetIndexI18nSuffix; - } - - @Override - public String getHelpsetTitleI18nSuffix() { - return helpsetTitleI18nSuffix; - } - - @Override - public String getHelpsetTocI18nSuffix() { - return helpsetTocI18nSuffix; - } - - @Override - public String getHelpSetName() { - return helpSetName; - } - - @Override - public String getHelpsetI18nPrefix() { - return helpsetI18nPrefix; - } - - @Override public Class<?> getValidatorClass() { return validatorClass; } Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java =================================================================== --- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -44,8 +44,8 @@ if (options.isGenerateHelp()) { - // add JaxxHelpUI interface - Class<?> validatorInterface = jaxx.runtime.swing.JaxxHelpUI.class; + // add JAXXHelpUI interface + Class<?> validatorInterface = jaxx.runtime.swing.help.JAXXHelpUI.class; String helpBrokerFQN = getBrokerFQN(compiler); javaFile.addInterface(JAXXCompiler.getCanonicalName(validatorInterface) + "<" + helpBrokerFQN + ">"); Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/JAXXContext.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/JAXXContext.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/JAXXContext.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -91,7 +91,9 @@ * @param <O> type of container to obtain from context * @param clazz clazz desired * @return parent's container + * @deprecated since 2.0.0 : breaks neutral since Swing */ + @Deprecated public <O extends Container> O getParentContainer(Class<O> clazz); /** @@ -101,6 +103,8 @@ * @param top the top container * @param clazz desired * @return parent's container + * @deprecated since 2.0.0 : breaks neutral since Swing */ + @Deprecated public <O extends Container> O getParentContainer(Object top, Class<O> clazz); } Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -1,6 +1,5 @@ package jaxx.runtime.context; -import jaxx.runtime.JAXXContext; import jaxx.runtime.*; import static jaxx.runtime.context.JAXXContextEntryDef.newDef; import org.apache.commons.logging.Log; @@ -25,14 +24,25 @@ */ public class DefaultJAXXContext implements JAXXContext { + /** + * entry of the parent context + */ protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = newDef(JAXXContext.class); - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** + * Logger + */ static private final Log log = LogFactory.getLog(DefaultJAXXContext.class); - /** l'ui auquel est rattache le context */ + /** + * l'ui auquel est rattache le context + */ protected JAXXObject ui; - /** le context parent */ + /** + * le context parent + */ protected JAXXContext parentContext; - /** les données contenues dans le context */ + /** + * les données contenues dans le context + */ protected final Map<JAXXContextEntryDef<?>, Object> data; public DefaultJAXXContext() { Deleted: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -1,556 +0,0 @@ -package jaxx.runtime.swing; - -import java.applet.Applet; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.net.URL; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Locale; -import java.util.Map; -import java.util.Vector; -import javax.help.CSH; -import javax.help.HelpBroker; -import javax.help.HelpSet; -import javax.swing.AbstractButton; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXObject; -import jaxx.runtime.SwingUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * La classe pour encapsuler l'aide de l'application. - * - * @param <B> le type de broker - * @author tony - * @since 1.4 - */ -public abstract class JaxxHelpBroker<B extends JaxxHelpBroker<?>> { - - public static final String JAXX_CONTEXT_ENTRY = "jaxxcontext"; - /** - * Logger - */ - static private Log log = LogFactory.getLog(JaxxHelpBroker.class); - /** - * name of helpset - */ - protected final String helpsetName; - /** - * default id to use if none given - */ - protected final String defaultID; - /** - * help key - */ - protected final String helpKey; - /** - * helpset to use - */ - protected HelpSet helpset; - /** - * help broker - */ - protected HelpBroker helpBroker; - /** - * current locale used - */ - protected Locale locale; - /** - * cache of cursors modified when in context-sensitive mode - */ - protected Hashtable<Component, Cursor> cursors; - /** - * cursor to use in context-sensitive mode - */ - protected Cursor onItemCursor; - /** - * cache of component which cursor have been modified - */ - protected final Map<Component, String> cache; - - protected JaxxHelpBroker(String helpsetName, String helpKey, String defaultID) { - this(null, helpsetName, helpKey, defaultID); - } - - protected JaxxHelpBroker(Locale locale, String helpsetName, String helpKey, String defaultID) { - if (helpsetName == null) { - throw new NullPointerException("parameter helpsetName can not be null!"); - } - this.locale = locale; - this.helpsetName = helpsetName; - this.helpKey = helpKey; - this.defaultID = defaultID; - cache = new HashMap<Component, String>(); -// try { -// ClassLoader cl = getClass().getClassLoader(); -// URL url = HelpSet.findHelpSet(cl, helpsetName, this.locale); -// helpset = new HelpSet(cl, url); -// helpBroker = helpset.createHelpBroker(); -// } catch (Exception ee) { -// throw new IllegalStateException("could not find help set " + helpsetName + " for reason " + ee.getMessage(), ee); -// } - } - - public void prepareUI(JAXXObject c) { - if (c == null) { - throw new NullPointerException("parameter c can not be null!"); - } - - // l'ui doit avoir un boutton showHelp - AbstractButton help = getShowHelpButton(c); - - if (help == null) { - if (log.isDebugEnabled()) { - log.debug("no showButton detected for " + c.getClass()); - } - } else { - - // attach context to button - help.putClientProperty(JAXX_CONTEXT_ENTRY, c.getDelegateContext()); - - // add tracking action - ActionListener listener = getShowHelpAction(); - if (log.isDebugEnabled()) { - log.debug("adding tracking action " + listener); - } - help.addActionListener(listener); - - } - if (log.isDebugEnabled()) { - log.debug("done for " + c); - } - } - - public HelpBroker getHelpBroker() { - if (helpBroker == null) { - helpBroker = getHelpset().createHelpBroker(); - } - return helpBroker; - } - - public String getHelpKey() { - return helpKey; - } - - public HelpSet getHelpset() { - if (helpset == null) { - try { - ClassLoader cl = getClass().getClassLoader(); - URL url = HelpSet.findHelpSet(cl, helpsetName, this.locale); - helpset = new HelpSet(cl, url); - } catch (Exception ee) { - throw new IllegalStateException("could not find help set " + helpsetName + " for reason " + ee.getMessage(), ee); - } - } - return helpset; - } - - public String getHelpsetName() { - return helpsetName; - } - - public String getDefaultID() { - return defaultID; - } - - public void setLocale(Locale locale) { - this.locale = locale; - // need to reload helpset and helpbroker - helpset = null; - helpBroker = null; - getHelpset(); - getHelpBroker(); - } - - public void showHelpSet() { - if (log.isDebugEnabled()) { - log.debug(this); - } - new CSH.DisplayHelpFromSource(helpBroker); - } - - public void showHelp(JAXXContext context, String helpId) { - } - - public void installUI(Component comp, String helpId) { - CSH.setHelpIDString(comp, helpId); - if (log.isDebugEnabled()) { - log.debug(helpId + " : " + comp.getName()); - } - cache.put(comp, helpId); - } - - public class ShowHelpForTrackedComponentAction implements ActionListener { - - @Override - public void actionPerformed(ActionEvent e) { - AbstractButton source = (AbstractButton) e.getSource(); - - JAXXContext context = (JAXXContext) source.getClientProperty(JAXX_CONTEXT_ENTRY); - - // prepare cursor - onItemCursor = (Cursor) UIManager.get("HelpOnItemCursor"); - Vector<?> topComponents = null; - cursors = null; - - if (onItemCursor != null) { - cursors = new Hashtable<Component, Cursor>(); - topComponents = getTopContainers(source); - Enumeration<?> enums = topComponents.elements(); - while (enums.hasMoreElements()) { - setAndStoreCursors((Container) enums.nextElement(), onItemCursor); - } - } - - // get the tracked component - Component comp = null; - try { - MouseEvent event = getMouseEvent(); - if (event == null) { - // tracking canceled - return; - } - comp = (Component) event.getSource(); - if (log.isDebugEnabled()) { - log.debug("component traking " + comp.getName() + " : " + comp.getClass().getName()); - } - comp = SwingUtil.getDeepestObjectAt(comp, event.getX(), event.getY()); - if (log.isDebugEnabled()) { - log.debug("deepest component " + comp.getName() + " : " + comp.getClass().getName()); - } - } finally { - // restore the old cursors - if (topComponents != null) { - Enumeration<?> containers = topComponents.elements(); - while (containers.hasMoreElements()) { - resetAndRestoreCursors((Container) containers.nextElement()); - } - } - cursors = null; - } - - String helpID = findHelpId(comp); - showHelp(context, helpID); - } - - public String findHelpId(Component comp) { - String helpID = CSH.getHelpIDString(comp); - if (defaultID.equals(helpID)) { - String id = cache.get(comp); - // on verifie qu'on est bien sur sur le bon id - if (helpID.equals(id)) { - // ok - return helpID; - } - if (log.isDebugEnabled()) { - log.debug("will try to find better id for comp : " + comp.getName()); - } - // on est pas sur le bon id - // on recherche parmis les parents - helpID = findExtactHelpId(comp); - } - if (log.isInfoEnabled()) { - log.info("helpID " + helpID + " for comp " + comp.getName() + " : " + comp.getClass().getName()); - } - return helpID; - } - - protected String findExtactHelpId(Component comp) { - Container parent = comp.getParent(); - while (parent != null) { - String id = cache.get(parent); - if (id == null) { - // ce container n'a pas d'id - // on va directement sur le parent - parent = parent.getParent(); - continue; - } - // le parent possède un id - // on utilise cet id - return id; - } - // on a pas trouve d'id - // on retourne l'id par defaut - return defaultID; - } - } - - protected AbstractButton getShowHelpButton(JAXXObject c) { - return (AbstractButton) c.getObjectById("showHelp"); - } - - protected ActionListener getShowHelpAction() { - return new ShowHelpForTrackedComponentAction(); - } - - //------------------------------------------------------------------------- - //--- Copy CSH code but with accessible modifiers and little improvments - //------------------------------------------------------------------------- - /* - * Get all top level containers to change it's cursors - */ - protected Vector<?> getTopContainers(Object source) { - // This method is used to obtain all top level components of application - // for which the changing of cursor to question mark is wanted. - // Method Frame.getFrames() is used to get list of Frames and - // Frame.getOwnedWindows() method on elements of the list - // returns all Windows, Dialogs etc. It works correctly in application. - // Problem is in applets. There is no way how to get reference to applets - // from elsewhere than applet itself. So, if request for CSH (this means - // pressing help button or select help menu item) does't come from component - // in a Applet, cursor for applets is not changed to question mark. Only for - // Frames, Windows and Dialogs is cursor changed properly. - - Vector<Component> containers = new Vector<Component>(); - Component topComponent = null; - topComponent = getRoot(source); - if (topComponent instanceof Applet) { - try { - Enumeration<Applet> applets = ((Applet) topComponent).getAppletContext().getApplets(); - while (applets.hasMoreElements()) { - containers.add(applets.nextElement()); - } - } catch (NullPointerException npe) { - containers.add(topComponent); - } - } - Frame frames[] = Frame.getFrames(); - for (int i = 0; i < frames.length; i++) { - Window[] windows = frames[i].getOwnedWindows(); - for (int j = 0; j < windows.length; j++) { - containers.add(windows[j]); - } - if (!containers.contains(frames[i])) { - containers.add(frames[i]); - } - } - return containers; - } - - protected Component getRoot(Object comp) { - Object parent = comp; - while (parent != null) { - comp = parent; - if (comp instanceof MenuComponent) { - parent = ((MenuComponent) comp).getParent(); - } else if (comp instanceof Component) { - if (comp instanceof Window) { - break; - } - if (comp instanceof Applet) { - break; - } - parent = ((Component) comp).getParent(); - } else { - break; - } - } - if (comp instanceof Component) { - return ((Component) comp); - } - return null; - } - - /* - * Set the cursor for a component and its children. - * Store the old cursors for future resetting - */ - protected void setAndStoreCursors(Component comp, Cursor cursor) { - if (comp == null) { - return; - } - Cursor compCursor = comp.getCursor(); - if (compCursor != cursor) { - cursors.put(comp, compCursor); - log.debug("set cursor on " + comp); - comp.setCursor(cursor); - } - if (comp instanceof Container) { - Component component[] = ((Container) comp).getComponents(); - for (int i = 0; i < component.length; i++) { - setAndStoreCursors(component[i], cursor); - } - } - } - - /* - * Actually restore the cursor for a component and its children - */ - protected void resetAndRestoreCursors(Component comp) { - if (comp == null) { - return; - } - Cursor oldCursor = cursors.get(comp); - if (oldCursor != null) { - log.debug("restored cursor " + oldCursor + " on " + comp); - comp.setCursor(oldCursor); - } - if (comp instanceof Container) { - Component component[] = ((Container) comp).getComponents(); - for (int i = 0; i < component.length; i++) { - resetAndRestoreCursors(component[i]); - } - } - } - - /** - * Context Sensitive Event Tracking - * - * Creates a new EventDispatchThread from which to dispatch events. This - * method returns when stopModal is invoked. - * - * @return MouseEvent The mouse event occurred. Null if - * cancelled on an undetermined object. - */ - public static MouseEvent getMouseEvent() { - // Should the cursor change to a quesiton mark here or - // require the user to change the cursor externally to this method? - // The problem is that each component can have it's own cursor. - // For that reason it might be better to have the user change the - // cusor rather than us. - - // To track context-sensitive events get the event queue and process - // the events the same way EventDispatchThread does. Filter out - // ContextSensitiveEvents SelectObject & Cancel (MouseDown & ???). - // Note: This code only handles mouse events. Accessiblity might - // require additional functionality or event trapping - - // If the eventQueue can't be retrieved, the thread gets interrupted, - // or the thread isn't a instanceof EventDispatchThread then return - // a null as we won't be able to trap events. - try { - if (EventQueue.isDispatchThread()) { - EventQueue eq = null; - - // Find the eventQueue. If we can't get to it then just return - // null since we won't be able to trap any events. - - try { - eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - } catch (Exception ee) { - log.debug(ee); - } - - // Safe guard - if (eq == null) { - return null; - } - - int eventNumber = -1; - - // Process the events until an object has been selected or - // the context-sensitive search has been canceled. - while (true) { - // This is essentially the body of EventDispatchThread - // modified to trap context-senstive events and act - // appropriately - eventNumber++; - AWTEvent event = eq.getNextEvent(); - Object src = event.getSource(); - // can't call eq.dispatchEvent - // so I pasted it's body here - - if (log.isDebugEnabled()) { - log.debug(event); - } - - // Not sure if I should suppress ActiveEvents or not - // Modal dialogs do. For now we will not suppress the - // ActiveEvent events - - if (event instanceof ActiveEvent) { - ((ActiveEvent) event).dispatch(); - continue; - } - - if (src instanceof Component) { - // Trap the context-sensitive events here - if (event instanceof KeyEvent) { - KeyEvent e = (KeyEvent) event; - // if this is the cancel key then exit - // otherwise pass all other keys up - if (e.getKeyCode() == KeyEvent.VK_CANCEL || - e.getKeyCode() == KeyEvent.VK_ESCAPE) { - e.consume(); - return null; - } else { - e.consume(); - // dispatchEvent(event); - } - } else if (event instanceof MouseEvent) { - MouseEvent e = (MouseEvent) event; - int eID = e.getID(); - - if ((eID == MouseEvent.MOUSE_CLICKED || - eID == MouseEvent.MOUSE_PRESSED || - eID == MouseEvent.MOUSE_RELEASED) && - SwingUtilities.isRightMouseButton(e)) { - // cancel tracking - e.consume(); - if (log.isDebugEnabled()) { - log.debug("tracking canceled!!!"); - } - return null; - } - - if ((eID == MouseEvent.MOUSE_CLICKED || - eID == MouseEvent.MOUSE_PRESSED || - eID == MouseEvent.MOUSE_RELEASED) && - SwingUtilities.isLeftMouseButton(e)) { - if (eID == MouseEvent.MOUSE_CLICKED) { - if (eventNumber == 0) { - dispatchEvent(event); - continue; - } - } - e.consume(); - return e; - } else { - e.consume(); - } - } else { - dispatchEvent(event); - } - } else if (src instanceof MenuComponent) { - if (event instanceof InputEvent) { - ((InputEvent) event).consume(); - } - } else { - log.error("unable to dispatch event: " + event); - } - } - } - } catch (InterruptedException e) { - if (log.isDebugEnabled()) { - log.debug(e); - } - } - if (log.isDebugEnabled()) { - log.debug("Fall Through code"); - } - return null; - } - - private static void dispatchEvent(AWTEvent event) { - Object src = event.getSource(); - if (event instanceof ActiveEvent) { - // This could become the sole method of dispatching in time. - ((ActiveEvent) event).dispatch(); - } else if (src instanceof Component) { - ((Component) src).dispatchEvent(event); - } else if (src instanceof MenuComponent) { - ((MenuComponent) src).dispatchEvent(event); - } else { - log.error("unable to dispatch event: " + event); - } - } -} Deleted: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpUI.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpUI.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpUI.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -1,22 +0,0 @@ -package jaxx.runtime.swing; - -import java.awt.Component; - -/** - * - * Contract to be added on JAXXObject wihch wants to use javax help. - * - * @param <B> type of broker. - * - * @author tony - * @since 1.3 - * @see JaxxHelpBroker - */ -public interface JaxxHelpUI<B extends JaxxHelpBroker<?>> { - - B getBroker(); - - void registerHelpId(B broker, Component component, String helpId); - - void showHelp(String helpId); -} Copied: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java (from rev 1567, branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java) =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java (rev 0) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpBroker.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -0,0 +1,564 @@ +package jaxx.runtime.swing.help; + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Locale; +import java.util.Map; +import java.util.Vector; +import javax.help.CSH; +import javax.help.HelpBroker; +import javax.help.HelpSet; +import javax.swing.AbstractButton; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * La classe pour encapsuler l'aide de l'application. + * + * @author tony + * @since 1.4 + */ +public class JAXXHelpBroker { + + public static final String JAXX_CONTEXT_ENTRY = "jaxxcontext"; + /** + * Logger + */ + static private Log log = LogFactory.getLog(JAXXHelpBroker.class); + /** + * name of helpset + */ + protected final String helpsetName; + /** + * default id to use if none given + */ + protected final String defaultID; + /** + * help key + */ + protected final String helpKey; + /** + * helpset to use + */ + protected HelpSet helpset; + /** + * help broker + */ + protected HelpBroker helpBroker; + /** + * current locale used + */ + protected Locale locale; + /** + * cache of cursors modified when in context-sensitive mode + */ + protected Hashtable<Component, Cursor> cursors; + /** + * cursor to use in context-sensitive mode + */ + protected Cursor onItemCursor; + /** + * cache of component which cursor have been modified + */ + protected final Map<Component, String> cache; + /** + * help ui handler + */ + protected JAXXHelpUIHandler handler; + + public JAXXHelpBroker(String helpsetName, String helpKey, String defaultID, JAXXHelpUIHandler handler) { + this(null, helpsetName, helpKey, defaultID, handler); + } + + public JAXXHelpBroker(Locale locale, String helpsetName, String helpKey, String defaultID, JAXXHelpUIHandler handler) { + if (helpsetName == null) { + throw new NullPointerException("parameter helpsetName can not be null!"); + } + if (handler == null) { + throw new NullPointerException("handler can not be null"); + } + this.locale = locale; + this.helpsetName = helpsetName; + this.helpKey = helpKey; + this.defaultID = defaultID; + this.handler = handler; + this.cache = new HashMap<Component, String>(); + } + + public void prepareUI(JAXXObject c) { + if (c == null) { + throw new NullPointerException("parameter c can not be null!"); + } + + // l'ui doit avoir un boutton showHelp + AbstractButton help = getShowHelpButton(c); + + if (help == null) { + // no showHelp button + return; + } + + // attach context to button + if (log.isDebugEnabled()) { + log.debug("attach context to showhelp button " + c); + } + help.putClientProperty(JAXX_CONTEXT_ENTRY, c); + + // add tracking action + ActionListener listener = getShowHelpAction(); + if (log.isDebugEnabled()) { + log.debug("adding tracking action " + listener); + } + help.addActionListener(listener); + + if (log.isDebugEnabled()) { + log.debug("done for " + c); + } + + + getHelpBroker().enableHelpKey(((Component) c), getDefaultID(), getHelpset()); + } + + public void showHelp(JAXXContext context, String helpId) { + getHandler().showHelp(context, this, helpId); + } + + public JAXXHelpUIHandler getHandler() { + return handler; + } + + public HelpBroker getHelpBroker() { + if (helpBroker == null) { + helpBroker = getHelpset().createHelpBroker(); + } + return helpBroker; + } + + public String getHelpKey() { + return helpKey; + } + + public HelpSet getHelpset() { + if (helpset == null) { + try { + ClassLoader cl = getClass().getClassLoader(); + URL url = HelpSet.findHelpSet(cl, helpsetName, locale); + helpset = new HelpSet(cl, url); + } catch (Exception ee) { + throw new IllegalStateException("could not find help set " + helpsetName + " for reason " + ee.getMessage(), ee); + } + } + return helpset; + } + + public String getHelpsetName() { + return helpsetName; + } + + public String getDefaultID() { + return defaultID; + } + + public void setLocale(Locale locale) { + this.locale = locale; + // need to reload helpset and helpbroker + helpset = null; + helpBroker = null; + getHelpset(); + getHelpBroker(); + } + + public void showHelpSet() { + if (log.isDebugEnabled()) { + log.debug(this); + } + new CSH.DisplayHelpFromSource(getHelpBroker()); + } + + public void installUI(Component comp, String helpId) { + CSH.setHelpIDString(comp, helpId); + if (log.isDebugEnabled()) { + log.debug(helpId + " : " + comp.getName()); + } + cache.put(comp, helpId); + } + + public class ShowHelpForTrackedComponentAction implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + AbstractButton source = (AbstractButton) e.getSource(); + + JAXXContext context = (JAXXContext) source.getClientProperty(JAXX_CONTEXT_ENTRY); + + // prepare cursor + onItemCursor = (Cursor) UIManager.get("HelpOnItemCursor"); + Vector<?> topComponents = null; + cursors = null; + + if (onItemCursor != null) { + cursors = new Hashtable<Component, Cursor>(); + topComponents = getTopContainers(source); + Enumeration<?> enums = topComponents.elements(); + while (enums.hasMoreElements()) { + setAndStoreCursors((Container) enums.nextElement(), onItemCursor); + } + } + + // get the tracked component + Component comp = null; + try { + MouseEvent event = getMouseEvent(); + if (event == null) { + // tracking canceled + return; + } + comp = (Component) event.getSource(); + if (log.isDebugEnabled()) { + log.debug("component traking " + comp.getName() + " : " + comp.getClass().getName()); + } + comp = SwingUtil.getDeepestObjectAt(comp, event.getX(), event.getY()); + if (log.isDebugEnabled()) { + log.debug("deepest component " + comp.getName() + " : " + comp.getClass().getName()); + } + } finally { + // restore the old cursors + if (topComponents != null) { + Enumeration<?> containers = topComponents.elements(); + while (containers.hasMoreElements()) { + resetAndRestoreCursors((Container) containers.nextElement()); + } + } + cursors = null; + } + + String helpID = findHelpId(comp); + showHelp(context, helpID); + } + + public String findHelpId(Component comp) { + String helpID = CSH.getHelpIDString(comp); + if (defaultID.equals(helpID)) { + String id = cache.get(comp); + // on verifie qu'on est bien sur sur le bon id + if (helpID.equals(id)) { + // ok + return helpID; + } + if (log.isDebugEnabled()) { + log.debug("will try to find better id for comp : " + comp.getName()); + } + // on est pas sur le bon id + // on recherche parmis les parents + helpID = findExtactHelpId(comp); + } + if (log.isInfoEnabled()) { + log.info("helpID " + helpID + " for comp " + comp.getName() + " : " + comp.getClass().getName()); + } + return helpID; + } + + protected String findExtactHelpId(Component comp) { + Container parent = comp.getParent(); + while (parent != null) { + String id = cache.get(parent); + if (id == null) { + // ce container n'a pas d'id + // on va directement sur le parent + parent = parent.getParent(); + continue; + } + // le parent possède un id + // on utilise cet id + return id; + } + // on a pas trouve d'id + // on retourne l'id par defaut + return defaultID; + } + } + + protected AbstractButton getShowHelpButton(JAXXObject c) { + return (AbstractButton) c.getObjectById("showHelp"); + } + + protected ActionListener getShowHelpAction() { + return new ShowHelpForTrackedComponentAction(); + } + + //------------------------------------------------------------------------- + //--- Copy CSH code but with accessible modifiers and little improvments + //------------------------------------------------------------------------- + /* + * Get all top level containers to change it's cursors + */ + protected Vector<?> getTopContainers(Object source) { + // This method is used to obtain all top level components of application + // for which the changing of cursor to question mark is wanted. + // Method Frame.getFrames() is used to get list of Frames and + // Frame.getOwnedWindows() method on elements of the list + // returns all Windows, Dialogs etc. It works correctly in application. + // Problem is in applets. There is no way how to get reference to applets + // from elsewhere than applet itself. So, if request for CSH (this means + // pressing help button or select help menu item) does't come from component + // in a Applet, cursor for applets is not changed to question mark. Only for + // Frames, Windows and Dialogs is cursor changed properly. + + Vector<Component> containers = new Vector<Component>(); + Component topComponent = null; + topComponent = getRoot(source); + if (topComponent instanceof Applet) { + try { + Enumeration<Applet> applets = ((Applet) topComponent).getAppletContext().getApplets(); + while (applets.hasMoreElements()) { + containers.add(applets.nextElement()); + } + } catch (NullPointerException npe) { + containers.add(topComponent); + } + } + Frame frames[] = Frame.getFrames(); + for (int i = 0; i < frames.length; i++) { + Window[] windows = frames[i].getOwnedWindows(); + for (int j = 0; j < windows.length; j++) { + containers.add(windows[j]); + } + if (!containers.contains(frames[i])) { + containers.add(frames[i]); + } + } + return containers; + } + + protected Component getRoot(Object comp) { + Object parent = comp; + while (parent != null) { + comp = parent; + if (comp instanceof MenuComponent) { + parent = ((MenuComponent) comp).getParent(); + } else if (comp instanceof Component) { + if (comp instanceof Window) { + break; + } + if (comp instanceof Applet) { + break; + } + parent = ((Component) comp).getParent(); + } else { + break; + } + } + if (comp instanceof Component) { + return ((Component) comp); + } + return null; + } + + /* + * Set the cursor for a component and its children. + * Store the old cursors for future resetting + */ + protected void setAndStoreCursors(Component comp, Cursor cursor) { + if (comp == null) { + return; + } + Cursor compCursor = comp.getCursor(); + if (compCursor != cursor) { + cursors.put(comp, compCursor); + log.debug("set cursor on " + comp); + comp.setCursor(cursor); + } + if (comp instanceof Container) { + Component component[] = ((Container) comp).getComponents(); + for (int i = 0; i < component.length; i++) { + setAndStoreCursors(component[i], cursor); + } + } + } + + /* + * Actually restore the cursor for a component and its children + */ + protected void resetAndRestoreCursors(Component comp) { + if (comp == null) { + return; + } + Cursor oldCursor = cursors.get(comp); + if (oldCursor != null) { + log.debug("restored cursor " + oldCursor + " on " + comp); + comp.setCursor(oldCursor); + } + if (comp instanceof Container) { + Component component[] = ((Container) comp).getComponents(); + for (int i = 0; i < component.length; i++) { + resetAndRestoreCursors(component[i]); + } + } + } + + /** + * Context Sensitive Event Tracking + * + * Creates a new EventDispatchThread from which to dispatch events. This + * method returns when stopModal is invoked. + * + * @return MouseEvent The mouse event occurred. Null if + * cancelled on an undetermined object. + */ + public static MouseEvent getMouseEvent() { + // Should the cursor change to a quesiton mark here or + // require the user to change the cursor externally to this method? + // The problem is that each component can have it's own cursor. + // For that reason it might be better to have the user change the + // cusor rather than us. + + // To track context-sensitive events get the event queue and process + // the events the same way EventDispatchThread does. Filter out + // ContextSensitiveEvents SelectObject & Cancel (MouseDown & ???). + // Note: This code only handles mouse events. Accessiblity might + // require additional functionality or event trapping + + // If the eventQueue can't be retrieved, the thread gets interrupted, + // or the thread isn't a instanceof EventDispatchThread then return + // a null as we won't be able to trap events. + try { + if (EventQueue.isDispatchThread()) { + EventQueue eq = null; + + // Find the eventQueue. If we can't get to it then just return + // null since we won't be able to trap any events. + + try { + eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); + } catch (Exception ee) { + log.debug(ee); + } + + // Safe guard + if (eq == null) { + return null; + } + + int eventNumber = -1; + + // Process the events until an object has been selected or + // the context-sensitive search has been canceled. + while (true) { + // This is essentially the body of EventDispatchThread + // modified to trap context-senstive events and act + // appropriately + eventNumber++; + AWTEvent event = eq.getNextEvent(); + Object src = event.getSource(); + // can't call eq.dispatchEvent + // so I pasted it's body here + + if (log.isDebugEnabled()) { + log.debug(event); + } + + // Not sure if I should suppress ActiveEvents or not + // Modal dialogs do. For now we will not suppress the + // ActiveEvent events + + if (event instanceof ActiveEvent) { + ((ActiveEvent) event).dispatch(); + continue; + } + + if (src instanceof Component) { + // Trap the context-sensitive events here + if (event instanceof KeyEvent) { + KeyEvent e = (KeyEvent) event; + // if this is the cancel key then exit + // otherwise pass all other keys up + if (e.getKeyCode() == KeyEvent.VK_CANCEL || + e.getKeyCode() == KeyEvent.VK_ESCAPE) { + e.consume(); + return null; + } else { + e.consume(); + // dispatchEvent(event); + } + } else if (event instanceof MouseEvent) { + MouseEvent e = (MouseEvent) event; + int eID = e.getID(); + + if ((eID == MouseEvent.MOUSE_CLICKED || + eID == MouseEvent.MOUSE_PRESSED || + eID == MouseEvent.MOUSE_RELEASED) && + SwingUtilities.isRightMouseButton(e)) { + // cancel tracking + e.consume(); + if (log.isDebugEnabled()) { + log.debug("tracking canceled!!!"); + } + return null; + } + + if ((eID == MouseEvent.MOUSE_CLICKED || + eID == MouseEvent.MOUSE_PRESSED || + eID == MouseEvent.MOUSE_RELEASED) && + SwingUtilities.isLeftMouseButton(e)) { + if (eID == MouseEvent.MOUSE_CLICKED) { + if (eventNumber == 0) { + dispatchEvent(event); + continue; + } + } + e.consume(); + return e; + } else { + e.consume(); + } + } else { + dispatchEvent(event); + } + } else if (src instanceof MenuComponent) { + if (event instanceof InputEvent) { + ((InputEvent) event).consume(); + } + } else { + log.error("unable to dispatch event: " + event); + } + } + } + } catch (InterruptedException e) { + if (log.isDebugEnabled()) { + log.debug(e); + } + } + if (log.isDebugEnabled()) { + log.debug("Fall Through code"); + } + return null; + } + + private static void dispatchEvent(AWTEvent event) { + Object src = event.getSource(); + if (event instanceof ActiveEvent) { + // This could become the sole method of dispatching in time. + ((ActiveEvent) event).dispatch(); + } else if (src instanceof Component) { + ((Component) src).dispatchEvent(event); + } else if (src instanceof MenuComponent) { + ((MenuComponent) src).dispatchEvent(event); + } else { + log.error("unable to dispatch event: " + event); + } + } +} Copied: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUI.java (from rev 1567, branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/JaxxHelpUI.java) =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUI.java (rev 0) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUI.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -0,0 +1,22 @@ +package jaxx.runtime.swing.help; + +import java.awt.Component; + +/** + * + * Contract to be added on JAXXObject which wants to use javax help. + * + * @param <B> type of broker. + * + * @author tony + * @since 1.3 + * @see JAXXHelpBroker + */ +public interface JAXXHelpUI<B extends JAXXHelpBroker> { + + B getBroker(); + + void registerHelpId(B broker, Component component, String helpId); + + void showHelp(String helpId); +} Added: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUIHandler.java =================================================================== --- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUIHandler.java (rev 0) +++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUIHandler.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -0,0 +1,12 @@ +package jaxx.runtime.swing.help; + +import jaxx.runtime.JAXXContext; + +/** + * + * @author chemit + */ +public interface JAXXHelpUIHandler { + + void showHelp(JAXXContext context, JAXXHelpBroker broker, String helpID); +} Property changes on: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/help/JAXXHelpUIHandler.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -41,12 +41,6 @@ */ protected MavenProject project; /** - * Repertoire de destination des fichiers java a generer. - * - * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java" - */ - protected File outJava; - /** * verbose flag * * @parameter expression="${jaxx.verbose}" default-value="false" @@ -55,72 +49,15 @@ */ protected boolean verbose; /** - * to make compiler i18nable, says add the {@link org.nuiton.i18n.I18n#_(String, Object[])} method - * invocation on {@link jaxx.compiler.I18nHelper#I18N_ATTRIBUTES} attributes. - * - * @parameter expression="${jaxx.i18nable}" default-value="true" - * @see jaxx.compiler.I18nHelper - */ - protected boolean i18nable; - /** - * The store of helpIds generated by {@link JaxxGeneratorMojo}. - * <p/> - * - * @parameter expression="${jaxx.helpIdStore}" default-value="target/helpIds.properties" + * The store of helpIds generated by the goal {@link GenerateMojo} and then + * used by the goal {@link GenerateHelpMojo}. + * + * @parameter expression="${jaxx.helpIdsStore}" default-value="target/helpIds.properties" * @required * * @since 1.3 */ - protected File helpIdStore; - /** - * The name of the helpset to generate. - * - * @parameter expression="${jaxx.helpSetName}" default-value="${project.artifactId}" - * @required - * - * @since 1.3 - */ - protected String helpSetName; - /** - * The prefix to add to i18n key for any help i18n key. - * - * @parameter expression="${jaxx.helpsetI18nPrefix}" default-value="${jaxx.helpSetName}.help." - * @required - * - * @since 1.3 - */ - protected String helpsetI18nPrefix; - /** - * The suffix to add to i18n key for an help Id. - * - * @parameter expression="${jaxx.helpsetTitleI18nSuffix}" default-value=".title" - * @required - * - * @since 1.3 - */ - protected String helpsetTitleI18nSuffix; - /** - * The suffix to add to i18n key for an toc Id. - * - * @parameter expression="${jaxx.helpsetTocI18nSuffix}" default-value=".toc" - * @required - * - * @since 1.3 - */ - protected String helpsetTocI18nSuffix; - /** - * The suffix to add to i18n key for an toc Id. - * - * @parameter expression="${jaxx.helpsetIndexI18nSuffix}" default-value=".index" - * @required - * - * @since 1.3 - */ - protected String helpsetIndexI18nSuffix; - /** - * - */ - protected ClassLoader cl; + protected File helpIdsStore; @Override protected boolean checkPackaging() { @@ -146,4 +83,12 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } + + public File getHelpIdsStore() { + return helpIdsStore; + } + + public void setHelpIdsStore(File helpIdsStore) { + this.helpIdsStore = helpIdsStore; + } } Copied: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java (from rev 1566, branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxHelpGeneratorMojo.java) =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java (rev 0) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -0,0 +1,520 @@ +/* *##% + * Copyright (C) 2007 + * JaxxPlugin, Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ +package org.nuiton.jaxx.plugin; + +import org.apache.maven.plugin.MojoFailureException; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Locale; +import java.util.Properties; +import org.nuiton.i18n.I18n; +import org.nuiton.util.FileUtil; +import org.nuiton.util.SortedProperties; + +/** + * Mojo to generate javax help stuff for your project. + * + * HelpIds should have been discovered by the JaxxMojo. + * + * @author chemit + * @goal generate-help + * @phase process-sources + * + * @requiresProject + * @requiresDependencyResolution compile + * @since 1.3 + */ +public class GenerateHelpMojo extends AbstractJaxxMojo { + + private static final String AUTOREMOVE_LINE = "REMOVE THS LINE TO DISABLE AUTO-REGENERATE THE FILE"; + /** + * The directory where to generate help files. + * + * @parameter expression="${jaxx.outHelp}" default-value="${project.basedir}/src/main/help" + * @required + * + * @since 1.3 + */ + protected File outHelp; + /** + * The locales to generate for help, seprated by comma. + * + * The first locale given is the default locale. + * + * @parameter expression="${jaxx.locales}" + * @required + * + * @since 2.0.0 + */ + protected String locales; + /** + * The name of the helpset to generate. + * + * @parameter expression="${jaxx.helpsetName}" default-value="${project.artifactId}" + * @required + * + * @since 1.3 + */ + protected String helpsetName; + /** + * The template used to generate helpset file. + * + * Must be an existing file or a ressource in classp-ath + * + * @parameter expression="${jaxx.helpsetTemplate}" default-value="/defaultHelpSet.hs.vm" + * @required + * + * @since 1.3 + */ + protected File helpsetTemplate; + /** + * The template used to generate helpset map file. + * + * Must be an existing file or a ressource in classp-ath + * + * @parameter expression="${jaxx.mapTemplate}" default-value="/defaultMap.jhm.vm" + * @required + * + * @since 1.3 + */ + protected File mapTemplate; + /** + * The template used to generate helpset index file. + * + * Must be an existing file or a ressource in classp-ath + * + * @parameter expression="${jaxx.indexTemplate}" default-value="/defaultIndex.xml.vm" + * @required + * + * @since 1.3 + */ + protected File indexTemplate; + /** + * The template used to generate helpset toc file. + * + * Must be an existing file or a ressource in classp-ath + * + * @parameter expression="${jaxx.tocTemplate}" default-value="/defaultToc.xml.vm" + * @required + * + * @since 1.3 + */ + protected File tocTemplate; + /** + * The template used to generate helpset content file. + * + * Must be an existing file or a ressource in classp-ath + * + * @parameter expression="${jaxx.contentTemplate}" default-value="/defaultContent.html.vm" + * @required + * + * @since 1.3 + */ + protected File contentTemplate; + /** + * The help ids discovered in {@link #helpIdsStore} files. + */ + private Properties helpIds; + /** + * Default locale (the first locale in {@link #localesToTreate}. + */ + private Locale defaultLocale; + /** + * Locales to treate + */ + private Locale[] localesToTreate; + + @Override + public boolean init() throws Exception { + + File idsStore = getHelpIdsStore(); + + if (!idsStore.exists()) { + getLog().info("no helpIdStore to react at " + idsStore); + return false; + } + + if (locales == null || locales.trim().isEmpty()) { + throw new MojoFailureException("You must set the 'locales' property properly (was " + locales + ")."); + } + + // check there is a outHelp + if (outHelp == null) { + throw new MojoFailureException("You must set the 'target' property."); + } + + List<Locale> tmp = new ArrayList<Locale>(); + for (String loc : locales.split(",")) { + Locale l = I18n.newLocale(loc); + tmp.add(l); + } + + if (tmp.isEmpty()) { + throw new MojoFailureException("you must set the 'locales' property."); + } + + localesToTreate = tmp.toArray(new Locale[tmp.size()]); + defaultLocale = localesToTreate[0]; + + // check ressources + checkResource(helpsetTemplate); + checkResource(mapTemplate); + checkResource(indexTemplate); + checkResource(tocTemplate); + checkResource(contentTemplate); + + if (!outHelp.exists()) { + getLog().info("mkdir " + outHelp); + outHelp.mkdirs(); + } + + helpIds = new SortedProperties(); + + InputStream stream = new FileInputStream(idsStore); + + try { + helpIds.load(stream); + } finally { + if (stream != null) { + stream.close(); + } + } + + if (helpIds.isEmpty()) { + + // no ids detected + getLog().warn("No helpIds detected, will skip."); + return false; + } + + return true; + } + + @Override + public void doAction() throws Exception { + + int touchedFiles = 0; + + String mapFileName = helpsetName + "Map.jhm"; + String indexFileName = helpsetName + "Index.xml"; + String tocFileName = helpsetName + "TOC.xml"; + + for (Locale locale : localesToTreate) { + + boolean isDefaultLocale = locale == defaultLocale; + + String language = locale.getLanguage(); + + String localePath = (isDefaultLocale ? "default" : language); + + File localizedTarget = new File(outHelp, localePath); + + if (!localizedTarget.exists()) { + localizedTarget.mkdirs(); + } + getLog().info("Generate help for language " + language); + getLog().info(" Localized target : " + localizedTarget); + + Properties env = new Properties(); + + env.put("helpSetName", helpsetName); + env.put("locale", language); + env.put("localePath", localePath); + env.put("separator", " "); + env.put("autoremoveLine", AUTOREMOVE_LINE); + + String localeSuffix = isDefaultLocale ? "" : "_" + language; + String helpsetFileName = helpsetName + localeSuffix + ".hs"; + + env.put("helpSetFileName", helpsetFileName); + + env.put("mapFileName", mapFileName); + env.put("indexFileName", indexFileName); + env.put("tocFileName", tocFileName); +// env.put("searchData", localePath + "/index"); + + // --------------------------------------------------------------- + // --- main helpset file ----------------------------------------- + // --------------------------------------------------------------- + + File file = new File(outHelp, helpsetFileName); + + boolean doCreate = generateHelpsetFile(file, env); + + if (doCreate) { + touchedFiles++; + } + + // --------------------------------------------------------------- + // --- helpset map file ------------------------------------------ + // --------------------------------------------------------------- + + file = new File(localizedTarget, mapFileName); + + Properties mergedHelpIds = generateMapFile(file, env); + touchedFiles++; + + // --------------------------------------------------------------- + // --- helpset index file ---------------------------------------- + // --------------------------------------------------------------- + + file = new File(localizedTarget, indexFileName); + + NodeItem indexRootItem = generateIndexFile(file, env); + touchedFiles++; + + // --------------------------------------------------------------- + // --- helpset toc file ------------------------------------------ + // --------------------------------------------------------------- + + file = new File(localizedTarget, tocFileName); + + NodeItem tocRootItem = generateTocFile(file, env); + touchedFiles++; + + // --------------------------------------------------------------- + // --- helpset content files ------------------------------------- + // --------------------------------------------------------------- + + touchedFiles += generateContentFiles(localizedTarget, env, localePath); + + } + + getLog().info(touchedFiles + " file(s) treated."); + } + + protected int generateContentFiles(File localizedTarget, Properties env, String localePath) throws Exception { + + int touchedFiles = 0; + TemplateGenerator gen = prepareGenerator(contentTemplate); + Enumeration<?> keys = helpIds.keys(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + String url = (String) helpIds.get(key); + url = helpsetName + File.separator + url; + File f = new File(localizedTarget, url); + boolean exist = f.exists(); + if (exist) { + // check if there is a autoremoveLine in content + String content = FileUtil.readAsString(f); + if (!content.contains(AUTOREMOVE_LINE)) { + // no regenerate marker detected, so skip this file + if (verbose) { + getLog().debug("skip existing file " + f); + } + continue; + } + } + f.getParentFile().mkdirs(); + if (verbose) { + if (exist) { + getLog().info("regenerate content file " + f); + } else { + getLog().info("generate content file " + f); + } + } + env.put("helpId", key); + env.put("helpIdUrl", localePath + "/" + url); + gen.generate(env, f); + touchedFiles++; + } + return touchedFiles; + } + + protected boolean generateHelpsetFile(File file, Properties env) throws Exception { + + if (file.exists()) { + // check the autoremove line presence + String content = FileUtil.readAsString(file); + if (!content.contains(AUTOREMOVE_LINE)) { + // no regenerate marker detected, so skip this file + if (verbose) { + getLog().info("skip existing helpset main file " + file); + } + return false; + } + } + + if (verbose) { + if (file.exists()) { + getLog().info("regenerate helpset main file " + file); + } else { + getLog().info("generate helpset main file " + file); + } + } + doGen(helpsetTemplate, file, env); + return true; + } + + protected Properties generateMapFile(File file, Properties env) throws Exception { + + boolean create; + + Properties mergedHelpIds = null; + if (file.exists()) { + + // get back the exisiting data and merge it with incoming ones + + if (verbose) { + getLog().info("loading existing helpset map file " + file); + } + + mergedHelpIds = XmlHelper.getExistingHelpIds(file, verbose, getLog()); + create = false; + + } else { + + mergedHelpIds = new SortedProperties(); + create = true; + } + + // inject new helpIds + + for (Object k : helpIds.keySet()) { + mergedHelpIds.put(k, helpsetName + "/" + helpIds.get(k)); + } + + if (!mergedHelpIds.contains("top")) { + + // on ajoute une entree vers le root du helpset + + String topUrl = helpsetName + ".html"; + helpIds.put("top", topUrl); + mergedHelpIds.put("top", helpsetName + "/" + topUrl); + if (verbose) { + getLog().debug("add top entry with url " + topUrl); + } + } + + if (verbose) { + if (create) { + getLog().info("generate helpset map file " + file); + } else { + getLog().info("udpate helpset map file " + file); + } + } + + env.put("helpIds", mergedHelpIds); + doGen(mapTemplate, file, env); + env.remove("helpIds"); + return mergedHelpIds; + } + + protected NodeItem generateIndexFile(File file, Properties env) throws Exception { + NodeItem rootItem = null; + + boolean create; + + if (file.exists()) { + + create = false; + + rootItem = XmlHelper.getExistingItems("indexitem", file); + } else { + create = true; + } + + if (rootItem == null) { + rootItem = new NodeItem("top", helpsetName); + } + + // inject new index entries + + for (Object k : helpIds.keySet()) { + NodeItem toc = rootItem.findChild(k + ""); + if (verbose) { + getLog().debug("index " + k + " : " + toc); + } + } + + if (verbose) { + if (create) { + getLog().info("generate helpset index file " + file); + } else { + getLog().info("udpate helpset index file " + file); + } + } + + env.put("rootItem", rootItem); + doGen(indexTemplate, file, env); + env.remove("rootItem"); + return rootItem; + } + + protected NodeItem generateTocFile(File file, Properties env) throws Exception { + NodeItem rootItem = null; + + boolean create; + + if (file.exists()) { + + create = false; + + rootItem = XmlHelper.getExistingItems("tocitem", file); + } else { + create = true; + } + + if (rootItem == null) { + rootItem = new NodeItem("top", helpsetName); + } + // inject new toc entries + + for (Object k : helpIds.keySet()) { + NodeItem toc = rootItem.findChild(k + ""); + if (verbose) { + getLog().debug("toc " + k + " : " + toc); + } + } + + if (verbose) { + if (create) { + getLog().info("generate helpset toc file " + file); + } else { + getLog().info("udpate helpset toc file " + file); + } + } + + env.put("rootItem", rootItem); + doGen(tocTemplate, file, env); + env.remove("rootItem"); + return rootItem; + } + + protected void doGen(File template, File f, Properties env) throws Exception { + TemplateGenerator gen = prepareGenerator(template); + gen.generate(env, f); + } + + protected TemplateGenerator prepareGenerator(File template) throws Exception { + URL templateURL = getTemplate(template); + + if (verbose) { + getLog().info("using template " + templateURL); + } + TemplateGenerator gen = new TemplateGenerator(project, templateURL); + return gen; + } +} Copied: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java (from rev 1567, branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxGeneratorMojo.java) =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java (rev 0) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -0,0 +1,683 @@ +/* *##% + * Copyright (C) 2007 + * JaxxPlugin, Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ +package org.nuiton.jaxx.plugin; + +import jaxx.compiler.CompilerConfiguration; +import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.JAXXCompilerLaunchor; +import jaxx.compiler.beans.BeanInfoUtil; +import jaxx.compiler.decorators.CompiledObjectDecorator; +import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator; +import jaxx.compiler.tags.TagManager; +import jaxx.runtime.JAXXContext; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; + +import org.nuiton.io.FileUpdaterHelper; +import org.nuiton.io.MirroredFileUpdater; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.Map; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import jaxx.runtime.swing.help.JAXXHelpBroker; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * Generates some java code from jaxx files. + * + * @author chemit + * @goal generate + * @phase process-sources + * @requiresDependencyResolution compile + * @requiresProject + */ +public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfiguration { + + /** + * Default includes to use, if none provided + */ + private static final String[] INCLUDES = {"**\\/*.jaxx"}; + /** + * Repertoire sources des fichiers jaxx a generer. + * + * @parameter expression="${jaxx.src}" default-value="${maven.src.dir}/main/java" + */ + protected File src; + /** + * Repertoire de destination des fichiers java a generer. + * + * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java" + */ + protected File outJava; + /** + * pour filter les fichiers a traiter + * + * @parameter expression="${jaxx.includes}" + */ + protected String[] includes; + /** + * pour filter les fichiers a ne pas traiter + * + * @parameter expression="${jaxx.excludes}" + */ + protected String[] excludes; + /** + * Le compilateur à utiliser (par défaut celui de Swing) + * + * @parameter expression="${jaxx.compilerFQN}" default-value="jaxx.compiler.JAXXCompiler" + */ + protected String compilerFQN; + /** + * Le compilateur à utiliser (par défaut celui de Swing) + * + * @parameter expression="${jaxx.validatorFQN}" default-value="jaxx.runtime.validator.swing.SwingValidator" + */ + protected String validatorFQN; + /** + * the name of implementation of {@link jaxx.runtime.JAXXContext} + * to be used on {@link jaxx.runtime.JAXXObject}. + * <p/> + * Must not be abstract. + * + * @parameter expression="${jaxx.jaxxContextFQN}" default-value="jaxx.runtime.context.DefaultJAXXContext" + * @required + */ + protected String jaxxContextFQN; + /** + * the FQN of the ui to use for error notification. + * <p/> + * If not given, will use the one defined in validator + * + * @parameter expression="${jaxx.defaultErrorUIFQN}" + */ + protected String defaultErrorUIFQN; + /** + * the FQN of the ui to use for error notification. + * <p/> + * If not given, will use the one defined in validator + * + * @parameter expression="${jaxx.defaultDecoratorFQN}" default-value="jaxx.compiler.decorators.DefaultCompiledObjectDecorator" + * + * @see jaxx.compiler.decorators.CompiledObjectDecorator + */ + protected String defaultDecoratorFQN; + /** + * flag to include in compiler classpath the java sources directories (src and outJava). + * <p/> + * By default, false. + * + * @parameter expression="${jaxx.addSourcesToClassPath}" default-value="false" + */ + protected boolean addSourcesToClassPath; + /** + * flag to include in compiler classpath the java resources directories (src and outJava). + * <p/> + * By default, false. + * + * @parameter expression="${jaxx.addResourcesToClassPath}" default-value="false" + * @since 1.6.0 + */ + protected boolean addResourcesToClassPath; + /** + * flag to include in compiler classpath the compile class-path (can only be used in a test phase). + * <p/> + * By default, false. + * + * @parameter expression="${jaxx.addCompileClassPath}" default-value="false" + * @since 1.6.0 + */ + protected boolean addCompileClassPath; + /** + * flag to include in compiler classpath the project compile classpath. + * <p/> + * By default, false. + * + * @parameter expression="${jaxx.addProjectClassPath}" default-value="false" + */ + protected boolean addProjectClassPath; + /** + * to force generation of java source for any jaxx files with no timestamp checking. + * <p/> + * By default, never force generation. + * + * @parameter expression="${jaxx.force}" default-value="false" + */ + protected boolean force; + /** + * A flag to mark themojo to be used in a test phase. This will permits to add generated sources in test compile roots. + * + * @parameter expression="${jaxx.testPhase}" default-value="false" + * @since 1.6.0 + */ + protected boolean testPhase; + /** + * to make compiler i18nable, says add the {@link org.nuiton.i18n.I18n#_(String, Object[])} method + * invocation on {@link jaxx.compiler.I18nHelper#I18N_ATTRIBUTES} attributes. + * + * @parameter expression="${jaxx.i18nable}" default-value="true" + * @see jaxx.compiler.I18nHelper + */ + protected boolean i18nable; + /** + * pour optimizer le code compile ou genere ? + * + * @parameter expression="${jaxx.optimize}" default-value="false" + */ + protected boolean optimize; + /** + * flag to add logger to each generated jaxx file. + * <p/> + * By default, always add it. + * + * @parameter expression="${jaxx.addLogger}" default-value="true" + */ + protected boolean addLogger; + /** + * flag to keep compilers after the generate operation (usefull for tests. + * <p/> + * By default, always reset. + * + * @parameter expression="${jaxx.resetAfterCompile}" default-value="true" + */ + protected boolean resetAfterCompile; + /** + * extra path to be added in {@link java.beans.Introspector#setBeanInfoSearchPath(java.lang.String[])}. + * <p/> + * add beanInfoSearchPath to be registred by {@link BeanInfoUtil#addJaxxBeanInfoPath(java.lang.String[])} + * <p/> + * and then will be use by {@link jaxx.compiler.spi.DefaultInitializer#initialize()}. + * <p/> + * <p/> + * This permit to use real beanInfo of imported graphic libraries. + * + * @parameter expression="${jaxx.beanInfoSearchPath}" + */ + protected String[] beanInfoSearchPath; + /** + * list of fqn of class toimport for all generated jaxx files + * + * @parameter expression="${jaxx.extraImportList}" + */ + protected String extraImportList; + /** + * a flag to use UIManager to retreave icons. + * + * @parameter expression="${jaxx.useUIManagerForIcon}" default-value="false" + */ + protected boolean useUIManagerForIcon; + /** + * flag to activate profile mode. + * <p/> + * By default, not active. + * + * @parameter expression="${jaxx.profile}" default-value="false" + */ + protected boolean profile; + /** + * flag to activate help generation process. + * <p/> + * By default, not active. + * + * @parameter expression="${jaxx.generateHelp}" default-value="false" + * + * @since 1.3 + */ + protected boolean generateHelp; + /** + * the FQN of help broker + * <p/> + * By default, use the JAXX implementation {@link JAXXHelpBroker}. + * + * @parameter expression="${jaxx.helpBrokerFQN}" default-value="jaxx.runtime.swing.help.JAXXHelpBroker" + * + * @since 1.3 + */ + protected String helpBrokerFQN; + /** + * detected jaxx files in {@link #init()} method + */ + protected String[] files; + /** + * file updater used to detect jaxx files. + * + * <b>Note:</b> if {@link #verbose} flag is on, will ne be used + */ + protected MirroredFileUpdater updater; + /** + * + */ + private Class<?> defaultErrorUIClass; + /** + * + */ + private Class<?> validatorClass; + /** + * + */ + private Class<? extends CompiledObjectDecorator> defaultDecoratorClass; + /** + * + */ + private Class<? extends JAXXContext> jaxxContextClass; + /** + * + */ + private Class<? extends JAXXCompiler> compilerClass; + /** + * + */ + private String[] extraImports; + /** + * + */ + private boolean nofiles; + /** + * + */ + protected ClassLoader cl; + + @SuppressWarnings("unchecked") + @Override + public boolean init() throws Exception { + + if (generateHelp) { + // check there is some bundle + if (getHelpIdsStore() == null) { + throw new MojoFailureException("you must set the 'helpIdStore' property."); + } + } + + fixCompileSourceRoots(); + + if (includes == null || includes.length == 0) { + // use default includes + includes = INCLUDES; + } + updater = FileUpdaterHelper.newJaxxFileUpdater(src, outJava); + + Map<File, String[]> result = new HashMap<File, String[]>(); + getFilesToTreateForRoots(includes, excludes, Arrays.asList(src.getAbsolutePath()), result, force ? null : updater); + + this.files = result.get(src); + + nofiles = files == null || files.length == 0; + if (nofiles) { + return true; + } + +// if (addSourcesToClassPath || addProjectClassPath) { + cl = initClassLoader(project, + src, + addSourcesToClassPath, + testPhase, + addResourcesToClassPath, + addCompileClassPath, + addProjectClassPath); + + Thread.currentThread().setContextClassLoader(cl); +// } else { +// cl = getClass().getClassLoader(); + //cl = Thread.currentThread().getContextClassLoader(); +// } + + compilerClass = (Class<? extends JAXXCompiler>) Class.forName(compilerFQN, false, cl); + defaultDecoratorClass = (Class<? extends CompiledObjectDecorator>) Class.forName(defaultDecoratorFQN, false, cl); + jaxxContextClass = (Class<? extends JAXXContext>) Class.forName(jaxxContextFQN, false, cl); + if (!JAXXContext.class.isAssignableFrom(jaxxContextClass)) { + throw new MojoExecutionException("jaxxContextFQN must be an implementation of " + JAXXContext.class + " but was : " + jaxxContextClass); + } + validatorClass = Class.forName(validatorFQN, false, cl); + + if (defaultErrorUIFQN != null && !defaultErrorUIFQN.trim().isEmpty()) { + defaultErrorUIClass = Class.forName(defaultErrorUIFQN, false, cl); + } + + if (beanInfoSearchPath != null && beanInfoSearchPath.length > 0) { + // register extra path + BeanInfoUtil.addJaxxBeanInfoPath(beanInfoSearchPath); + } + + if (!outJava.exists()) { + outJava.mkdirs(); + } + + // compute extra imports (can not use java classes since some of + // imports can not be still compiled) + if (extraImportList != null && !extraImportList.isEmpty()) { + String[] imports = extraImportList.split(","); + int i = 0; + for (String importS : imports) { + imports[i++] = importS.trim(); + } + if (verbose) { + getLog().info("extra imports " + java.util.Arrays.toString(imports)); + } + extraImports = imports; + } + + if (verbose) { + printInit(); + } + return true; + } + + @Override + public void doAction() throws MojoExecutionException { + + if (nofiles) { + getLog().info("No files to treate."); + return; + } + + getLog().info("Detects " + files.length + " modify jaxx file(s). "); + + try { + + // force compiler init from here, not in a static block + TagManager.reset(verbose); + + JAXXCompilerLaunchor launchor; + launchor = JAXXCompilerLaunchor.newLaunchor(src, files, this); + boolean success = launchor.compile(); + getLog().info("Generated " + launchor.getCompilerCount() + " file(s). "); + + if (!success) { + throw new MojoExecutionException("Aborting due to errors reported by jaxxc"); + } + + if (generateHelp) { + // generate help + generateHelp(); + } + + } catch (MojoExecutionException e) { + getLog().error(e); + throw e; + } catch (Exception e) { + //getLog().error(e); + Throwable e2 = e; + while (e2.getCause() != null) { + e2 = e.getCause(); + } + getLog().error(e2); + + throw new MojoExecutionException(e2.getMessage(), e2); + } + } + + @Override + public File getTargetDirectory() { + return outJava; + } + + @Override + public boolean getOptimize() { + return optimize; + } + + @Override + public boolean isI18nable() { + return i18nable; + } + + @Override + public boolean isUseUIManagerForIcon() { + return useUIManagerForIcon; + } + + @Override + public boolean isAddLogger() { + return addLogger; + } + + @Override + public Class<? extends JAXXContext> getJaxxContextClass() { + return jaxxContextClass; + } + + @Override + public String[] getExtraImports() { + return extraImports; + } + + @Override + public boolean isResetAfterCompile() { + return resetAfterCompile; + } + + @Override + public boolean isOptimize() { + return optimize; + } + + @Override + public Class<?> getDefaultErrorUI() { + return defaultErrorUIClass; + } + + @Override + public ClassLoader getClassLoader() { + return cl; + } + + @Override + public Class<? extends JAXXCompiler> getCompilerClass() { + return compilerClass; + } + + @Override + public Class<? extends CompiledObjectDecorator> getDefaultDecoratorClass() { + return defaultDecoratorClass; + } + + @Override + public boolean isProfile() { + return profile; + } + + @Override + public boolean isGenerateHelp() { + return generateHelp; + } + + @Override + public String getHelpBrokerFQN() { + return helpBrokerFQN; + } + + @Override + public Class<?> getValidatorClass() { + return validatorClass; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + protected void fixCompileSourceRoots() { + if (project == null) { + // no project defined, can not fix anything + // this case could appears if we wanted to do some tests of the plugin + return; + } + + if (testPhase) { + if (!project.getTestCompileSourceRoots().contains( + outJava.getPath())) { + getLog().info("Add test compile source root : " + outJava); + project.addTestCompileSourceRoot(outJava.getPath()); + } + } else { + if (!project.getCompileSourceRoots().contains(outJava.getPath())) { + getLog().info("Add compile source root : " + outJava); + project.addCompileSourceRoot(outJava.getPath()); + } + } + } + + protected void printInit() { + getLog().info(toString()); + getLog().info("includes : " + Arrays.toString(includes)); + for (String file : files) { + getLog().info("will generate " + file); + } + + ClassLoader threadLoader = Thread.currentThread().getContextClassLoader(); + getLog().info(threadLoader.toString()); + if (threadLoader.getClass().getSimpleName().equals("RealmClassLoader")) { + try { + java.lang.reflect.Method m = threadLoader.getClass().getDeclaredMethod("getURLs"); + m.setAccessible(true); + URL[] urls = (URL[]) m.invoke(threadLoader); + + for (URL url : urls) { + getLog().info("url in class loader " + url); + } + } catch (Exception e) { + getLog().warn("??? : " + e.getMessage(), e); + } + } + } + + protected void generateHelp() throws IOException { + Set<String> helpIds = HelpRootCompiledObjectDecorator.getHelpIds(); + if (helpIds.isEmpty()) { + if (verbose) { + // no ids detected in this compilation round + getLog().info("no helpIds detected."); + } + return; + } + File idsStore = getHelpIdsStore(); + + if (!idsStore.getParentFile().exists()) { + idsStore.getParentFile().mkdirs(); + } + + Properties p = new Properties(); + + for (String helpId : helpIds) { + String path = helpId.replaceAll("\\.", File.separator); + path = removeQuote(path) + ".html"; + p.put(removeQuote(helpId), path); + } + + FileOutputStream w = new FileOutputStream(idsStore); + + try { + p.store(w, null); + } finally { + w.close(); + } + + getLog().info("helpIdStore generated in " + idsStore); + + helpIds.clear(); + } + + //TODO use the AbstractPublig method + @SuppressWarnings({"unchecked"}) + protected URLClassLoader initClasLoader(MavenProject project, org.apache.maven.plugin.logging.Log log) throws MalformedURLException { + URLClassLoader loader = null; + if (project != null) { + + URLClassLoader result; + try { + + List<URL> lUrls = new ArrayList<URL>(); + List<String> sources = project.getCompileSourceRoots(); + + if (addSourcesToClassPath) { + for (String source : sources) { + lUrls.add(new File(source).toURI().toURL()); + } + if (testPhase) { + for (Object source : project.getTestCompileSourceRoots()) { + lUrls.add(new File(source.toString()).toURI().toURL()); + } + } + } + if (addResourcesToClassPath) { + for (Object source : project.getResources()) { + Resource r = (Resource) source; + lUrls.add(new File(r.getDirectory()).toURI().toURL()); + } + } + if (testPhase && addCompileClassPath) { + if (project != null) { + lUrls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); + } + } + if (addProjectClassPath) { + getLog().info("use project compile scope class-path"); + // add also all dependencies of the project in compile scope + Set<?> artifacts = project.getArtifacts(); + for (Object o : artifacts) { + Artifact a = (Artifact) o; + lUrls.add(a.getFile().toURI().toURL()); + } + } + + result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); + + } catch (IOException e) { + throw new RuntimeException("Can't create ClassLoader for reason " + e.getMessage(), e); + } + loader = result; + } else { + List<URL> lUrls = new ArrayList<URL>(); + if (addSourcesToClassPath) { + lUrls.add(src.toURI().toURL()); + } + loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); + } + if (verbose) { + for (URL entry : loader.getURLs()) { + log.info("classpath : " + entry); + } + } + return loader; + } + + protected String removeQuote(String txt) { + if (txt.startsWith("\"")) { + txt = txt.substring(1); + } + if (txt.endsWith("\"")) { + txt = txt.substring(0, txt.length() - 1); + } + return txt; + } +} Deleted: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxGeneratorMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxGeneratorMojo.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxGeneratorMojo.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -1,688 +0,0 @@ -/* *##% - * Copyright (C) 2007 - * JaxxPlugin, Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ -package org.nuiton.jaxx.plugin; - -import jaxx.compiler.CompilerConfiguration; -import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.JAXXCompilerLaunchor; -import jaxx.compiler.beans.BeanInfoUtil; -import jaxx.compiler.decorators.CompiledObjectDecorator; -import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator; -import jaxx.compiler.tags.TagManager; -import jaxx.runtime.JAXXContext; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Resource; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.MavenProject; - -import org.nuiton.io.FileUpdaterHelper; -import org.nuiton.io.MirroredFileUpdater; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.Map; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - -/** - * Generates some java code from jaxx files. - * - * @author chemit - * @goal generate - * @phase process-sources - * @requiresDependencyResolution compile - * @requiresProject - */ -public class JaxxGeneratorMojo extends AbstractJaxxMojo implements CompilerConfiguration { - - /** - * Default includes to use, if none provided - */ - private static final String[] INCLUDES = {"**\\/*.jaxx"}; - /** - * Repertoire sources des fichiers jaxx a generer. - * - * @parameter expression="${jaxx.src}" default-value="${maven.src.dir}/main/java" - */ - protected File src; - /** - * pour filter les fichiers a traiter - * - * @parameter expression="${jaxx.includes}" - */ - protected String[] includes; - /** - * pour filter les fichiers a ne pas traiter - * - * @parameter expression="${jaxx.excludes}" - */ - protected String[] excludes; - /** - * Le compilateur à utiliser (par défaut celui de Swing) - * - * @parameter expression="${jaxx.compilerFQN}" default-value="jaxx.compiler.JAXXCompiler" - */ - protected String compilerFQN; - /** - * Le compilateur à utiliser (par défaut celui de Swing) - * - * @parameter expression="${jaxx.validatorFQN}" default-value="jaxx.runtime.validator.swing.SwingValidator" - */ - protected String validatorFQN; - /** - * the name of implementation of {@link jaxx.runtime.JAXXContext} - * to be used on {@link jaxx.runtime.JAXXObject}. - * <p/> - * Must not be abstract. - * - * @parameter expression="${jaxx.jaxxContextFQN}" default-value="jaxx.runtime.context.DefaultJAXXContext" - * @required - */ - protected String jaxxContextFQN; - /** - * the FQN of the ui to use for error notification. - * <p/> - * If not given, will use the one defined in validator - * - * @parameter expression="${jaxx.defaultErrorUIFQN}" - */ - protected String defaultErrorUIFQN; - /** - * the FQN of the ui to use for error notification. - * <p/> - * If not given, will use the one defined in validator - * - * @parameter expression="${jaxx.defaultDecoratorFQN}" default-value="jaxx.compiler.decorators.DefaultCompiledObjectDecorator" - * - * @see jaxx.compiler.decorators.CompiledObjectDecorator - */ - protected String defaultDecoratorFQN; - /** - * flag to include in compiler classpath the java sources directories (src and outJava). - * <p/> - * By default, false. - * - * @parameter expression="${jaxx.addSourcesToClassPath}" default-value="false" - */ - protected boolean addSourcesToClassPath; - /** - * flag to include in compiler classpath the java resources directories (src and outJava). - * <p/> - * By default, false. - * - * @parameter expression="${jaxx.addResourcesToClassPath}" default-value="false" - * @since 1.6.0 - */ - protected boolean addResourcesToClassPath; - /** - * flag to include in compiler classpath the compile class-path (can only be used in a test phase). - * <p/> - * By default, false. - * - * @parameter expression="${jaxx.addCompileClassPath}" default-value="false" - * @since 1.6.0 - */ - protected boolean addCompileClassPath; - /** - * flag to include in compiler classpath the project compile classpath. - * <p/> - * By default, false. - * - * @parameter expression="${jaxx.addProjectClassPath}" default-value="false" - */ - protected boolean addProjectClassPath; - /** - * to force generation of java source for any jaxx files with no timestamp checking. - * <p/> - * By default, never force generation. - * - * @parameter expression="${jaxx.force}" default-value="false" - */ - protected boolean force; - /** - * A flag to mark themojo to be used in a test phase. This will permits to add generated sources in test compile roots. - * - * @parameter expression="${jaxx.testPhase}" default-value="false" - * @since 1.6.0 - */ - protected boolean testPhase; - /** - * pour optimizer le code compile ou genere ? - * - * @parameter expression="${jaxx.optimize}" default-value="false" - */ - protected boolean optimize; - /** - * flag to add logger to each generated jaxx file. - * <p/> - * By default, always add it. - * - * @parameter expression="${jaxx.addLogger}" default-value="true" - */ - protected boolean addLogger; - /** - * flag to keep compilers after the generate operation (usefull for tests. - * <p/> - * By default, always reset. - * - * @parameter expression="${jaxx.resetAfterCompile}" default-value="true" - */ - protected boolean resetAfterCompile; - /** - * extra path to be added in {@link java.beans.Introspector#setBeanInfoSearchPath(java.lang.String[])}. - * <p/> - * add beanInfoSearchPath to be registred by {@link BeanInfoUtil#addJaxxBeanInfoPath(java.lang.String[])} - * <p/> - * and then will be use by {@link jaxx.compiler.spi.DefaultInitializer#initialize()}. - * <p/> - * <p/> - * This permit to use real beanInfo of imported graphic libraries. - * - * @parameter expression="${jaxx.beanInfoSearchPath}" - */ - protected String[] beanInfoSearchPath; - /** - * list of fqn of class toimport for all generated jaxx files - * - * @parameter expression="${jaxx.extraImportList}" - */ - protected String extraImportList; - /** - * a flag to use UIManager to retreave icons. - * - * @parameter expression="${jaxx.useUIManagerForIcon}" default-value="false" - */ - protected boolean useUIManagerForIcon; - /** - * flag to activate profile mode. - * <p/> - * By default, not active. - * - * @parameter expression="${jaxx.profile}" default-value="false" - */ - protected boolean profile; - /** - * flag to activate help generation process. - * <p/> - * By default, not active. - * - * @parameter expression="${jaxx.generateHelp}" default-value="false" - * - * @since 1.3 - */ - protected boolean generateHelp; - /** - * the FQN of help broker - * <p/> - * By default, none. - * - * @parameter expression="${jaxx.helpBrokerFQN}" - * - * @since 1.3 - */ - protected String helpBrokerFQN; - /** - * detected jaxx files in {@link #init()} method - */ - protected String[] files; - /** - * file updater used to detect jaxx files. - * - * <b>Note:</b> if {@link #verbose} flag is on, will ne be used - */ - protected MirroredFileUpdater updater; - /** - * - */ - private Class<?> defaultErrorUIClass; - /** - * - */ - private Class<?> validatorClass; - /** - * - */ - private Class<? extends CompiledObjectDecorator> defaultDecoratorClass; - /** - * - */ - private Class<? extends JAXXContext> jaxxContextClass; - /** - * - */ - private Class<? extends JAXXCompiler> compilerClass; - /** - * - */ - private String[] extraImports; - /** - * - */ - private boolean nofiles; - - @SuppressWarnings("unchecked") - @Override - public boolean init() throws Exception { - - if (generateHelp) { - // check there is some bundle - if (helpIdStore == null) { - throw new MojoFailureException("you must set the helpIdStore property."); - } - } - - fixCompileSourceRoots(); - - if (includes == null || includes.length == 0) { - // use default includes - includes = INCLUDES; - } - updater = FileUpdaterHelper.newJaxxFileUpdater(src, outJava); - - Map<File, String[]> result = new HashMap<File, String[]>(); - getFilesToTreateForRoots(includes, excludes, Arrays.asList(src.getAbsolutePath()), result, force ? null : updater); - - this.files = result.get(src); - - nofiles = files == null || files.length == 0; - if (nofiles) { - return true; - } - -// if (addSourcesToClassPath || addProjectClassPath) { - cl = initClassLoader(project, - src, - addSourcesToClassPath, - testPhase, - addResourcesToClassPath, - addCompileClassPath, - addProjectClassPath); - - Thread.currentThread().setContextClassLoader(cl); -// } else { -// cl = getClass().getClassLoader(); - //cl = Thread.currentThread().getContextClassLoader(); -// } - - compilerClass = (Class<? extends JAXXCompiler>) Class.forName(compilerFQN, false, cl); - defaultDecoratorClass = (Class<? extends CompiledObjectDecorator>) Class.forName(defaultDecoratorFQN, false, cl); - jaxxContextClass = (Class<? extends JAXXContext>) Class.forName(jaxxContextFQN, false, cl); - if (!JAXXContext.class.isAssignableFrom(jaxxContextClass)) { - throw new MojoExecutionException("jaxxContextFQN must be an implementation of " + JAXXContext.class + " but was : " + jaxxContextClass); - } - validatorClass = Class.forName(validatorFQN, false, cl); - - if (defaultErrorUIFQN != null && !defaultErrorUIFQN.trim().isEmpty()) { - defaultErrorUIClass = Class.forName(defaultErrorUIFQN, false, cl); - } - - if (beanInfoSearchPath != null && beanInfoSearchPath.length > 0) { - // register extra path - BeanInfoUtil.addJaxxBeanInfoPath(beanInfoSearchPath); - } - - if (!outJava.exists()) { - outJava.mkdirs(); - } - - // compute extra imports (can not use java classes since some of - // imports can not be still compiled) - if (extraImportList != null && !extraImportList.isEmpty()) { - String[] imports = extraImportList.split(","); - int i = 0; - for (String importS : imports) { - imports[i++] = importS.trim(); - } - if (verbose) { - getLog().info("extra imports " + java.util.Arrays.toString(imports)); - } - extraImports = imports; - } - - if (verbose) { - printInit(); - } - return true; - } - - @Override - public void doAction() throws MojoExecutionException { - - if (nofiles) { - getLog().info("No files to treate."); - return; - } - - getLog().info("Detects " + files.length + " modify jaxx file(s). "); - - try { - - // force compiler init from here, not in a static block - TagManager.reset(verbose); - - JAXXCompilerLaunchor launchor; - launchor = JAXXCompilerLaunchor.newLaunchor(src, files, this); - boolean success = launchor.compile(); - getLog().info("Generated " + launchor.getCompilerCount() + " file(s). "); - - if (!success) { - throw new MojoExecutionException("Aborting due to errors reported by jaxxc"); - } - - if (generateHelp) { - // generate help - generateHelp(); - } - - } catch (MojoExecutionException e) { - getLog().error(e); - throw e; - } catch (Exception e) { - //getLog().error(e); - Throwable e2 = e; - while (e2.getCause() != null) { - e2 = e.getCause(); - } - getLog().error(e2); - - throw new MojoExecutionException(e2.getMessage(), e2); - } - } - - @Override - public File getTargetDirectory() { - return outJava; - } - - @Override - public boolean getOptimize() { - return optimize; - } - - @Override - public boolean isI18nable() { - return i18nable; - } - - @Override - public boolean isUseUIManagerForIcon() { - return useUIManagerForIcon; - } - - @Override - public boolean isAddLogger() { - return addLogger; - } - - @Override - public Class<? extends JAXXContext> getJaxxContextClass() { - return jaxxContextClass; - } - - @Override - public String[] getExtraImports() { - return extraImports; - } - - @Override - public boolean isResetAfterCompile() { - return resetAfterCompile; - } - - @Override - public boolean isOptimize() { - return optimize; - } - - @Override - public Class<?> getDefaultErrorUI() { - return defaultErrorUIClass; - } - - @Override - public ClassLoader getClassLoader() { - return cl; - } - - @Override - public Class<? extends JAXXCompiler> getCompilerClass() { - return compilerClass; - } - - @Override - public Class<? extends CompiledObjectDecorator> getDefaultDecoratorClass() { - return defaultDecoratorClass; - } - - @Override - public boolean isProfile() { - return profile; - } - - @Override - public boolean isGenerateHelp() { - return generateHelp; - } - - @Override - public String getHelpBrokerFQN() { - return helpBrokerFQN; - } - - @Override - public String getHelpsetIndexI18nSuffix() { - return helpsetIndexI18nSuffix; - } - - @Override - public String getHelpsetTitleI18nSuffix() { - return helpsetTitleI18nSuffix; - } - - @Override - public String getHelpsetTocI18nSuffix() { - return helpsetTocI18nSuffix; - } - - @Override - public String getHelpSetName() { - return helpSetName; - } - - @Override - public String getHelpsetI18nPrefix() { - return helpsetI18nPrefix; - } - - @Override - public Class<?> getValidatorClass() { - return validatorClass; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); - } - - protected void fixCompileSourceRoots() { - if (project == null) { - // no project defined, can not fix anything - // this case could appears if we wanted to do some tests of the plugin - return; - } - - if (testPhase) { - if (!project.getTestCompileSourceRoots().contains( - outJava.getPath())) { - getLog().info("Add test compile source root : " + outJava); - project.addTestCompileSourceRoot(outJava.getPath()); - } - } else { - if (!project.getCompileSourceRoots().contains(outJava.getPath())) { - getLog().info("Add compile source root : " + outJava); - project.addCompileSourceRoot(outJava.getPath()); - } - } - } - - protected void printInit() { - getLog().info(toString()); - getLog().info("includes : " + Arrays.toString(includes)); - for (String file : files) { - getLog().info("will generate " + file); - } - - ClassLoader threadLoader = Thread.currentThread().getContextClassLoader(); - getLog().info(threadLoader.toString()); - if (threadLoader.getClass().getSimpleName().equals("RealmClassLoader")) { - try { - java.lang.reflect.Method m = threadLoader.getClass().getDeclaredMethod("getURLs"); - m.setAccessible(true); - URL[] urls = (URL[]) m.invoke(threadLoader); - - for (URL url : urls) { - getLog().info("url in class loader " + url); - } - } catch (Exception e) { - getLog().warn("??? : " + e.getMessage(), e); - } - } - } - - protected void generateHelp() throws IOException { - Set<String> helpIds = HelpRootCompiledObjectDecorator.getHelpIds(); - if (helpIds.isEmpty()) { - if (verbose) { - // no ids detected in this compilation round - getLog().info("no helpIds detected."); - } - return; - } - - if (!helpIdStore.getParentFile().exists()) { - helpIdStore.getParentFile().mkdirs(); - } - - Properties p = new Properties(); - - for (String helpId : helpIds) { - String path = helpId.replaceAll("\\.", File.separator); - path = removeQuote(path) + ".html"; - p.put(removeQuote(helpId), path); - } - - FileOutputStream w = new FileOutputStream(helpIdStore); - - try { - p.store(w, null); - } finally { - w.close(); - } - - getLog().info("helpIdStore generated in " + helpIdStore); - - helpIds.clear(); - } - - //TODO use the AbstractPublig method - @SuppressWarnings({"unchecked"}) - protected URLClassLoader initClasLoader(MavenProject project, org.apache.maven.plugin.logging.Log log) throws MalformedURLException { - URLClassLoader loader = null; - if (project != null) { - - URLClassLoader result; - try { - - List<URL> lUrls = new ArrayList<URL>(); - List<String> sources = project.getCompileSourceRoots(); - - if (addSourcesToClassPath) { - for (String source : sources) { - lUrls.add(new File(source).toURI().toURL()); - } - if (testPhase) { - for (Object source : project.getTestCompileSourceRoots()) { - lUrls.add(new File(source.toString()).toURI().toURL()); - } - } - } - if (addResourcesToClassPath) { - for (Object source : project.getResources()) { - Resource r = (Resource) source; - lUrls.add(new File(r.getDirectory()).toURI().toURL()); - } - } - if (testPhase && addCompileClassPath) { - if (project != null) { - lUrls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); - } - } - if (addProjectClassPath) { - getLog().info("use project compile scope class-path"); - // add also all dependencies of the project in compile scope - Set<?> artifacts = project.getArtifacts(); - for (Object o : artifacts) { - Artifact a = (Artifact) o; - lUrls.add(a.getFile().toURI().toURL()); - } - } - - result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); - - } catch (IOException e) { - throw new RuntimeException("Can't create ClassLoader for reason " + e.getMessage(), e); - } - loader = result; - } else { - List<URL> lUrls = new ArrayList<URL>(); - if (addSourcesToClassPath) { - lUrls.add(src.toURI().toURL()); - } - loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); - } - if (verbose) { - for (URL entry : loader.getURLs()) { - log.info("classpath : " + entry); - } - } - return loader; - } - - protected String removeQuote(String txt) { - if (txt.startsWith("\"")) { - txt = txt.substring(1); - } - if (txt.endsWith("\"")) { - txt = txt.substring(0, txt.length() - 1); - } - return txt; - } -} Deleted: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxHelpGeneratorMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxHelpGeneratorMojo.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/JaxxHelpGeneratorMojo.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -1,780 +0,0 @@ -/* *##% - * Copyright (C) 2007 - * JaxxPlugin, Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ -package org.nuiton.jaxx.plugin; - -import org.apache.maven.plugin.MojoFailureException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.Stack; -import org.apache.maven.model.Resource; -import org.nuiton.i18n.I18n; -import org.nuiton.util.FileUtil; -import org.nuiton.util.SortedProperties; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; -import static org.nuiton.i18n.I18n._; - -/** - * Mojo to generate javax help stuff for your project. - * - * HelpIds should have been discovered by the JaxxMojo. - * - * @author chemit - * @goal generate-help - * @phase process-sources - * - * @requiresProject - * @requiresDependencyResolution compile - * @since 1.3 - */ -public class JaxxHelpGeneratorMojo extends AbstractJaxxMojo { - - /** - * The directory where to generate javaHelp skeleton files. - * <p/> - * Is required if generateHelp is on. - * - * @parameter expression="${jaxx.helpTarget}" alias="target" default-value="${maven.src.dir}/main/help" - * @required - * - * @since 1.3 - */ - protected File target; - /** - * The locale to generate for help. - * - * By default, stay in France. - * - * @parameter expression="${jaxx.locale}" default-value="fr" - * @required - * - * @since 1.3 - */ - protected String locale; - /** - * The package where to generate i18n java file. - * - * @parameter expression="${jaxx.packageName}" default-value="${project.groupId}" - * @required - * - * @since 1.3 - */ - protected String packageName; - /** - * The file name of the helpset to generate. - * - * @parameter expression="${jaxx.helpSetFileName}" default-value="${jaxx.helpSetName}.hs" - * @required - * - * @since 1.3 - */ - protected String helpsetFileName; - /** - * The file name of the helpset map to generate. - * - * @parameter expression="${jaxx.mapFileName}" default-value="${jaxx.helpSetName}Map.jhm" - * @required - * - * @since 1.3 - */ - protected String mapFileName; - /** - * The file name of the helpset index to generate. - * - * @parameter expression="${jaxx.indexFileName}" default-value="${jaxx.helpSetName}Index.xml" - * @required - * - * @since 1.3 - */ - protected String indexFileName; - /** - * The file name of the helpset toc to generate. - * - * @parameter expression="${jaxx.tocFileName}" default-value="${jaxx.helpSetName}TOC.xml" - * @required - * - * @since 1.3 - */ - protected String tocFileName; - /** - * The file name of the i18n java file to generate. - * - * @parameter expression="${jaxx.i8nFileName}" default-value="${jaxx.helpSetName}I18n.java" - * @required - * - * @since 1.3 - */ - protected String i8nFileName; - /** - * The template used to generate helpset file. - * - * Must be an existing file or a ressource in classp-ath - * - * @parameter expression="${jaxx.helpSetTemplate}" default-value="/defaultHelpSet.hs.vm" - * @required - * - * @since 1.3 - */ - protected File helpSetTemplate; - /** - * The template used to generate helpset map file. - * - * Must be an existing file or a ressource in classp-ath - * - * @parameter expression="${jaxx.mapTemplate}" default-value="/defaultMap.jhm.vm" - * @required - * - * @since 1.3 - */ - protected File mapTemplate; - /** - * The template used to generate helpset index file. - * - * Must be an existing file or a ressource in classp-ath - * - * @parameter expression="${jaxx.indexTemplate}" default-value="/defaultIndex.xml.vm" - * @required - * - * @since 1.3 - */ - protected File indexTemplate; - /** - * The template used to generate helpset toc file. - * - * Must be an existing file or a ressource in classp-ath - * - * @parameter expression="${jaxx.tocTemplate}" default-value="/defaultToc.xml.vm" - * @required - * - * @since 1.3 - */ - protected File tocTemplate; - /** - * The template used to generate helpset content file. - * - * Must be an existing file or a ressource in classp-ath - * - * @parameter expression="${jaxx.contentTemplate}" default-value="/defaultContent.html.vm" - * @required - * - * @since 1.3 - */ - protected File contentTemplate; - /** - * The template used to generate helpset content file. - * - * Must be an existing file or a ressource in classp-ath - * - * @parameter expression="${jaxx.i18nTemplate}" default-value="/defaultI18n.java.vm" - * @required - * - * @since 1.3 - */ - protected File i18nTemplate; - /** - * The help ids discovered by Jaxx compilation - */ - protected Properties helpIds; - private static final String AUTOREMOVE_LINE = "REMOVE THS LINE TO DISABLE AUTO-REGENERATE THE FILE"; - - @Override - public boolean init() throws Exception { - - if (!helpIdStore.exists()) { - getLog().info("no helpIdStore to react at " + helpIdStore); - return false; - } - - // check there is some bundle - if (locale == null) { - throw new MojoFailureException("you must set the bundles property."); - } - // check there is some bundle - if (target == null) { - throw new MojoFailureException("you must set the target property."); - } - // check ressources - checkResource(helpSetTemplate); - checkResource(mapTemplate); - checkResource(indexTemplate); - checkResource(tocTemplate); - checkResource(contentTemplate); - - if (!target.exists()) { - getLog().info("mkdir " + target); - target.mkdirs(); - } - - helpIds = new SortedProperties(); - - InputStream stream = new FileInputStream(helpIdStore); - - helpIds.load(stream); - - stream.close(); - - if (helpIds.isEmpty()) { - - // no ids detected - getLog().warn("no helpIds detected, will skip."); - return false; - } - - return true; - } - - @Override - public void doAction() throws Exception { - - if (i18nable) { - - List<URL> lUrls = new java.util.ArrayList<URL>(); - List<?> resources = project.getResources(); - for (Object o : resources) { - Resource resource = (Resource) o; - lUrls.add(new File(resource.getDirectory()).toURI().toURL()); - } - I18n.setExtraURL(lUrls.toArray(new URL[lUrls.size()])); - I18n.init(locale, null); - } - - File file; - - Properties env = new Properties(); - - env.put("helpSetName", helpSetName); - env.put("helpSetFileName", helpsetFileName); - env.put("mapFileName", mapFileName); - env.put("indexFileName", indexFileName); - env.put("tocFileName", tocFileName); - env.put("separator", " "); - env.put("autoremoveLine", AUTOREMOVE_LINE); - - - int touchedFiles = 0; - - // --------------------------------------------------------------- - // --- main helpset file ----------------------------------------- - // --------------------------------------------------------------- - - - file = new File(target, helpsetFileName); - - boolean doCreate = generateHelSetFile(file, env); - - if (doCreate) { - touchedFiles++; - } - - // --------------------------------------------------------------- - // --- helpset map file ------------------------------------------ - // --------------------------------------------------------------- - - file = new File(target, mapFileName); - - Properties mergedHelpIds = generateMapFile(file, env); - touchedFiles++; - - // --------------------------------------------------------------- - // --- helpset index file ---------------------------------------- - // --------------------------------------------------------------- - - file = new File(target, indexFileName); - - NodeItem indexRootItem = generateIndexFile(file, env); - touchedFiles++; - - // --------------------------------------------------------------- - // --- helpset toc file ------------------------------------------ - // --------------------------------------------------------------- - - file = new File(target, tocFileName); - - NodeItem tocRootItem = generateTocFile(file, env); - touchedFiles++; - - // --------------------------------------------------------------- - // --- helpset content files ------------------------------------- - // --------------------------------------------------------------- - - TemplateGenerator gen = prepareGenerator(contentTemplate); - - Enumeration<?> keys = helpIds.keys(); - - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - String url = (String) helpIds.get(key); - url = helpSetName + File.separator + url; - - File f = new File(target, url); - - boolean exist = f.exists(); - - if (exist) { - // check if there is a autoremoveLine in content - String content = FileUtil.readAsString(f); - if (!content.contains(AUTOREMOVE_LINE)) { - // no regenerate marker detected, so skip this file - if (verbose) { - getLog().debug("skip existing file " + f); - } - continue; - } - } - - f.getParentFile().mkdirs(); - - if (verbose) { - if (exist) { - getLog().info("regenerate content file " + f); - } else { - getLog().info("generate content file " + f); - } - } - - env.put("helpId", key); - String i18n = helpsetI18nPrefix + key + helpsetTitleI18nSuffix; - env.put("helpIdTitle", _(i18n)); - env.put("helpIdUrl", url); - - gen.generate(env, f); - touchedFiles++; - } - - // --------------------------------------------------------------- - // --- i18n file ------------------------------------------------- - // --------------------------------------------------------------- - - String path = packageName.replaceAll("\\.", File.separator); - path += File.separator + i8nFileName; - file = new File(outJava, path); - generateI18nFile(file, env, mergedHelpIds, indexRootItem, tocRootItem); - touchedFiles++; - - getLog().info(touchedFiles + " file(s) treated."); - } - - protected void generateI18nFile(File file, Properties env, Properties mergedHelpIds, NodeItem indexRootItem, NodeItem tocRootItem) throws Exception { - - boolean create = !file.exists(); - - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - - Set<String> keys = new java.util.HashSet<String>(); - - for (Object k : mergedHelpIds.keySet()) { - String key = helpsetI18nPrefix + k + helpsetTitleI18nSuffix; - keys.add(key); - } - indexRootItem.extractI18n(keys, helpsetI18nPrefix, helpsetIndexI18nSuffix); - tocRootItem.extractI18n(keys, helpsetI18nPrefix, helpsetTocI18nSuffix); - - env.put("keys", keys); - env.put("packageName", packageName); - String className = file.getName(); - int index = className.lastIndexOf("."); - className = className.substring(0, index); - env.put("className", className); - - if (verbose) { - if (create) { - getLog().info("generate i18n java file " + file); - } else { - getLog().info("udpate i18n java file " + file); - } - } - - doGen(i18nTemplate, file, env); - - } - - protected boolean generateHelSetFile(File file, Properties env) throws Exception { - - if (file.exists()) { - // check the auto removeline presence - String content = FileUtil.readAsString(file); - if (!content.contains(AUTOREMOVE_LINE)) { - // no regenerate marker detected, so skip this file - if (verbose) { - getLog().info("skip existing helpset main file " + file); - } - return false; - } - } - - if (verbose) { - if (file.exists()) { - getLog().info("regenerate helpset main file " + file); - } else { - getLog().info("generate helpset main file " + file); - } - } - doGen(helpSetTemplate, file, env); - return true; - } - - protected Properties generateMapFile(File file, Properties env) throws Exception { - - boolean create; - - Properties mergedHelpIds = null; - if (file.exists()) { - - // get back the exisiting data and merge it with incoming ones - - if (verbose) { - getLog().info("loading existing helpset map file " + file); - } - - mergedHelpIds = getExistingHelpIds(file); - create = false; - - } else { - - mergedHelpIds = new SortedProperties(); - create = true; - } - - // inject new helpIds - - for (Object k : helpIds.keySet()) { - mergedHelpIds.put(k, helpSetName + "/" + helpIds.get(k)); - } - - if (!mergedHelpIds.contains("top")) { - // on ajoute une entree vers le root du helpset - - String topUrl = helpSetName + ".html"; - helpIds.put("top", topUrl); - mergedHelpIds.put("top", helpSetName + "/" + topUrl); - if (verbose) { - getLog().debug("add top entry with url " + topUrl); - } - } - - if (verbose) { - if (create) { - getLog().info("generate helpset map file " + file); - } else { - getLog().info("udpate helpset map file " + file); - } - } - - env.put("helpIds", mergedHelpIds); - doGen(mapTemplate, file, env); - env.remove("helpIds"); - return mergedHelpIds; - } - - protected NodeItem generateIndexFile(File file, Properties env) throws Exception { - NodeItem rootItem = null; - - boolean create; - - if (file.exists()) { - - create = false; - - rootItem = getExistingItems("indexitem", file); - } else { - create = true; - } - - if (rootItem == null) { - rootItem = new NodeItem("top", helpSetName); - } - - // inject new index entries - - for (Object k : helpIds.keySet()) { - NodeItem toc = rootItem.findChild(k + ""); - if (verbose) { - getLog().debug("index " + k + " : " + toc); - } - } - - //String prefix = helpsetI18nPrefix; - //String prefix = helpsetI18nPrefix + helpSetName + "."; - rootItem.applyI18n(helpsetI18nPrefix, helpsetIndexI18nSuffix); - - if (verbose) { - if (create) { - getLog().info("generate helpset index file " + file); - } else { - getLog().info("udpate helpset index file " + file); - } - } - - env.put("rootItem", rootItem); - doGen(indexTemplate, file, env); - env.remove("rootItem"); - return rootItem; - } - - protected NodeItem generateTocFile(File file, Properties env) throws Exception { - NodeItem rootItem = null; - - boolean create; - - if (file.exists()) { - - create = false; - - rootItem = getExistingItems("tocitem", file); - } else { - create = true; - } - - if (rootItem == null) { - rootItem = new NodeItem("top", helpSetName); - } - // inject new toc entries - - for (Object k : helpIds.keySet()) { - NodeItem toc = rootItem.findChild(k + ""); - if (verbose) { - getLog().debug("toc " + k + " : " + toc); - } - } - - //String prefix = helpsetI18nPrefix + helpSetName + "."; - rootItem.applyI18n(helpsetI18nPrefix, helpsetTocI18nSuffix); - - if (verbose) { - if (create) { - getLog().info("generate helpset toc file " + file); - } else { - getLog().info("udpate helpset toc file " + file); - } - } - - env.put("rootItem", rootItem); - doGen(tocTemplate, file, env); - env.remove("rootItem"); - return rootItem; - } - - protected void doGen(File template, File f, Properties env) throws Exception { - TemplateGenerator gen = prepareGenerator(template); - gen.generate(env, f); - } - - protected TemplateGenerator prepareGenerator(File template) throws Exception { - URL templateURL = getTemplate(template); - - if (verbose) { - getLog().info("using template " + templateURL); - } - TemplateGenerator gen = new TemplateGenerator(project, templateURL); - return gen; - } - -// protected URL getTemplate(File f) throws IOException { -// URL r = null; -// if (f.exists()) { -// r = f.toURI().toURL(); -// } else { -// r = getClass().getResource(f.toString()); -// } -// return r; -// } -// -// protected void checkResource(File f) throws MojoFailureException { -// if (!f.exists()) { -// // test in classPath -// InputStream r = getClass().getResourceAsStream(f.toString()); -// if (r == null) { -// throw new MojoFailureException("could not find ressource " + f); -// } -// } -// } - protected Properties getExistingHelpIds(File file) throws SAXException, IOException { - - final Properties result = new SortedProperties(); - - XMLReader parser = XMLReaderFactory.createXMLReader(); - - parser.setContentHandler(new ContentHandlerAdapter() { - - String target; - String url; - - @Override - public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { - if ("mapID".equals(localName)) { - target = atts.getValue("target"); - url = atts.getValue("url"); - if (verbose) { - getLog().debug("detect map entry : " + target + " : " + url); - } - result.put(target, url); - } - } - }); - - InputStream s = new FileInputStream(file); - try { - parser.parse(new InputSource(s)); - } finally { - s.close(); - } - return result; - } - - protected NodeItem getExistingItems(String tagName, File file) throws SAXException, IOException { - - XMLReader parser = XMLReaderFactory.createXMLReader(); - NodeItemHandler handler = new NodeItemHandler(tagName); - - parser.setContentHandler(handler); - - NodeItem rootItem = null; - InputStream s = new FileInputStream(file); - try { - parser.parse(new InputSource(s)); - rootItem = handler.rootItem; - } finally { - s.close(); - } - return rootItem; - } - - static class NodeItemHandler extends ContentHandlerAdapter { - - NodeItem rootItem; - NodeItem currentItem; - final Stack<NodeItem> stack; - final String tagName; - - public NodeItemHandler(String tagName) { - this.tagName = tagName; - this.stack = new Stack<NodeItem>(); - } - - @Override - public void startDocument() throws SAXException { - rootItem = new NodeItem("top", null); - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { - if (tagName.equals(localName)) { - - String target = atts.getValue("target"); - String text = atts.getValue("text"); - - // debut d'un item - if (currentItem == null) { - // premier item - if (rootItem.getTarget().equals(target)) { - // le premier item est bien top - //rootItem.setText(text); - currentItem = rootItem; - } else { - // le premier noeud n'est pas top - // en l'encapsule - stack.push(rootItem); - currentItem = new NodeItem(target, text); - rootItem.addChild(currentItem); - } - } else { - NodeItem newItem = new NodeItem(target, text); - currentItem.addChild(newItem); - currentItem = newItem; - } - currentItem.adjustTarget(); - stack.push(currentItem); - - } - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - if (tagName.equals(localName)) { - // fin d'un item - stack.pop(); - if (!stack.isEmpty()) { - currentItem = stack.peek(); - } - } - } - } - - static class ContentHandlerAdapter implements ContentHandler { - - @Override - public void setDocumentLocator(Locator locator) { - } - - @Override - public void startDocument() throws SAXException { - } - - @Override - public void endDocument() throws SAXException { - } - - @Override - public void startPrefixMapping(String prefix, String uri) throws SAXException { - } - - @Override - public void endPrefixMapping(String prefix) throws SAXException { - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - } - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - } - - @Override - public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { - } - - @Override - public void processingInstruction(String target, String data) throws SAXException { - } - - @Override - public void skippedEntity(String name) throws SAXException { - } - } -} Added: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java (rev 0) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -0,0 +1,187 @@ +package org.nuiton.jaxx.plugin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.Stack; +import org.apache.maven.plugin.logging.Log; +import org.nuiton.util.SortedProperties; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * To load {@link NodeItem} from xml. + * + * @author chemit + * @since 2.0.0 + */ +public class XmlHelper { + + public static Properties getExistingHelpIds(File file, final boolean verbose, final Log log) throws SAXException, IOException { + + final Properties result = new SortedProperties(); + + XMLReader parser = XMLReaderFactory.createXMLReader(); + + parser.setContentHandler(new ContentHandlerAdapter() { + + String target; + String url; + + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { + if ("mapID".equals(localName)) { + target = atts.getValue("target"); + url = atts.getValue("url"); + if (verbose) { + log.debug("detect map entry : " + target + " : " + url); + } + result.put(target, url); + } + } + }); + + InputStream s = new FileInputStream(file); + try { + parser.parse(new InputSource(s)); + } finally { + if (s != null) { + s.close(); + } + } + return result; + } + + public static NodeItem getExistingItems(String tagName, File file) throws SAXException, IOException { + + XMLReader parser = XMLReaderFactory.createXMLReader(); + NodeItemHandler handler = new NodeItemHandler(tagName); + + parser.setContentHandler(handler); + + NodeItem rootItem = null; + InputStream s = new FileInputStream(file); + try { + parser.parse(new InputSource(s)); + rootItem = handler.rootItem; + } finally { + s.close(); + } + return rootItem; + } + + static class NodeItemHandler extends ContentHandlerAdapter { + + NodeItem rootItem; + NodeItem currentItem; + final Stack<NodeItem> stack; + final String tagName; + + public NodeItemHandler(String tagName) { + this.tagName = tagName; + this.stack = new Stack<NodeItem>(); + } + + @Override + public void startDocument() throws SAXException { + rootItem = new NodeItem("top", null); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { + if (tagName.equals(localName)) { + + String target = atts.getValue("target"); + String text = atts.getValue("text"); + + // debut d'un item + if (currentItem == null) { + // premier item + if (rootItem.getTarget().equals(target)) { + // le premier item est bien top + //rootItem.setText(text); + currentItem = rootItem; + } else { + // le premier noeud n'est pas top + // en l'encapsule + stack.push(rootItem); + currentItem = new NodeItem(target, text); + rootItem.addChild(currentItem); + } + } else { + NodeItem newItem = new NodeItem(target, text); + currentItem.addChild(newItem); + currentItem = newItem; + } + currentItem.adjustTarget(); + stack.push(currentItem); + + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (tagName.equals(localName)) { + // fin d'un item + stack.pop(); + if (!stack.isEmpty()) { + currentItem = stack.peek(); + } + } + } + } + + static class ContentHandlerAdapter implements ContentHandler { + + @Override + public void setDocumentLocator(Locator locator) { + } + + @Override + public void startDocument() throws SAXException { + } + + @Override + public void endDocument() throws SAXException { + } + + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + } + + @Override + public void endPrefixMapping(String prefix) throws SAXException { + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + } + + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + } + + @Override + public void processingInstruction(String target, String data) throws SAXException { + } + + @Override + public void skippedEntity(String name) throws SAXException { + } + } +} Property changes on: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm 2009-10-08 16:48:27 UTC (rev 1568) @@ -2,11 +2,11 @@ <HTML> <HEAD> <TITLE> -$helpIdTitle +$helpId </TITLE> </HEAD> <BODY BGCOLOR="#ffffff"> -<H1>$helpIdTitle</H1> +<H1>$helpId</H1> <!-- $autoremoveLine --> Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm 2009-10-08 16:48:27 UTC (rev 1568) @@ -3,7 +3,7 @@ PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN" "http://java.sun.com/products/javahelp/helpset_1_0.dtd"> -<helpset version="1.0"> +<helpset version="1.0" xml:lang="$locale"> <!-- $autoremoveLine --> @@ -13,7 +13,7 @@ <!-- maps --> <maps> <homeID>top</homeID> - <mapref location="$mapFileName"/> + <mapref location="$localePath/$mapFileName"/> </maps> <!-- views --> @@ -21,17 +21,17 @@ <name>TOC</name> <label>Table Of Contents</label> <type>javax.help.TOCView</type> - <data>$tocFileName</data> + <data>$localePath/$tocFileName</data> </view> <view> <name>Index</name> <label>Index</label> <type>javax.help.IndexView</type> - <data>$indexFileName</data> + <data>$localePath/$indexFileName</data> </view> -#if ( $!searchData != "" ) +#if ( $searchData ) <view> <name>Search</name> <label>Search</label> Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -7,7 +7,7 @@ @Test public void Bug_1751() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); assertNumberJaxxFiles(3); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -23,7 +23,7 @@ @Test public void Icon() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); checkPattern(mojo, ".createImageIcon(\"myIcon.png\")", true); checkPattern(mojo, ".createActionIcon(\"myActionIcon.png\")", true); @@ -40,7 +40,7 @@ @Test public void ClientProperty() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); checkPattern(mojo, ".putClientProperty(\"testOne\", \"oneTest\")", true); checkPattern(mojo, ".putClientProperty(\"testTwo\", \"anotherTest\")", true); @@ -60,7 +60,7 @@ @Test public void WithLog() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); String[] files = mojo.files; assertNumberJaxxFiles(2); @@ -85,7 +85,7 @@ @Test public void NoLog() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); assertNumberJaxxFiles(2); checkPattern(mojo, "Log log = LogFactory.getLog(", false); @@ -96,7 +96,7 @@ @SuppressWarnings({"unchecked"}) @Test public void Errors() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); // init mojo to get alls files to treate mojo.init(); @@ -160,7 +160,7 @@ @Test public void ErrorJaxxContextImplementorClass() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.jaxxContextFQN = null; try { mojo.init(); @@ -213,7 +213,7 @@ public void Force() throws Exception { // first round, with force option so will generate theonly JButton.jaxx file - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); String[] files = mojo.files; assertNumberJaxxFiles(1); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerValidatorTest.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerValidatorTest.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerValidatorTest.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -24,7 +24,7 @@ @SuppressWarnings({"unchecked"}) public void ValidatorErrors() throws Exception { // init mojo to get alls files to treate - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.init(); String[] files = mojo.files; assertNumberJaxxFiles(19); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DecoratorTest.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DecoratorTest.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DecoratorTest.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -6,7 +6,7 @@ @Test public void Decorator() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); assertNumberJaxxFiles(1); checkPattern(mojo, "root.add(jaxx.runtime.SwingUtil.boxComponentWithJxLayer(boxedButton))", true); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Evolution74Test.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Evolution74Test.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Evolution74Test.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -15,7 +15,7 @@ @Test public void ok() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.execute(); assertNumberJaxxFiles(6); @@ -38,7 +38,7 @@ @SuppressWarnings({"unchecked"}) @Test public void error() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); // init mojo to get alls files to treate mojo.init(); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/I18nTest.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/I18nTest.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/I18nTest.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -6,7 +6,7 @@ @Test public void I18nText() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.i18nable = false; mojo.execute(); checkPattern(mojo, "testId.setText(_(\"test.text\"));", false); @@ -19,7 +19,7 @@ @Test public void I18nTitle() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.i18nable = false; mojo.execute(); checkPattern(mojo, "testId.setTitle(_(\"test.title\"));", false); @@ -32,7 +32,7 @@ @Test public void I18nToolTipText() throws Exception { - JaxxGeneratorMojo mojo = getMojo(); + GenerateMojo mojo = getMojo(); mojo.i18nable = false; mojo.execute(); checkPattern(mojo, "testId.setToolTipText(_(\"test.toolTipText\"));", false); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java 2009-10-07 21:03:42 UTC (rev 1567) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java 2009-10-08 16:48:27 UTC (rev 1568) @@ -15,9 +15,9 @@ * * @author chemit * @see AbstractMojoTest - * @see JaxxGeneratorMojo + * @see GenerateMojo */ -public abstract class JaxxBaseTest extends AbstractMojoTest<JaxxGeneratorMojo> { +public abstract class JaxxBaseTest extends AbstractMojoTest<GenerateMojo> { @Override protected String getGoalName(String methodName) { @@ -25,7 +25,7 @@ } @Override - protected void setUpMojo(JaxxGeneratorMojo mojo, File pomFile) throws Exception { + protected void setUpMojo(GenerateMojo mojo, File pomFile) throws Exception { super.setUpMojo(mojo, pomFile); mojo.jaxxContextFQN = DefaultJAXXContext.class.getName(); mojo.compilerFQN = jaxx.compiler.JAXXCompiler.class.getName(); @@ -33,7 +33,7 @@ mojo.defaultDecoratorFQN = jaxx.compiler.decorators.DefaultCompiledObjectDecorator.class.getName(); } - protected void checkPattern(JaxxGeneratorMojo mojo, String pattern, boolean required, String... files) throws IOException { + protected void checkPattern(GenerateMojo mojo, String pattern, boolean required, String... files) throws IOException { if (files.length == 0) { files = mojo.files; }