Revision: 9231
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=9231&view=rev
Author:   dnaber
Date:     2013-01-26 21:57:09 +0000 (Sat, 26 Jan 2013)
Log Message:
-----------
remove the hunspell stuff from the OXT, merge the property files and make sure 
the merged files (keys now occur more than once!) are still interpreted 
correctly

Modified Paths:
--------------
    
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/Language.java
    trunk/languagetool/languagetool-office-extension/pom.xml
    trunk/languagetool/languagetool-office-extension/src/main/assembly/oxt.xml
    trunk/languagetool/languagetool-standalone/src/main/assembly/zip.xml

Added Paths:
-----------
    
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/MultiKeyProperties.java

Modified: 
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/Language.java
===================================================================
--- 
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/Language.java
   2013-01-26 21:25:44 UTC (rev 9230)
+++ 
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/Language.java
   2013-01-26 21:57:09 UTC (rev 9231)
@@ -31,6 +31,7 @@
 import org.languagetool.tokenizers.SentenceTokenizer;
 import org.languagetool.tokenizers.Tokenizer;
 import org.languagetool.tokenizers.WordTokenizer;
+import org.languagetool.tools.MultiKeyProperties;
 import org.languagetool.tools.StringTools;
 
 import java.io.IOException;
@@ -70,14 +71,17 @@
         final URL url = propertyFiles.nextElement();
         final InputStream inputStream = url.openStream();
         try {
-          final Properties props = new Properties();
-          props.load(inputStream);
-          final String classNamesStr = props.getProperty(PROPERTIES_KEY);
+          // We want to be able to read properties file with duplicate key, as 
produced by
+          // Maven when merging files:
+          final MultiKeyProperties props = new MultiKeyProperties(inputStream);
+          final List<String> classNamesStr = props.getProperty(PROPERTIES_KEY);
           if (classNamesStr == null) {
             throw new RuntimeException("Key '" + PROPERTIES_KEY + "' not found 
in " + url);
           }
-          final String[] classNames = classNamesStr.split(",");
-          languages.addAll(createLanguageObject(url, classNames));
+          for (String classNames : classNamesStr) {
+            final String[] classNamesSplit = classNames.split("\\s*,\\s*");
+            languages.addAll(createLanguageObject(url, classNamesSplit));
+          }
         } finally {
           inputStream.close();
         }

Added: 
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/MultiKeyProperties.java
===================================================================
--- 
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/MultiKeyProperties.java
                           (rev 0)
+++ 
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/MultiKeyProperties.java
   2013-01-26 21:57:09 UTC (rev 9231)
@@ -0,0 +1,69 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2013 Daniel Naber (http://www.danielnaber.de)
+ * 
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.tools;
+
+import java.io.InputStream;
+import java.util.*;
+
+/**
+ * A very simple property-style configuration. If a key occurs more than once, 
the
+ * values will be merged to a list with the other properties of that key. This
+ * is useful if property files get merged by Maven.
+ * 
+ * Note: this is not a full replacement for {@link java.util.Properties}, e.g. 
it does
+ * not support values that span multiple lines
+ */
+public class MultiKeyProperties {
+
+  private final Map<String, List<String>> properties = new HashMap<String, 
List<String>>();
+
+  public MultiKeyProperties(InputStream inStream) {
+    final Scanner scanner = new Scanner(inStream);
+    try {
+      while (scanner.hasNextLine()) {
+        final String line = scanner.nextLine().trim();
+        if (line.startsWith("#") || line.isEmpty()) {
+          continue;
+        }
+        final String[] parts = line.split("\\s*=\\s*");
+        if (parts.length != 2) {
+          continue;
+        }
+        final String key = parts[0];
+        final String value = parts[1];
+        List<String> list = properties.get(key);
+        if (list == null) {
+          list = new ArrayList<String>();
+        }
+        list.add(value);
+        properties.put(key, list);
+      }
+    } finally {
+      scanner.close();
+    }
+  }
+
+  /**
+   * @return a list of values or {@code null} if there's no such key
+   */
+  public List<String> getProperty(String key) {
+    return properties.get(key);
+  }
+
+}

Modified: trunk/languagetool/languagetool-office-extension/pom.xml
===================================================================
--- trunk/languagetool/languagetool-office-extension/pom.xml    2013-01-26 
21:25:44 UTC (rev 9230)
+++ trunk/languagetool/languagetool-office-extension/pom.xml    2013-01-26 
21:57:09 UTC (rev 9231)
@@ -83,6 +83,8 @@
                             <addClasspath>true</addClasspath>
                         </manifest>
                         <manifestEntries>
+                            <!-- as we later unzip the language JARs (see 
oxt.xml), we need to add the top directory to the classpath: -->
+                            <Class-Path>./</Class-Path>
                             
<RegistrationClassName>org.languagetool.openoffice.Main</RegistrationClassName>
                             
<ComponentVersion>${project.version}</ComponentVersion>
                             
<Implementation-Date>${maven.build.timestamp}</Implementation-Date>
@@ -120,7 +122,7 @@
                 <configuration>
                   
<tagBase>https://languagetool.svn.sourceforge.net/svnroot/languagetool/tags/</tagBase>
                 </configuration>
-            </plugin>            
+            </plugin>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>2.3.2</version>

Modified: 
trunk/languagetool/languagetool-office-extension/src/main/assembly/oxt.xml
===================================================================
--- trunk/languagetool/languagetool-office-extension/src/main/assembly/oxt.xml  
2013-01-26 21:25:44 UTC (rev 9230)
+++ trunk/languagetool/languagetool-office-extension/src/main/assembly/oxt.xml  
2013-01-26 21:57:09 UTC (rev 9231)
@@ -20,6 +20,19 @@
             </includes>
         </fileSet>
     </fileSets>
+    <containerDescriptorHandlers>
+        <!-- both of these handlers are needed so all 
language-module.properties get merged into one file: -->
+        <containerDescriptorHandler>
+            <handlerName>metaInf-services</handlerName>
+        </containerDescriptorHandler>
+        <containerDescriptorHandler>
+            <handlerName>file-aggregator</handlerName>
+            <configuration>
+                
<filePattern>META-INF/org/languagetool/language-module.properties</filePattern>
+                
<outputPath>META-INF/org/languagetool/language-module.properties</outputPath>
+            </configuration>
+        </containerDescriptorHandler>
+    </containerDescriptorHandlers>
     <dependencySets>
         <dependencySet>
             <outputDirectory>/</outputDirectory>
@@ -30,7 +43,23 @@
                 <exclude>org.openoffice:*</exclude>
                 <exclude>com.carrotsearch:hppc</exclude>
                 <exclude>net.java.dev.jna:jna</exclude>
+                <exclude>org.languagetool:hunspell-native-libs</exclude>
+                <exclude>org.languagetool:language-*</exclude>
             </excludes>
         </dependencySet>
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <unpack>true</unpack>
+            <unpackOptions>
+                <excludes>
+                     <!-- we don't offer spell checking in 
LibreOffice/OpenOffice -->
+                    <exclude>**/hunspell/**</exclude>
+                </excludes>
+            </unpackOptions>
+            <scope>runtime</scope>
+            <includes>
+                <include>org.languagetool:language-*</include>
+            </includes>
+        </dependencySet>
     </dependencySets>
 </assembly>

Modified: trunk/languagetool/languagetool-standalone/src/main/assembly/zip.xml
===================================================================
--- trunk/languagetool/languagetool-standalone/src/main/assembly/zip.xml        
2013-01-26 21:25:44 UTC (rev 9230)
+++ trunk/languagetool/languagetool-standalone/src/main/assembly/zip.xml        
2013-01-26 21:57:09 UTC (rev 9231)
@@ -21,7 +21,6 @@
             <excludes>
                 <exclude>junit:junit</exclude>
                 <exclude>org.openoffice:*</exclude>
-                <exclude>com.carrotsearch:hppc</exclude>
             </excludes>
         </dependencySet>
     </dependencySets>

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits

Reply via email to