Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#nullable enable
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using Microsoft.Android.Build.Tasks;

namespace Xamarin.Android.Tasks
{
public class ReadLibraryProjectImportsCache : AndroidTask
[MSBuildMultiThreadableTask]
public class ReadLibraryProjectImportsCache : MultithreadedAndroidTask
{
public override string TaskPrefix => "RLC";

Expand Down Expand Up @@ -66,11 +64,11 @@ public override bool RunTask ()
{
Log.LogDebugMessage ("Task ReadLibraryProjectImportsCache");
Log.LogDebugMessage (" CacheFile: {0}", CacheFile);
if (!File.Exists (CacheFile)) {
if (CacheFile.IsNullOrEmpty () || !File.Exists (TaskEnvironment.GetAbsolutePath (CacheFile))) {
Log.LogDebugMessage ("{0} does not exist. No Project Library Imports found", CacheFile);
return !Log.HasLoggedErrors;
}
var doc = XDocument.Load (CacheFile);
var doc = XDocument.Load (TaskEnvironment.GetAbsolutePath (CacheFile));
Jars = doc.GetPathsAsTaskItems ("Jars", "Jar");
ResolvedAssetDirectories = doc.GetPathsAsTaskItems ("ResolvedAssetDirectories", "ResolvedAssetDirectory");
ResolvedResourceDirectories = doc.GetPathsAsTaskItems ("ResolvedResourceDirectories", "ResolvedResourceDirectory");
Expand All @@ -84,4 +82,3 @@ public override bool RunTask ()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,48 @@
using Microsoft.Build.Framework;
using Mono.Cecil;
using NUnit.Framework;
using Xamarin.Android.Tasks;
using Xamarin.ProjectTools;

namespace Xamarin.Android.Build.Tests
{
[TestFixture]
public class MultiThreadedMigrationTests
{
[Test]
public void ReadLibraryProjectImportsCacheUsesProjectDirectory ()
{
var directory = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
Directory.CreateDirectory (directory);
try {
var cacheFile = Path.GetRandomFileName ();
File.WriteAllText (Path.Combine (directory, cacheFile), "<Paths><Jars><Jar>a.jar</Jar></Jars></Paths>");
var task = new ReadLibraryProjectImportsCache {
BuildEngine = new MockBuildEngine (TextWriter.Null),
TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment (directory, new Dictionary<string, string> ()),
CacheFile = cacheFile,
};
Assert.IsTrue (task.Execute ());
Assert.AreEqual ("a.jar", task.Jars?.Single ().ItemSpec);
} finally {
Directory.Delete (directory, recursive: true);
}
}

[TestCase ("")]
[TestCase ("missing.xml")]
public void ReadLibraryProjectImportsCacheMissingFile (string cacheFile)
{
var task = new ReadLibraryProjectImportsCache {
BuildEngine = new MockBuildEngine (TextWriter.Null),
TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment (
Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ()), new Dictionary<string, string> ()),
CacheFile = cacheFile,
};
Assert.IsTrue (task.Execute ());
Assert.IsNull (task.Jars);
}

[Test]
public void MigratedTasksHaveDirectAttribute ()
{
Expand Down
Loading