Skip to content

Commit 59ec488

Browse files
committed
[Xamarin.Android.Build.Tasks] Import from monodroid/301e7238
Added Xamarin.Android.Build.Tasks and its supporting Libraries. Code has also been updated to make uses of the new libraries in the Java.Interop repository Note : Xamarin.Android.Build.Tasks has a compile time code generation step which generates Profile.g.cs. This file contains the list of SharedRuntimeAssemblies. If building manually you will need to make sure that Xamarin.Android.Tools.BootstrapTasks is built first.
1 parent a549be3 commit 59ec488

File tree

194 files changed

+43528
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+43528
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bin
33
Configuration.Override.props
44
obj
55
packages
6+
.DS_Store

Xamarin.Android.sln

Lines changed: 103 additions & 59 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Mono.Cecil;
6+
using Microsoft.Build.Utilities;
7+
8+
using Java.Interop.Tools.Diagnostics;
9+
using Java.Interop.Tools.JavaCallableWrappers;
10+
11+
namespace Xamarin.Android.Tasks
12+
{
13+
class Generator
14+
{
15+
public static bool CreateJavaSources (TaskLoggingHelper log, IEnumerable<TypeDefinition> javaTypes, string outputPath, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference)
16+
{
17+
bool ok = true;
18+
foreach (var t in javaTypes) {
19+
try {
20+
GenerateJavaSource (log, t, outputPath, useSharedRuntime, generateOnCreateOverrides, hasExportReference);
21+
} catch (XamarinAndroidException xae) {
22+
ok = false;
23+
log.LogError (
24+
subcategory: "",
25+
errorCode: "XA" + xae.Code,
26+
helpKeyword: string.Empty,
27+
file: xae.SourceFile,
28+
lineNumber: xae.SourceLine,
29+
columnNumber: 0,
30+
endLineNumber: 0,
31+
endColumnNumber: 0,
32+
message: xae.MessageWithoutCode,
33+
messageArgs: new object [0]
34+
);
35+
}
36+
}
37+
return ok;
38+
}
39+
40+
static void GenerateJavaSource (TaskLoggingHelper log, TypeDefinition t, string outputPath, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference)
41+
{
42+
try {
43+
var jti = new JavaCallableWrapperGenerator (t, log.LogWarning) {
44+
UseSharedRuntime = useSharedRuntime,
45+
GenerateOnCreateOverrides = generateOnCreateOverrides,
46+
};
47+
48+
jti.Generate (outputPath);
49+
if (jti.HasExport && !hasExportReference)
50+
Diagnostic.Error (4210, "You need to add a reference to Mono.Android.Export.dll when you use ExportAttribute or ExportFieldAttribute.");
51+
} catch (Exception ex) {
52+
if (ex is XamarinAndroidException)
53+
throw;
54+
Diagnostic.Error (4209, "Failed to create JavaTypeInfo for class: {0} due to {1}", t.FullName, ex);
55+
}
56+
}
57+
}
58+
}

src/Xamarin.Android.Build.Tasks/Ionic.Zip.xml

Lines changed: 18132 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Xamarin.Android.Tasks
4+
{
5+
public enum LinkModes
6+
{
7+
None,
8+
SdkOnly,
9+
Full
10+
}
11+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using Mono.Cecil;
5+
6+
using Mono.Tuner;
7+
8+
namespace Mobile.Tuner {
9+
10+
public abstract class MobileProfile : Profile {
11+
12+
static readonly HashSet<string> Sdk = new HashSet<string> {
13+
"mscorlib",
14+
"System",
15+
"System.ComponentModel.Composition",
16+
"System.ComponentModel.DataAnnotations",
17+
"System.Core",
18+
"System.Data",
19+
"System.Data.Services.Client",
20+
"System.IO.Compression.FileSystem",
21+
"System.IO.Compression",
22+
"System.Json",
23+
"System.Net",
24+
"System.Net.Http",
25+
"System.Numerics",
26+
"System.Runtime.Serialization",
27+
"System.ServiceModel",
28+
"System.ServiceModel.Web",
29+
"System.Transactions",
30+
"System.Web.Services",
31+
"System.Windows",
32+
"System.Xml",
33+
"System.Xml.Linq",
34+
"System.Xml.Serialization",
35+
"Microsoft.CSharp",
36+
"Microsoft.VisualBasic",
37+
"Mono.CSharp",
38+
"Mono.Cairo",
39+
"Mono.CompilerServices.SymbolWriter",
40+
"Mono.Data.Tds",
41+
"Mono.Data.Sqlite",
42+
"Mono.Security",
43+
"OpenTK",
44+
"OpenTK-1.0",
45+
// Facades assemblies (PCL)
46+
"System.Collections.Concurrent",
47+
"System.Collections",
48+
"System.ComponentModel.Annotations",
49+
"System.ComponentModel.EventBasedAsync",
50+
"System.ComponentModel",
51+
"System.Diagnostics.Contracts",
52+
"System.Diagnostics.Debug",
53+
"System.Diagnostics.Tools",
54+
"System.Dynamic.Runtime",
55+
"System.EnterpriseServices",
56+
"System.Globalization",
57+
"System.IO",
58+
"System.Linq.Expressions",
59+
"System.Linq.Parallel",
60+
"System.Linq.Queryable",
61+
"System.Linq",
62+
"System.Net.NetworkInformation",
63+
"System.Net.Primitives",
64+
"System.Net.Requests",
65+
"System.ObjectModel",
66+
"System.Reflection.Extensions",
67+
"System.Reflection.Primitives",
68+
"System.Reflection",
69+
"System.Resources.ResourceManager",
70+
"System.Runtime.Extensions",
71+
"System.Runtime.InteropServices",
72+
"System.Runtime.InteropServices.WindowsRuntime",
73+
"System.Runtime.Numerics",
74+
"System.Runtime.Serialization.Json",
75+
"System.Runtime.Serialization.Primitives",
76+
"System.Runtime.Serialization.Xml",
77+
"System.Runtime",
78+
"System.Security.Principal",
79+
"System.ServiceModel.Http",
80+
"System.ServiceModel.Primitives",
81+
"System.Text.Encoding.Extensions",
82+
"System.Text.Encoding",
83+
"System.Text.RegularExpressions",
84+
"System.Threading.Tasks.Parallel",
85+
"System.Threading.Tasks",
86+
"System.Threading",
87+
"System.Xml.ReaderWriter",
88+
"System.Xml.XDocument",
89+
"System.Xml.XmlSerializer",
90+
};
91+
92+
protected override bool IsSdk (string assemblyName)
93+
{
94+
return Sdk.Contains (assemblyName);
95+
}
96+
}
97+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2011, 2015 Xamarin Inc. All rights reserved.
2+
3+
using System;
4+
5+
using Mono.Linker;
6+
using Mono.Tuner;
7+
8+
using Mono.Cecil;
9+
10+
namespace MonoDroid.Tuner {
11+
12+
public class ApplyPreserveAttribute : ApplyPreserveAttributeBase {
13+
14+
// System.ServiceModeldll is an SDK assembly but it does contain types with [DataMember] attributes
15+
public override bool IsActiveFor (AssemblyDefinition assembly)
16+
{
17+
if (Profile.IsSdkAssembly (assembly)) {
18+
if (assembly.Name.Name != "System.ServiceModel")
19+
return false;
20+
}
21+
return Annotations.GetAction (assembly) == AssemblyAction.Link;
22+
}
23+
24+
protected override bool IsPreservedAttribute (ICustomAttributeProvider provider, CustomAttribute attribute, out bool removeAttribute)
25+
{
26+
removeAttribute = false;
27+
TypeReference type = attribute.Constructor.DeclaringType;
28+
29+
switch (type.Namespace) {
30+
case "Android.Runtime":
31+
// there's no need to keep the [Preserve] attribute in the assembly once it was processed
32+
if (type.Name == "PreserveAttribute") {
33+
removeAttribute = true;
34+
return true;
35+
}
36+
break;
37+
case "System.Runtime.Serialization":
38+
bool srs = false;
39+
// http://bugzilla.xamarin.com/show_bug.cgi?id=1415
40+
// http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx
41+
if (provider is PropertyDefinition || provider is FieldDefinition || provider is EventDefinition)
42+
srs = (type.Name == "DataMemberAttribute");
43+
else if (provider is TypeDefinition)
44+
srs = (type.Name == "DataContractAttribute");
45+
46+
if (srs) {
47+
MarkDefautConstructor (provider);
48+
return true;
49+
}
50+
break;
51+
case "System.Xml.Serialization":
52+
// http://msdn.microsoft.com/en-us/library/83y7df3e.aspx
53+
string name = type.Name;
54+
if ((name.StartsWith ("Xml", StringComparison.Ordinal) && name.EndsWith ("Attribute", StringComparison.Ordinal))) {
55+
// but we do not have to keep things that XML serialization will ignore anyway!
56+
if (name != "XmlIgnoreAttribute") {
57+
// the default constructor of the type *being used* is needed
58+
MarkDefautConstructor (provider);
59+
return true;
60+
}
61+
}
62+
break;
63+
default:
64+
if (type.Name == "PreserveAttribute") {
65+
// there's no need to keep the [Preserve] attribute in the assembly once it was processed
66+
removeAttribute = true;
67+
return true;
68+
}
69+
break;
70+
}
71+
// keep them (provider and attribute)
72+
return false;
73+
}
74+
75+
// xml serialization requires the default .ctor to be present
76+
void MarkDefautConstructor (ICustomAttributeProvider provider)
77+
{
78+
TypeDefinition td = (provider as TypeDefinition);
79+
if (td == null) {
80+
PropertyDefinition pd = (provider as PropertyDefinition);
81+
if (pd != null) {
82+
MarkDefautConstructor (pd.DeclaringType);
83+
MarkGenericType (pd.PropertyType as GenericInstanceType);
84+
td = pd.PropertyType.Resolve ();
85+
} else {
86+
FieldDefinition fd = (provider as FieldDefinition);
87+
if (fd != null) {
88+
MarkDefautConstructor (fd.DeclaringType);
89+
MarkGenericType (fd.FieldType as GenericInstanceType);
90+
td = (fd.FieldType as TypeReference).Resolve ();
91+
}
92+
}
93+
}
94+
95+
// e.g. <T> property (see bug #5543) or field (see linkall unit tests)
96+
if (td != null)
97+
MarkDefautConstructor (td);
98+
}
99+
100+
void MarkGenericType (GenericInstanceType git)
101+
{
102+
if (git == null || !git.HasGenericArguments)
103+
return;
104+
105+
foreach (TypeReference tr in git.GenericArguments)
106+
MarkDefautConstructor (tr.Resolve ());
107+
}
108+
109+
void MarkDefautConstructor (TypeDefinition type)
110+
{
111+
if ((type == null) || !type.HasMethods)
112+
return;
113+
114+
foreach (MethodDefinition ctor in type.Methods) {
115+
if (!ctor.IsConstructor || ctor.IsStatic || ctor.HasParameters)
116+
continue;
117+
118+
Annotations.AddPreservedMethod (type, ctor);
119+
}
120+
}
121+
}
122+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using Mono.Cecil;
5+
6+
using Mono.Linker;
7+
8+
using Mono.Tuner;
9+
10+
namespace MonoDroid.Tuner {
11+
12+
static class Extensions {
13+
14+
const string JavaObject = "Java.Lang.Object";
15+
const string IJavaObject = "Android.Runtime.IJavaObject";
16+
const string JavaThrowable = "Java.Lang.Throwable";
17+
18+
public static bool IsJavaObject (this TypeDefinition type)
19+
{
20+
return type.Inherits (JavaObject);
21+
}
22+
23+
public static bool IsJavaException (this TypeDefinition type)
24+
{
25+
return type.Inherits (JavaThrowable);
26+
}
27+
28+
public static bool ImplementsIJavaObject (this TypeDefinition type)
29+
{
30+
return type.Implements (IJavaObject);
31+
}
32+
33+
public static object GetSettableValue (this CustomAttributeArgument arg)
34+
{
35+
TypeReference tr = arg.Value as TypeReference;
36+
TypeDefinition td = tr != null ? tr.Resolve () : null;
37+
return td != null ? td.FullName + "," + td.Module.Assembly.FullName : arg.Value;
38+
}
39+
40+
public static bool Implements (this TypeReference self, string interfaceName)
41+
{
42+
if (interfaceName == null)
43+
throw new ArgumentNullException ("interfaceName");
44+
if (self == null)
45+
return false;
46+
47+
TypeDefinition type = self.Resolve ();
48+
if (type == null)
49+
return false; // not enough information available
50+
51+
// special case, check if we implement ourselves
52+
if (type.IsInterface && (type.FullName == interfaceName))
53+
return true;
54+
55+
return Implements (type, interfaceName, (interfaceName.IndexOf ('`') >= 0));
56+
}
57+
58+
public static bool Implements (TypeDefinition type, string interfaceName, bool generic)
59+
{
60+
while (type != null) {
61+
// does the type implements it itself
62+
if (type.HasInterfaces) {
63+
foreach (TypeReference iface in type.Interfaces) {
64+
string fullname = (generic) ? iface.GetElementType ().FullName : iface.FullName;
65+
if (fullname == interfaceName)
66+
return true;
67+
//if not, then maybe one of its parent interfaces does
68+
if (Implements (iface.Resolve (), interfaceName, generic))
69+
return true;
70+
}
71+
}
72+
73+
type = type.BaseType != null ? type.BaseType.Resolve () : null;
74+
}
75+
return false;
76+
}
77+
78+
public static bool Inherits (this TypeReference self, string className)
79+
{
80+
if (className == null)
81+
throw new ArgumentNullException ("className");
82+
if (self == null)
83+
return false;
84+
85+
TypeReference current = self.Resolve ();
86+
while (current != null) {
87+
string fullname = current.FullName;
88+
if (fullname == className)
89+
return true;
90+
if (fullname == "System.Object")
91+
return false;
92+
93+
TypeDefinition td = current.Resolve ();
94+
if (td == null)
95+
return false; // could not resolve type
96+
current = td.BaseType;
97+
}
98+
return false;
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)