Skip to content

Commit

Permalink
Moved the JAR conversion into a IKVM.Net.Sdk project. The goal here i…
Browse files Browse the repository at this point in the history
…s to be able to provide additional integrated class for SLF4J, so we can relay logging messages out of Aether. Implemented a ThreadLocal context design, so we can direct logs for specific task calls (even if multiple outstanding).
  • Loading branch information
wasabii committed Dec 10, 2023
1 parent 2b04e78 commit dfb2631
Show file tree
Hide file tree
Showing 14 changed files with 1,011 additions and 47 deletions.
10 changes: 8 additions & 2 deletions IKVM.Maven.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.Maven.Sdk.Tasks.Tests"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dist", "dist", "{2B1DC931-2EBF-4544-8076-3C7BF5870163}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dist-nuget", "src\dist-nuget\dist-nuget.csproj", "{9DC62B51-6F8F-4764-B29E-588AFE9EE643}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dist-nuget", "src\dist-nuget\dist-nuget.csproj", "{9DC62B51-6F8F-4764-B29E-588AFE9EE643}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dist-tests", "src\dist-tests\dist-tests.csproj", "{7CF45054-BD9C-4874-8A4B-3C2BE86FDB25}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dist-tests", "src\dist-tests\dist-tests.csproj", "{7CF45054-BD9C-4874-8A4B-3C2BE86FDB25}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKVM.Maven.Sdk.Tasks.Java", "src\IKVM.Maven.Sdk.Tasks.Java\IKVM.Maven.Sdk.Tasks.Java.csproj", "{45334A6F-F78C-4D95-81F6-7D6E2B8C5798}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -62,6 +64,10 @@ Global
{7CF45054-BD9C-4874-8A4B-3C2BE86FDB25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CF45054-BD9C-4874-8A4B-3C2BE86FDB25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CF45054-BD9C-4874-8A4B-3C2BE86FDB25}.Release|Any CPU.Build.0 = Release|Any CPU
{45334A6F-F78C-4D95-81F6-7D6E2B8C5798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45334A6F-F78C-4D95-81F6-7D6E2B8C5798}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45334A6F-F78C-4D95-81F6-7D6E2B8C5798}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45334A6F-F78C-4D95-81F6-7D6E2B8C5798}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 7 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"sdk": {
"version": "7.0.100",
"rollForward": "latestFeature"
}
"sdk": {
"version": "7.0.100",
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"IKVM.NET.Sdk": "8.7.3"
}
}
20 changes: 20 additions & 0 deletions src/IKVM.Maven.Sdk.Tasks.Java/AdapterLoggerFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package IKVM.Maven.Sdk.Tasks.Java;

import org.slf4j.*;

public class AdapterLoggerFactory implements ILoggerFactory {

public static ILoggerFactory LoggerFactory;

final ILoggerFactory factory;

public AdapterLoggerFactory(ILoggerFactory factory) {
this.factory = factory;
}

@Override
public final Logger getLogger(final String name) {
return factory.getLogger(name);
}

}
23 changes: 23 additions & 0 deletions src/IKVM.Maven.Sdk.Tasks.Java/IKVM.Maven.Sdk.Tasks.Java.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="IKVM.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Folder Include="org\slf4j\impl\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>

<Target Name="DownloadMavenArtifacts">
<Exec Command="mvn org.apache.maven.plugins:maven-dependency-plugin:3.3.0:copy-dependencies -f ikvm-maven-sdk-tasks-java.pom -DoutputDirectory=$(IntermediateOutputPath)maven" />
</Target>

<Target Name="AddJavaReferences" DependsOnTargets="DownloadMavenArtifacts" BeforeTargets="GetIkvmReferenceItemsFromIkvmReferences">
<ItemGroup>
<Convert Include="$(IntermediateOutputPath)maven\*.jar" />
<Classpath Include="$(IntermediateOutputPath)maven\*.jar" />
</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>ikvm.maven</groupId>
<artifactId>ikvm-maven-sdk-tasks</artifactId>
<artifactId>ikvm-maven-sdk-tasks-java</artifactId>
<version>1</version>
<properties>
<java.version>1.8</java.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.slf4j.impl;

import org.slf4j.*;
import org.slf4j.spi.*;

import IKVM.Maven.Sdk.Tasks.Java.*;

