Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic java lib mappings #731

Closed
neokoenig opened this issue Mar 7, 2017 · 9 comments
Closed

Add automatic java lib mappings #731

neokoenig opened this issue Mar 7, 2017 · 9 comments
Assignees
Milestone

Comments

@neokoenig
Copy link
Contributor

Would make plugins more powerful if there was a way to have /plugins/pluginName/lib/ automatically added to the this.javamappings: that way you could easily deploy javalib based plugins without additional configuration.

yay? nay?

@perdjurner
Copy link
Contributor

Not familiar with this, can you give me a real world example?
Can the plugin itself add the mapping or is that impossible currently?

@neokoenig
Copy link
Contributor Author

i.e, lets say you wanted to make a bCrypt plugin. The easiest way is via

this.javaSettings = {
    	LoadPaths = ["miscellaneous"]
  	};

in config/app.cfm

Chuck your .class file in, the do bCrypt = CreateObject( "java", "BCrypt" );

So what I'm saying is it would be great if /lib or /java as auto-added to this.javasettings if it exists: that way you don't need to change code outside of the plugin to use it.

@neokoenig
Copy link
Contributor Author

The more I think about this the more I like it: it means you could very easily add plugins which just expose java libs and add a few convenience functions. Bycrypt, iCal4J, MarkdownJ would be some easy wins for new plugins (I've actually already written these too).

I'll implement unless there are any strong objections.

@neokoenig neokoenig self-assigned this Mar 14, 2017
@neokoenig neokoenig added this to the 2.0.0 milestone Mar 14, 2017
@andybellenie
Copy link
Contributor

I thought you could use a path on CreateObject() but I've just checked and it's a Lucee only feature, so I agree this would be useful.

I got this to work but recursing over plugin directories and adding them all to JavaSettings.LoadPaths. Then all a plugin author has to do is place the java file directly in a plugin directory or subdirectory.

@neokoenig
Copy link
Contributor Author

Cool, that was pretty much my thinking. Have you done this got the code already? If so that would be fab, otherwise I'm happy to do it

@andybellenie
Copy link
Contributor

andybellenie commented Mar 14, 2017

No problem

param name="this.javaSettings.loadPaths" default=ArrayNew(1);
for (file in DirectoryList(path=ExpandPath("/#application.$wheels.pluginPath#"), recurse="true", filter="*.class|*.jar|*.java")) {
	ArrayAppend(this.javaSettings.loadPaths, GetDirectoryFromPath(file)); 
}

It needs to go in /wheels/events/onapplicationstart.cfm somewhere so as not to override any paths the user may have set themselves

@neokoenig
Copy link
Contributor Author

hmm. I can get the folder path into the loadpaths array, but for the life of my can't work out why the .class etc files refuse to load. @andybellenie you're using this in lucee 4.5.x?

@andybellenie
Copy link
Contributor

Lucee 4.5.3.020

neokoenig added a commit that referenced this issue Mar 14, 2017
Not 100% convinced by the implementation here; it would mean the developer has to use `arrayAppend()` when adding their own javaSettings.LoadPaths, as the danger is they override what we've set unintentionally.
neokoenig added a commit that referenced this issue Mar 14, 2017
@neokoenig
Copy link
Contributor Author

Added in 3c4a231
Leaving open to document

@neokoenig neokoenig added the docs label Mar 15, 2017
@neokoenig neokoenig modified the milestones: 2.0.0 Beta, 2.0.0 Mar 15, 2017
@neokoenig neokoenig modified the milestones: 2.0.0, 2.0.0 Beta Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants