[rfc][icedtea-web] Generate Bash Completion file

Jiri Vanek jvanek at redhat.com
Sun Jun 14 18:06:10 UTC 2015



hi!

A lot of nits just from quick web based reading.


diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -259,13 +259,13 @@
   check-local: $(RHINO_TESTS) $(JUNIT_TESTS)

   clean-local: clean-netx clean-plugin clean-liveconnect \
- clean-native-ecj clean-launchers clean-desktop-files clean-docs clean-generated-docs clean-tests clean-bootstrap-directory
+ clean-native-ecj clean-launchers clean-desktop-files clean-docs clean-generated-docs clean-generated-bash-completion clean-tests clean-bootstrap-directory
   	if [ -e stamps ] ; then \
   	  rmdir stamps ; \
   	fi

   .PHONY: clean-IcedTeaPlugin clean-add-netx clean-add-netx-debug clean-add-plugin clean-add-plugin-debug \
- clean-bootstrap-directory clean-native-ecj clean-desktop-files clean-netx-docs clean-docs clean-plugin-docs clean-generated-docs \
+ clean-bootstrap-directory clean-native-ecj clean-desktop-files clean-netx-docs clean-docs clean-plugin-docs clean-generated-docs clean-generated-bash-completion \
    clean-tests check-local clean-launchers stamps/check-pac-functions.stamp stamps/run-netx-unit-tests.stamp clean-netx-tests \
    clean-junit-runner clean-netx-unit-tests

@@ -504,6 +504,12 @@
   	sed -i '/RhinoBasedPacEvaluator/ d' $@
   endif

+stamps/generate-bash-completion.stamp: stamps/netx.stamp
+	BC_COMMAND="$(SYSTEM_JRE_DIR)/bin/java -cp $(NETX_DIR) net.sourceforge.jnlp.OptionsDefinitions" ; \
+	$$BC_COMMAND; \
+	sudo mv icedteaweb-completion /etc/bash_completion.d/ ; \

This is absolyutely no go. You must split this to two targets
   - first during make. during  make you generate this file o BUILD_DIR
   - second, during install, you install the genrated file to PREFIX/etc/bash_completion.d/icedteaweb-completion

You do not need to handle permissions - user decide in configure time what is PREFIX, and then in install time he use root or not, acording to his prefix. By default prefix is "/" so by default you hav eto be root to call make install.
But only make install. not make.
+	touch $@ ;
+
   stamps/generate-docs.stamp: stamps/netx.stamp
   	mkdir -p "$(DOCS_DIR)" ; \
   	HTML_DOCS_TARGET_DIR="$(DOCS_DIR)/html"  ; \
@@ -571,7 +577,7 @@
   	mkdir -p stamps
   	touch $@


acordingly the clean phases have to be splited.

By the way - make install is generated target. Yo just add generated  icedteaweb-completion to list of cared files.

Also, please dont use stamps fo simple generation. The target is file itself. ( see lower)

-stamps/netx-dist.stamp: stamps/netx.stamp $(abs_top_builddir)/netx.manifest stamps/generate-docs.stamp
+stamps/netx-dist.stamp: stamps/netx.stamp $(abs_top_builddir)/netx.manifest stamps/generate-docs.stamp stamps/generate-bash-completion.stamp stamps/
   	(cd $(NETX_DIR) ; \
   	 mkdir -p lib ; \
   	 $(SYSTEM_JDK_DIR)/bin/jar cfm lib/classes.jar \
@@ -686,6 +692,8 @@
   	rm -rf "$(DOCS_DIR)"
   	rm -f stamps/generate-docs.stamp

+clean-generated-bash-completion:
+	rm -rf stamps/generate-bash-completion.stamp

Ok. Here is the bug. What the target  is cleaning?  It is removing stamp! not generated file!
   # check
   # ==========================
diff --git a/icedteaweb-completion b/icedteaweb-completion
deleted file mode 100644
--- a/icedteaweb-completion
+++ /dev/null

Hmm... Why to remove. The file in javacode is absolutely unreadable. I would rater move this file to
icedteaweb-completion.in and durng generation just replaced the stings ifn "opts"

@@ -1,44 +0,0 @@
-#/bin/bash
-#place this file over to /etc/bash_completion.d/ to make this file useful
-#Note: If you do not have bash-completion you will need to install it
-_itweb-settings()
-{
-    local cur prev opts base
-    cur="${COMP_WORDS[COMP_CWORD]}"
-    prev="${COMP_WORDS[COMP_CWORD-1]}"
-
-    # Icedtea-web settings Options
-    opts="-check -get -headless -help -info -list -reset -set -verbose"
-
-    COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
-    return 0
-}
-complete -F _itweb-settings itweb-settings
-
-_policyeditor()
-{
-    local cur prev opts base
-    cur="${COMP_WORDS[COMP_CWORD]}"
-    prev="${COMP_WORDS[COMP_CWORD-1]}"
-
-    # PolicyEditor Options
-    opts="-codebase -file -help"
-
-    COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
-    return 0
-}
-complete -F _policyeditor policyeditor
-
-_javaws()
-{
-    local cur prev opts base
-    cur="${COMP_WORDS[COMP_CWORD]}"
-    prev="${COMP_WORDS[COMP_CWORD-1]}"
-
-    # JavaWs Options
-    opts="-about -help -license -viewer -Xclearcache -allowredirect -arg -headless -html -jnlp -nosecurity -noupdate -param -property -strict -update -verbose -version -Xignoreheaders -xml -Xnofork -Xoffline -Xtrustnone"
-
-    COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
-    return 0
-}
-complete -F _javaws javaws
diff --git a/netx/net/sourceforge/jnlp/OptionsDefinitions.java b/netx/net/sourceforge/jnlp/OptionsDefinitions.java
--- a/netx/net/sourceforge/jnlp/OptionsDefinitions.java
+++ b/netx/net/sourceforge/jnlp/OptionsDefinitions.java
@@ -36,6 +36,9 @@
   */
   package net.sourceforge.jnlp;

+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.List;
@@ -223,5 +226,65 @@
           return l;
       }

