Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NIkita Chernyadev committed Sep 14, 2023
0 parents commit 6132d55
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Recordings can get excessive in size
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

### Changed

### Fixed

## [0.1.0] - 2023-09-14

Initial release.
3 changes: 3 additions & 0 deletions CHANGELOG.md.meta

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

8 changes: 8 additions & 0 deletions Editor.meta

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

95 changes: 95 additions & 0 deletions Editor/NoticesGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEngine;

namespace Editor
{
public static class NoticesGenerator
{
public const string DefaultFileName = "THIRD-PARTY-NOTICES.md";

public const string DefaultHeader =
"This project contains third-party software components governed by the license(s) indicated below:";

private const string Separator = "\n\n----------------------------------------\n\n";

/// <summary>
/// Request list of used packages and generate notices file. Could be used in build scripts for CI.
/// </summary>
/// <param name="offlineMode">Specifies whether or not the Package Manager requests the latest information about the project's packages from the remote Unity package registry. When offlineMode is true, the PackageManager.PackageInfo objects in the PackageCollection returned by the Package Manager contain information obtained from the local package cache, which could be out of date.</param>
/// <param name="includeIndirectDependencies">Set to true to include indirect dependencies in the PackageCollection returned by the Package Manager. Indirect dependencies include packages referenced in the manifests of project packages or in the manifests of other indirect dependencies. Set to false to include only the packages listed directly in the project manifest.
/// Note: The version reported might not match the version requested in the project manifest.</param>
/// <param name="excludeBuiltInPackages">Skip built-in Unity packages.</param>
/// <param name="writeToStreamingAssetsFolder">Write the file to Streaming Assets folder.</param>
/// <param name="fileName">Custom filename for the notices file.</param>
/// <param name="header">Custom header for the notices file.</param>
public static async Task Generate(bool offlineMode = false, bool includeIndirectDependencies = true,
bool excludeBuiltInPackages = true, bool writeToStreamingAssetsFolder = true,
string fileName = DefaultFileName, string header = DefaultHeader)
{
var request = Client.List(offlineMode, includeIndirectDependencies);

while (!request.IsCompleted)
{
await Task.Yield();
}

if (request.Status == StatusCode.Success)
{
Write(request.Result, excludeBuiltInPackages, writeToStreamingAssetsFolder, fileName, header);
}
else if (request.Status >= StatusCode.Failure)
{
Debug.Log(request.Error.message);
}
}

private static void Write(PackageCollection packageCollection, bool excludeBuiltInPackages,
bool writeToStreamingAssetsFolder, string fileName, string header)
{
var notices = new List<string> { header };

foreach (var package in packageCollection)
{
if (excludeBuiltInPackages && package.source == PackageSource.BuiltIn)
{
continue;
}

var licenseFile = Directory
.GetFiles(package.resolvedPath)
.FirstOrDefault(f => Path.GetFileNameWithoutExtension((string)f).ToLower() == "license");

if (licenseFile == null || !File.Exists(licenseFile))
{
Debug.Log($"No license file found, skipping: {package.name}");
continue;
}

var licenseText = File.ReadAllText(licenseFile);
var packageData = $"### {package.displayName}\n" +
$"#### Package: [{package.name}]({package})\n" +
$"#### Version: {package.version}\n" +
$"#### [Documentation]({package.documentationUrl})\n" +
$"{licenseText}";

notices.Add(packageData);
}

if (writeToStreamingAssetsFolder)
{
fileName = Path.Combine(Application.streamingAssetsPath, fileName);
}

var file = new FileInfo(fileName);
file.Directory?.Create();
File.WriteAllText(file.FullName, string.Join(Separator, notices));

AssetDatabase.Refresh();
}
}
}
3 changes: 3 additions & 0 deletions Editor/NoticesGenerator.cs.meta

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

93 changes: 93 additions & 0 deletions Editor/NoticesGeneratorWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Editor
{
public class NoticesGeneratorWindow : EditorWindow
{
private TextField _fileNameField;
private TextField _headerField;

private Toggle _offlineModeToggle;
private Toggle _includeIndirectDependenciesToggle;
private Toggle _excludeBuiltInPackagesToggle;
private Toggle _writeToStreamingAssetsFolderToggle;

private Button _generateButton;

[MenuItem("Window/Third Party Notices Generator")]
public static void ShowExample()
{
var window = GetWindow<NoticesGeneratorWindow>();
window.titleContent = new GUIContent("Third Party Notices Generator");
}

public void CreateGUI()
{
var root = rootVisualElement;

_fileNameField = new TextField("Notices file name")
{
value = NoticesGenerator.DefaultFileName
};
root.Add(_fileNameField);

_headerField = new TextField("File header", -1, true, false, '*')
{
value = NoticesGenerator.DefaultHeader
};
root.Add(_headerField);

_offlineModeToggle = new Toggle("Offline mode")
{
value = false,
tooltip =
"Specifies whether or not the Package Manager requests the latest information about the project's packages from the remote Unity package registry. When offlineMode is true, the PackageManager.PackageInfo objects in the PackageCollection returned by the Package Manager contain information obtained from the local package cache, which could be out of date."
};
root.Add(_offlineModeToggle);

_includeIndirectDependenciesToggle = new Toggle("Include indirect dependencies")
{
value = true,
tooltip =
"Set to true to include indirect dependencies in the PackageCollection returned by the Package Manager. Indirect dependencies include packages referenced in the manifests of project packages or in the manifests of other indirect dependencies. Set to false to include only the packages listed directly in the project manifest."
};
root.Add(_includeIndirectDependenciesToggle);

_excludeBuiltInPackagesToggle = new Toggle("Exclude built-in packages")
{
value = true,
tooltip = "Skip built-in Unity packages."
};
root.Add(_excludeBuiltInPackagesToggle);

_writeToStreamingAssetsFolderToggle = new Toggle("Write file to the StreamingAssets folder")
{
value = true,
tooltip = "Write the file to Streaming Assets folder."
};
root.Add(_writeToStreamingAssetsFolderToggle);

_generateButton = new Button(OnGenerateButtonHandler)
{
text = "Generate"
};
root.Add(_generateButton);
}

private async void OnGenerateButtonHandler()
{
_generateButton.SetEnabled(false);
var initialButtonText = _generateButton.text;
_generateButton.text = "Fetching packages list...";

await NoticesGenerator.Generate(_offlineModeToggle.value, _includeIndirectDependenciesToggle.value,
_excludeBuiltInPackagesToggle.value, _writeToStreamingAssetsFolderToggle.value, _fileNameField.value,
_headerField.value);

_generateButton.text = initialButtonText;
_generateButton.SetEnabled(true);
}
}
}
11 changes: 11 additions & 0 deletions Editor/NoticesGeneratorWindow.cs.meta

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

16 changes: 16 additions & 0 deletions Editor/ThirdPartyNoticeGenerator.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "NewAssembly",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/ThirdPartyNoticeGenerator.Editor.asmdef.meta

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

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Nikita Cherniadev

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
3 changes: 3 additions & 0 deletions LICENSE.md.meta

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

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Third Party Notices Generator Utility

This a tool designed for generating third-party notices for your Unity project. It helps you create a list of third-party packages used in your project, making it easier to comply with licensing requirements and provide proper attribution.

## Features

- **Notices file name:** Specify the name of the notices file you want to generate.
- **File header:** Customize the header for the notices file, allowing you to include relevant information.
- **Offline mode:** Enable this option to generate notices using cached package information, useful when you're working offline.
- **Include indirect dependencies:** Choose whether to include indirect package dependencies in the notices.
- **Exclude built-in packages:** Skip built-in Unity packages from the generated notices.
- **Write file to the StreamingAssets folder:** Save the generated notices file to the StreamingAssets folder within your Unity project.

## How to Use

1. Open the Unity Editor.
2. Navigate to `Window > Third Party Notices Generator` to open the utility window.
3. Customize the settings as needed.
4. Click the "Generate" button to create the third-party notices file.

## Important Notes

- The utility fetches package information from the Unity package registry.
- Ensure that you have an active internet connection when using this tool, especially if you want to fetch the latest package information.

Feel free to use this utility to simplify the process of managing third-party notices for your Unity project. It can help you stay compliant with licensing requirements and provide proper attribution for the packages you use.
Loading

0 comments on commit 6132d55

Please sign in to comment.