Skip to content

Commit

Permalink
Fix issue when files are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
dellis1972 committed Mar 12, 2024
1 parent 3d1e651 commit 53231e0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
<_AndroidIntermediateBindingClassesZip>$(IntermediateOutputPath)binding\bin\$(MSBuildProjectName).jar</_AndroidIntermediateBindingClassesZip>
<_AndroidIntermediateBindingClassesDocs>$(IntermediateOutputPath)binding\bin\$(MSBuildProjectName)-docs.xml</_AndroidIntermediateBindingClassesDocs>
<_AndroidCompileJavaStampFile>$(_AndroidStampDirectory)_CompileJava.stamp</_AndroidCompileJavaStampFile>
<_AndroidCompileJavaFileList>$(IntermediateOutputPath)_CompileJava.FileList.txt</_AndroidCompileJavaFileList>
<_AndroidCompileBindingJavaStampFile>$(_AndroidStampDirectory)_CompileBindingJava.stamp</_AndroidCompileBindingJavaStampFile>
<_AndroidCompileBindingJavaFileList>$(IntermediateOutputPath)_CompileBindingJava.FileList.txt</_AndroidCompileBindingJavaFileList>
</PropertyGroup>

<Target Name="_AdjustJavacVersionArguments">
Expand Down Expand Up @@ -74,18 +76,36 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
<ItemGroup>
<_JavaBindingSource Include="@(AndroidJavaSource)" Condition=" '%(AndroidJavaSource.Bind)' == 'True' " />
</ItemGroup>
<WriteLinesToFile
File="$(_AndroidCompileBindingJavaFileList)"
Lines="@(_JavaBindingSource->ToLowerInvariant())"
Overwrite="true"
WriteOnlyWhenDifferent="true"
/>
<ItemGroup>
<FileWrites Include="$(_AndroidCompileBindingJavaFileList)" />
</ItemGroup>
</Target>

<Target Name="_CollectJavaSource">
<ItemGroup>
<_JavaSource Include="@(AndroidJavaSource)" Condition=" '%(AndroidJavaSource.Bind)' != 'True' " />
</ItemGroup>
<WriteLinesToFile
File="$(_AndroidCompileJavaFileList)"
Lines="@(_JavaSource->ToLowerInvariant())"
Overwrite="true"
WriteOnlyWhenDifferent="true"
/>
<ItemGroup>
<FileWrites Include="$(_AndroidCompileJavaFileList)" />
</ItemGroup>
</Target>

<Target Name="_CompileBindingJava"
Condition=" '@(_JavaBindingSource->Count())' != '0' "
DependsOnTargets="$(_CompileBindingJavaDependsOnTargets)"
Inputs="@(_AndroidMSBuildAllProjects);$(MonoPlatformJarPath);@(_JavaBindingSource)"
Inputs="@(_AndroidMSBuildAllProjects);$(_AndroidCompileBindingJavaFileList);$(MonoPlatformJarPath);@(_JavaBindingSource)"
Outputs="$(_AndroidCompileBindingJavaStampFile)">

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

<Target Name="_CompileJava"
DependsOnTargets="$(_CompileJavaDependsOnTargets);_CollectJavaSource"
Inputs="@(_AndroidMSBuildAllProjects);$(MonoPlatformJarPath);@(_JavaStubFiles);@(_JavaSource)"
Inputs="@(_AndroidMSBuildAllProjects);$(_AndroidCompileJavaFileList);$(MonoPlatformJarPath);@(_JavaStubFiles);@(_JavaSource)"
Outputs="$(_AndroidCompileJavaStampFile)">

<!-- remove existing <Javac /> outputs, since *.class files and classes.zip could contain old files -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void DotNetBuildBinding ()
proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javaclasses-sources.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar,
});
proj.OtherBuildItems.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") {
proj.AndroidJavaSources.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") {
Encoding = Encoding.ASCII,
TextContent = () => ResourceData.JavaSourceTestExtension,
Metadata = { { "Bind", "True"} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ protected DotNetXamarinProject (string debugConfigurationName = "Debug", string

Sources = new List<BuildItem> ();
OtherBuildItems = new List<BuildItem> ();
AndroidJavaSources = new List<BuildItem> ();

ItemGroupList.Add (References);
ItemGroupList.Add (OtherBuildItems);
ItemGroupList.Add (Sources);
ItemGroupList.Add (AndroidJavaSources);

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

public IList<BuildItem> OtherBuildItems { get; private set; }
public IList<BuildItem> Sources { get; private set; }
public IList<BuildItem> AndroidJavaSources { get; private set; }

public IList<Property> ActiveConfigurationProperties {
get { return IsRelease ? ReleaseProperties : DebugProperties; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,8 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="$(_AndroidMainDexListFile)" />
<Delete Files="$(_AndroidBuildIdFile)" />
<Delete Files="$(_ResolvedUserAssembliesHashFile)" />
<Delete Files="$(_AndroidCompileBindingJavaFileList)" />
<Delete Files="$(_AndroidCompileJavaFileList)" />
</Target>

<Target Name="_CleanAndroidBuildPropertiesCache">
Expand Down
8 changes: 5 additions & 3 deletions tests/MSBuildDeviceIntegration/Tests/InstallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ public String test(){
},
};
var proj = new XamarinAndroidApplicationProject {
OtherBuildItems = {
EnableDefaultItems = true,
AndroidJavaSources = {
new AndroidItem.AndroidJavaSource ("TestJavaClass.java") {
Encoding = Encoding.ASCII,
TextContent = () => @"package com.test.java;
Expand Down Expand Up @@ -664,8 +665,9 @@ public String test(){
Assert.IsTrue (b.Output.IsTargetSkipped ("_ClearGeneratedManagedBindings", defaultIfNotUsed: true), $"`_ClearGeneratedManagedBindings` should be skipped on DTB build!");
FileAssert.Exists (generatedCode, $"'{generatedCode}' should have not be deleted on DTB build.");
FileAssert.Exists (generatedCode2, $"'{generatedCode2}' should have not be deleted on DTB build.");
proj.OtherBuildItems.Remove (itemToDelete);
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: true), "Second build should have succeeded.");
proj.AndroidJavaSources.Remove (itemToDelete);
File.Delete (Path.Combine (Root, b.ProjectDirectory, itemToDelete.Include ()));
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "Second build should have succeeded.");
FileAssert.Exists (generatedCode, $"'{generatedCode}' should have not be deleted on second build.");
FileAssert.DoesNotExist (generatedCode2, $"'{generatedCode2}' should have be deleted on second build.");
Assert.IsFalse (b.Output.IsTargetSkipped ("_CompileBindingJava"), $"`_CompileBindingJava` should run on second build!");
Expand Down

0 comments on commit 53231e0

Please sign in to comment.