Skip to content

Commit

Permalink
Fix build issues after refactor
Browse files Browse the repository at this point in the history
- Do not repack since it will break reflection call in MsBuild
- Parameter tweak on ProjectFileParser to avoid recongize as
  Win32/Repjexi
- Tested by building gradle-msbuild-plugin itself
  • Loading branch information
ngyukman authored and gluck committed Feb 19, 2016
1 parent dbad208 commit ad1ab3a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.gradle.internal.os.OperatingSystem;
plugins {
id 'nu.studer.plugindev' version '1.0.3'
id 'com.jfrog.bintray' version '1.2'
id 'com.ullink.msbuild' version '2.11'
id 'com.ullink.msbuild' version '2.12'
id 'com.ullink.nuget' version '2.13'
id 'com.ullink.nunit' version '1.5'
id 'net.researchgate.release' version '2.3.4'
Expand Down Expand Up @@ -43,19 +43,21 @@ nunit {
}
nunit.dependsOn msbuild

task generateExe(dependsOn: nunit, type: Exec) {
workingDir = msbuild.mainProject.getProjectPropertyPath('OutputPath')
commandLine = [file('packages/ILRepack.2.0.10/tools/ILRepack.exe'),
'/log', '/wildcards', '/internalize', '/ndebug',
'/out:'+file('src/main/resources/META-INF/bin/ProjectFileParser.exe'),
msbuild.mainProject.properties.TargetPath,
'Newtonsoft.Json.dll', 'Microsoft.Build.dll', 'Microsoft.Build.Utilities.Core.dll']
task generateZip(dependsOn: msbuild, type: Zip) {
from (msbuild.mainProject.properties.TargetDir) {
include '*.exe'
include '*.dll'
}
into '/'
destinationDir file('src/main/resources/META-INF/')
archiveName 'ProjectFileParser.zip'
}

msbuild.onlyIf { OperatingSystem.current().windows }
nunit.onlyIf { OperatingSystem.current().windows }
generateExe.onlyIf { OperatingSystem.current().windows }
generateZip.onlyIf { OperatingSystem.current().windows }

jar.dependsOn generateExe
jar.dependsOn generateZip

bintray {
// to remove when upgraded plugindev to 1.0.4
Expand Down
11 changes: 8 additions & 3 deletions src/main/dotnet/ProjectFileParser/ProjectFileParser.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -28,16 +28,21 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup>
<StartupObject>ProjectFileParser.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build">
<HintPath>..\..\..\..\packages\MSBuild.0.1.2\tools\Unix\Microsoft.Build.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down
54 changes: 33 additions & 21 deletions src/main/groovy/com/ullink/Msbuild.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.ullink
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.nio.file.Files
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.gradle.api.GradleException
Expand Down Expand Up @@ -70,30 +73,39 @@ class Msbuild extends ConventionTask {
if (!new File(file.toString()).exists()) {
throw new GradleException("Project/Solution file $file does not exist")
}

File tmp = File.createTempFile('ProjectFileParser', '.exe', temporaryDir)
File tempDir = Files.createTempDirectory('ProjectFileParser').toFile()
tempDir.deleteOnExit()

def zipFileStream = this.class.getResourceAsStream("/META-INF/ProjectFileParser.zip")
ZipInputStream zis = new ZipInputStream(zipFileStream)
ZipEntry ze = zis.getNextEntry()
while (ze != null) {
String fileName = ze.getName()
File target = new File(tempDir, fileName)
target.newOutputStream().leftShift(zis).close()
target.deleteOnExit()
ze = zis.getNextEntry()
}
zis.closeEntry()
zis.close()

def executable = new File(tempDir, 'ProjectFileParser.exe')
def builder = resolver.executeDotNet(executable)
builder.command().add(file.toString())
def proc = builder.start()
def stderrBuffer = new StringBuffer()
proc.consumeProcessErrorStream(stderrBuffer)
try {
def src = getClass().getResourceAsStream('/META-INF/bin/ProjectFileParser.exe')
tmp.newOutputStream().leftShift(src).close();
def builder = resolver.executeDotNet(tmp)
builder.command().add(file.toString())
def proc = builder.start()
def stderrBuffer = new StringBuffer()
proc.consumeProcessErrorStream(stderrBuffer)
try {
proc.out.leftShift(JsonOutput.toJson(getInitProperties())).close()
return new JsonSlurper().parseText(new FilterJson(proc.in).toString())
}
finally {
if (proc.waitFor() != 0) {
stderrBuffer.eachLine { line ->
logger.error line
}
throw new GradleException('Project file parsing failed')
proc.out.leftShift(JsonOutput.toJson(getInitProperties())).close()
return new JsonSlurper().parseText(new FilterJson(proc.in).toString())
}
finally {
if (proc.waitFor() != 0) {
stderrBuffer.eachLine { line ->
logger.error line
}
throw new GradleException('Project file parsing failed')
}
} finally {
tmp.delete()
}
}

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit ad1ab3a

Please sign in to comment.