Skip to content

Commit

Permalink
first iteration of debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ArsenShnurkov committed Jan 21, 2017
1 parent c57bc97 commit 86afe4f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
32 changes: 21 additions & 11 deletions mpt-core/03_msbuild/MSBuildFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public MSBuildFile(string filename)
XmlDocument d = new XmlDocument();
d.Load(filename);
this.doc = d;
this.filename = filename;
FindAllImports();
FindAllTargets();
}
Expand Down Expand Up @@ -108,16 +109,17 @@ public void FindAllImports()
{
return;
}
do
while (nodeIterator.MoveNext())
{
if (nodeIterator.Current is IHasXmlNode)
{
XmlElement node = (XmlElement)((IHasXmlNode)nodeIterator.Current).GetNode();
MSBuildImport wrapperObject = new MSBuildImport(this, node);
XmlNode node = ((IHasXmlNode)nodeIterator.Current).GetNode();
XmlElement element = (XmlElement)node;
MSBuildImport wrapperObject = new MSBuildImport(this, element);
importNodes.Add(wrapperObject);
}
}
while (nodeIterator.MoveNext()); // see also https://weblogs.asp.net/cazzu/86609
// see also https://weblogs.asp.net/cazzu/86609
}

// locate if there is import of Microsoft.CSharp.targets
Expand Down Expand Up @@ -149,8 +151,11 @@ public void InsertImport(MSBuildImport newImport)
XPathNavigator navigator = doc.CreateNavigator();
navigator.MoveToRoot();

XmlElement root = (XmlElement)navigator.UnderlyingObject;
root.AppendChild(newXmlElement);
XmlNode root = (XmlNode)navigator.UnderlyingObject;
XmlNode lc = root.LastChild;
lc.AppendChild(newXmlElement);

bSaveRequired = true;
}

public void InsertImportAfter(MSBuildImport existingImport, MSBuildImport newImport)
Expand All @@ -160,7 +165,9 @@ public void InsertImportAfter(MSBuildImport existingImport, MSBuildImport newImp
// вставить в нижележащий слой
XmlElement existingElement = existingImport.UnderlyingObject;
XmlElement newElement = newImport.UnderlyingObject;
existingElement.ParentNode.InsertAfter(existingElement, newElement);
existingElement.ParentNode.InsertAfter(newElement, existingElement);

bSaveRequired = true;
}

public MSBuildTarget CreateTarget()
Expand All @@ -186,16 +193,17 @@ public void FindAllTargets()
{
return;
}
do
while (nodeIterator.MoveNext())
{
if (nodeIterator.Current is IHasXmlNode)
{
XmlElement node = (XmlElement)((IHasXmlNode)nodeIterator.Current).GetNode();
MSBuildTarget wrapperObject = new MSBuildTarget(this, node);
XmlNode node = ((IHasXmlNode)nodeIterator.Current).GetNode();
XmlElement element = (XmlElement)node;
MSBuildTarget wrapperObject = new MSBuildTarget(this, element);
targetNodes.Add(wrapperObject);
}
}
while (nodeIterator.MoveNext()); // see also https://weblogs.asp.net/cazzu/86609
// see also https://weblogs.asp.net/cazzu/86609
}

public MSBuildTarget FindTarget(string v)
Expand Down Expand Up @@ -228,5 +236,7 @@ public void InsertTarget(MSBuildTarget newTarget)

XmlElement root = (XmlElement)navigator.UnderlyingObject;
root.AppendChild(newXmlElement);

bSaveRequired = true;
}
}
16 changes: 14 additions & 2 deletions mpt-core/03_msbuild/MSBuildImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public XmlElement UnderlyingObject
}
}

public string Project { get { return uo.Attributes["Project"].Value; } set { uo.Attributes["Project"].Value = value; } }
public string Project { get { return uo.Attributes["Project"].Value; } set { uo.SetAttribute("Project", value); } }

public MSBuildImport(MSBuildFile f, XmlElement el)
{
Expand All @@ -27,6 +27,18 @@ public MSBuildImport(MSBuildFile f)
{
this.file = f;
// string element = "<Import Project=\"" + import_name + "\" />";
uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Import", this.uo.NamespaceURI);
uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Import", MSBuildFile.NamespaceName);
}

/*void SetProject(string value)
{
if (uo.HasAttribute("Project))" +
{
uo.Attributes["Project"].Value = value;
}
else
{
uo.SetAttribute("Project", value);
}
}*/
}
2 changes: 1 addition & 1 deletion mpt-core/03_msbuild/MSBuildTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MSBuildTarget : ICanHaveProperties, ICanHaveItems
public MSBuildTarget(MSBuildFile f)
{
this.file = f;
uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Target", this.uo.NamespaceURI);
uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Target", MSBuildFile.NamespaceName);
}

