[bspell commit] r7 - in trunk: . extensions extensions/maven-bspell-plugin extensions/maven-bspell-plugin/src ext...

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 17, 2007, 4:28:19 AM8/17/07
to bsp...@googlegroups.com
Author: maomaode
Date: Fri Aug 17 01:27:30 2007
New Revision: 7

Added:
trunk/extensions/
trunk/extensions/maven-bspell-plugin/
trunk/extensions/maven-bspell-plugin/pom.xml
trunk/extensions/maven-bspell-plugin/src/
trunk/extensions/maven-bspell-plugin/src/main/
trunk/extensions/maven-bspell-plugin/src/main/java/
trunk/extensions/maven-bspell-plugin/src/main/java/com/
trunk/extensions/maven-bspell-plugin/src/main/java/com/google/
trunk/extensions/maven-bspell-plugin/src/main/java/com/google/bspell/
trunk/extensions/maven-bspell-plugin/src/main/java/com/google/bspell/BSpellMojo.java
trunk/src/main/java/com/google/bspell/model/SpellConfiguration.java
Removed:
trunk/src/main/java/com/google/bspell/model/Configuration.java
Modified:
trunk/build.xml
trunk/src/main/java/com/google/bspell/BSpellCheck.java
trunk/src/main/java/com/google/bspell/ant/BSpellTask.java
trunk/src/main/java/com/google/bspell/parsers/ParserFactory.java

Log:
* Maven plugin
* Rename the Configuration
* Clean up the build

Modified: trunk/build.xml
==============================================================================
--- trunk/build.xml (original)
+++ trunk/build.xml Fri Aug 17 01:27:30 2007
@@ -1,4 +1,4 @@
-<project name="bspell" default="clean" basedir="." xmlns:fant="antlib:com.google.ant.extensions">
+<project name="bspell" default="all" basedir="." xmlns:fant="antlib:com.google.ant.extensions">

<property name="fant.etc.dir" value="${ant.home}/etc/fant"/>

@@ -12,24 +12,9 @@
<dependency groupid="suggester" artifactid="suggester" version="1.0.0"/>
</fant:dependencies>

-
- <target name="spell.check">
- <taskdef name="bspell" classname="com.google.bspell.ant.BSpellTask" classpathref="classpath"/>
- <bspell>
- <configuration spellCheckConfig="${fant.etc.dir}/bspell/spellCheck.config"
- format="console"
- dictionary="${fant.etc.dir}/bspell/english.jar"
- reservedDict="${fant.etc.dir}/bspell/reserved.dict"
- registry="${fant.etc.dir}/bspell/registry.txt"/>
- <fileset dir="${src.main.java.dir}" includes="**/*.java **/*.properties"/>
- <fileset dir="${src.main.resources.dir}" includes="**/*.xml"/>
- </bspell>
- </target>
-
- <target name="bspell">
- <antcall target="java.run">
- <param name="class.name" value="com.google.bspell.Main"/>
- </antcall>
+ <target name="deploy">
+ <fant:install destdir="${ant.home}/lib"/>
</target>

+ <target name="all" depends="clean,test,install,deploy"/>
</project>

Added: trunk/extensions/maven-bspell-plugin/pom.xml
==============================================================================
--- (empty file)
+++ trunk/extensions/maven-bspell-plugin/pom.xml Fri Aug 17 01:27:30 2007
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+
+ <parent>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugins</artifactId>
+ <version>8</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-bspell-plugin</artifactId>
+ <version>0.1</version>
+ <packaging>maven-plugin</packaging>
+ <name>Maven bSpell Plugin</name>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.4.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.bspell</groupId>
+ <artifactId>bspell</artifactId>
+ <version>0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>suggester</groupId>
+ <artifactId>suggester</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
\ No newline at end of file

