Skip to content

Commit 53231e0

Browse files
committed
Fix issue when files are deleted
1 parent 3d1e651 commit 53231e0

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Javac.targets

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
2121
<_AndroidIntermediateBindingClassesZip>$(IntermediateOutputPath)binding\bin\$(MSBuildProjectName).jar</_AndroidIntermediateBindingClassesZip>
2222
<_AndroidIntermediateBindingClassesDocs>$(IntermediateOutputPath)binding\bin\$(MSBuildProjectName)-docs.xml</_AndroidIntermediateBindingClassesDocs>
2323
<_AndroidCompileJavaStampFile>$(_AndroidStampDirectory)_CompileJava.stamp</_AndroidCompileJavaStampFile>
24+
<_AndroidCompileJavaFileList>$(IntermediateOutputPath)_CompileJava.FileList.txt</_AndroidCompileJavaFileList>
2425
<_AndroidCompileBindingJavaStampFile>$(_AndroidStampDirectory)_CompileBindingJava.stamp</_AndroidCompileBindingJavaStampFile>
26+
<_AndroidCompileBindingJavaFileList>$(IntermediateOutputPath)_CompileBindingJava.FileList.txt</_AndroidCompileBindingJavaFileList>
2527
</PropertyGroup>
2628

2729
<Target Name="_AdjustJavacVersionArguments">
@@ -74,18 +76,36 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
7476
<ItemGroup>
7577
<_JavaBindingSource Include="@(AndroidJavaSource)" Condition=" '%(AndroidJavaSource.Bind)' == 'True' " />
7678
</ItemGroup>
79+
<WriteLinesToFile
80+
File="$(_AndroidCompileBindingJavaFileList)"
81+
Lines="@(_JavaBindingSource->ToLowerInvariant())"
82+
Overwrite="true"
83+
WriteOnlyWhenDifferent="true"
84+
/>
85+
<ItemGroup>
86+
<FileWrites Include="$(_AndroidCompileBindingJavaFileList)" />
87+
</ItemGroup>
7788
</Target>
7889

7990
<Target Name="_CollectJavaSource">
8091
<ItemGroup>
8192
<_JavaSource Include="@(AndroidJavaSource)" Condition=" '%(AndroidJavaSource.Bind)' != 'True' " />
8293
</ItemGroup>
94+
<WriteLinesToFile
95+
File="$(_AndroidCompileJavaFileList)"
96+
Lines="@(_JavaSource->ToLowerInvariant())"
97+
Overwrite="true"
98+
WriteOnlyWhenDifferent="true"
99+
/>
100+
<ItemGroup>
101+
<FileWrites Include="$(_AndroidCompileJavaFileList)" />
102+
</ItemGroup>
83103
</Target>
84104

85105
<Target Name="_CompileBindingJava"
86106
Condition=" '@(_JavaBindingSource->Count())' != '0' "
87107
DependsOnTargets="$(_CompileBindingJavaDependsOnTargets)"
88-
Inputs="@(_AndroidMSBuildAllProjects);$(MonoPlatformJarPath);@(_JavaBindingSource)"
108+
Inputs="@(_AndroidMSBuildAllProjects);$(_AndroidCompileBindingJavaFileList);$(MonoPlatformJarPath);@(_JavaBindingSource)"
89109
Outputs="$(_AndroidCompileBindingJavaStampFile)">
90110

91111
<!-- remove existing <Javac /> outputs, since *.class files and classes.zip could contain old files -->
@@ -132,7 +152,7 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
132152

133153
<Target Name="_CompileJava"
134154
DependsOnTargets="$(_CompileJavaDependsOnTargets);_CollectJavaSource"
135-
Inputs="@(_AndroidMSBuildAllProjects);$(MonoPlatformJarPath);@(_JavaStubFiles);@(_JavaSource)"
155+
Inputs="@(_AndroidMSBuildAllProjects);$(_AndroidCompileJavaFileList);$(MonoPlatformJarPath);@(_JavaStubFiles);@(_JavaSource)"
136156
Outputs="$(_AndroidCompileJavaStampFile)">
137157

