Skip to content

Commit e056bc0

Browse files
committed
Copy JCW .jar to OutputPath
Context: 37f68a3 Commit 37f68a3 contained a comment+TODO: # Something is missing in the targets that `Hello-Java.Base.jar` isn't copied; copy it. # TODO: fix this. cp samples/Hello-Java.Base/bin/Release/Hello-Java.Base.jar samples/Hello-Java.Base/bin/Release/osx-x64/publish Fix that. The extra `cp` is no longer needed. Fixing this required three things: 1. Adding the JCW `.jar` to `@(Content)` (or `@(None)`, or…) 2. Setting `%(Content.CopyToOutputDirectory)`=PreserveNewest 3. Setting `%(Content.TargetPath)` `%(TargetPath)` is used to control the filename within the final `$(OutputPath)` directory tree; *without* `%(TargetPath)`, then `%(Identity)` is used, and since `%(Identity)` is now within `$(IntermediateOutputPath)`, that's *wrong*. Rename `$(JavaOutputJar)` to `$(JavaOutputJarName)`, as the new implied semantic is that it *cannot* contain a directory; it's *just* the filename. Update the `_JavaCreateJcws` so that instead of being a post-Build target it's instead a post-CoreCompile target. This is required because post-Build is too late; MSBuild tries to copy the `@(Content)` entries to `$(OutputPath)` *before the end* of `Build`, and as a post-Build step it didn't have a chance to *create* the jar yet! A post-CoreCompile target works nicer in this context. Because we're now post-CoreCompile, `$(TargetPath)` doesn't exist. (That's created during the build, by copying the intermediate assembly to the outptu path.) Update `_JavaCreateJcws` to use `@(IntermediateAssembly)` instead of `$(TargetPath)`. Update unit tests accordingly.
1 parent 224433e commit e056bc0

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

build-tools/Java.Interop.Sdk/Sdk/Sdk.targets

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</ItemDefinitionGroup>
1111

1212
<PropertyGroup>
13-
<JavaOutputJar Condition=" '$(JavaOutputJar)' == '' ">$(OutputPath)$(AssemblyName).jar</JavaOutputJar>
13+
<JavaOutputJarName Condition=" '$(JavaOutputJarName)' == '' ">$(AssemblyName).jar</JavaOutputJarName>
1414
</PropertyGroup>
1515

1616
<PropertyGroup>
@@ -32,7 +32,7 @@
3232
</Target>
3333

3434
<Target Name="JavaCreateOutputJar"
35-
AfterTargets="Build"
35+
AfterTargets="CoreCompile"
3636
DependsOnTargets="$(JavaCreateOutputJarDependsOn)">
3737
</Target>
3838

@@ -43,8 +43,16 @@
4343
<_JavaManagedBindingDir>$(_JavaIntermediateDir)mcw\</_JavaManagedBindingDir>
4444
<_JavaJcwClassesDir>$(_JavaIntermediateDir)classes\</_JavaJcwClassesDir>
4545
<_JavaJcwSourcesDir>$(_JavaIntermediateDir)java\</_JavaJcwSourcesDir>
46+
<_JavaOutputJarPath>$(_JavaIntermediateDir)$(JavaOutputJarName)</_JavaOutputJarPath>
4647
</PropertyGroup>
4748

49+
<ItemGroup>
50+
<Content Include="$(_JavaOutputJarPath)"
51+
CopyToOutputDirectory="PreserveNewest"
52+
TargetPath="$(JavaOutputJarName)"
53+
/>
54+
</ItemGroup>
55+
4856
<Target Name="_CollectJavaCompileForManagedBindingInputs">
4957
<ItemGroup>
5058
<_JavaCompileForBindingInputs
@@ -169,8 +177,8 @@
169177
<Target Name="_CleanupManagedBinding" />
170178

171179
<Target Name="_JavaCreateJcws"
172-
Condition=" '$(TargetPath)' != '' And Exists($(TargetPath))"
173-
Inputs="$(TargetPath)"
180+
Condition=" '@(IntermediateAssembly)' != '' And Exists(@(IntermediateAssembly))"
181+
Inputs="@(IntermediateAssembly)"
174182
Outputs="$(_JavaJcwSourcesDir).stamp">
175183
<RemoveDir Directories="$(_JavaJcwSourcesDir)" />
176184
<MakeDir Directories="$(_JavaJcwSourcesDir)" />
@@ -184,7 +192,7 @@
184192
<_Output>-o "$(_JavaJcwSourcesDir)."</_Output>
185193
<_Libpath>@(_RefAsmDirs->'-L "%(Identity)"', ' ')</_Libpath>
186194
</PropertyGroup>
187-
<Exec Command="$(DotnetToolPath) $(_JcwGen) -v &quot;$(TargetPath)&quot; $(_Target) $(_Output) $(_Libpath)" />
195+
<Exec Command="$(DotnetToolPath) $(_JcwGen) -v @(IntermediateAssembly->'&quot;%(Identity)&quot;', ' ') $(_Target) $(_Output) $(_Libpath)" />
188196
<Touch Files="$(_JavaJcwSourcesDir).stamp" AlwaysCreate="True" />
189197
</Target>
190198

@@ -197,7 +205,7 @@
197205
<Target Name="_JavaCreateOutputJar"
198206
DependsOnTargets="_JavaCollectGeneratdJcwSource;_JavaCollectJavacRefs"
199207
Inputs="@(_JavaGeneratedJcwSource)"
200-
Outputs="$(JavaOutputJar)">
208+
Outputs="$(_JavaOutputJarPath)">
201209
<RemoveDir Directories="$(_JavaJcwClassesDir)" />
202210
<MakeDir Directories="$(_JavaJcwClassesDir)" />
203211
<PropertyGroup>
@@ -215,7 +223,11 @@
215223
/>
216224
<Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(_JavaJcwClassesDir).&quot; -classpath &quot;$(_Classpath)&quot; &quot;@$(_JavaIntermediateDir)_java_sources.txt&quot;" />
217225
<Delete Files="$(_JavaIntermediateDir)_java_sources.txt" />
218-
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(JavaOutputJar)&quot; -C &quot;$(_JavaJcwClassesDir).&quot; ." />
226+
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(_JavaOutputJarPath)&quot; -C &quot;$(_JavaJcwClassesDir).&quot; ." />
227+
228+
<ItemGroup>
229+
<FileWrites Include="$(_JavaOutputJarPath)" />
230+
</ItemGroup>
219231
</Target>
220232

221233
</Project>

tests/Java.Base-Tests/Java.Base-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<PropertyGroup>
1515
<OutputPath>$(TestOutputFullPath)</OutputPath>
16-
<JavaOutputJar>$(OutputPath)java.base-tests.jar</JavaOutputJar>
16+
<JavaOutputJarName>java.base-tests.jar</JavaOutputJarName>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)