#455 Allow to put in the clipboard the jEdit version string....

closed
nobody
core (195)
5
2012-12-03
2012-11-30
No

...from window "About jEdit" in order to be able to paste it (in bug tracker for instance)

Discussion

  • tvojeho
    tvojeho
    2012-12-02

    Hi Christophe,

    some time ago I cobbled together a macro that I think does what you want - it's quite rough around the edges, but works for me. I used MenuEditor plugin to insert it into jEdit Help menu. You can use it until this feature gets professionally implemented ;)

    tvojeho

    "jEdit and Java version....bsh"
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //
    // Title: jEdit and Java version
    //
    // Script Function: Get jEdit, java and system version/properties and copy
    // to clipboard.
    //
    // 1.00.00 -- 2012/02/02
    //
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    //-- Date formatting
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;
    import java.sql.Timestamp;

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[FileGetSize]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    FileGetSize(String filePath)
    {
    FileGetSize(filePath, "");
    }

    FileGetSize(String filePath, String Units)
    {
    File file = new File(filePath);
    if(file.exists()) // Soubor existuje
    {
    //-- Get the number of bytes in the file
    long length = file.length();
    if(Units.equals("K"))
    fileSize = length/1024;
    else if(Units.equals("M"))
    fileSize = length/1024/1024;
    else if(Units.equals("B") || Units.equals(""))
    fileSize = length;
    return fileSize;
    } else return null;
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[FileRead]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    //-- Reads a file's text into a variable.
    // Use: text = fileRead(filePath);
    FileRead(String filePath)
    {
    if(! new File(filePath).exists()) // Soubor neexistuje
    {
    Macros.message(null, "\"Soubor '"+filePath+"' neexistuje.\"");
    return null;
    }
    try
    {
    BufferedReader in = new BufferedReader(new FileReader(filePath));
    String line, contents; int count;
    while ((line = in.readLine()) != null) {
    ++count;
    if(count==1)
    contents = line;
    else contents = contents+"\n"+line;
    }
    in.close();
    return contents;
    } catch (IOException e) {
    }
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[FileGetTime]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    FileGetTime(String filePath)
    {
    FileGetTime(filePath, "");
    }

    FileGetTime(String filePath, String flags)
    {
    File file = new File(filePath);
    if(file.exists()) // Soubor existuje
    {
    long modifiedTime = file.lastModified();

    //-- Formatter.
    java.text.SimpleDateFormat formatter
    = new java.text.SimpleDateFormat ("yyyyMMddHHmmss");

    //-- Apply the formatter
    if(flags.indexOf('l') != -1)
    {
    return modifiedTime; // long format
    } else {
    timeOfModification = formatter.format(modifiedTime);
    return timeOfModification; // string format
    }
    } else return null;
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[FormatTime]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    //-- Format such as "d.M.yyyy H:mm:ss"
    FormatTime(String Format) // current date/time
    {
    java.util.Date currentTime = new java.util.Date();

    //-- Formatter.
    java.text.SimpleDateFormat formatter
    = new java.text.SimpleDateFormat (Format);

    //-- Apply the formatter
    String OutputVar = formatter.format(currentTime);
    return OutputVar;
    }

    //-- Format such as "d.M.yyyy H:mm:ss"
    FormatTime(YYYYMMDDHHMISS, String Format) // timestamp date/time
    {
    if(YYYYMMDDHHMISS==null)
    return;
    DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");

    try
    {
    Date today = df.parse(YYYYMMDDHHMISS);

    //-- Formatter.
    java.text.SimpleDateFormat formatter
    = new java.text.SimpleDateFormat (Format);

    //-- Apply the formatter
    String OutputVar = formatter.format(today);
    return OutputVar;

    } catch (ParseException e)
    {
    Macros.message(null, e.toString());
    }
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[MsgBox - Options]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    MsgBox(String Text)
    {
    MsgBox(new Object[] {"OK"}, 0, 1, "Message", Text);
    }

    MsgBox(String Title, String Text)
    {
    MsgBox(new Object[] {"OK"}, 0, 1, Title, Text);
    }

    MsgBox(Object[] buttons, String Title, String Text) // older
    {
    MsgBox(buttons, 0, 3, Title, Text);
    }

    MsgBox(Object[] buttons, int defaultButton, int JOptionPaneMESSAGE, String Title, String Text) // older
    {
    int JOptionPaneOPTION;
    View v = jEdit.getActiveView();
    if(buttons.length==1)
    {
    JOptionPaneOPTION = 0;
    }
    else if(buttons.length==2)
    {
    JOptionPaneOPTION = 1;
    }
    else if(buttons.length==3)
    {
    JOptionPaneOPTION = 2;
    }

    int result = JOptionPane.showOptionDialog(v, // could be null
    Text, // Text
    Title, // Title
    JOptionPaneOPTION, // 0=DEFAULT_OPTION, 1=YES_NO_OPTION, 2=YES_NO_CANCEL_OPTION, 3=OK_CANCEL_OPTION
    JOptionPaneMESSAGE, // 0=ERROR_MESSAGE, 1=INFORMATION_MESSAGE, 2=WARNING_MESSAGE, 3=QUESTION_MESSAGE, 4=PLAIN_MESSAGE
    null, //do not use a custom Icon
    buttons, //the titles of buttons
    buttons[defaultButton]); //default button title
    return result;
    }

    //-- Get daily version from jedit.jar timestamp
    String timeStamp = FileGetTime(jEdit.getJEditHome()+"/jedit.jar");
    Main_app_daily_version_show = FormatTime(timeStamp, "yyyy-MM-dd");

    java_version = System.getProperty("java.runtime.version");
    os_name = System.getProperty("os.name");
    os_version = System.getProperty("os.version");
    os_arch = System.getProperty("os.arch");

    //-- Get jEdit plugins
    EditPlugin[] plugins = jEdit.getPlugins();
    String pluginCollection; int count;
    for (int i=0; i<plugins.length; i++) {
    name = jEdit.getProperty("plugin." + plugins[i].getClassName() + ".name");
    version = jEdit.getProperty("plugin." + plugins[i].getClassName() + ".version");
    if (name != null) {
    ++count;
    if(count==1)
    pluginCollection = name + " (" + version + ")";
    else pluginCollection = pluginCollection + "|" + name + " (" + version + ")";
    }
    }

    //-- sort plugins
    String[] pluginsToShow = pluginCollection.split("\\|");
    Arrays.sort(pluginsToShow);

    Active_Plugins = ""; int divider = 0; int plugin_nr = 3;
    for(int i = 0; i < pluginsToShow.length; i++)
    {
    value = pluginsToShow[i];
    ++divider;
    if(divider>plugin_nr)
    {
    divider = 1;
    Active_Plugins = Active_Plugins+"\n" + value;
    } else {
    if(i==0)
    Active_Plugins = Active_Plugins + value;
    else Active_Plugins = Active_Plugins+", " + value;
    }
    }

    msg = "jEdit info:\n"
    +"Daily build: "+Main_app_daily_version_show+"\n"
    +"Java runtime version: "+java_version+"\n"
    +"OS name: "+os_name+"\n"
    +"OS version: "+os_version+"\n"
    +"OS arch: "+os_arch;

    msg_plugins = "jEdit info:\n"
    +"Daily build: "+Main_app_daily_version_show+"\n"
    +"Java runtime version: "+java_version+"\n"
    +"OS name: "+os_name+"\n"
    +"OS version: "+os_version+"\n"
    +"OS arch: "+os_arch+"\n\n"
    +"Active plugins: "+Active_Plugins;

    msg1 = MsgBox(new Object[] {"OK", "Copy"},
    0,
    1,
    "App version...",
    msg);

    if(msg1==1) // copy
    { // add activity.log to clipboard
    activity_log = jEdit.getSettingsDirectory()+"/activity.log";
    long fileSize = FileGetSize(activity_log, "K");
    msg2 = MsgBox(new Object[] {"Yes", "No"},
    0,
    2,
    "Activity Log",
    "Add contents of activity.log ("+fileSize+"kB) to clipboard?");

    if(msg2==0) // Yes
    {
    String text = FileRead(activity_log);
    msg_plugins = msg_plugins+"\n\nActivity Log:\n"+text;
    msg2 = "jEdit details and activity.log copied...";
    } else msg2 = "jEdit details copied...";
    Registers.setRegister('$', msg_plugins); // Insert 'var' to Clipboard
    Macros.message(view, msg2);
    }
    return;

     
  • tvojeho
    tvojeho
    2012-12-02

    Sorry, forgot to add main jEdit version - I got it from activity.log file.

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[FileReadLine]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    //-- Reads the specified line from a file and stores the text in a variable.
    FileReadLine(String filePath, int LineNum)
    {
    if(! new File(filePath).exists()) // Soubor neexistuje
    {
    Macros.message(null, "\"Soubor '"+filePath+"' neexistuje.\"");
    return null;
    }
    try
    {
    BufferedReader in = new BufferedReader(new FileReader(filePath));
    String line, contents; int count;
    while ((line = in.readLine()) != null) {
    ++count;
    if(count<LineNum)
    continue;
    else break;
    }
    in.close();
    if(count<LineNum) // line was not in the file
    return null;
    else return line;
    } catch (IOException e) {
    }
    }

    //-- Get jEdit version info
    // Main_app_version = IniRead( jEdit.getJEditHome()+"/Nastaveni/Settings "+jEdit.getProperty("workstation")+"/jEdit AHK Macros "+jEdit.getProperty("workstation")+".ini", "jEdit Daily Builds "+host_user_name_legalized, "jEdit App version", "-----", "w");
    activity_log = jEdit.getSettingsDirectory()+"/activity.log";
    for (i = 20; i < 30; i++){ // start at line...
    line = FileReadLine(activity_log, i);
    if(line.contains("jEdit version"))
    break;
    }
    Main_app_version = line.replaceFirst("^.+jEdit version (.+)$", "$1"); // main jEdit version

     
  • Thomas Meyer
    Thomas Meyer
    2012-12-02

    I guess the official way of doing this is to open the Activity Log and copy&paste the first few lines from it.

    You can enable the Log window with "Extras->Options"->Dock(?)

     
  • Hi tvojeho,

    Your macro is working fine except for jEdit Version : where am i supposed to insert the second part you sent (FileReadLine) ? I tried to place it after the "imports" or before the final "return" but it is not working.

    The advantage of the macro compared to tha activity log file is to give a synthetic display of used plugins.

     
  • tvojeho
    tvojeho
    2012-12-03

    Hi Christophe,

    Put the FileReadLine() function somewhere at the beginning, e.g. after the FileRead function, and the '//-- Get jEdit version info' somewhere in macro proper, can be before '//-- Get daily version from jedit.jar timestamp' for example.

    Then you can put the information in the final message, instead of 'msg = "jEdit info:\n"' you put 'msg = "jEdit version: "+Main_app_version+"\n" and you're set.

    tvojeho

     
  • Working better....

    I also updated msg_plugins but the wrong line seems to be catched from log :

    jEdit version: 9:23:45 AM [main] [notice] jEdit: at java.net.PlainSocketImpl.connect(Unknown Source)
    Daily build: 2012-11-27
    Java runtime version: 1.6.0_37-b06
    OS name: Windows 7
    OS version: 6.1
    OS arch: x86

    Active plugins: Beauty (0.7.0), BufferTabs (1.2.3), Common Controls (1.5)
    Completion (0.3), Configurable Fold Handler (0.8), Console (4.5)
    CtagsInterface (2.2), CtagsSideKick (1.5), EclipseIcons (1.0)
    ErrorList (1.9), FoldViewer (1.1), GnuRegexp (1.0.1)
    Hex Edit (0.1.3), Highlight (1.9.10), Info Viewer (1.6.1)
    JDiff Plugin (3.2.0), JNAPlugin (3.2.4), LucenePlugin (2.8)
    MacroManager (1.2), MarkerSets (0.9), Menu Editor (0.5)
    QuickNotepad (5.0), SideKick (1.3), SuperAbbrevs (1.0)
    SwitchBuffer (1.1.1), Tags (3.1.0), WhiteSpace (1.0.2)
    XML (2.8.3-jedit-4.5), XercesPlugin (2.9.1)

     
  • tvojeho
    tvojeho
    2012-12-03

    It looks like a problem with regex expression. Look at your Log file to see the line which shows jEdit version - for me it's line 24: "9:48:24 [main] [notice] jEdit: jEdit version 5.1pre1".

    In macro, the RE ("^.+jEdit version (.+)$", "$1") returns "5.1pre1" but you may have to adjust it if it's different in your system. Or maybe you have this info on a different line, I put the loop to scan lines 20-30 so you may want to widen the search, maybe 10-40, depending where in Log the information is.

     
    • status: open --> closed
     
  • Working fine since I widen the scan up to line 40 (info si at line 39 in my case).
    It was taking info from last line (30).

    Thanks