[SCM] UNNAMED PROJECT branch, master, updated. debian/1.6.2-14-g814c033

Emmanuel Bourg ebourg at apache.org
Tue Jun 11 13:00:23 UTC 2013


The following commit has been merged in the master branch:
commit 61c50b8ced7453e344f6517a535e0a48d8756a73
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Tue Jun 11 14:53:35 2013 +0200

    Moved the formatting of the package description into a separate method

diff --git a/maven-packager-utils/src/main/java/org/debian/maven/packager/GenerateDebianFilesMojo.java b/maven-packager-utils/src/main/java/org/debian/maven/packager/GenerateDebianFilesMojo.java
index 840e5c9..d8966d0 100644
--- a/maven-packager-utils/src/main/java/org/debian/maven/packager/GenerateDebianFilesMojo.java
+++ b/maven-packager-utils/src/main/java/org/debian/maven/packager/GenerateDebianFilesMojo.java
@@ -193,7 +193,7 @@ public class GenerateDebianFilesMojo extends AbstractMojo {
             context.put("licenses", licenses);
 
             if (licenses.size() == 1) {
-                packagerLicense = (String) licenses.iterator().next();
+                packagerLicense = licenses.iterator().next();
             }
             if (packagerLicense == null) {
                 String q = "Packager license for the debian/ files was not found, please enter a license name preferably in one of:\n"
@@ -245,27 +245,10 @@ public class GenerateDebianFilesMojo extends AbstractMojo {
             context.put("copyrightYear", copyrightYear);
             context.put("currentYear", new Integer(currentYear));
 
-            List<String> description = new ArrayList<String>();
             if (project.getDescription() == null || project.getDescription().trim().isEmpty()) {
                 project.setDescription(userInteraction.askMultiLine("Please enter a short description of the project, press Enter twice to stop."));
             }
-            if (project.getDescription() != null) {
-                StringTokenizer st = new StringTokenizer(project.getDescription().trim(), "\n\t ");
-                StringBuilder descLine = new StringBuilder();
-                while (st.hasMoreTokens()) {
-                    descLine.append(st.nextToken());
-                    descLine.append(" ");
-                    if (descLine.length() > 70 || !st.hasMoreTokens()) {
-                        String line = descLine.toString().trim();
-                        if (line.isEmpty()) {
-                            line = ".";
-                        }
-                        description.add(line);
-                        descLine = new StringBuilder();
-                    }
-                }
-            }
-            context.put("description", description);
+            context.put("description", formatDescription(project.getDescription()));
 
             File substvarsFile = new File(outputDirectory, binPackageName + ".substvars");
             if (substvarsFile.exists()) {
@@ -477,6 +460,35 @@ public class GenerateDebianFilesMojo extends AbstractMojo {
         }
     }
 
+    /**
+     * Format the specified text to be suitable as a package long description.
+     * Lines are wrapped after 70 characters and a dot is placed on empty lines.
+     * 
+     * @param description
+     */
+    List<String> formatDescription(String description) {
+        List<String> lines = new ArrayList<String>();
+        
+        if (description != null) {
+            StringTokenizer st = new StringTokenizer(description.trim(), "\n\t ");
+            StringBuilder descLine = new StringBuilder();
+            while (st.hasMoreTokens()) {
+                descLine.append(st.nextToken());
+                descLine.append(" ");
+                if (descLine.length() > 70 || !st.hasMoreTokens()) {
+                    String line = descLine.toString().trim();
+                    if (line.isEmpty()) {
+                        line = ".";
+                    }
+                    lines.add(line);
+                    descLine = new StringBuilder();
+                }
+            }
+        }
+        
+        return lines;
+    }
+
     private List<WrappedProject> wrapMavenProjects(List<MavenProject> projects) {
         List<WrappedProject> wrappedProjects = new ArrayList<WrappedProject>();
         for (MavenProject aProject: projects) {
diff --git a/maven-packager-utils/src/test/java/org/debian/maven/packager/GenerateDebianFilesMojoTest.java b/maven-packager-utils/src/test/java/org/debian/maven/packager/GenerateDebianFilesMojoTest.java
new file mode 100644
index 0000000..9ac962a
--- /dev/null
+++ b/maven-packager-utils/src/test/java/org/debian/maven/packager/GenerateDebianFilesMojoTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2013 Emmanuel Bourg
+ *
+ * Licensed 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 applicab le 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 org.debian.maven.packager;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ */
+public class GenerateDebianFilesMojoTest extends TestCase {
+
+    public void testFormatDescription() {
+        GenerateDebianFilesMojo mojo = new GenerateDebianFilesMojo();
+        
+        String description = "A framework for constructing recognizers, compilers, and translators from grammatical descriptions containing Java, C#, C++, or Python actions.";
+
+        List<String> lines = mojo.formatDescription(description);
+        assertNotNull(lines);
+        assertEquals("number of lines", 2, lines.size());
+        assertEquals("formatted description - line 1", "A framework for constructing recognizers, compilers, and translators from", lines.get(0));
+        assertEquals("formatted description - line 2", "grammatical descriptions containing Java, C#, C++, or Python actions.", lines.get(1));
+    }
+    
+    public void testFormatNullDescription() {
+        GenerateDebianFilesMojo mojo = new GenerateDebianFilesMojo();
+        
+        List<String> lines = mojo.formatDescription(null);
+        assertNotNull(lines);
+        assertEquals("number of lines", 0, lines.size());
+    }
+}

-- 
UNNAMED PROJECT



More information about the pkg-java-commits mailing list