138158
<!-- remove existing <Javac /> outputs, since *.class files and classes.zip could contain old files -->

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void DotNetBuildBinding ()
3939
proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javaclasses-sources.jar") {
4040
BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar,
4141
});
42-
proj.OtherBuildItems.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") {
42+
proj.AndroidJavaSources.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") {
4343
Encoding = Encoding.ASCII,
4444
TextContent = () => ResourceData.JavaSourceTestExtension,
4545
Metadata = { { "Bind", "True"} },

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetXamarinProject.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ protected DotNetXamarinProject (string debugConfigurationName = "Debug", string
1717

1818
Sources = new List<BuildItem> ();
1919
OtherBuildItems = new List<BuildItem> ();
20+
AndroidJavaSources = new List<BuildItem> ();
2021

2122
ItemGroupList.Add (References);
2223
ItemGroupList.Add (OtherBuildItems);
2324
ItemGroupList.Add (Sources);
25+
ItemGroupList.Add (AndroidJavaSources);
2426

2527
SetProperty ("RootNamespace", () => RootNamespace ?? ProjectName);
2628
SetProperty ("AssemblyName", () => AssemblyName ?? ProjectName);
@@ -40,6 +42,7 @@ protected DotNetXamarinProject (string debugConfigurationName = "Debug", string
4042

4143
public IList<BuildItem> OtherBuildItems { get; private set; }
4244
public IList<BuildItem> Sources { get; private set; }
45+
public IList<BuildItem> AndroidJavaSources { get; private set; }
4346

4447
public IList<Property> ActiveConfigurationProperties {
4548
get { return IsRelease ? ReleaseProperties : DebugProperties; }

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,8 @@ because xbuild doesn't support framework reference assemblies.
25692569
<Delete Files="$(_AndroidMainDexListFile)" />
25702570
<Delete Files="$(_AndroidBuildIdFile)" />
25712571
<Delete Files="$(_ResolvedUserAssembliesHashFile)" />
2572+
<Delete Files="$(_AndroidCompileBindingJavaFileList)" />
2573+
<Delete Files="$(_AndroidCompileJavaFileList)" />
25722574
</Target>
25732575

25742576
<Target Name="_CleanAndroidBuildPropertiesCache">

tests/MSBuildDeviceIntegration/Tests/InstallTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ public String test(){
631631
},
632632
};
633633
var proj = new XamarinAndroidApplicationProject {
634-
OtherBuildItems = {
634+
EnableDefaultItems = true,
635+
AndroidJavaSources = {
635636
new AndroidItem.AndroidJavaSource ("TestJavaClass.java") {
636637
Encoding = Encoding.ASCII,
637638
TextContent = () => @"package com.test.java;
@@ -664,8 +665,9 @@ public String test(){
664665
Assert.IsTrue (b.Output.IsTargetSkipped ("_ClearGeneratedManagedBindings", defaultIfNotUsed: true), $"`_ClearGeneratedManagedBindings` should be skipped on DTB build!");
665666
FileAssert.Exists (generatedCode, $"'{generatedCode}' should have not be deleted on DTB build.");
666667
FileAssert.Exists (generatedCode2, $"'{generatedCode2}' should have not be deleted on DTB build.");
667-
proj.OtherBuildItems.Remove (itemToDelete);
668-
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: true), "Second build should have succeeded.");
668+
proj.AndroidJavaSources.Remove (itemToDelete);
669+
File.Delete (Path.Combine (Root, b.ProjectDirectory, itemToDelete.Include ()));
670+
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "Second build should have succeeded.");
669671
FileAssert.Exists (generatedCode, $"'{generatedCode}' should have not be deleted on second build.");
670672
FileAssert.DoesNotExist (generatedCode2, $"'{generatedCode2}' should have be deleted on second build.");
671673
Assert.IsFalse (b.Output.IsTargetSkipped ("_CompileBindingJava"), $"`_CompileBindingJava` should run on second build!");

0 commit comments

Comments
 (0)