Java Plugins in combination with Maven\Lombok\Spring

Hello Community,
today i came across an issue with importing jar files of a maven project utilising spring.
In order to avoid issues i wrote a spring based layer of objects and functions and wrote a very simple plugin interface with a dozen of functions. I wanted to test the functionality in delphi and tried to import my new plugin. It seems like the importer has a problem with maven projects.


As far i see it, the import function via hydra try to parse and wrap also some classes without any references of hydra. Maybe it would be a good idea adding a way to annotate hydra wrapable code in order to avoid that reflections having trouble to parse content it does not need.

Are there any limitations or restrictions known? Or how could i solve this issue? My hydra interface just have plain methods like

public boolean Connect();
public boolean Disconnect();
public String GetChallenge(String clientId);

Any ideas?

Hi,

hmm, I can’t reproduce any issues with such declarations
I have

classlibrary1_Import.pas
unit classlibrary1_Import;

interface

uses
  uHYCrossPlatformInterfaces,
  uHYJavaTypes,
  uHYJavaNonVisualPluginWrapper;

type
  { Forward declarations }
  IPluginInterface = interface;
  TPluginImplementationWrapper = class;

  IPluginInterface = interface(IHYCrossPlatformNonVisualPlugin)
  ['{F19727E4-D526-48A5-957A-CC710B519C37}']
    function Connect: JBoolean;
    function Disconnect: JBoolean;
    function GetChallenge(arg0: UnicodeString): UnicodeString;
  end;

  TPluginImplementationWrapper = class(THYJavaNonVisualPluginWrapper, IPluginInterface)
  public
    function Connect: JBoolean;
    function Disconnect: JBoolean;
    function GetChallenge(arg0: UnicodeString): UnicodeString;
  end;

implementation

uses
  uHYCrossPlatformModuleController;

function TPluginImplementationWrapper.Connect: JBoolean;
var
  lmethodId: JMethodID;
  largs: JValueDynArray;
begin
  lmethodId := Self.JVM.Reflection.GetMethodId(Self.ClassID, 'Connect', '()Z');
  System.SetLength(largs, 0);
  result := Self.JVM.Reflection.CallBooleanMethod(Self.InstanceID, lmethodId, largs);
  exit;
end;

function TPluginImplementationWrapper.Disconnect: JBoolean;
var
  lmethodId: JMethodID;
  largs: JValueDynArray;
begin
  lmethodId := Self.JVM.Reflection.GetMethodId(Self.ClassID, 'Disconnect', '()Z');
  System.SetLength(largs, 0);
  result := Self.JVM.Reflection.CallBooleanMethod(Self.InstanceID, lmethodId, largs);
  exit;
end;

function TPluginImplementationWrapper.GetChallenge(arg0: UnicodeString): UnicodeString;
var
  lmethodId: JMethodID;
  largs: JValueDynArray;
begin
  lmethodId := Self.JVM.Reflection.GetMethodId(Self.ClassID, 'GetChallenge', '(Ljava/lang/String;)Ljava/lang/String;');
  System.SetLength(largs, 1);
  largs[0] := Self.JVM.ValueConverter.ConvertFromString(arg0);
  result := Self.JVM.ValueConverter.ConvertToString(Self.JVM.Reflection.CallObjectMethod(Self.InstanceID, lmethodId, largs));
  exit;
end;

initialization
  RegisterPlugin('ClassLibrary1/PluginImplementation', nil, TPluginImplementationWrapper);
end.

for classlibrary1.zip (3.2 KB)

Note: our wizard is designed for importing hydra/java plugins only and it isn’t designed for importing others .jar

Hi,
i will give it a try. My jar file is written as followed :
hydra plugin descriptor -> only supported and very basical as described in documentation.
hydra plugin interface -> only supported native functions as described above. absolute no reference to spring\maven.
hydra plugin implementation -> implements interface and as private object a client that utilize spring.

calls are like this :

	@Override
	public boolean Connect() {
		return client.Connect();
	}

	@Override
	public boolean Disconnect() {
		return client.Disconnect();
	}

	@Override
	public boolean IsConnected() {
		return client.IsConnected();
	}

	@Override
	public boolean SetConnectivity(String host, int port) {
		client.setHost(host);
		client.setPort(port);
		return true;
	}

I dont see a problem at all. The file the importer declares as issue is not even used by client or hydra at all.

Edit : Your sample works as import… I´m pretty unsure where this issue might come across.

Hi,

Can you create a simple testcase that reproduces import issue, pls?
body of methods can be empty or returns simple values like False.
you can drop it to support@ for keeping privacy.

Its very simple to reproduce. I can attach a plain sample without any sensitive code here :

Goto https://start.spring.io/


I generated a maven project with spring by this.
I runned app as maven install in order to get maven assemblies to my project.
I added Hydra as external library and added those 3 files

demo.zip (1.3 KB)

Then exported as Jar and import it in delphi:

So it should not be a problem by my code overall, but something hydra does wrong while parsing the jar file. If this is not enough, i could still pack the project and send it via mail (its 16MB compressed)

Hi,

can you attach generated .jar for above demo.zip too, pls?

according to error, you have extra paths in class name

Its bigger then 16MB. I will send it to you through mail.

Hi,

thx.
you can try to send it here via PM to me or support group

Thanks, logged as bugs://84193

Hi,

if you open your .jar as usual archive and remove target\test-classes folder:


everything will work as expected.

we are still investigating this case.

You are correct for the simple sample I´ve provided you. In my complex case it still have trouble

I ended up eliminating everything related to junit tests on eclipse export (there i can remove those folders without any zip) but then there will be a problem with maven projects in use.

If you add

		<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
		<dependency>
			<groupId>com.fasterxml.jackson.datatype</groupId>
			<artifactId>jackson-datatype-jsr310</artifactId>
			<version>2.11.0.rc1</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.module</groupId>
			<artifactId>jackson-module-parameter-names</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.datatype</groupId>
			<artifactId>jackson-datatype-jdk8</artifactId>
		</dependency>

To your pom.xml file and try to load your plugin it will be troublesome again:

Hi,

these errors mean that our wizard can’t find other .jar that were used in your project.

try to put .jar with these classes into folder with your plugin and try import again

Maven Assemblies are not inlined into jar files but linked to the maven repository on workspace. I have an idea i might test if i can get a way to link it. I will give a feedback once we know more.

bugs://84193 got closed with status fixed.