Added: trunk/extensions/maven-bspell-plugin/src/main/java/com/google/bspell/BSpellMojo.java
==============================================================================
--- (empty file)
+++ trunk/extensions/maven-bspell-plugin/src/main/java/com/google/bspell/BSpellMojo.java Fri Aug 17 01:27:30 2007
@@ -0,0 +1,152 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.google.bspell;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.bspell.BSpellCheck;
+import com.google.bspell.model.SpellConfiguration;
+import com.google.bspell.model.Word;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
+import java.util.Iterator;
+
+/**
+ * A spell check mojo
+ *
+ * @goal bspell
+ * @description Spell check the source files
+ * @requiresDependencyResolution test
+ */
+
+public class BSpellMojo extends AbstractMojo {
+ /**
+ * The Maven Project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * @component
+ */
+ protected ArtifactFactory artifactFactory;
+
+ /**
+ * Build directory
+ *
+ * @parameter expression="${project.build.outputDirectory}"
+ * @required
+ */
+ private File buildDirectory;
+
+ /**
+ * Base directory of the project.
+ * @parameter expression="${basedir}"
+ */
+ private File baseDirectory;
+
+ /**
+ * A set of file patterns to include.
+ * @parameter property="includes"
+ */
+ private String[] includes;
+
+ /**
+ * A set of file patterns to exclude.
+ * @parameter property="excludes"
+ */
+ private String[] excludes;
+
+ /**
+ * A set of file patterns to exclude.
+ * @parameter property="spellConfiguration"
+ */
+ private SpellConfiguration config;
+
+ public void setSpellConfiguration(SpellConfiguration c) {
+ this.config = c;
+ }
+
+ public void execute() throws MojoExecutionException {
+ System.out.println("==== " + config.getFormat() + " == " + config.getRegistry());
+ System.out.println("includes: " + Arrays.asList(includes));
+ try {
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setIncludes(includes);
+ ds.setExcludes(excludes);
+ ds.setBasedir(baseDirectory);
+ ds.setCaseSensitive(true);
+ ds.scan();
+ String[] files = ds.getIncludedFiles();
+
+ BSpellCheck checker = new BSpellCheck();
+ checker.init(this.config);
+
+ Map failures = new HashMap();
+
+ try {
+ for (int i = 0; i < files.length; i++) {
+ File source = new File(baseDirectory, files[i]);
+ List failed = checker.check(source);
+ if (!failed.isEmpty()) {
+ failures.put(source, failed);
+ }
+ }
+
+ System.out.println("Summary:");
+ System.out.println("Processed " + files.length + " file(s), Found misspelt in " + failures.size() + " file(s)");
+ dumpResults(failures);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ } catch (Exception e) {
+ getLog().debug(e);
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ private void dumpResults(Map failures) {
+ if (config.getFormat() == null || "console".equals(config.getFormat())) {
+ System.out.println("bSpell check reports: ");
+ for (Iterator iter = failures.keySet().iterator(); iter.hasNext();) {
+ File file = (File) iter.next();
+ System.out.println("=========================");
+ System.out.println("file: " + file);
+ System.out.println("=========================");
+ for (Iterator iter1 = ((List)failures.get(file)).iterator(); iter1.hasNext();) {
+ Word word = (Word) iter1.next();
+ System.out.println("*" + word.getValue().toString() + "* locations ---> " + word.getLocations() + " suggestion(s) ---> " + word.getSuggestions());
+ }
+ }
+ }
+ }
+}

Modified: trunk/src/main/java/com/google/bspell/BSpellCheck.java
==============================================================================
--- trunk/src/main/java/com/google/bspell/BSpellCheck.java (original)
+++ trunk/src/main/java/com/google/bspell/BSpellCheck.java Fri Aug 17 01:27:30 2007
@@ -7,7 +7,7 @@
import java.util.List;
import java.util.StringTokenizer;

-import com.google.bspell.model.Configuration;
+import com.google.bspell.model.SpellConfiguration;
import com.google.bspell.model.Word;
import com.google.bspell.parsers.Parser;
import com.google.bspell.parsers.ParserFactory;
@@ -21,13 +21,13 @@
import com.softcorporation.suggester.util.SpellCheckConfiguration;

public class BSpellCheck {
- private Configuration config;
+ private SpellConfiguration config;
private SpellCheck spellCheck;

public BSpellCheck() {
}

- public void init(final Configuration c) {
+ public void init(final SpellConfiguration c) {
this.config = c;

BasicDictionary dictionary = new BasicDictionary("file://" + config.getDictionary());

Modified: trunk/src/main/java/com/google/bspell/ant/BSpellTask.java
==============================================================================
--- trunk/src/main/java/com/google/bspell/ant/BSpellTask.java (original)
+++ trunk/src/main/java/com/google/bspell/ant/BSpellTask.java Fri Aug 17 01:27:30 2007
@@ -8,7 +8,7 @@
import java.util.Vector;

import com.google.bspell.BSpellCheck;
-import com.google.bspell.model.Configuration;
+import com.google.bspell.model.SpellConfiguration;
import com.google.bspell.model.Word;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
@@ -22,9 +22,9 @@
protected Vector rcs = new Vector();
protected boolean failonerror = true;

- private Configuration config;
+ private SpellConfiguration config;

- public void addConfiguration(Configuration c) {
+ public void addSpellConfiguration(SpellConfiguration c) {
this.config = c;
}

Added: trunk/src/main/java/com/google/bspell/model/SpellConfiguration.java
==============================================================================
--- (empty file)
+++ trunk/src/main/java/com/google/bspell/model/SpellConfiguration.java Fri Aug 17 01:27:30 2007
@@ -0,0 +1,119 @@
+package com.google.bspell.model;
+
+public class SpellConfiguration {
+
+ /**
+ * Describe dictionary here.
+ */
+ private String dictionary;
+
+ /**
+ * Describe reservedDict here.
+ */
+ private String reservedDict;
+
+ /**
+ * Describe spellCheckConfig here.
+ */
+ private String spellCheckConfig;
+
+ /**
+ * Describe format here.
+ */
+ private String format;
+
+ /**
+ * Describe registry here.
+ */
+ private String registry;
+
+ /**
+ * Get the <code>Dictionary</code> value.
+ *
+ * @return a <code>String</code> value
+ */
+ public final String getDictionary() {
+ return dictionary;
+ }
+
+ /**
+ * Set the <code>Dictionary</code> value.
+ *
+ * @param newDictionary The new Dictionary value.
+ */
+ public final void setDictionary(final String newDictionary) {
+ this.dictionary = newDictionary;
+ }
+
+ /**
+ * Get the <code>ReservedDict</code> value.
+ *
+ * @return a <code>String</code> value
+ */
+ public final String getReservedDict() {
+ return reservedDict;
+ }
+
+ /**
+ * Set the <code>ReservedDict</code> value.
+ *
+ * @param newReservedDict The new ReservedDict value.
+ */
+ public final void setReservedDict(final String newReservedDict) {
+ this.reservedDict = newReservedDict;
+ }
+
+ /**
+ * Get the <code>SpellCheckConfig</code> value.
+ *
+ * @return a <code>String</code> value
+ */
+ public final String getSpellCheckConfig() {
+ return spellCheckConfig;
+ }
+
+ /**
+ * Set the <code>SpellCheckConfig</code> value.
+ *
+ * @param newSpellCheckConfig The new SpellCheckConfig value.
+ */
+ public final void setSpellCheckConfig(final String newSpellCheckConfig) {
+ this.spellCheckConfig = newSpellCheckConfig;
+ }
+
+ /**
+ * Get the <code>Format</code> value.
+ *
+ * @return a <code>String</code> value
+ */
+ public final String getFormat() {
+ return format;
+ }
+
+ /**
+ * Set the <code>Format</code> value.
+ *
+ * @param newFormat The new Format value.
+ */
+ public final void setFormat(final String newFormat) {
+ this.format = newFormat;
+ }
+
+ /**
+ * Get the <code>Registry</code> value.
+ *
+ * @return a <code>String</code> value
+ */
+ public final String getRegistry() {
+ return registry;
+ }
+
+ /**
+ * Set the <code>Registry</code> value.
+ *
+ * @param newRegistry The new Registry value.
+ */
+ public final void setRegistry(final String newRegistry) {
+ this.registry = newRegistry;
+ }
+}
\ No newline at end of file

Modified: trunk/src/main/java/com/google/bspell/parsers/ParserFactory.java
==============================================================================
--- trunk/src/main/java/com/google/bspell/parsers/ParserFactory.java (original)
+++ trunk/src/main/java/com/google/bspell/parsers/ParserFactory.java Fri Aug 17 01:27:30 2007
@@ -7,17 +7,18 @@
import java.util.Map;
import java.util.Properties;

-import com.google.bspell.model.Configuration;
+import com.google.bspell.model.SpellConfiguration;
import com.google.bspell.utils.PropertiesUtils;
import com.google.bspell.utils.StringUtils;

public final class ParserFactory {
private static ParserFactory instance;
- private final Configuration config;
+ private final SpellConfiguration config;

private Map<String, Parser> registry = new HashMap<String, Parser>();
+ private Map<String, List<String>> excludesMap = new HashMap<String, List<String>>();

- private ParserFactory(Configuration c) {
+ private ParserFactory(SpellConfiguration c) {
this.config = c;
initRegistry();
}
@@ -28,8 +29,8 @@
}

try {
- initRegistry(config.getRegistry());
initExcludes(config.getReservedDict());
+ initRegistry(config.getRegistry());
} catch (Exception e) {
System.err.println("Warning: Initialization failed.");
}
@@ -37,22 +38,11 @@

protected void initExcludes(final String reservedDict) throws Exception {
Properties properties = PropertiesUtils.loadProperties(reservedDict);
- List<String> generalExcludes = StringUtils.tokenize(properties.getProperty("general"));

Enumeration<?> extensions = properties.propertyNames();
while (extensions.hasMoreElements()) {
String extension = (String) extensions.nextElement();
- if ("general".equals(extension)) {
- continue;
- }
- Parser parser = getParser(extension);
- if (parser == null) {
- System.err.println("Warning: Can not find the " + extension
- + " parser, drop excludes " + properties.getProperty(extension));
- continue;
- }
- parser.getUserExcludes().addAll(StringUtils.tokenize(properties.getProperty(extension)));
- parser.getUserExcludes().addAll(generalExcludes);
+ excludesMap.put(extension, StringUtils.tokenize(properties.getProperty(extension)));
}
}

@@ -69,7 +59,7 @@
return getInstance(null);
}

- public static ParserFactory getInstance(Configuration c) {
+ public static ParserFactory getInstance(SpellConfiguration c) {
if (instance == null) {
instance = new ParserFactory(c);
}
@@ -96,6 +86,10 @@
public Parser newParser(final String extension, final String fullClassName) {
try {
Parser parser = (Parser) Class.forName(fullClassName).newInstance();
+ if (excludesMap.get(extension) != null) {
+ parser.getUserExcludes().addAll(excludesMap.get(extension));
+ }
+ parser.getUserExcludes().addAll(excludesMap.get("general"));
registry.put(extension, parser);
return parser;
} catch (Exception e) {

Reply all
Reply to author
Forward
0 new messages