Skip to content

Commit

Permalink
Fix #13: web api components must be depoyed in the folder specified w…
Browse files Browse the repository at this point in the history
…ith the main build output.
  • Loading branch information
tom-englert committed Jan 5, 2017
1 parent 3ea0cef commit b49c60a
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 75 deletions.
5 changes: 2 additions & 3 deletions Wax.Model/Mapping/DirectoryMapping.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Mapping
namespace tomenglertde.Wax.Model.Mapping
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
Expand Down
31 changes: 20 additions & 11 deletions Wax.Model/Mapping/FileMapping.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Mapping
namespace tomenglertde.Wax.Model.Mapping
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -52,7 +51,7 @@ public FileMapping([NotNull] ProjectOutput projectOutput, ObservableCollection<P
_wixProject = wixProject;
_allUnmappedFiles = allUnmappedFiles;

_id = wixProject.GetFileId(SourceName);
_id = wixProject.GetFileId(TargetName);

MappedNode = wixProject.FileNodes.FirstOrDefault(node => node.Id == _id);

Expand Down Expand Up @@ -94,7 +93,7 @@ public string UniqueName
{
Contract.Ensures(Contract.Result<string>() != null);

return _projectOutput.FullName;
return _projectOutput.TargetName;
}
}

Expand All @@ -105,24 +104,34 @@ public string Extension
{
Contract.Ensures(Contract.Result<string>() != null);

return Path.GetExtension(_projectOutput.FullName);
return Path.GetExtension(_projectOutput.TargetName);
}

}

[NotNull]
public string SourceName
public string TargetName
{
get
{
Contract.Ensures(Contract.Result<string>() != null);

var fileName = _projectOutput.FullName;
return _projectOutput.TargetName;
}
}

[NotNull]
public string SourceName
{
get
{
Contract.Ensures(Contract.Result<string>() != null);

return Path.IsPathRooted(fileName) ? Path.GetFileName(fileName) : fileName;
return _projectOutput.SourceName;
}
}


