Skip to content

Commit

Permalink
Various syntax and naming modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
niezbop committed Nov 27, 2017
1 parent f7b4280 commit f21deff
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 331 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 23 additions & 20 deletions Assets/Plugins/Editor/Uplift/Schemas/Extensions/Upfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,35 +242,38 @@ private void AddOrReplaceDependency(XmlDocument document, DependencyDefinition d

public virtual void LoadOverrides()
{
try
Repository[] overrides = GetRepositoryOverrides();
if (Repositories == null)
{
Repository[] overrides = GetRepositoryOverrides();
if (Repositories == null)
{
Repositories = overrides;
}
else if(overrides != null)
{
int repositoriesSize = Repositories.Length + overrides.Length;
Repositories = overrides;
}
else if(overrides != null)
{
int repositoriesSize = Repositories.Length + overrides.Length;

Repository[] newRepositoryArray = new Repository[repositoriesSize];
Array.Copy(Repositories, newRepositoryArray, Repositories.Length);
Array.Copy(overrides, 0, newRepositoryArray, Repositories.Length, overrides.Length);
Repository[] newRepositoryArray = new Repository[repositoriesSize];
Array.Copy(Repositories, newRepositoryArray, Repositories.Length);
Array.Copy(overrides, 0, newRepositoryArray, Repositories.Length, overrides.Length);

Repositories = newRepositoryArray;
}
Repositories = newRepositoryArray;
}
}

internal Repository[] GetRepositoryOverrides()
{
Repository[] result = new Repository[0];
try
{
result = string.IsNullOrEmpty(overridePath) ?
UpliftSettings.FromDefaultFile().Repositories :
UpliftSettings.FromFile(overridePath).Repositories;
}
catch (Exception e)
{
Debug.LogError("Could not load repositories overrides from .Uplift file\n" + e);
}
}

internal Repository[] GetRepositoryOverrides()
{
return string.IsNullOrEmpty(overridePath) ?
DotUplift.FromDefaultFile().Repositories :
DotUplift.FromFile(overridePath).Repositories;
return result;
}

public string GetPackagesRootPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@

namespace Uplift.Schemas
{
public partial class DotUplift
public partial class UpliftSettings
{
public static readonly string defaultName = ".Uplift.xml";

internal DotUplift() {}
internal UpliftSettings() {}

public static DotUplift FromDefaultFile()
public static UpliftSettings FromDefaultFile()
{
return FromFile(defaultName);
}

public static DotUplift FromFile(string name)
public static UpliftSettings FromFile(string name)
{
string source = System.IO.Path.Combine(GetHomePath(), name);

StrictXmlDeserializer<DotUplift> deserializer = new StrictXmlDeserializer<DotUplift>();
StrictXmlDeserializer<UpliftSettings> deserializer = new StrictXmlDeserializer<UpliftSettings>();

DotUplift result = new DotUplift { Repositories = new Repository[0], AuthenticationMethods = new RepositoryAuthentication[0] };
UpliftSettings result = new UpliftSettings { Repositories = new Repository[0], AuthenticationMethods = new RepositoryToken[0] };
using (FileStream fs = new FileStream(source, FileMode.Open))
{
try
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public override TemporaryDirectory DownloadPackage(Upset package)

GitHubAsset packageAsset = release.assets.First(asset => asset.name.Contains(sourceName));
TemporaryDirectory td = new TemporaryDirectory();
StreamReader sr = new StreamReader(GitHub.GetAssetStream(packageAsset, GetToken()));
UnityPackage unityPackage = new UnityPackage();
unityPackage.Extract(sr.BaseStream, td.Path);
using(StreamReader sr = new StreamReader(GitHub.GetAssetStream(packageAsset, GetToken())))
{
UnityPackage unityPackage = new UnityPackage();
unityPackage.Extract(sr.BaseStream, td.Path);
}
return td;
}

Expand All @@ -68,16 +70,18 @@ public override Upset[] ListPackages()
int index = 0;

List<Upset> upsetList = new List<Upset>();
EditorUtility.DisplayProgressBar(progressBarTitle, "Please wait a little bit while Uplift parses the Upset in the GitHub repository at " + urlField, (100f * (float)index) / upsetAssets.Length);
EditorUtility.DisplayProgressBar(progressBarTitle, "Please wait a little bit while Uplift parses the Upset in the GitHub repository at " + urlField, 0f);
foreach(GitHubAsset asset in upsetAssets)
{
StrictXmlDeserializer<Upset> deserializer = new StrictXmlDeserializer<Upset>();

StreamReader sr = new StreamReader(GitHub.GetAssetStream(asset, GetToken()));
UnityPackage unityPackage = new UnityPackage();
Upset upset = deserializer.Deserialize(sr.BaseStream);
upset.MetaInformation.dirName = asset.name;
upsetList.Add(upset);
using(StreamReader sr = new StreamReader(GitHub.GetAssetStream(asset, GetToken())))
{
Upset upset = deserializer.Deserialize(sr.BaseStream);
upset.MetaInformation.dirName = asset.name;
upsetList.Add(upset);
}

EditorUtility.DisplayProgressBar(
progressBarTitle,
"Parsing " + asset.name,
Expand All @@ -100,18 +104,19 @@ private GitHubRelease GetPackagesRelease()
if (releases == null)
throw new ApplicationException("This github repository does not have releases");

if (!releases.Any(rel => rel.tag == "packages"))
throw new ApplicationException("This repository does not have a release untitled 'packages'");
release = releases.FirstOrDefault(rel => rel.tag == "packages");

if (release == null)
throw new ApplicationException("This repository does not have a release tagged as 'packages'");

release = releases.First(rel => rel.tag == "packages");
}

return release;
}

private string GetToken()
{
DotUplift dotUplift = DotUplift.FromDefaultFile();
UpliftSettings dotUplift = UpliftSettings.FromDefaultFile();
if(dotUplift.AuthenticationMethods != null)
foreach(RepositoryAuthentication auth in dotUplift.AuthenticationMethods)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<xs:include schemaLocation="Common.xsd"/>
<xs:include schemaLocation="RepositoryTypes.xsd"/>

<xs:element name="DotUplift" type="DotUplift"/>
<xs:element name="UpliftSettings" type="UpliftSettings"/>

<xs:complexType name="DotUplift">
<xs:complexType name="UpliftSettings">
<xs:sequence>
<xs:element type="RepositoriesList" name="Repositories" minOccurs="0" />
<xs:element type="AuthenticationList" name="AuthenticationMethods" minOccurs="0" />
Expand All @@ -18,7 +18,7 @@
<xs:complexType name="AuthenticationList">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element type="RepositoryToken" name="RepositoryToken"/>
<xs:element type="RepositoryCredentials" name="RepositoryCredentials"/>
<!-- <xs:element type="RepositoryCredentials" name="RepositoryCredentials"/> -->
</xs:choice>
</xs:complexType>

Expand All @@ -36,6 +36,8 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<!-- TODO: Use me somewhere
<xs:complexType name="RepositoryCredentials">
<xs:simpleContent>
<xs:extension base="RepositoryAuthentication">
Expand All @@ -44,4 +46,6 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
-->

</xs:schema>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void LoadXmlAbsent()
// public void LoadPresentOverrideTest()
// {
// string upfilePath = Helper.PathCombine ("TestData", "UpfileTest", "Upfile.xml");
// string upfileOverridePath = Helper.PathCombine ("TestData", "UpfileTest", "DotUplift.xml");
// string upfileOverridePath = Helper.PathCombine ("TestData", "UpfileTest", "UpliftSettings.xml");
// Upfile upfile = Upfile.LoadXml(upfilePath);
// upfile.LoadOverrides(upfileOverridePath);

Expand All @@ -140,7 +140,7 @@ public void LoadXmlAbsent()
// public void LoadAbsentOverrideTest()
// {
// string upfilePath = Helper.PathCombine ("TestData", "UpfileTest", "Upfile.xml");
// string upfileOverridePath = Helper.PathCombine ("TestData", "UpfileTest", "NoUpfileInIt", "DotUplift.xml");
// string upfileOverridePath = Helper.PathCombine ("TestData", "UpfileTest", "NoUpfileInIt", "UpliftSettings.xml");
// Upfile upfile = Upfile.LoadXml(upfilePath);
// upfile.LoadOverrides(upfileOverridePath);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Plugins/Editor/Uplift/Utils/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public static Stream GetAssetStream(GitHubAsset asset, string token)
if(!string.IsNullOrEmpty(token))
request.Headers["Authorization"] = "token " + token;
request.Accept = "application/octet-stream";
request.UserAgent = "curl/7.47.0";
request.UserAgent = "Uplift GithubRepository/1.0 - https://github.com/DragonBox/uplift";
request.AllowAutoRedirect = false;

ServicePointManager.ServerCertificateValidationCallback = GitHub.CertificateValidationCallback;
Expand All @@ -369,7 +369,7 @@ public static Stream GetAssetStream(GitHubAsset asset, string token)

request = (HttpWebRequest)WebRequest.Create(address);
request.Method = "GET";
request.UserAgent = "curl/7.47.0";
request.UserAgent = "Uplift GithubRepository/1.0 - https://github.com/DragonBox/uplift";
HttpWebResponse finalResponse = (HttpWebResponse)request.GetResponse();
responseStatus = finalResponse.StatusCode;
if((int)finalResponse.StatusCode >= 200 && (int)finalResponse.StatusCode <= 299)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<DotUplift>
<UpliftSettings>
<Repositories>
<FileRepository Path="Path/To/Another/Repository"/>
</Repositories>
</DotUplift>
</UpliftSettings>

0 comments on commit f21deff

Please sign in to comment.