-
+    public static void main(String [ ] args) throws IOException {
+        makeTabCompletionFile();
+    }
+
+    public static String transformToLine (List<OPTIONS>  options) {
+        String line = "";
+        for (OPTIONS option : options) {
+            line = line + option.option + " ";
+        }
+        return line;
+    }
+    public static void makeTabCompletionFile() throws IOException {

Is there any difference against orignal file? if no,please use .in format.

If yes, then please split this patch to two parts. Firt, replace already pushed file by this new powerful (and it will be valid also for 1.6!) and as second patch, chnage it to .in form, and proceed with generation.
+        String header = "#/bin/bash\n" +
+                "#place this file over to /etc/bash_completion.d/ to make this file useful\n" +
+                "#Note: If you do not have bash-completion you will need to install it\n";
+        String itwebSettings = "_itweb-settings()\n" +
+                "{\n" +
+                "    local cur prev opts base\n" +
+                "    cur=\"${COMP_WORDS[COMP_CWORD]}\"\n" +
+                "    prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n" +
+                "\n" +
+                "    # Icedtea-web settings Options\n" +
+                "    opts=\"" + transformToLine(getItwsettingsCommands()) + "\"\n" +
+                "\n" +
+                "    COMPREPLY=($(compgen -W \"${opts}\" -- ${cur}))\n" +
+                "    return 0\n" +
+                "}\n" +
+                "complete -F _itweb-settings itweb-settings\n" +
+                "\n";
+        String policyeditor = "_policyeditor()\n" +
+                "{\n" +
+                "    local cur prev opts base\n" +
+                "    cur=\"${COMP_WORDS[COMP_CWORD]}\"\n" +
+                "    prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n" +
+                "\n" +
+                "    # PolicyEditor Options\n" +
+                "    opts=\"" + transformToLine(getPolicyEditorOptions()) + "\"\n" +
+                "\n" +
+                "    COMPREPLY=($(compgen -W \"${opts}\" -- ${cur}))\n" +
+                "    return 0\n" +
+                "}\n" +
+                "complete -F _policyeditor policyeditor\n" +
+                "\n";
+        String javaws = "_javaws()\n" +
+                "{\n" +
+                "    local cur prev opts base\n" +
+                "    cur=\"${COMP_WORDS[COMP_CWORD]}\"\n" +
+                "    prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n" +
+                "\n" +
+                "    # JavaWs Options\n" +
+                "    opts=\"" + transformToLine(getJavaWsOptions()) + "\"\n" +
+                "\n" +
+                "    COMPREPLY=($(compgen -W \"${opts}\" -- ${cur}))\n" +
+                "    return 0\n" +
+                "}\n" +
+                "complete -F _javaws javaws\n";
+        String body = header + itwebSettings + policyeditor + javaws;
+        File completionFile = new File("icedteaweb-completion");
+        completionFile.createNewFile();
+        Files.write(completionFile.toPath(), body.getBytes());
+    }
   }



-- 
Mgr. Jiri Vanek
judovana at email.cz





More information about the distro-pkg-dev mailing list