public final class StaticLoggerBinder implements LoggerFactoryBinder {

public static String REQUESTED_API_VERSION = "1.7";
static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

final ILoggerFactory loggerFactory;

private StaticLoggerBinder() {
loggerFactory = new AdapterLoggerFactory(AdapterLoggerFactory.LoggerFactory);
}

public static StaticLoggerBinder getSingleton() {
return SINGLETON;
}

@Override
public ILoggerFactory getLoggerFactory() {
return loggerFactory;
}

@Override
public String getLoggerFactoryClassStr() {
return AdapterLoggerFactory.class.getName();
}

}
47 changes: 32 additions & 15 deletions src/IKVM.Maven.Sdk.Tasks.Tests/MavenReferenceItemResolveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ static ITaskItem GetLocalRepositoryItem()
return item;
}

public TestContext TestContext { get; set; }

[TestMethod]
public void CanResolve()
{
var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.Repositories = new[] { GetCentralRepositoryItem() };
Expand Down Expand Up @@ -76,7 +79,8 @@ public void CanResolveWithClassifier()
{
var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.Repositories = new[] { GetCentralRepositoryItem() };
Expand Down Expand Up @@ -104,7 +108,8 @@ public void CanResolveWithMajorVersionOnly()
{
var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.Repositories = new[] { GetCentralRepositoryItem() };
Expand Down Expand Up @@ -134,7 +139,8 @@ public void CanResolvePackagingTypePom()
{
var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.Repositories = new[] { GetCentralRepositoryItem() };
Expand Down Expand Up @@ -164,7 +170,8 @@ public void CanResolveWithCache()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));

{
var t = new MavenReferenceItemResolve();
Expand Down Expand Up @@ -221,7 +228,8 @@ public void CanResolveWithVersionOverride()
{
var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.Repositories = new[] { GetCentralRepositoryItem() };
Expand Down Expand Up @@ -252,7 +260,8 @@ public void CanResolveWithTransitiveDependencies()
{
var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.Repositories = new[] { GetCentralRepositoryItem() };
Expand Down Expand Up @@ -285,7 +294,8 @@ public void ShouldIncludeUnifiedVersions()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand Down Expand Up @@ -317,7 +327,8 @@ public void ShouldIncludeProvidedDependencies()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand All @@ -344,7 +355,8 @@ public void CompileDependencyShouldBePrivateAndReferenced()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand Down Expand Up @@ -373,7 +385,8 @@ public void RuntimeDependencyShouldBePrivateAndReferenced()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand Down Expand Up @@ -402,7 +415,8 @@ public void ProvidedDependencyShouldBeNotPrivateAndReferenced()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand Down Expand Up @@ -431,7 +445,8 @@ public void SystemDependencyShouldBeExcluded()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand All @@ -457,7 +472,8 @@ public void CanResolveApacheFop()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand All @@ -484,7 +500,8 @@ public void CanResolveFromLocalRepository()

var engine = new Mock<IBuildEngine>();
var errors = new List<BuildErrorEventArgs>();
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => errors.Add(e));
engine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback((BuildErrorEventArgs e) => { errors.Add(e); TestContext.WriteLine(e.Message); });
engine.Setup(x => x.LogMessageEvent(It.IsAny<BuildMessageEventArgs>())).Callback((BuildMessageEventArgs e) => TestContext.WriteLine(e.Message));
var t = new MavenReferenceItemResolve();
t.BuildEngine = engine.Object;
t.CacheFile = cacheFile;
Expand Down
16 changes: 3 additions & 13 deletions src/IKVM.Maven.Sdk.Tasks/IKVM.Maven.Sdk.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@
<PackageReference Include="NuGet.ProjectModel" Version="6.2.4" />
</ItemGroup>

<Target Name="DownloadMavenArtifacts">
<Exec Command="mvn org.apache.maven.plugins:maven-dependency-plugin:3.3.0:copy-dependencies -f ikvm-maven-sdk-tasks.pom -DoutputDirectory=$(IntermediateOutputPath)ikvm-maven-sdk-tasks" />
</Target>

<Target Name="GetIkvmReferenceFromMaven" DependsOnTargets="DownloadMavenArtifacts" BeforeTargets="GetIkvmReferenceItemsFromIkvmReferences">
<ItemGroup>
<IkvmReference Include="ikvm-maven-sdk-tasks">
<AssemblyName>ikvm-maven-sdk-tasks</AssemblyName>
<AssemblyVersion>$(AssemblyVersion)</AssemblyVersion>
<Compile>$(IntermediateOutputPath)\ikvm-maven-sdk-tasks\*.jar</Compile>
</IkvmReference>
</ItemGroup>
</Target>
<ItemGroup>
<ProjectReference Include="..\IKVM.Maven.Sdk.Tasks.Java\IKVM.Maven.Sdk.Tasks.Java.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\SR.Designer.cs">
Expand Down
Loading

0 comments on commit dfb2631

Please sign in to comment.