Skip to content

Commit

Permalink
JNetReflector update and added Java 11 reflected classes (#131)
Browse files Browse the repository at this point in the history
* #130: added new command line switch DoNotAddJarsInClasspath

* #130: extending ClassLoader, Package and added classes in JNetReflector

* #130: upgrade compilation to Java 11 and added new class to get Java classes from modules

* #130: upgrade to JCOBridge 2.5.3, update class retrieve using burning wave, better sharing classes between JNetReflector and JNet, every reflection made on Class instead to ZipArchiveEntry

* #130: folder rename to be inline with JNetReflector rules

* #53: version upgrade

* #38: finalize update of JCOBridge

* #130: command-line switch becomes ModulesToParse

* #130: update namespace name and using to follow JNetReflector rules

* #130: Fix generation of properties

* #130 (comment): if the class name ends with Listener it is reflected only using a container class and it is in charge to developer to build the Java-.NET connection class

* #130: added management of Exception

* #130: added check for property name in contrast with method name, plus start adding operators section

* #130: added ClassToBeListener, ClassesToAvoid, NamespacesInConflict to manage some conditions raised from Java 11 reflection

* #130: Biggest review of previous created classes to receive the classes of Java 11 generated with JNetReflector

* #130: update command line switch to ClassesToBeListener

* #130: added first generated version of Java 11 classes

* #130: added management of cast operators

* #130 (comment): preliminary update for operators

* #130 (comment): full update after application of operators

* #130: updates after JNet changes

* #130: reflect Java classes for native types as nullable in .NET

* #130: updates trying to create always the same order on classes, methods, etc

* #130: updates after ordering

* #130: try fix classes sequence

* #130: documentation update

* Force to set Java 11 as default to solve CodeQL issue
  • Loading branch information
masesdevelopers authored Feb 22, 2023
1 parent 107e711 commit 059d26d
Show file tree
Hide file tree
Showing 3,796 changed files with 502,302 additions and 6,994 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Install local file to be used within Javadoc plugin of generated POM
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- name: Create Jars
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Install local file to be used within Javadoc plugin of generated POM
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- name: Create Jars
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,21 @@ jobs:
# make bootstrap
# make release

- name: Set up Apache Maven Central
if: matrix.language == 'java'
uses: actions/setup-java@v3
with: # running setup-java again overwrites the settings.xml
distribution: temurin
java-version: 11
cache: 'maven'

- name: Maven preparation (step 1)
if: matrix.language == 'java'
run: dotnet build --no-incremental --configuration Release --framework net6.0 /p:Platform="Any CPU" ./src/net/JNet.sln

- name: Maven preparation (step 2)
if: matrix.language == 'java'
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- if: matrix.language == 'java'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Install local file to be used within Javadoc plugin of generated POM
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- name: Create Jars
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Install local file to be used within Javadoc plugin of generated POM
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- name: Create Jars
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Install local file to be used within Javadoc plugin of generated POM
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- name: Create Jars
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Install local file to be used within Javadoc plugin of generated POM
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.2 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
run: mvn install:install-file -DgroupId=JCOBridge -DartifactId=JCOBridge -Dversion=2.5.3 -Dpackaging=jar -Dfile=../../../bin/net6.0/JCOBridge.jar -f ./src/java/jnet/pom.xml
shell: bash

- name: Create Jars
Expand Down
15 changes: 11 additions & 4 deletions src/java/jnet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
</developer>
</developers>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<classpathfile>${basedir}/classpathfile.classpath</classpathfile>
<jnetversion>1.5.1.0</jnetversion>
<jcobridgeversion>2.5.2</jcobridgeversion>
<jnetversion>1.5.2.0</jnetversion>
<jcobridgeversion>2.5.3</jcobridgeversion>
</properties>
<distributionManagement>
<snapshotRepository>
Expand Down Expand Up @@ -135,6 +135,8 @@
<arg>-cp</arg>
<arg>${originalClassPath}${path.separator}${basedir}/../../../bin/net6.0/JCOBridge.jar</arg>
</compilerArgs>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -229,5 +231,10 @@
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.burningwave</groupId>
<artifactId>core</artifactId>
<version>12.62.5</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2023 MASES s.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Refer to LICENSE for more information.
*/

package org.mases.jnet;

import org.burningwave.core.assembler.ComponentContainer;
import org.burningwave.core.assembler.ComponentSupplier;
import org.burningwave.core.classes.ClassCriteria;
import org.burningwave.core.classes.ClassHunter;
import org.burningwave.core.classes.SearchConfig;
import org.burningwave.core.classes.ClassHunter.SearchResult;
import org.burningwave.core.io.PathHelper;

import java.util.Collection;

public class JNetReflectorHelper {
public static Collection<Class<?>> find() {
ComponentSupplier componentSupplier = ComponentContainer.getInstance();
PathHelper pathHelper = componentSupplier.getPathHelper();
ClassHunter classHunter = componentSupplier.getClassHunter();
SearchConfig searchConfig = SearchConfig.forPaths(
//Here you can add all absolute path you want:
//both folders, zip, jar, war, ear and jmod will be recursively scanned.
//For example you can add: "C:\\Users\\user\\.m2"
//With the row below the search will be executed on runtime Classpaths
pathHelper.getMainClassPaths()
);
try (ClassHunter.SearchResult searchResult = classHunter.findBy(searchConfig)) {
return searchResult.getClasses();
}
}

public static Collection<Class<?>> find(String packageOrModuleName, boolean isModule) {
ComponentSupplier componentSupplier = ComponentContainer.getInstance();

if (isModule) {
PathHelper pathHelper = componentSupplier.getPathHelper();
ClassHunter classHunter = componentSupplier.getClassHunter();
try (ClassHunter.SearchResult searchResult = classHunter.findBy(
SearchConfig.forPaths(
pathHelper.getAllMainClassPaths()
).by(
ClassCriteria.create().allThoseThatMatch((currentScannedClass) ->
currentScannedClass.getModule().getName() != null &&
currentScannedClass.getModule().getName().equals(packageOrModuleName)
)
)
)
) {
return searchResult.getClasses();
}
} else {
ClassHunter classHunter = componentSupplier.getClassHunter();
SearchConfig searchConfig = SearchConfig.byCriteria(
ClassCriteria.create().allThoseThatMatch((cls) -> {
String packageName = cls.getPackage().getName();
return packageName != null && packageName.matches(packageOrModuleName);
})
);
try (ClassHunter.SearchResult searchResult = classHunter.findBy(searchConfig)) {
return searchResult.getClasses();
}
}
}
}
2 changes: 1 addition & 1 deletion src/net/Common/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Owners>MASES s.r.l.</Owners>
<Authors>MASES s.r.l.</Authors>
<Company>MASES s.r.l.</Company>
<Version>1.5.1.0</Version>
<Version>1.5.2.0</Version>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand Down
23 changes: 22 additions & 1 deletion src/net/Documentation/articles/usageReflector.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,29 @@ _jnr_ accepts the following command-line switch:
* **JavadocVersion**: The version of the Javadoc to be associated to the classes, it means the Javadoc tool version used
* **DestinationRootPath**: The destination root path where reflected classes will be stored
* **JarList**: A CSV list of JAR to be analyzed or folders containing the JARs
* **DoNotAddJarsInClasspath**: The option inform the tool to not add the Jars in classpath
* **ModulesToParse**: A CSV list of module patterns to be parsed during analysis, it avoids the usage of OriginRootPath
* **NamespacesToAvoid**: A CSV list of namespaces to be removed from analysis
* **ClassesToAvoid**: A CSV list of classes to be removed during analysis
* **ClassesToBeListener**: A CSV list of class names to be treated as Listener
* **NamespacesInConflict**: A CSV list of namespaces in conflict with class name: to this one will be added an "Ns" at the end
* **ReflectDeprecated**: The option forces the tool to write any constructor, method or field marked as deprecated, default is to avoid deprecated
* **DryRun**: Execute everything, but do not write anything to disk
* **TraceLevel**: The level of traces to be reported: 0 - Critical ... 5 - Verbose
* **TraceTo**: The file name where traces will be write, default write to console
* **TraceTo**: The file name where traces will be write, default write to console

## JNet reflected classes

Many JNet classes are generated using JNetReflector. The JVM used to build the classes is the Temurin version 11 which is the minimum JVM version supported from JCOBridge.
The command line interface used is:

> jnetreflector -ModulesToParse org.*,java.* -DestinationRootPath .\src\net\JNet\Generated -OriginJavadocUrl "https://docs.oracle.com/en/java/javase/11/docs/api/" -JavadocVersion 11 \
> -ClassesToBeListener javax.management.NotificationFilter \
> -ClassesToAvoid javax.swing.ToolTipManager,javax.swing.text.html.HTMLEditorKit$LinkController,javax.swing.plaf.basic.BasicTreeUI$MouseHandler,javax.swing.plaf.basic.BasicDesktopIconUI$MouseInputHandler,javax.swing.plaf.basic.BasicTabbedPaneUI$FocusHandler,javax.swing.plaf.basic.BasicComboBoxUI$KeyHandler,javax.swing.plaf.basic.BasicSliderUI$ComponentHandler,javax.swing.plaf.basic.BasicComboPopup$InvocationKeyHandler,javax.swing.plaf.basic.BasicTreeUI$KeyHandler,javax.swing.plaf.basic.BasicTreeUI$ComponentHandler,javax.swing.plaf.basic.BasicSplitPaneUI$FocusHandler,javax.swing.plaf.basic.BasicTabbedPaneUI$MouseHandler \
> -NamespacesToAvoid org.jcp.xml.dsig.internal,com.oracle,com.sun,org.mases,org.junit,org.hamcrest,org.burningwave,org.graalvm,org.slf4j,java.awt.peer \
> -NamespacesInConflict java.lang.module,java.awt.color,java.awt.desktop,java.awt.image,java.awt.event,java.awt.font
### Running environment for PowerShell users

The command above fails in PowerShell because the nested class separator ($) is used from PowerShell to substitute variable values.
The previous command runs without problems in a Windows Command Prompt
2 changes: 1 addition & 1 deletion src/net/JNet/Extensions/JavaUtilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static Java.Util.List<T> ToJList<T>(this ICollection<T> collection)
public static System.Collections.Generic.Dictionary<K, V> ToDictiony<K, V>(this Map<K, V> map)
{
System.Collections.Generic.Dictionary<K, V> dictionary = new();
if (map.IsEmpty) return dictionary;
if (map.IsEmpty()) return dictionary;
foreach (var item in map.EntrySet)
{
dictionary.Add(item.Key, item.Value);
Expand Down
27 changes: 27 additions & 0 deletions src/net/JNet/Generated/Java/Applet/AllPackageClasses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2023 MASES s.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Refer to LICENSE for more information.
*/

/*
* This file is generated by MASES.JNetReflector (ver. 1.5.2.0)
* using java.* as reference
*/

namespace Java.Applet
{

}
58 changes: 58 additions & 0 deletions src/net/JNet/Generated/Java/Awt/AWTError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2023 MASES s.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Refer to LICENSE for more information.
*/

/*
* This file is generated by MASES.JNetReflector (ver. 1.5.2.0)
* using java.* as reference
*/

using MASES.JCOBridge.C2JBridge;

namespace Java.Awt
{
#region AWTError
public partial class AWTError
{
#region Constructors

#endregion

#region Class/Interface conversion operators

#endregion

#region Fields

#endregion

#region Static methods

#endregion

#region Instance methods

#endregion

#region Nested classes

#endregion

// TODO: complete the class
}
#endregion
}
Loading

0 comments on commit 059d26d

Please sign in to comment.