News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

AutoVersioning Plugin

Started by JGM, June 27, 2007, 08:18:25 PM

Previous topic - Next topic

JGM

#135
Quote from: killerbot on April 16, 2008, 11:58:02 PM
or it is not correctly updated during switching of the projects ... ?

Yep, thats the problem, to stop the headache inmmediatley just replaced the member with this:
std::map<cbProject*, bool> m_IsVersioned;

The patch is attached to this message

Changes:

- Now works correctly on workspaces
- Warns when first time configuration and version.h exist on the projects path
- Formats the header file name and uses it as the header guard

If you want to have a quick look

Index: src/plugins/contrib/AutoVersioning/AutoVersioning.cpp
===================================================================
--- src/plugins/contrib/AutoVersioning/AutoVersioning.cpp (revision 5005)
+++ src/plugins/contrib/AutoVersioning/AutoVersioning.cpp (working copy)
@@ -65,7 +65,6 @@
     ProjectLoaderHooks::HookFunctorBase* AutoVerHook =

       new ProjectLoaderHooks::HookFunctor<AutoVersioning>(this, &AutoVersioning::OnProjectLoadingHook);

     m_AutoVerHookId = ProjectLoaderHooks::RegisterHook(AutoVerHook);

-    m_IsCurrentProjectVersioned = false;

     m_Modified = false;

     m_Project = 0;

} // end of constructor
@@ -128,11 +127,11 @@
// TODO (KILLERBOT) : should we have default values, in case something would be missing ?

// OPTI : we could choose not to write out default values in the xml --> smaller cbp

avConfig Config;

- m_IsCurrentProjectVersioned = false; // default not active unless we find xml for it

+ m_IsVersioned[project] = false; // default not active unless we find xml for it

const TiXmlElement* Node = elem->FirstChildElement("AutoVersioning");

if (Node)

{

- m_IsCurrentProjectVersioned = true;

+ m_IsVersioned[project] = true;

TiXmlHandle Handle(const_cast<TiXmlElement*>(Node));

if(const TiXmlElement* pElem = Handle.FirstChildElement("Scheme").ToElement())

{

@@ -215,7 +214,6 @@
         }

m_ProjectMap[project] = Config;

m_ProjectMapVersionState[project] = VersionState;

- m_Project = project;

}

else

{

@@ -226,7 +224,7 @@
// if plugins that use that element are not loaded atm).

// so, instead of blindly inserting the element, we must first check it's

// not already there (and if it is, clear its contents)

- if(m_IsCurrentProjectVersioned)

+ if(m_IsVersioned[project])

{

TiXmlElement* node = elem->FirstChildElement("AutoVersioning");

if (!node)

@@ -281,7 +279,8 @@
if (IsAttached())

{

m_ProjectMap.erase(event.GetProject());

- m_ProjectMapVersionState.erase(event.GetProject());

+ m_ProjectMapVersionState.erase(event.GetProject());
+        m_IsVersioned.erase(event.GetProject());

if(m_Project == event.GetProject())

{   // should always be the case (??? we hope ??)

    m_Project = 0;

@@ -294,7 +293,7 @@
// be activated and each has the compilerstarted/Finished ?????
void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)
{
-    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)

+    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])

     {
if (m_Modified)
{
@@ -317,7 +316,7 @@

void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)
{
-    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)

+    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])

{
++(GetVersionState().Values.BuildCount);
}
@@ -325,7 +324,7 @@

void AutoVersioning::OnTimerVerify(wxTimerEvent& event)
{
-    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)

