Skip to content

Commit 88e1cf7

Browse files
Merge pull request #1 from ChartBoost/release/Mediation/4.9.0
Chartboost Unity Utilities 1.0.0 into Main
2 parents a04c87d + f0f5277 commit 88e1cf7

30 files changed

+606
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>Chartboost.CSharp.Utilities.Unity</id>
5+
<version>1.0.0</version>
6+
<title>Chartboost Utilities for Unity</title>
7+
<description>Reusable Utilities for Chartboost's Unity Projects</description>
8+
<authors>Chartboost</authors>
9+
<owners>Chartboost</owners>
10+
<license type="file">LICENSE.md</license>
11+
<readme>README.md</readme>
12+
<copyright>Copyright 2024</copyright>
13+
<tags>Chartboost, Ads, Mediation, Unity, cs</tags>
14+
<repository type="git" url="https://github.com/ChartBoost/chartboost-unity-utilities"/>
15+
</metadata>
16+
</package>

Chartboost.CSharp.Utilities.Unity.nuspec.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Chartboost.Utilities.Editor",
3+
"rootNamespace": "Chartboost.Editor",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [
12+
""
13+
],
14+
"autoReferenced": true,
15+
"defineConstraints": [],
16+
"versionDefines": [],
17+
"noEngineReferences": false
18+
}

Editor/Chartboost.Utilities.Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/VersionCheck.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Xml;
5+
using NUnit.Framework;
6+
using UnityEngine;
7+
8+
namespace Chartboost.Editor
9+
{
10+
public static class VersionCheck
11+
{
12+
private const string NuGetVersionXPath = "/package/metadata/version";
13+
private const string NuGetXmlNamespace = "ns";
14+
private static readonly string NuGetVersionXPathWithNameSpace = $"/{NuGetXmlNamespace}:package/{NuGetXmlNamespace}:metadata/{NuGetXmlNamespace}:version";
15+
16+
public static void ValidateVersions(string upmPackageName, string nuGetPackageName, string codeVersion = null)
17+
{
18+
var packageLocation = Directory.Exists($"Packages/{upmPackageName}") ?
19+
// UPM
20+
$"Packages/{upmPackageName}" :
21+
// NuGet
22+
Directory.GetDirectories($"Assets/Packages", $"{nuGetPackageName}*").First();
23+
24+
var packageJson = Directory.GetFiles(packageLocation, "*.json").First();
25+
var nuspec = Directory.GetFiles(packageLocation, "*.nuspec").First();
26+
27+
var upmVersion = GetUnityPackageManagerVersion(packageJson);
28+
var nugetVersion = GetNuGetVersion(nuspec);
29+
30+
Debug.Log($"UPM Version : {upmVersion}");
31+
Debug.Log($"NuGet Version : {nugetVersion}");
32+
33+
if (codeVersion == null)
34+
Assert.AreEqual(upmVersion, nugetVersion);
35+
else
36+
{
37+
Debug.Log($"Code Version: {codeVersion}");
38+
Assert.AreEqual(upmVersion, nugetVersion, codeVersion);
39+
}
40+
}
41+
42+
private static string GetUnityPackageManagerVersion(string filePath)
43+
{
44+
Debug.Log($"UPM path : {filePath}");
45+
try
46+
{
47+
var jsonContent = System.IO.File.ReadAllText(filePath);
48+
var jsonData = JsonUtility.FromJson<PackageJsonData>(jsonContent);
49+
return jsonData.version;
50+
}
51+
catch (Exception ex)
52+
{
53+
Debug.LogError($"An error occurred while reading the package.json file: {ex.Message}");
54+
return null;
55+
}
56+
}
57+
58+
private static string GetNuGetVersion(string filePath)
59+
{
60+
Debug.Log($"NuGet path : {filePath}");
61+
var xmlDoc = new XmlDocument();
62+
63+
try
64+
{
65+
xmlDoc.Load(filePath);
66+
XmlNode versionNode;
67+
68+
if (!string.IsNullOrEmpty(xmlDoc.DocumentElement?.NamespaceURI))
69+
{
70+
// Create an XmlNamespaceManager to handle namespaces
71+
// https://stackoverflow.com/a/1089210
72+
var namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
73+
namespaceManager.AddNamespace(NuGetXmlNamespace, xmlDoc.DocumentElement.NamespaceURI);
74+
versionNode = xmlDoc.SelectSingleNode(NuGetVersionXPathWithNameSpace, namespaceManager);
75+
}
76+
else
77+
{
78+
versionNode = xmlDoc.SelectSingleNode(NuGetVersionXPath);
79+
}
80+
81+
if (versionNode != null)
82+
{
83+
return versionNode.InnerText.Trim();
84+
}
85+
86+
Debug.LogError("Version not found in the .nuspec metadata section.");
87+
return null;
88+
}
89+
catch (Exception ex)
90+
{
91+
Debug.LogError($"An error occurred while reading the .nuspec file: {ex.Message}");
92+
return null;
93+
}
94+
}
95+
96+
[Serializable]
97+
internal class PackageJsonData
98+
{
99+
public string version;
100+
// Add other properties as needed
101+
}
102+
}
103+
}

Editor/VersionCheck.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright 2024 Chartboost Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

LICENSE.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
# chartboost-unity-utilities
1+
# Chartboost Canary Utilities
2+
3+
Simple utilities package for the Chartboost Unity development environment.
4+
5+
# Installation
6+
This package is meant to be a dependency for other Chartboost Packages;however, if you wish to use it by itself, it can be installed through UPM & NuGet as follows:
7+
8+
```json
9+
"dependencies": {
10+
"com.chartboost.unity.utilities": "1.0.0",
11+
...
12+
},
13+
"scopedRegistries": [
14+
{
15+
"name": "NpmJS",
16+
"url": "https://registry.npmjs.org",
17+
"scopes": [
18+
"com.chartboost"
19+
]
20+
}
21+
]
22+
```

0 commit comments

Comments
 (0)