[Buix-commits] r745 - in trunk/lutinjaxx: . jaxx-swing-action/src/main/java/org/codelutin/jaxx/action maven maven/src/main/java maven/src/main/java/org maven/src/main/java/org/codelutin maven/src/main/java/org/codelutin/jaxx
Author: tchemit Date: 2008-07-21 00:25:38 +0000 (Mon, 21 Jul 2008) New Revision: 745 Added: trunk/lutinjaxx/maven/src/main/java/org/ trunk/lutinjaxx/maven/src/main/java/org/codelutin/ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java trunk/lutinjaxx/maven/pom.xml trunk/lutinjaxx/pom.xml Log: utilisation org.codelutin:lutinutil en 0.30-SNAPSHOT mise en place d'un goal de generation des mappings d'actions Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java 2008-07-20 22:16:56 UTC (rev 744) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java 2008-07-21 00:25:38 UTC (rev 745) @@ -75,19 +75,19 @@ public abstract String largeIcon() default ""; /** - * @return + * @return accelerator * @see javax.swing.Action#ACCELERATOR_KEY */ public abstract String accelerator() default ""; /** - * @return + * @return mnemonic key * @see javax.swing.Action#MNEMONIC_KEY */ public abstract int mnemonic() default '\0'; /** - * @return + * @return mnemonic key index * @see javax.swing.Action#DISPLAYED_MNEMONIC_INDEX_KEY */ public abstract int displayedMnemonicIndex() default '\0'; @@ -99,16 +99,15 @@ public abstract boolean selected() default false; /** - * @return + * @return enabled state * @see javax.swing.Action#isEnabled() */ public abstract boolean enabled() default true; - /** - * @return - * @see javax.swing.Action#isEnabled() - */ + /** @return hideActionText state */ public abstract boolean hideActionText() default false; + /** @return array of names to be used in actions mapping */ + public abstract String[] multiNames() default {}; } \ No newline at end of file Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java 2008-07-20 22:16:56 UTC (rev 744) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java 2008-07-21 00:25:38 UTC (rev 745) @@ -63,7 +63,7 @@ public abstract String longDescription() default ""; /** - * @return + * @return accelerator key * @see javax.swing.Action#ACCELERATOR_KEY */ public abstract String accelerator() default ""; @@ -75,9 +75,12 @@ public abstract int selectedIndex() default 0; /** - * @return + * @return enabled state * @see javax.swing.Action#isEnabled() */ public abstract boolean enabled() default true; + /** @return array of names to be used in actions mapping */ + public abstract String[] multiNames() default {}; + } \ No newline at end of file Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java 2008-07-20 22:16:56 UTC (rev 744) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java 2008-07-21 00:25:38 UTC (rev 745) @@ -74,13 +74,13 @@ public abstract String largeIcon() default ""; /** - * @return + * @return accelerator key of default state * @see javax.swing.Action#ACCELERATOR_KEY */ public abstract String accelerator() default ""; /** - * @return + * @return mnemonic key of default state * @see javax.swing.Action#MNEMONIC_KEY */ public abstract int mnemonic() default '\0'; @@ -116,13 +116,13 @@ public abstract String largeIcon2() default ""; /** - * @return + * @return accelerator key of default state * @see javax.swing.Action#ACCELERATOR_KEY */ public abstract String accelerator2() default ""; /** - * @return + * @return mnemonic key of second state * @see javax.swing.Action#MNEMONIC_KEY */ public abstract int mnemonic2() default '\0'; @@ -134,15 +134,14 @@ public abstract boolean selected() default false; /** - * @return + * @return enaled state * @see javax.swing.Action#isEnabled() */ public abstract boolean enabled() default true; - /** - * @return - * @see javax.swing.Action#isEnabled() - */ + /** @return hideActionText state */ public abstract boolean hideActionText() default false; + /** @return array of names to be used in actions mapping */ + public abstract String[] multiNames() default {}; } \ No newline at end of file Modified: trunk/lutinjaxx/maven/pom.xml =================================================================== --- trunk/lutinjaxx/maven/pom.xml 2008-07-20 22:16:56 UTC (rev 744) +++ trunk/lutinjaxx/maven/pom.xml 2008-07-21 00:25:38 UTC (rev 745) @@ -19,13 +19,27 @@ <name>maven plugin</name> <dependencies> + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutinutil</artifactId> + <scope>compile</scope> + </dependency> + + <dependency> <groupId>org.codelutin.jaxx</groupId> <artifactId>core</artifactId> <scope>compile</scope> </dependency> + <dependency> <groupId>org.codelutin.jaxx</groupId> + <artifactId>jaxx-swing-action</artifactId> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.codelutin.jaxx</groupId> <artifactId>jaxx-swing</artifactId> <scope>test</scope> </dependency> Added: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java =================================================================== --- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java (rev 0) +++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java 2008-07-21 00:25:38 UTC (rev 745) @@ -0,0 +1,331 @@ +/* *##% + * 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.codelutin.jaxx; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.DirectoryScanner; +import static org.codelutin.i18n.I18n._; +import org.codelutin.jaxx.action.ActionConfig; +import org.codelutin.jaxx.action.SelectActionConfig; +import org.codelutin.jaxx.action.ToggleActionConfig; +import org.codelutin.util.SortedProperties; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Properties; +import java.util.Set; + +/** + * Classe permettant de generer le fichier de propri�t�s des actions d�tect�es. + * + * @author chemit + * @goal generate-actions + * @phase process-classes + */ +public class ActionGeneratorGoal extends AbstractMojo { + + /** + * @description D�pendance du projet. + * @parameter default-value="${project}" + * @readonly + */ + protected MavenProject project; + + /** + * @description R�pertoire sources des fichiers java � traiter. + * @parameter expression="${jaxx.src}" default-value="${basedir}/src/main/java" + */ + protected File src; + + /** + * @description Nom du fichier destination � g�n�rer. + * @parameter expression="${jaxx.out}" default-value="${basedir}/src/main/resources/jaxx/${project.artifactId}-actions.properties" + */ + protected File out; + + /** + * @description Nom du fichier destination � g�n�rer. + * @parameter expression="${jaxx.cp}" default-value="${basedir}/target/classes" + */ + protected File cp; + + + /** + * @description pour filter + * @parameter expression="${jaxx.includes}" + */ + protected String[] includes; + + /** + * @description pour filter + * @parameter expression="${jaxx.excludes}" + */ + protected String[] excludes; + + /** + * @description verbose + * @parameter expression="${jaxx.verbose}" default-value="false" + */ + protected boolean verbose; + + protected String[] files; + + private static final String[] INCLUDES = {"**\\/*.java"}; + + private ClassLoader loader; + + public void execute() throws MojoExecutionException, MojoFailureException { + + init(); + if (verbose) { + printInit(); + } + + Properties result = loadProperties(); + + try { + saveProperties(result); + } catch (IOException e) { + + throw new MojoExecutionException(e.getMessage(), e); + } + + } + + protected void saveProperties(Properties result) throws IOException { + OutputStream writer = null; + try { + writer = new org.codelutin.util.PropertiesDateRemoveFilterStream(new java.io.FileOutputStream(out)); + + result.store(writer, null); + + } finally { + if (writer != null) { + + writer.flush(); + writer.close(); + + } + } + } + + protected Properties loadProperties() { + Properties result = new SortedProperties(); + for (String file : files) { + String fqn = file.substring(0, file.length() - 5).replaceAll("\\/", "."); + + if (getLog().isDebugEnabled()) { + getLog().debug("fqn to treate " + fqn); + } + + try { + Class<?> clazz = Class.forName(fqn, false, loader); + + // try a ActionConfig + ActionConfig actionConfig = clazz.getAnnotation(ActionConfig.class); + if (actionConfig != null) { + if (actionConfig.multiNames().length > 0) { + // multinames + registerEntry(clazz, result, actionConfig.multiNames()); + continue; + } + + if (!actionConfig.actionCommand().isEmpty()) { + registerEntry(clazz, result, actionConfig.actionCommand()); + continue; + } + + getLog().warn("could not treate class " + clazz); + continue; + } + + // try a SelectActionConfig + SelectActionConfig selectActionConfig = clazz.getAnnotation(SelectActionConfig.class); + if (selectActionConfig != null) { + if (selectActionConfig.multiNames().length > 0) { + // multinames + registerEntry(clazz, result, selectActionConfig.multiNames()); + continue; + } + + if (!selectActionConfig.actionCommand().isEmpty()) { + registerEntry(clazz, result, selectActionConfig.actionCommand()); + continue; + } + getLog().warn("could not treate class " + clazz); + continue; + } + // try a toggleAction + ToggleActionConfig toggleActionConfig = clazz.getAnnotation(ToggleActionConfig.class); + if (toggleActionConfig != null) { + if (toggleActionConfig.multiNames().length > 0) { + // multinames + registerEntry(clazz, result, toggleActionConfig.multiNames()); + continue; + } + + if (!toggleActionConfig.actionCommand().isEmpty()) { + registerEntry(clazz, result, toggleActionConfig.actionCommand()); + continue; + } + + getLog().warn("could not treate class " + clazz); + } + + } catch (ClassNotFoundException e) { + getLog().error("could not find class " + e.getMessage()); + } + } + return result; + } + + public File getSrc() { + return src; + } + + public File getOut() { + return out; + } + + public String[] getIncludes() { + return includes; + } + + public void setOut(File out) { + this.out = out; + } + + public void setSrc(File src) { + this.src = src; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public void setIncludes(String[] includes) { + this.includes = includes; + } + + public String[] getFiles() { + return files; + } + + protected void init() { + DirectoryScanner ds; + ds = new DirectoryScanner(); + ds.setBasedir(getSrc()); + boolean noIncludes = includes == null || includes.length == 0; + ds.setIncludes(noIncludes ? INCLUDES : includes); + boolean noExcludes = excludes == null || excludes.length == 0; + if (!noExcludes) { + ds.setExcludes(excludes); + } + ds.scan(); + files = ds.getIncludedFiles(); + + getLog().info("jaxx - found " + files.length + " file(s) to generate. "); + + loader = initClassLoader(project, getLog()); + } + + protected void registerEntry(Class<?> clazz, Properties result, String... names) { + for (String name : names) { + if (getLog().isDebugEnabled()) { + getLog().debug("name: " + name + ", class:" + clazz); + } + result.put("action." + name, clazz.getName()); + } + } + + protected void printInit() { + + for (String file : files) { + getLog().debug(file); + } + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + + getLog().debug(cl.toString()); + if (cl.getClass().getSimpleName().equals("RealmClassLoader")) { + try { + java.lang.reflect.Method m = cl.getClass().getDeclaredMethod("getURLs"); + m.setAccessible(true); + URL[] urls = (URL[]) m.invoke(cl); + + for (URL url : urls) { + getLog().debug("ulr in class loader " + url); + } + } catch (Exception e) { + getLog().warn("??? : " + e.getMessage(), e); + } + } + } + + @SuppressWarnings({"unchecked"}) + protected URLClassLoader initClassLoader(MavenProject project, Log log) { + URLClassLoader loader = null; + if (project != null) { + URLClassLoader result; + try { + Set<Artifact> compileClasspathElements = project.getArtifacts(); + URL[] url = new URL[compileClasspathElements.size() + 1]; + url[0] = cp.toURI().toURL(); + int i = 1; + for (Artifact artifact : compileClasspathElements) { + File file = new File(artifact.getFile().getAbsolutePath()); + if (file.getName().endsWith(".jar")) { + url[i] = new URL("jar", "", file.toURI().toURL().toString() + "!/"); + } else { + url[i] = file.toURI().toURL(); + } + i++; + } + //ClassLoader parent = Thread.currentThread().getContextClassLoader(); + if (compileClasspathElements.size() == 0) { + result = new URLClassLoader(url, getClass().getClassLoader()); + } else { + result = new URLClassLoader(url, getClass().getClassLoader()); + } + } catch (MalformedURLException eee) { + throw new RuntimeException(_("Can't create ClassLoader for script, bad directory: {0} for reason {1}", getOut(), eee.getMessage()), eee); + } catch (IOException e) { + throw new RuntimeException(_("Can't create ClassLoader for script, bad directory: {0} for reason {1}", getOut(), e.getMessage()), e); + } + loader = result; + } + if (log.isDebugEnabled() && loader != null) { + for (URL entry : loader.getURLs()) { + log.info("cp url " + entry); + } + } + return loader; + } + + +} \ No newline at end of file Modified: trunk/lutinjaxx/pom.xml =================================================================== --- trunk/lutinjaxx/pom.xml 2008-07-20 22:16:56 UTC (rev 744) +++ trunk/lutinjaxx/pom.xml 2008-07-21 00:25:38 UTC (rev 745) @@ -30,7 +30,7 @@ <dependencies> <dependency> - <groupId>lutinlib</groupId> + <groupId>org.codelutin</groupId> <artifactId>lutinutil</artifactId> </dependency> </dependencies> @@ -174,9 +174,9 @@ <dependencyManagement> <dependencies> <dependency> - <groupId>lutinlib</groupId> + <groupId>org.codelutin</groupId> <artifactId>lutinutil</artifactId> - <version>0.29</version> + <version>0.30-SNAPSHOT</version> </dependency> <dependency>
participants (1)
-
tchemit@users.labs.libre-entreprise.org