+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])

     {
if (!m_Modified)
{
@@ -348,7 +347,7 @@
     {
         if (m_Project)
         {
-            if (m_IsCurrentProjectVersioned)
+            if (m_IsVersioned[m_Project])
             {
                 SetVersionAndSettings(*m_Project, true);
                 UpdateVersionHeader();
@@ -357,8 +356,20 @@
             {
                 if (wxMessageBox(_("Configure the project \"") + m_Project->GetTitle() + _("\" for Autoversioning?"),_("Autoversioning"),wxYES_NO) == wxYES)
                 {
+                    if(wxFileExists(m_Project->GetBasePath() + _T("version.h")))
+                    {
+                        wxMessageBox(
+                         _T("The header version.h already exist on your projects path. "
+                            "The content will be overwritten by the the version info generated code."
+                            "\n\nYou can change the default version.h file on the \"Settings\" Tab."
+                           ),
+                         _T("Warning"),
+                         wxICON_EXCLAMATION  | wxOK
+                        );
+                    }
+
// we activated
- m_IsCurrentProjectVersioned = true;
+ m_IsVersioned[m_Project] = true;
// just becasue we activated the project becomes modified
m_Project->SetModified();

@@ -382,7 +393,7 @@

void AutoVersioning::OnMenuCommitChanges(wxCommandEvent&)
{
-    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
     {

         if(m_Modified)

         {
@@ -406,7 +417,7 @@
             {
                 event.Enable(true);
             }
-            else if (m_IsCurrentProjectVersioned)
+            else if (m_IsVersioned[m_Project])
             {
                 if (m_Modified)
                 {
@@ -528,9 +539,15 @@
{
     m_timerStatus->Stop();

+    //Declares the header guard to be used based on the filename
+    wxFileName filename(cbC2U(GetConfig().Settings.HeaderPath.c_str()));
+    wxString headerGuard = filename.GetName() + _T("_") + filename.GetExt();
+    headerGuard.Replace(_T(" "), _T("_"), true);
+    headerGuard.UpperCase();
+
     wxString headerOutput = _T("");
-    headerOutput << _T("#ifndef VERSION_H") << _T("\n");
-    headerOutput << _T("#define VERSION_H") << _T("\n");
+    headerOutput << _T("#ifndef ") << headerGuard << _T("\n");
+    headerOutput << _T("#define ") << headerGuard  << _T("\n");
     headerOutput << _T("\n");

     if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
@@ -610,9 +627,9 @@
         headerOutput << _T("}") << _T("\n");
     }

-    headerOutput << _T("#endif //VERSION_h\n");
+    headerOutput << _T("#endif //") << headerGuard << _T("\n");

-    m_versionHeaderPath = FileNormalize(cbC2U(GetConfig().Settings.HeaderPath.c_str()),m_Project->GetBasePath());;
+    m_versionHeaderPath = FileNormalize(cbC2U(GetConfig().Settings.HeaderPath.c_str()),m_Project->GetBasePath());
     wxFile versionHeaderFile(m_versionHeaderPath, wxFile::write);
     versionHeaderFile.Write(headerOutput);
     versionHeaderFile.Close();
@@ -622,7 +639,7 @@

void AutoVersioning::CommitChanges()
{
-    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
     {
         if (m_Modified)
         {
Index: src/plugins/contrib/AutoVersioning/AutoVersioning.h
===================================================================
--- src/plugins/contrib/AutoVersioning/AutoVersioning.h (revision 5005)
+++ src/plugins/contrib/AutoVersioning/AutoVersioning.h (working copy)
@@ -56,10 +56,10 @@
     wxTimer* m_timerStatus;

     int m_AutoVerHookId; //!< project loader hook ID

     std::map<cbProject*, avConfig> m_ProjectMap;

-    std::map<cbProject*, avVersionState> m_ProjectMapVersionState;

+    std::map<cbProject*, avVersionState> m_ProjectMapVersionState;
+    std::map<cbProject*, bool> m_IsVersioned;

     cbProject* m_Project; // keeps track of the last 'activated' project
     bool m_Modified; // have some settings been modified

-    bool m_IsCurrentProjectVersioned;

     /// fires when a project is being loaded / saved

     void OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading);



Index: src/plugins/contrib/AutoVersioning/manifest.xml
===================================================================
--- src/plugins/contrib/AutoVersioning/manifest.xml (revision 5005)
+++ src/plugins/contrib/AutoVersioning/manifest.xml (working copy)
@@ -3,7 +3,7 @@
     <SdkVersion major="1" minor="10" release="0" />

     <Plugin name="AutoVersioning">

         <Value title="AutoVersioning" />

-        <Value version="1.1" />

+        <Value version="1.2" />

         <Value description="Auto increments the version and build number of your application every time a change has been made and stores it in version.h with easy to use variable declarations. Also have a feature for committing changes a la SVN style, a version scheme editor and a change log generator.



Example:

@@ -40,7 +40,7 @@
  static const char SVN_REVISION[]

  static const char SVN_DATE[]

" />

-        <Value author="JGM" />

+        <Value author="Jefferson Gonzalez" />

         <Value authorEmail="jgmdev@gmail.com" />

         <Value authorWebsite="" />

         <Value thanksTo="Killerbot - Code Optimizations, conversion from version.ini to project file and many more...



[attachment deleted by admin]

mandrav

Well done JGM, sorting things out :)
Be patient!
This bug will be fixed soon...

JGM

Thank you, I have learned a lot from the codeblocks team (especially killerbot) :D

JGM

Submitted the patch to berlios, so it doesn't get lost or forgetted

killerbot

 :lol: wanted to apply the patch, couldn't find it at berlios, so was gonna use the above attached one, and I saw no differences  :? ----> biplab was way faster than me  :P

JGM

 :lol: thank you anyways!

JGM

#141
Discovered a bug introduced by the new changes while using the plugin on the development of my simple application.

The plugin is not autoincrementing the values before compiling. Here is the fix for oncompiler started and oncompilerfinished:

==================================================
void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)
{
    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
    {
      if (m_Modified)
      {
         const bool doAutoIncrement = GetConfig().Settings.DoAutoIncrement;
         const bool askToIncrement = GetConfig().Settings.AskToIncrement;
         if (doAutoIncrement && askToIncrement)
         {
            if (wxMessageBox(_("Do you want to increment the version?"),_T(""),wxYES_NO) == wxYES)
            {
               CommitChanges();
            }
         }
         else if(doAutoIncrement)
         {
            CommitChanges();
         }
      }
    }
} // end of OnCompilerStarted

void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)
{
    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
   {
      ++(GetVersionState().Values.BuildCount);
   }
}
==================================================

I dont know why but the previous code wasn't working:
m_IsVersioned[event.GetProject()]

Maybe the function (event) wasn't passing the correct project pointer, I didn't deeply tested. I wanted to create a patch but I'm still downloading a fresh copy cb svn, since svn update sucks (I don't know how to manages it well)

I will provide a patch later since the checkouts takes an eternity :lol:

JGM

#142
Here is the patch to resolve the bug:

Changes:
Now the auto incrementation is behaving normally again.

Quick look of the patch attached

Index: src/plugins/contrib/AutoVersioning/AutoVersioning.cpp
===================================================================
--- src/plugins/contrib/AutoVersioning/AutoVersioning.cpp (revision 5010)
+++ src/plugins/contrib/AutoVersioning/AutoVersioning.cpp (working copy)
@@ -293,7 +293,7 @@
// be activated and each has the compilerstarted/Finished ?????

void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)

{

-    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])

+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])

     {

         if (m_Modified)

         {

@@ -316,7 +316,7 @@


void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)

{

-    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])

+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])

     {

         ++(GetVersionState().Values.BuildCount);

     }

Index: src/plugins/contrib/AutoVersioning/manifest.xml
===================================================================
--- src/plugins/contrib/AutoVersioning/manifest.xml (revision 5010)
+++ src/plugins/contrib/AutoVersioning/manifest.xml (working copy)
@@ -3,7 +3,7 @@
     <SdkVersion major="1" minor="10" release="0" />

     <Plugin name="AutoVersioning">

         <Value title="AutoVersioning" />

-        <Value version="1.2" />

+        <Value version="1.3" />

         <Value description="Auto increments the version and build number of your application every time a change has been made and stores it in version.h with easy to use variable declarations. Also have a feature for committing changes a la SVN style, a version scheme editor and a change log generator.



Example:



[attachment deleted by admin]

killerbot

I will apply it soon ;-)

However I think it is good to find out why that event.GetProject() *might* be incorrect ?
Could you specify how you saw this misbehavior and how easily we could reproduce it (workspace with project in a zip file or something)

We should find the real cause and fix it over there ;-)

JGM

I submitted the patch to berlios also.

I will make some testing this night if possible, to check if it is an autoversioning error not updating the m_Project pointer correctly or it's the event.getproject sending a diffrent pointer value, since the pointer by event.getproject is not found on the m_IsVersioned map :?

killerbot

okay I will wait till you have finished that experiment.

JGM

I have found the time in the day to do the testing since my daughter was sleeping so i waited until she woke up to go now to do some business  :D

Well the oncompilerstarted event.getproject is returning a null pointer 0

The test I made
===================================================
void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)
{
    wxString print;
    print.Printf(_T("m_Project: %d event.GetProject: %d"),m_Project,event.GetProject());
    wxMessageBox(print);


    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
    {
      if (m_Modified)
      {
         const bool doAutoIncrement = GetConfig().Settings.DoAutoIncrement;
         const bool askToIncrement = GetConfig().Settings.AskToIncrement;
         if (doAutoIncrement && askToIncrement)
         {
            if (wxMessageBox(_("Do you want to increment the version?"),_T(""),wxYES_NO) == wxYES)
            {
               CommitChanges();
            }
         }
         else if(doAutoIncrement)
         {
            CommitChanges();
         }
      }
    }
} // end of OnCompilerStarted
===================================================

Attached is a screenshot showing the results

[attachment deleted by admin]

JGM

Should I submit a bug to berlios about the OnCompilerStarted event.GetProject() returning a null pointer?

killerbot

Quote from: JGM on April 23, 2008, 04:31:17 PM
Should I submit a bug to berlios about the OnCompilerStarted event.GetProject() returning a null pointer?

yes please do that, and attach sample project/workspace if possible.

JGM

Ok, I made a bug report (id: 13676), but until the problem is solved the patch #2444 should be applied i think, since now the autoversioning plugin is not working properly:
https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=2444&group_id=5358

Quote from: JGM on April 21, 2008, 11:36:28 PM

Index: src/plugins/contrib/AutoVersioning/AutoVersioning.cpp
===================================================================
--- src/plugins/contrib/AutoVersioning/AutoVersioning.cpp (revision 5010)
+++ src/plugins/contrib/AutoVersioning/AutoVersioning.cpp (working copy)
@@ -293,7 +293,7 @@
// be activated and each has the compilerstarted/Finished ?????

void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)

{

-    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])

+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])

     {

         if (m_Modified)

         {

@@ -316,7 +316,7 @@


void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)

{

-    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])

+    if (m_Project && IsAttached() && m_IsVersioned[m_Project])

     {

         ++(GetVersionState().Values.BuildCount);

     }

Index: src/plugins/contrib/AutoVersioning/manifest.xml
===================================================================
--- src/plugins/contrib/AutoVersioning/manifest.xml (revision 5010)
+++ src/plugins/contrib/AutoVersioning/manifest.xml (working copy)
@@ -3,7 +3,7 @@
     <SdkVersion major="1" minor="10" release="0" />

     <Plugin name="AutoVersioning">

         <Value title="AutoVersioning" />

-        <Value version="1.2" />

+        <Value version="1.3" />

         <Value description="Auto increments the version and build number of your application every time a change has been made and stores it in version.h with easy to use variable declarations. Also have a feature for committing changes a la SVN style, a version scheme editor and a change log generator.



Example: