Browse Source

Add reference to IronPython when converting projects to Python.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4068 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
81b50dc839
  1. 21
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConvertProjectToPythonProjectCommand.cs
  2. 25
      src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs
  3. 36
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertToPythonProjectCommandTestFixture.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  5. 47
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInHelper.cs
  6. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedConvertProjectToPythonProjectCommand.cs
  7. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs

21
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConvertProjectToPythonProjectCommand.cs

@ -36,6 +36,18 @@ namespace ICSharpCode.PythonBinding @@ -36,6 +36,18 @@ namespace ICSharpCode.PythonBinding
get { return PythonLanguageBinding.LanguageName; }
}
/// <summary>
/// Creates an PythonProject.
/// </summary>
protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject)
{
// Add IronPython reference.
IProject targetProject = base.CreateProject(targetProjectDirectory, sourceProject);
IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider;
targetProjectItems.AddProjectItem(CreateIronPythonReference(targetProject));
return targetProject;
}
/// <summary>
/// Converts C# and VB.NET files to Python and saves the files.
/// </summary>
@ -76,6 +88,13 @@ namespace ICSharpCode.PythonBinding @@ -76,6 +88,13 @@ namespace ICSharpCode.PythonBinding
protected virtual string GetParseableFileContent(string fileName)
{
return ParserService.GetParseableFileContent(fileName);
}
}
ReferenceProjectItem CreateIronPythonReference(IProject project)
{
ReferenceProjectItem reference = new ReferenceProjectItem(project, "IronPython");
reference.SetMetadata("HintPath", @"$(PythonBinPath)\IronPython.dll");
return reference;
}
}
}

25
src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs

@ -14,6 +14,7 @@ using ICSharpCode.Core; @@ -14,6 +14,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.TextEditor.Document;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests
{
@ -704,29 +705,9 @@ namespace PythonBinding.Tests @@ -704,29 +705,9 @@ namespace PythonBinding.Tests
Assert.AreEqual("VBNet", condition["activeproject"]);
}
/// <summary>
/// Gets the codon with the specified extension path and name.
/// </summary>
Codon GetCodon(string extensionPath, string name)
Codon GetCodon(string name, string extensionPath)
{
if (addin.Paths.ContainsKey(extensionPath)) {
ExtensionPath path = addin.Paths[extensionPath];
return GetCodon(path.Codons, name);
}
return null;
}
/// <summary>
/// Gets the codon with the specified name.
/// </summary>
Codon GetCodon(List<Codon> codons, string name)
{
foreach (Codon codon in codons) {
if (codon.Id == name) {
return codon;
}
}
return null;
return AddInHelper.GetCodon(addin, name, extensionPath);
}
}
}

36
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertToPythonProjectCommandTestFixture.cs

@ -9,8 +9,11 @@ using System; @@ -9,8 +9,11 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
@ -24,10 +27,11 @@ namespace PythonBinding.Tests.Converter @@ -24,10 +27,11 @@ namespace PythonBinding.Tests.Converter
FileProjectItem source;
FileProjectItem target;
MockProject sourceProject;
MockProject targetProject;
IProject targetProject;
FileProjectItem textFileSource;
FileProjectItem textFileTarget;
MockTextEditorProperties mockTextEditorProperties;
ReferenceProjectItem ironPythonReference;
string sourceCode = "class Foo\r\n" +
"{\r\n" +
"}";
@ -35,6 +39,13 @@ namespace PythonBinding.Tests.Converter @@ -35,6 +39,13 @@ namespace PythonBinding.Tests.Converter
[TestFixtureSetUp]
public void SetUpFixture()
{
List<LanguageBindingDescriptor> bindings = new List<LanguageBindingDescriptor>();
using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
AddIn addin = AddIn.Load(reader, String.Empty);
bindings.Add(new LanguageBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/LanguageBindings", "Python")));
}
LanguageBindingService.SetBindings(bindings);
mockTextEditorProperties = new MockTextEditorProperties();
convertProjectCommand = new DerivedConvertProjectToPythonProjectCommand(mockTextEditorProperties);
mockTextEditorProperties.Encoding = Encoding.Unicode;
@ -42,8 +53,7 @@ namespace PythonBinding.Tests.Converter @@ -42,8 +53,7 @@ namespace PythonBinding.Tests.Converter
sourceProject = new MockProject();
sourceProject.Directory = @"d:\projects\test";
source = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Program.cs");
targetProject = new MockProject();
targetProject.Directory = @"d:\projects\test\converted";
targetProject = convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
target = new FileProjectItem(targetProject, source.ItemType, source.Include);
source.CopyMetadataTo(target);
@ -51,6 +61,14 @@ namespace PythonBinding.Tests.Converter @@ -51,6 +61,14 @@ namespace PythonBinding.Tests.Converter
textFileTarget = new FileProjectItem(targetProject, textFileSource.ItemType, textFileSource.Include);
textFileSource.CopyMetadataTo(textFileTarget);
foreach (ProjectItem item in targetProject.Items) {
ReferenceProjectItem reference = item as ReferenceProjectItem;
if ((reference != null) && (reference.Name == "IronPython")) {
ironPythonReference = reference;
break;
}
}
convertProjectCommand.AddParseableFileContent(source.FileName, sourceCode);
convertProjectCommand.CallConvertFile(source, target);
@ -93,5 +111,17 @@ namespace PythonBinding.Tests.Converter @@ -93,5 +111,17 @@ namespace PythonBinding.Tests.Converter
expectedSavedFiles.Add(new ConvertedFile(target.FileName, expectedCode, mockTextEditorProperties.Encoding));
Assert.AreEqual(expectedSavedFiles, convertProjectCommand.SavedFiles);
}
[Test]
public void IronPythonReferenceAddedToProject()
{
Assert.IsNotNull(ironPythonReference, "No IronPython reference added to converted project.");
}
[Test]
public void IronPythonReferenceHintPath()
{
Assert.AreEqual(@"$(PythonBinPath)\IronPython.dll", ironPythonReference.GetMetadata("HintPath"));
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -271,6 +271,7 @@ @@ -271,6 +271,7 @@
<Compile Include="RunPythonCommandTestFixture.cs" />
<Compile Include="StopPythonCommandTestFixture.cs" />
<Compile Include="Utils\AddedComponent.cs" />
<Compile Include="Utils\AddInHelper.cs" />
<Compile Include="Utils\BrowseButtonInfo.cs" />
<Compile Include="Utils\BrowseFolderButtonInfo.cs" />
<Compile Include="Utils\ConvertedFile.cs" />

47
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInHelper.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
namespace PythonBinding.Tests.Utils
{
public class AddInHelper
{
AddInHelper()
{
}
/// <summary>
/// Gets the codon with the specified extension path and name.
/// </summary>
public static Codon GetCodon(AddIn addin, string extensionPath, string name)
{
if (addin.Paths.ContainsKey(extensionPath)) {
ExtensionPath path = addin.Paths[extensionPath];
return GetCodon(path.Codons, name);
}
return null;
}
/// <summary>
/// Gets the codon with the specified name.
/// </summary>
public static Codon GetCodon(List<Codon> codons, string name)
{
foreach (Codon codon in codons) {
if (codon.Id == name) {
return codon;
}
}
return null;
}
}
}

5
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedConvertProjectToPythonProjectCommand.cs

@ -62,6 +62,11 @@ namespace PythonBinding.Tests.Utils @@ -62,6 +62,11 @@ namespace PythonBinding.Tests.Utils
ConvertFile(source, target);
}
public IProject CallCreateProject(string directory, IProject sourceProject)
{
return base.CreateProject(directory, sourceProject);
}
protected override void LanguageConverterConvertFile(FileProjectItem source, FileProjectItem target)
{
sourceAndTargetFilesPassedToBaseClass.Add(new SourceAndTargetFile(source, target));

14
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockProject.cs

@ -95,11 +95,8 @@ namespace PythonBinding.Tests.Utils @@ -95,11 +95,8 @@ namespace PythonBinding.Tests.Utils
}
public string RootNamespace {
get {
throw new NotImplementedException();
}
get { return String.Empty; }
set {
throw new NotImplementedException();
}
}
@ -176,9 +173,7 @@ namespace PythonBinding.Tests.Utils @@ -176,9 +173,7 @@ namespace PythonBinding.Tests.Utils
}
public Solution ParentSolution {
get {
throw new NotImplementedException();
}
get { return new Solution(); }
}
public string TypeGuid {
@ -209,11 +204,8 @@ namespace PythonBinding.Tests.Utils @@ -209,11 +204,8 @@ namespace PythonBinding.Tests.Utils
}
public string Name {
get {
throw new NotImplementedException();
}
get { return String.Empty; }
set {
throw new NotImplementedException();
}
}

Loading…
Cancel
Save