public MSBuildTarget(MSBuildFile f, XmlElement el)
Expand Down
43 changes: 40 additions & 3 deletions mpt-csproj/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,32 @@ enum ExitCode : int
NoInputFileSpecified = 2,
NoDataProviderNameSpecified = 3,
NothingToDo = 4,
HelpOrVersion = 5,
Exception = 6,
}
public static int Main (string[] args)
public static int Main(string[] args)
{
try
{
return MainProcessing(args);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
ShowVersion();
for (int i = 0; i < args.Length; i++)
{
if (i > 0)
{
Console.Write(" ");
}
Console.Write(args[i]);
}
Console.WriteLine();
}
return (int)ExitCode.Exception;
}
public static int MainProcessing(string[] args)
{
var verbose = (string)null;
var remove_warnings_as_errors = (string)null;
Expand All @@ -40,7 +64,8 @@ public static int Main (string[] args)
{
/* General options */
// output usage summary and exit
{ "h|?|help", v => ShowHelp() },
{ "h|?|help", v => { ShowHelp(); System.Environment.Exit((int)ExitCode.HelpOrVersion); } },
{ "v|V|version", v => { ShowVersion(); System.Environment.Exit((int)ExitCode.HelpOrVersion); } },
// give more explainations during work
{ "verbose", b => verbose = b },

Expand Down Expand Up @@ -193,8 +218,10 @@ public static int Main (string[] args)
}
if (remove_warnings_as_errors != null)
{
Console.WriteLine($"Removing warnings as errors");
foreach (var csproj_file in listOfCsproj)
{
Console.WriteLine($"from file {csproj_file}");
if (verbose != null)
{
string output_or_inplace = (as_unified_patch == null) ? ", inplace conversion" : String.Format(" >> {0}", as_unified_patch);
Expand All @@ -205,8 +232,10 @@ public static int Main (string[] args)
}
if (remove_signing != null)
{
Console.WriteLine($"Removing signing");
foreach (var csproj_file in listOfCsproj)
{
Console.WriteLine($"from file {csproj_file}");
if (verbose != null)
{
string output_or_inplace = (as_unified_patch == null) ? ", inplace conversion" : String.Format(" >> {0}", as_unified_patch);
Expand All @@ -220,6 +249,7 @@ public static int Main (string[] args)
Console.WriteLine($"Replacing reference {reference_name}");
foreach (var csproj_file in listOfCsproj)
{
Console.WriteLine($"in file {csproj_file}");
ProjectTools.ReplaceReference(csproj_file, reference_name, bForceReferenceAppending);
}
}
Expand All @@ -228,6 +258,7 @@ public static int Main (string[] args)
Console.WriteLine($"Injecting import of project {import_name}");
foreach (var csproj_file in listOfCsproj)
{
Console.WriteLine($"into file {csproj_file}");
using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file))
{
file.InjectProjectImport(import_name);
Expand All @@ -239,6 +270,7 @@ public static int Main (string[] args)
Console.WriteLine($"Injecting version property {version_string}");
foreach (var csproj_file in listOfCsproj)
{
Console.WriteLine($"into file {csproj_file}");
using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file))
{
file.InjectVersioning(version_string);
Expand All @@ -250,6 +282,7 @@ public static int Main (string[] args)
Console.WriteLine($"Injecting version property {version_string}");
foreach (var csproj_file in listOfCsproj)
{
Console.WriteLine($"into file {csproj_file}");
using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file))
{
// null is ok - http://stackoverflow.com/questions/637308/why-is-adding-null-to-a-string-legal
Expand All @@ -268,10 +301,14 @@ public static int Main (string[] args)
}
return (int)ExitCode.Success;
}
public static void ShowHelp()
public static void ShowVersion()
{
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Console.WriteLine($"mpt-cspoj.exe, version {version}");
}
public static void ShowHelp()
{
ShowVersion();
Console.WriteLine("Usage: ");
Console.WriteLine("\tmpt-csproj --list-refs");
Console.WriteLine("\t\tPrints references");
Expand Down
4 changes: 2 additions & 2 deletions mpt-csproj/mpt-csproj.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\..\..\..\..\..\..\usr\share\mono-packaging-tools-0</OutputPath>
<OutputPath>..\..\..\..\..\..\..\usr\share\mono-packaging-tools\slot-0\</OutputPath>
<Commandlineparameters></Commandlineparameters>
<CustomCommands>
<CustomCommands>
<Command type="Execute" command="${TargetFile} src/Castle.Core/Castle.Core-vs2008.csproj --inject-import='\usr\lib64\mono\xbuild\12.0\bin\\MSBuild.Community.Tasks.Targets'" workingdir="/var/calculate/remote/distfiles/egit-src/Castle.Core-READONLY.git" />
<Command type="Execute" command="${TargetFile} ./src --inject-import=$(MSBuildToolsPath)\MSBuild.Community.Tasks.Targets" workingdir="/var/calculate/remote/distfiles/egit-src/Castle.Core-READONLY.git" externalConsole="True" pauseExternalConsole="True" />
<Command type="Custom" />
</CustomCommands>
</CustomCommands>
Expand Down

0 comments on commit 86afe4f

Please sign in to comment.