-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from ngyukman/master
Support dependencies from PackageReference
- Loading branch information
Showing
8 changed files
with
210 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
version = 2.16 | ||
|
||
version = 2.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/groovy/com/ullink/packagesparser/PackageReferenceParser.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.ullink.packagesparser | ||
|
||
import groovy.util.slurpersupport.GPathResult | ||
|
||
|
||
class PackageReferenceParser implements NugetParser { | ||
|
||
// Limitation: does not resolve the conditional package references into groups | ||
|
||
@Override | ||
Collection getDependencies(File file) { | ||
def defaultDependencies = [] | ||
|
||
def project = new XmlSlurper().parse(file) | ||
|
||
project.'**' | ||
.findAll { it.name() == 'PackageReference' && getAttributeOrNodeText(it, 'PrivateAssets') != 'all' } | ||
.each { | ||
def reference = it as GPathResult | ||
def includeAssets = getAttributeOrNodeText(reference, 'IncludeAssets') | ||
def excludeAssets = getAttributeOrNodeText(reference, 'ExcludeAssets') | ||
def args = [ | ||
id: getAttributeOrNodeText(reference, 'Include'), version: getAttributeOrNodeText(reference, 'Version') | ||
] | ||
if (includeAssets) { | ||
args.include = includeAssets | ||
} | ||
if (excludeAssets) { | ||
args.exclude = excludeAssets | ||
} | ||
|
||
defaultDependencies.add({ | ||
dependency(args) | ||
}) | ||
} | ||
return defaultDependencies | ||
} | ||
|
||
private static String getAttributeOrNodeText(GPathResult parentNode, String key) { | ||
def node = parentNode."${key}".toString().trim() | ||
if (node) { | ||
return node | ||
} | ||
return parentNode["@${key}"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/groovy/com/ullink/packageparser/PackageReferenceParserSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/************************************************************************* | ||
* ULLINK CONFIDENTIAL INFORMATION | ||
* _______________________________ | ||
* | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: This file and its content are the property of Ullink. The | ||
* information included has been classified as Confidential and may | ||
* not be copied, modified, distributed, or otherwise disseminated, in | ||
* whole or part, without the express written permission of Ullink. | ||
************************************************************************/ | ||
package com.ullink.packageparser | ||
|
||
import com.ullink.packagesparser.PackageReferenceParser | ||
import groovy.xml.MarkupBuilder | ||
import spock.lang.Specification | ||
|
||
class PackageReferenceParserSpec extends Specification { | ||
def 'Extract dependencies from PackageReference from csproj'() { | ||
given: | ||
def csproj = new File(getClass().getResource('packagereference.csproj').toURI()) | ||
|
||
when: | ||
def result = new PackageReferenceParser().getDependencies(csproj) | ||
|
||
then: | ||
def writer = new StringWriter() | ||
def xml = new MarkupBuilder(writer) | ||
xml.dependencies() { | ||
result.each { | ||
it.resolveStrategy = DELEGATE_FIRST | ||
it.delegate = delegate | ||
it.call() | ||
} | ||
} | ||
writer.toString() == '''<dependencies> | ||
<dependency id='Microsoft.AspNetCore.Mvc.Abstractions' version='1.1.2' /> | ||
<dependency id='Microsoft.AspNetCore.Mvc.Core' version='1.1.2' /> | ||
<dependency id='Microsoft.Extensions.Caching.Abstractions' version='1.1.1' /> | ||
<dependency id='Microsoft.Extensions.Configuration.Binder' version='1.1.1' /> | ||
<dependency id='Newtonsoft.Json' version='9.0.1' /> | ||
<dependency id='StyleCop.Analyzers' version='1.0.0' /> | ||
<dependency id='NuGet.Versioning' version='3.6.0' include='build' exclude='none' /> | ||
<dependency id='System.Xml.XDocument' version='4.3.0' /> | ||
</dependencies>''' | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...y/com/ullink/ProjectJsonParserSpec.groovy → ...ackageparser/ProjectJsonParserSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/resources/com/ullink/packageparser/packagereference.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Description>...</Description> | ||
<AssemblyTitle>ASP.NET Core MVC 6 Boilerplate Framework</AssemblyTitle> | ||
<VersionPrefix>2.2.2</VersionPrefix> | ||
<Authors>Muhammad Rehan Saeed (RehanSaeed.com)</Authors> | ||
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<AssemblyName>Boilerplate.AspNetCore</AssemblyName> | ||
<AssemblyOriginatorKeyFile>../../../Key.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> | ||
<PackageId>Boilerplate.AspNetCore</PackageId> | ||
<PackageTags>ASP.NET;ASP.NET Core;MVC;MVC 6;Boilerplate;Muhammad Rehan Saeed;Framework</PackageTags> | ||
<PackageReleaseNotes>Updated to ASP.NET Core 1.1.2.</PackageReleaseNotes> | ||
<PackageIconUrl>https://raw.githubusercontent.com/RehanSaeed/ASP.NET-MVC-Boilerplate/master/Images/Icon.png</PackageIconUrl> | ||
<PackageProjectUrl>https://github.com/ASP-NET-MVC-Boilerplate/Framework</PackageProjectUrl> | ||
<PackageLicenseUrl>https://github.com/ASP-NET-MVC-Boilerplate/Framework/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/ASP-NET-MVC-Boilerplate/Framework.git</RepositoryUrl> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Boilerplate\Boilerplate.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions"> | ||
<Version>1.1.2</Version> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="1.1.1" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0"> | ||
<PrivateAssets>All</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="NuGet.Versioning" Version="3.6.0"> | ||
<IncludeAssets>build</IncludeAssets> | ||
<ExcludeAssets>none</ExcludeAssets> | ||
<PrivateAssets>contentfiles;analyzers;build</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' "> | ||
<PackageReference Include="System.Xml.XDocument" Version="4.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' "> | ||
<Reference Include="System.ServiceModel" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
</ItemGroup> | ||
|
||
</Project> |