r2015 - trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl
Author: tchemit Date: 2014-02-03 12:38:28 +0100 (Mon, 03 Feb 2014) New Revision: 2015 Url: http://nuiton.org/projects/i18n/repository/revisions/2015 Log: fixes #3020: Remove deprecated parser (jsp and tapestry) Removed: trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java Deleted: trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java =================================================================== --- trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java 2013-08-09 09:04:00 UTC (rev 2014) +++ trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java 2014-02-03 11:38:28 UTC (rev 2015) @@ -1,317 +0,0 @@ -/* - * #%L - * I18n :: Maven Plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2007 - 2010 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.i18n.plugin.parser.impl; - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.nuiton.i18n.plugin.parser.I18nSourceEntry; -import org.nuiton.i18n.plugin.parser.SourceEntry; -import org.nuiton.io.FileUpdater; -import org.nuiton.io.MirroredFileUpdater; -import org.nuiton.plugin.PluginHelper; -import org.nuiton.processor.ProcessorUtil; -import org.nuiton.processor.filters.DefaultFilter; -import org.nuiton.processor.filters.Filter; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.xpath.XPath; -import java.io.File; -import java.io.IOException; - -/** - * Find i18n keys from jsp files. - * <p/> - * <b>Note: </b> this goal must always be invoked before the {@code process-resources} - * phase, otherwise all files will be considered as uptodate. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - * @deprecated since 2.5, hard to maintain jsp as valid xml docs. Will be removed soon - */ -@Mojo(name = "parserJsp", defaultPhase = LifecyclePhase.GENERATE_RESOURCES) -public class ParserJspMojo extends AbstractParserXmlMojo { - - public static final String DEFAULT_INCLUDES = "**/*.jsp"; - - /** - * Root directory of the default entry. - * - * @since 2.0 - */ - @Parameter(property = "i18n.defaultBasedir", defaultValue = "${basedir}/src/main/webapp", required = true) - protected File defaultBasedir; - - /** - * Default included files to process (ant-like expression). - * <p/> - * <strong>Note:</strong> default value is **\/*.jsp - * - * @since 2.0 - */ - @Parameter(property = "i18n.defaultIncludes", defaultValue = DEFAULT_INCLUDES, required = true) - protected String defaultIncludes; - - /** - * Defines the core rules file used to detect i18n keys in jsp files. - * <p/> - * <b>Note :</b> If you do not want to use it, set it to empty and fill the - * {@link #userRulesFiles} parameter. - * - * @since 2.0 - */ - @Parameter(property = "i18n.coreRuleFile") - protected String coreRuleFile; - - /** - * Defines the file name of the getter where to put detected i18n keys - * while getter phase. - * - * @since 2.0 - */ - @Parameter(property = "i18n.outputGetter", defaultValue = "jsp.getter", required = true) - protected String outputGetter; - - /** - * Where to generated temporary processed files. - * - * @since 2.0 - */ - @Parameter(property = "i18n.workdir", defaultValue = "${basedir}/target/i18n-workdir", required = true) - protected File workdir; - - @Override - public String[] getDefaultIncludes() { - return new String[]{defaultIncludes}; - } - - @Override - public String[] getDefaultExcludes() { - return I18nSourceEntry.EMPTY_STRING_ARRAY; - } - - @Override - public File getDefaultBasedir() { - return defaultBasedir; - } - - MirroredFileUpdater entryUpdater; - - @Override - protected boolean onEnterEntry(I18nSourceEntry entry) { - boolean b = super.onEnterEntry(entry); - if (!b) { - - // no skipped entry - // keep the file updater - entryUpdater = (MirroredFileUpdater) entry.getUpdater(); - } - return b; - } - - @Override - public FileUpdater newFileUpdater(SourceEntry entry) { - return new MirroredFileUpdater("", "", entry.getBasedir(), workdir) { - - @Override - public File getMirrorFile(File f) { - String file = - f.getAbsolutePath().substring(prefixSourceDirecotory); - return new File(destinationDirectory + File.separator + file + "~"); - } - }; - } - - @Override - protected String getOutGetter() { - return outputGetter; - } - - @Override - protected String getCoreRuleFile() { - return coreRuleFile; - } - - protected XmlFileParser newXmlFileParser(final XPath xpath, - final DocumentBuilder builder) { - - return new XmlFileParser(getLog(), - encoding, - oldParser, - acceptPattern, - showTouchedFiles, - rules, - xpath, - builder, - namespaces, - isVerbose()) { - - @Override - public File prepareFile(File file) throws IOException { - - // clean the jsp to make it xml - - File result = entryUpdater.getMirrorFile(file); - createDirectoryIfNecessary(result.getParentFile()); - JspFileProcessor processor = new JspFileProcessor(); - processor.process(file, result, getEncoding()); - String resultFileContent = - PluginHelper.readAsString(result, getEncoding()); - resultFileContent = resultFileContent.trim(); - - if (StringUtils.isBlank(resultFileContent)) { - - // nothing to scan inside this file - result = null; - } else { - - if (resultFileContent.startsWith("<html") || - resultFileContent.startsWith("<HTML") || - resultFileContent.startsWith("<?xml") - ) { - - // document should be well-formed... - - } else { - // to be sure, document is well formed, add a start and end tag - resultFileContent = "<div>\n" + resultFileContent + "\n</div>"; - - PluginHelper.writeString(result, resultFileContent, getEncoding()); - } - - } - - return result; - } - - @Override - public String extract(String i18nString) { - String s = null; - if (!StringUtils.isEmpty(i18nString.trim())) { - s = i18nString.trim(); - } - if (getLog().isDebugEnabled()) { - getLog().debug(i18nString + " = " + s); - } - return s; - } - - }; - } - - /** - * To transform jsp files to valid xml files. - * <p/> - * Says : - * <ul> - * <li>Remove jsp directive</li> - * <li>Remove jsp comment</li> - * <li>Remove any tags in attributes (used for example in struts)</li> - * <li>? Other thing</li> - * </ul> - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ - public static class JspFileProcessor extends ProcessorHelper.AbstractParserProcessor { - - protected ProcessorHelper.FragmentRemover remover1 = - new ProcessorHelper.FragmentRemover( - "<" + "%" + "-" + "-", - "-" + "-" + "%" + ">" - ); - - protected ProcessorHelper.FragmentRemover remover2 = - new ProcessorHelper.FragmentRemover( - "<" + "%", - "%" + ">" - ); - - protected ProcessorHelper.FragmentRemover remover3 = - new ProcessorHelper.FragmentRemover( - "<" + "!" + "-" + "-", - "-" + "-" + ">" - ); - - public JspFileProcessor() { - setInputFilter( - new Filter[]{ - remover1, - remover2, - remover3, - new JspAttributeWithTagFilter() - } - ); - } - - /** - * @param filein the source file to process - * @param fileout the output file to generate - * @param encoding encoding used to read and write files - * @throws IOException if any io problems while processing - * @since 1.0.4 - */ - @Override - public void process(File filein, - File fileout, - String encoding) throws IOException { - ProcessorUtil.doProcess(this, filein, fileout, encoding); - } - - /** - * To remove in attributes any sub tags inside it (used for example in - * struts) from jsp files. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ - public static class JspAttributeWithTagFilter extends DefaultFilter { - - private String header = "=" + "\"" + "<"; - - private String footer = "\"" + "/" + ">" + "\""; - - @Override - protected String performInFilter(String ch) { - return "=\"\""; - } - - @Override - protected String performOutFilter(String ch) { - return ch; - } - - protected String getHeader() { - return header; - } - - protected String getFooter() { - return footer; - } - } - } -} Deleted: trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java =================================================================== --- trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2013-08-09 09:04:00 UTC (rev 2014) +++ trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2014-02-03 11:38:28 UTC (rev 2015) @@ -1,299 +0,0 @@ -/* - * #%L - * I18n :: Maven Plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.i18n.plugin.parser.impl; - -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.nuiton.i18n.plugin.parser.AbstractFileParser; -import org.nuiton.i18n.plugin.parser.AbstractI18nParserMojo; -import org.nuiton.i18n.plugin.parser.FileParser; -import org.nuiton.i18n.plugin.parser.I18nSourceEntry; -import org.nuiton.i18n.plugin.parser.ParserException; -import org.nuiton.i18n.plugin.parser.SourceEntry; -import org.nuiton.io.FileUpdater; -import org.nuiton.io.MirroredFileUpdater; -import org.nuiton.io.SortedProperties; -import org.nuiton.processor.ProcessorUtil; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Pattern; - -/** - * To parse Tapestry templates to detect new I18n keys, says content of patterns : - * {@code ${message:XXX}} and {@code ${format:XXX=...}}. - * <p/> - * <p/> - * <b>Note: </b> this goal must always be invoked before the {@code process-resources} - * phase, otherwise all files will be considered as uptodate. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.1 - * @deprecated since 2.5, Not very usefull, since not very efficient, will be removed soon. - */ -@Mojo(name = "parserTapestry", defaultPhase = LifecyclePhase.GENERATE_RESOURCES) -public class ParserTapestryMojo extends AbstractI18nParserMojo { - - public static final String DEFAULT_INCLUDES = "**/*.tml"; - - /** - * Root directory of the default entry. - * - * @since 2.1 - */ - @Parameter(property = "i18n.defaultBasedir", defaultValue = "${basedir}/src/main/webapp", required = true) - protected File defaultBasedir; - - /** - * Default included files to process (ant-like expression). - * <p/> - * <strong>Note:</strong> default value is **\/*.tml - * - * @since 2.1 - */ - @Parameter(property = "i18n.defaultIncludes", defaultValue = DEFAULT_INCLUDES, required = true) - protected String defaultIncludes; - - /** - * Defines the file name of the getter where to put detected i18n keys - * while getter phase. - * - * @since 2.1 - */ - @Parameter(property = "i18n.outputGetter", defaultValue = "tapestry.getter", required = true) - protected String outputGetter; - - /** - * Where to generated temporary processed files. - * - * @since 2.1 - */ - @Parameter(property = "i18n.workdir", defaultValue = "${basedir}/target/i18n-workdir") - protected File workdir; - - protected MirroredFileUpdater entryUpdater; - - @Override - public String[] getDefaultIncludes() { - return new String[]{defaultIncludes}; - } - - @Override - public String[] getDefaultExcludes() { - return I18nSourceEntry.EMPTY_STRING_ARRAY; - } - - @Override - public File getDefaultBasedir() { - return defaultBasedir; - } - - @Override - protected boolean onEnterEntry(I18nSourceEntry entry) { - boolean b = super.onEnterEntry(entry); - if (!b) { - - // no skipped entry - // keep the file updater - entryUpdater = (MirroredFileUpdater) entry.getUpdater(); - } - return b; - } - - @Override - public FileUpdater newFileUpdater(SourceEntry entry) { - return new MirroredFileUpdater("", "", entry.getBasedir(), workdir) { - - @Override - public File getMirrorFile(File f) { - String file = - f.getAbsolutePath().substring(prefixSourceDirecotory); - return new File(destinationDirectory + File.separator + file); - } - }; - } - - @Override - protected String getOutGetter() { - return outputGetter; - } - - @Override - public FileParser newFileParser(Pattern acceptPattern) { - - return new TapestryFileParser(getLog(), - encoding, - oldParser, - acceptPattern, - isShowTouchedFiles() - ); - } - - protected class TapestryFileParser extends AbstractFileParser { - - - public TapestryFileParser(Log log, - String encoding, - SortedProperties oldParser, - Pattern acceptKeyPattern, - boolean showTouchedFiles) { - super(log, encoding, oldParser, acceptKeyPattern, showTouchedFiles); - } - - - protected File prepareFile(File file) throws IOException { - - // clean the jsp to make it xml - - File result = entryUpdater.getMirrorFile(file); - if (isVerbose()) { - getLog().info("Will process [" + file + "] to " + result); - } - try { - createDirectoryIfNecessary(result.getParentFile()); - } catch (IOException e) { - // don't care about it... - } - TapestryFileProcessor processor = new TapestryFileProcessor(); - processor.setVerbose(isVerbose()); - processor.process(file, result, getEncoding()); - return result; - } - - @Override - public void parseFile(File file) throws IOException { - - // clean the jsp to make it xml - - File processedFile = prepareFile(file); - - // process file to obtain - String line = null; - LineNumberReader lnr = new LineNumberReader(new InputStreamReader( - new FileInputStream(processedFile), getEncoding())); - try { - while ((line = lnr.readLine()) != null) { - parseLine(processedFile, line); - } - } catch (Exception e) { - if (line != null) { - getLog().error( - "could not parse line (" + lnr.getLineNumber() + ") '" - + line + "' of file " + file); - } - throw new ParserException(e); - } finally { - lnr.close(); - } - } - - @Override - public void parseLine(File file, String line) throws IOException { - - String key = line.trim(); - - if (key.isEmpty()) { - // no key detected on this line - return; - } - -// // one key found in file, so file is marked as touched -// setTouched(true); - // Found a i18n key, register it. - if (getLog().isDebugEnabled()) { - getLog().debug(file.getName() + " detected key = " + key); - } - registerKey(key); - } - } - - /** - * To Extract i18n keys from tapestry template files. - * <p/> - * Says : - * <ul> - * <li>Remove all xml comments</li> - * <li>Keep content of {@code ${message:XXX}}</li> - * <li>Keep content of {@code ${format:XXX}}}</li> - * </ul> - * - * @author tchemit <chemit@codelutin.com> - * @since 2.1 - */ - public static class TapestryFileProcessor extends ProcessorHelper.AbstractParserProcessor { - - protected ProcessorHelper.FragmentRemover remover1 = - new ProcessorHelper.FragmentRemover( - "<" + "!" + "-" + "-", - "-" + "-" + ">" - ); - - protected ProcessorUtil.FragmentExtractor extractor1 = - new ProcessorUtil.FragmentExtractor( - "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":", - "}" - ); - - protected ProcessorUtil.FragmentExtractor extractor2 = - new ProcessorUtil.FragmentExtractor( - "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":", - "}") { - - @Override - protected String performInFilter(String ch) { - int i = ch.indexOf('='); - if (verbose) { - log.info("Detected key " + ch); - } - if (i == -1) { - return ""; - } - return ch.substring(0, i) + "\n"; - } - }; - - - public void process(File filein, - File fileout, - String encoding) throws IOException { - - // remove comment fragments - File fileTemp = new File(fileout.getAbsolutePath() + "-no-comment"); - removefragments(remover1, filein, fileTemp, encoding, false); - - Set<String> keys = new HashSet<String>(); - extractKeys(extractor1, fileTemp, encoding, verbose, keys); - extractKeys(extractor2, fileTemp, encoding, verbose, keys); - saveKeysToFile(fileout, keys); - } - } -}
participants (1)
-
tchemit@users.nuiton.org