[NotNull]
public IList<UnmappedFile> UnmappedNodes
{
Expand Down Expand Up @@ -218,15 +227,15 @@ private void MappedNode_Changed(WixFileNode oldValue, WixFileNode newValue)
if (oldValue != null)
{
_allUnmappedFiles.Add(new UnmappedFile(oldValue, _allUnmappedFiles));
_wixProject.UnmapFile(SourceName);
_wixProject.UnmapFile(TargetName);
_allUnmappedProjectOutputs.Add(_projectOutput);
}

if (newValue != null)
{
var unmappedFile = _allUnmappedFiles.FirstOrDefault(file => Equals(file.Node, newValue));
_allUnmappedFiles.Remove(unmappedFile);
_wixProject.MapFile(SourceName, newValue);
_wixProject.MapFile(TargetName, newValue);
_allUnmappedProjectOutputs.Remove(_projectOutput);
}

Expand Down
5 changes: 2 additions & 3 deletions Wax.Model/Mapping/UnmappedFile.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Mapping
namespace tomenglertde.Wax.Model.Mapping
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Windows.Input;

Expand Down
6 changes: 3 additions & 3 deletions Wax.Model/Tools/XmlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using JetBrains.Annotations;

namespace tomenglertde.Wax.Model.Tools
namespace tomenglertde.Wax.Model.Tools
{
using System.Diagnostics.Contracts;
using System.Xml;
using System.Xml.Linq;

using JetBrains.Annotations;

public static class XmlExtensions
{
public static void RemoveSelfAndWhiteSpace([NotNull] this XElement element)
Expand Down
25 changes: 16 additions & 9 deletions Wax.Model/VisualStudio/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

using JetBrains.Annotations;
Expand Down Expand Up @@ -60,16 +59,17 @@ public IEnumerable<ProjectReference> ProjectReferences
}

[NotNull, ItemNotNull]
public IEnumerable<ProjectOutput> GetLocalFileReferences([NotNull] Project rootProject)
public IEnumerable<ProjectOutput> GetLocalFileReferences([NotNull] Project rootProject, [NotNull] string targetDirectory)
{
Contract.Requires(rootProject != null);
Contract.Requires(targetDirectory != null);
Contract.Ensures(Contract.Result<IEnumerable<ProjectOutput>>() != null);

var localFileReferences = References
.Where(reference => reference.GetSourceProject() == null)
.Where(reference => reference.CopyLocal)
.Select(reference => new ProjectOutput(rootProject, reference))
.Concat(GetSecondTierReferences(rootProject));
.Select(reference => new ProjectOutput(rootProject, reference, targetDirectory))
.Concat(GetSecondTierReferences(rootProject, targetDirectory));

return localFileReferences;
}
Expand Down Expand Up @@ -132,16 +132,23 @@ public IEnumerable<ProjectOutput> GetProjectOutput([NotNull] Project rootProject
Contract.Ensures(Contract.Result<IEnumerable<ProjectOutput>>() != null);

var projectOutput = GetBuildFiles(rootProject, deploySymbols)
.Concat(GetLocalFileReferences(rootProject))
.Concat(ProjectReferences.SelectMany(reference => reference.SourceProject.GetProjectOutput(rootProject, deploySymbols)));
.ToArray();

return projectOutput;
var targetDirectory = projectOutput
.Where(output => output.BuildFileGroup == BuildFileGroups.Built)
.Select(output => Path.GetDirectoryName(output.TargetName))
.FirstOrDefault() ?? string.Empty;

return projectOutput
.Concat(GetLocalFileReferences(rootProject, targetDirectory)) // references must go to the same folder as the referencing component.
.Concat(ProjectReferences.SelectMany(reference => reference.SourceProject.GetProjectOutput(rootProject, deploySymbols)));
}

[NotNull, ItemNotNull]
private IEnumerable<ProjectOutput> GetSecondTierReferences([NotNull] Project rootProject)
private IEnumerable<ProjectOutput> GetSecondTierReferences([NotNull] Project rootProject, [NotNull] string targetDirectory)
{
Contract.Requires(rootProject != null);
Contract.Requires(targetDirectory != null);
Contract.Ensures(Contract.Result<IEnumerable<ProjectOutput>>() != null);

// Try to resolve second-tier references for CopyLocal references
Expand All @@ -152,7 +159,7 @@ private IEnumerable<ProjectOutput> GetSecondTierReferences([NotNull] Project roo
.SelectMany(GetReferencedAssemblyNames)
.Distinct()
.Where(File.Exists)
.Select(file => new ProjectOutput(rootProject, file));
.Select(file => new ProjectOutput(rootProject, file, targetDirectory));
}

[NotNull]
Expand Down
52 changes: 33 additions & 19 deletions Wax.Model/VisualStudio/ProjectOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.IO;

Expand All @@ -14,48 +15,59 @@ public class ProjectOutput : IEquatable<ProjectOutput>

[NotNull]
private readonly Project _project;
private readonly bool _isReference;

public ProjectOutput([NotNull] Project project, [NotNull] string fullName, BuildFileGroups buildFileGroup)
{
Contract.Requires(project != null);
Contract.Requires(fullName != null);

if (buildFileGroup == BuildFileGroups.Built || buildFileGroup == BuildFileGroups.Symbols)
{
// Build output should be only a file name, without folder.
// => Workaround: In Web API projects (ASP.NET MVC) the build output is always "bin\<targetname>.dll" instead of just "<targetname>.dll",
// where "bin" seems to be hard coded.
fullName = Path.GetFileName(fullName);
}

BuildFileGroup = buildFileGroup;
_fullName = fullName;
_project = project;
}

public ProjectOutput([NotNull] Project project, [NotNull] string fullName)
public ProjectOutput([NotNull] Project project, [NotNull] string fullName, [NotNull] string targetDirectory)
{
Contract.Requires(project != null);
Contract.Requires(fullName != null);
Contract.Requires(targetDirectory != null);

_isReference = true;
_fullName = fullName;
_fullName = Path.Combine(targetDirectory, Path.GetFileName(fullName));
_project = project;
}

public ProjectOutput([NotNull] Project project, [NotNull] VSLangProj.Reference reference)
[ContractVerification(false), SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
public ProjectOutput([NotNull] Project project, [NotNull] VSLangProj.Reference reference, [NotNull] string targetDirectory)
: this(project, reference.Path, targetDirectory)
{
Contract.Requires(project != null);
Contract.Requires(reference != null);
Contract.Requires(targetDirectory != null);
}

_isReference = true;
Contract.Assume(reference.Path != null);
_fullName = reference.Path;
_project = project;
[NotNull]
public string SourceName
{
get
{
Contract.Ensures(Contract.Result<string>() != null);

switch (BuildFileGroup)
{
case BuildFileGroups.Built:
case BuildFileGroups.Symbols:
case BuildFileGroups.None: // references...
return FileName;

default:
return _fullName;
}
}
}


[NotNull]
public string FullName
public string TargetName
{
get
{
Expand Down Expand Up @@ -87,7 +99,9 @@ public Project Project
}
}

public bool IsReference => _isReference;
public bool IsReference => BuildFileGroup == BuildFileGroups.None;

public BuildFileGroups BuildFileGroup { get; }

public override string ToString()
{
Expand Down
5 changes: 2 additions & 3 deletions Wax.Model/VisualStudio/ProjectReference.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.VisualStudio
namespace tomenglertde.Wax.Model.VisualStudio
{
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;

Expand Down
5 changes: 2 additions & 3 deletions Wax.Model/VisualStudio/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.VisualStudio
namespace tomenglertde.Wax.Model.VisualStudio
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
Expand Down
3 changes: 1 addition & 2 deletions Wax.Model/Wix/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Wix
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Xml.Serialization;
Expand Down
5 changes: 2 additions & 3 deletions Wax.Model/Wix/WixDefine.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Wix
namespace tomenglertde.Wax.Model.Wix
{
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Xml.Linq;
Expand Down
3 changes: 1 addition & 2 deletions Wax.Model/Wix/WixFileNode.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Wix
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
Expand Down
3 changes: 1 addition & 2 deletions Wax.Model/Wix/WixNode.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Wix
{
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Xml.Linq;
Expand Down
11 changes: 5 additions & 6 deletions Wax.Model/Wix/WixProject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.Contracts;
namespace tomenglertde.Wax.Model.Wix
{
using System;
Expand Down Expand Up @@ -247,11 +246,11 @@ public WixFileNode AddFileNode([NotNull] FileMapping fileMapping)
Contract.Requires(fileMapping != null);
Contract.Ensures(Contract.Result<WixFileNode>() != null);

var filePath = fileMapping.SourceName;
var targetName = fileMapping.TargetName;

var name = Path.GetFileName(filePath);
var id = GetFileId(filePath);
var directoryName = Path.GetDirectoryName(filePath);
var name = Path.GetFileName(targetName);
var id = GetFileId(targetName);
var directoryName = Path.GetDirectoryName(targetName);
var directoryId = GetDirectoryId(directoryName);
var directory = DirectoryNodes.FirstOrDefault(node => node.Id.Equals(directoryId, StringComparison.OrdinalIgnoreCase));
directoryId = directory != null ? directory.Id : "TODO: unknown directory " + directoryName;
Expand Down Expand Up @@ -317,7 +316,7 @@ public bool HasDefaultFileId([NotNull] FileMapping fileMapping)
{
Contract.Requires(fileMapping != null);

var filePath = fileMapping.SourceName;
var filePath = fileMapping.TargetName;
var id = GetFileId(filePath);
var defaultId = GetDefaultId(filePath);

Expand Down
3 changes: 1 addition & 2 deletions Wax.Model/Wix/WixSourceFile.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Diagnostics;

namespace tomenglertde.Wax.Model.Wix
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
Expand Down
Loading

0 comments on commit b49c60a

Please sign in to comment.