Skip to content

Commit

Permalink
Merge pull request #109 from dotnet-campus/t/lindexi/DebUOSPackageFil…
Browse files Browse the repository at this point in the history
…eStructCreator

通过异常打断后续打包逻辑 防止后续逻辑继续执行抛空异常
  • Loading branch information
kkwpsv committed Jan 29, 2024
2 parents 85e73ae + 4ebaded commit fd5c5cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Expand Up @@ -50,7 +50,7 @@ public DebUOSConfiguration() : base("")
public string? AppId
{
set => SetValue(value);
get => GetString() ?? AssemblyName;
get => GetString() ?? AssemblyName?.ToLowerInvariant();
}

/// <summary>
Expand Down
17 changes: 6 additions & 11 deletions DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Logging;
using Packaging.DebUOS.Contexts;
using Packaging.DebUOS.Contexts.Configurations;
using Packaging.DebUOS.Exceptions;
using Walterlv.IO.PackageManagement;

namespace Packaging.DebUOS;
Expand All @@ -28,8 +29,7 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
var projectPublishFolder = configuration.ProjectPublishFolder;
if (!Directory.Exists(projectPublishFolder))
{
Logger.LogError($"Project publish folder '{projectPublishFolder}' not exist");
return;
throw new PackagingException($"Project publish folder '{projectPublishFolder}' not exist");
}

var workingFolder = configuration.WorkingFolder;
Expand Down Expand Up @@ -60,16 +60,13 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
var appId = configuration.UOSAppId;
if (string.IsNullOrEmpty(appId))
{
Logger.LogError($"找不到 UOS 的 AppId 内容,请确保已经配置 UOSAppId 属性");
return;
throw new PackagingException($"找不到 UOS 的 AppId 内容,请确保已经配置 UOSAppId 属性");
}

var match = Regex.Match(appId, @"[a-z\.]+");
if (!match.Success || match.Value != appId)
{
Logger.LogError(
$"UOS 的 AppId 内容不符合规范,请确保配置的 UOSAppId 属性符合规范。请务必使用厂商的倒置域名+产品名作为应用包名,如 `com.example.demo` 格式,且只允许使用小写字母");
return;
throw new PackagingException($"UOS 的 AppId 内容不符合规范,请确保配置的 UOSAppId 属性符合规范。请务必使用厂商的倒置域名+产品名作为应用包名,如 `com.example.demo` 格式,且只允许使用小写字母。UOSAppId={appId}");
}

// opt\apps\AppId\
Expand All @@ -82,8 +79,7 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
var symbol = Directory.CreateSymbolicLink(applicationBin, projectPublishFolder);
if (!symbol.Exists)
{
Logger.LogError($"创建符号链接失败,从 '{projectPublishFolder}' 到 '{applicationBin}'");
return;
throw new PackagingException($"创建符号链接失败,从 '{projectPublishFolder}' 到 '{applicationBin}'");
}

// opt\apps\AppId\entries
Expand Down Expand Up @@ -166,8 +162,7 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
// 如果开发者配置了自定义的图标文件夹,则使用开发者的文件夹
if (!Directory.Exists(configuration.UOSDebIconFolder))
{
Logger.LogError($"配置了 Icon 文件夹的 UOSDebIconFolder 属性,但文件夹不存在 UOSDebIconFolder={configuration.UOSDebIconFolder} FullPath={Path.GetFullPath(configuration.UOSDebIconFolder)}");
return;
throw new PackagingException($"配置了 Icon 文件夹的 UOSDebIconFolder 属性,但文件夹不存在 UOSDebIconFolder={configuration.UOSDebIconFolder} FullPath={Path.GetFullPath(configuration.UOSDebIconFolder)}");
}

PackageDirectory.Copy(configuration.UOSDebIconFolder, iconsFolder);
Expand Down
18 changes: 18 additions & 0 deletions DebUOS/Packaging.DebUOS/Exceptions/PackagingException.cs
@@ -0,0 +1,18 @@
using System;

namespace Packaging.DebUOS.Exceptions;

public class PackagingException : Exception
{
public PackagingException()
{
}

public PackagingException(string? message) : base(message)
{
}

public PackagingException(string? message, Exception? innerException) : base(message, innerException)
{
}
}

0 comments on commit fd5c5cc

Please sign in to comment.