Wish IDE State and Code Bundle JSONs

aeric

Expert
Licensed User
Longtime User
I think it might be useful (for me) if the json files (at least ide_state.json only) also contains an entry for the module path.
I am referring to modules added by absolute or relative paths.
I have a quick check on the CodeBundle source code but not really sure how to modify it.



 
Last edited:

aeric

Expert
Licensed User
Longtime User
I don't have JDK 8 installed so I tried to compile CodeBundle2.jar using JDK19.

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

'comment these lines:
'#JavaCompilerPath: 8, C:\Program Files\Java\jdk1.8.0_211\bin\javac.exe
'#CustomBuildAction: 2, %COMSPEC%, /c copy /Y "%PROJECT%\Objects\%PROJECT_NAME%.jar" "%B4X%\CodeBundle2.jar"
'#CustomBuildAction: 2, %COMSPEC%, /c copy /Y "%PROJECT%\Objects\%PROJECT_NAME%.jar" "%B4X%\..\..\..\..\B4A\B4A\bin\Debug\CodeBundle2.jar"
'#CustomBuildAction: 2, %COMSPEC%, /c copy /Y "%PROJECT%\Objects\%PROJECT_NAME%.jar" "%B4X%\..\..\..\..\B4R\B4R\bin\Debug\CodeBundle2.jar"
'#CustomBuildAction: 2, %COMSPEC%, /c copy /Y "%PROJECT%\Objects\%PROJECT_NAME%.jar" "%B4X%\..\..\..\..\B4i\B4i\bin\Debug\CodeBundle2.jar"
Sub Process_Globals
    Private CodeBundleVersion As Float = 2.00
    Private SchemaVersion As Float = 1.00
    Private ProjectFile As String

B4X:
Private Sub ReadModule(ModulePath As String) As CodeModule
    'If ModulePath.StartsWith("|relative|") Then
    '    ModulePath = File.Combine(ProjectDir, ModulePath.SubString("|relative|".Length))
    'Else If ModulePath.StartsWith("|absolute|") Then
    '    ModulePath = ModulePath.SubString("|absolute|".Length)
    'Else
        ModulePath = File.Combine(ProjectDir, ModulePath)
    'End If
    Dim cm As CodeModule = ReadFile(ModulePath & ".bas")
    cm.Clazz = ParseModule(cm)
    Return cm
End Sub

I am getting this error:

 

aeric

Expert
Licensed User
Longtime User
For the time being I will restrict to only use modules inside project directory.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Given the project main file, you can find the modules with:
B4X:
Private Sub FindProjectModules(MainFile As String) As Map
    Dim result As Map = CreateMap()
    Dim ProjectDir As String = File.GetFileParent(MainFile)
    Dim lines As List = File.ReadList(MainFile, "")
    For Each line As String In lines
        If line = "@EndOfDesignText@" Then Exit
        Dim m As Matcher = Regex.Matcher("([^=]*)=(.*)", line)
        m.Find
        Dim key As String = m.Group(1)
        Dim value As String = m.Group(2)
        If key.StartsWith("Module") Then
            Dim path As String = DecodeModulePath(ProjectDir, value)
            Dim ModuleName As String = File.GetName(path)
            result.Put(ModuleName, path & ".bas")
        End If
    Next
    Return result
End Sub

Private Sub DecodeModulePath(ProjectDir As String, ModulePath As String) As String
    If ModulePath.StartsWith("|relative|") Then
        ModulePath = File.Combine(ProjectDir, ModulePath.SubString("|relative|".Length))
    Else If ModulePath.StartsWith("|absolute|") Then
        ModulePath = ModulePath.SubString("|absolute|".Length)
    Else
        ModulePath = File.Combine(ProjectDir, ModulePath)
    End If
    Return ModulePath
End Sub

Example:
B4X:
Dim modules As Map = FindProjectModules("C:\Users\H\Documents\B4X\SimpleMediaManager\B4i\SimpleMediaManager.b4i")
For Each module As String In modules.Keys
    Dim Path As String = modules.Get(module)
    Log(module & ": " & Path & ", " & File.Exists(Path, ""))
Next
 

aeric

Expert
Licensed User
Longtime User
Yes, I can read the project main file to get the module path but it is best if I can get all information I needed by just reading from the single ide_state.json file.
 

aeric

Expert
Licensed User
Longtime User
Thanks Erel.
I use your code above and successfully build my MiniORM table code generator.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…