How to remove old versions of Eclipse plugins?

后端 未结 11 2137
南方客
南方客 2020-12-13 02:06

After update, old Eclipse plugins remain in \"plugins\" folder (there are also leftovers in \"features\" folder).

Is there a way to remove those automatically?

11条回答
  •  自闭症患者
    2020-12-13 02:46

    I also want to remove old plugins, but still found no answer today, so I wrote a quick and dirty script guess-old-eclipse-plugins.sh to handle old plugins.

    This script will scan plugins directory under Eclipse directory. and will generate a remove-old-eclipse-plugins.txt file which can be used to remove old plugins.

    This script is tested under Cygwin 1.7.15 on Windows XP.

    guess-old-eclipse-plugins.sh

    PluginsDir=plugins
    FeaturesDir=features
    PluginIDSeparator=_
    RemovingScriptFileName=remove-old-eclipse-plugins.txt
    rm -rf $RemovingScriptFileName
    
    #for dir in $PluginsDir $FeaturesDir
    for dir in $PluginsDir  # $FeaturesDir: most file names in features dir contains more than 1 _ character
    do
        echo "Processing [$dir] directory..."
        # split PluginID from filename
        # (not reliable, but general working. (ex: will get one junit PluginID because there're move than 1 _ characters in file name))
        file_list=$(ls $dir);
        echo "$file_list" | cut -f1 -d $PluginIDSeparator         > $dir-all.txt
        echo "$file_list" | cut -f1 -d $PluginIDSeparator  | uniq > $dir-uniq.txt
    
        # get the PluginList which VERY POSSIBLY has old versions
        diff_result=$(diff -U 0 $dir-uniq.txt $dir-all.txt)
        plugins_which_has_old_versions=$(echo "$diff_result" | grep -e "^+[^+]" | cut -f 2 -d +)
    
        #
        for p in $(echo "$plugins_which_has_old_versions")
        do
            echo "$p"
            i=0
            for f in $(ls -d -t $dir/$p$PluginIDSeparator*) # use 'ls' command, can sort result by file time, but can not handle file name contains special characters (white space) when using wildcard
            #for f in $(find $dir -name "$p$PluginIDSeparator*")    # use 'find' command
            do
                if [ -d $f ]
                then
                    # should use rm -rf
                    echo -n "[D]"
                else
                    echo -n "   "
                fi
                echo -n "$f"
    
                ((i++))
                if [ $i -eq 1 ]
                then
                    echo ""
                    continue    # first file, the newest version
                fi
                echo "    [old]"
                echo "rm -rf $f" >> $RemovingScriptFileName
            done
    
            echo
        done
    done
    

    IMPORTANT NOTICE

    Before use the generated remove-old-eclipse-plugins.txt file to remove plugins, make sure all the listed plugins in it are REALLY old plugins. Because, this script can't handle file name contains more than 1 _ characters. For example: JUnit v3 and v4 plugins are 2 different plugins, but the script will treat it as same plugins because these 2 file names use same org.junit_ prefix.

    org.junit
    [D]plugins/org.junit_3.8.2.v3_8_2_v20100427-1100
    [D]plugins/org.junit_4.8.2.v4_8_2_v20110321-1705    [old]  <-- wrong
    

    So, use it VERY CAREFULLY, remove the wrong part before use it, or your Eclipse IDE may not work properly.

    Sample output

    $ ./guess-old-eclipse-plugins.sh
    Processing [plugins] directory...
    org.eclipse.gef
       plugins/org.eclipse.gef_3.7.2.v20111106-2020.jar
       plugins/org.eclipse.gef_3.6.2.v20110110-2020.jar    [old]
    
    org.eclipse.help.base
       plugins/org.eclipse.help.base_3.6.2.v201202080800.jar
       plugins/org.eclipse.help.base_3.5.3.v201102101200.jar    [old]
    
    org.eclipse.help.ui
       plugins/org.eclipse.help.ui_3.5.101.r37_20110819.jar
       plugins/org.eclipse.help.ui_3.5.3.r36_20101116.jar    [old]
    ...
    

    Sample generated script

    rm -rf plugins/org.eclipse.gef_3.6.2.v20110110-2020.jar
    rm -rf plugins/org.eclipse.help.base_3.5.3.v201102101200.jar
    rm -rf plugins/org.eclipse.help.ui_3.5.3.r36_20101116.jar
    rm -rf plugins/org.eclipse.help.webapp_3.5.3.r36_20101130.jar
    rm -rf plugins/org.eclipse.jdt.apt.core_3.3.402.R36_v20110120-1000.jar
    rm -rf plugins/org.eclipse.jdt.debug.ui_3.5.2.v20100928a_r362.jar
    

提交回复
热议问题