configure javadoc links in offline mode to link to local copy - java

How do I create javadocs that link to files in the local filesystem in offline mode?
I am building javadocs for a java package and want the links of external packages (including java.lang) to point to a local copy. This works by setting the links property like so:
<configuration>
<links>
<link>/usr/share/doc/default-jdk-doc/api/</link>
</links>
</configuration>
However, the links property is ignored when working offline, even when
linking to a local copy of the javadocs. My understanding is that in such case, I should be using offlineLinks but I can't make it work.
All documentation I see for offlineLinks sets url to an external URL and location to a local file. The use case seems to be creating links to external server, by using a local copy. I have tried to set both url and location to the same value but this seems to be ignored.
<offlineLinks>
<offlineLink>
<url>/usr/share/doc/default-jdk-doc/api/</url>
<location>/usr/share/doc/default-jdk-doc/api/</location>
</offlineLink>
</offlineLinks>
I have created a minimal example as a github gist which I am calling like so:
mvn --offline javadoc:javadoc
It has a single package and method that takes a String as argument. I want the javadocs to create a link to a local copy of the docs but instead I keep getting String linked to docs.oracle.com instead.

The javadoc program would handle the -links option properly, even if it was a local directory and there was no without internet connection. The problem is the maven javadoc plugin which ignores the links property in offline mode. The solution is to pass that option directly to the javadoc program via the additionalparam property like so:
<configuration>
<additionalparam>-link /usr/share/doc/default-jdk-doc/api/</additionalparam>
</configuration>
This has two problems:
It becomes too long if linking to many different packages. In theory, one should be able to pass multiple -link options in a single additionalparam parameter.
The additionalparam is deprecated. However, there is no other maven property to pass javadoc options directly so hopefully they won't actually remove it.
The offlineLinks property, which would map to the command line option -linkoffline seems to really require an external URL. I am unsure if that's a requirement in the javadoc program or in the maven javadoc plugin.

Related

jvm able to access with eclipse but not with jenkins

I have issue with jvm argument being passed:
1. I can pass jvm argument in eclipse as -Dname=value and access the same through java as system.getproperty("name");
2. But when i try the same with Jenkins, as it is a maven project with multiple pom, not able to pass this param i.e., it shows null on printing it.
Done with lot lot more surfing and tries... but didnt get a fix yet :(
passed param in mvn .. -Dname=value ...
tried with setting property in pom etc.., nothing helped
Is ther any other way to set system property in global access so that all the pom and java files can access it.
MAVAN_OPTS, jenkins ettings nothing worked...
You can set system variables via the <systemPropertyVariables> configuration of maven surfire plugin.
See documentation and full example here:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html

Cannot generate C# proxy dll with JNI4NET tool, running batch file as trusted assembly?

I am working on getting the tool JNI4NET working so that I can use some Java code I have within my C# application. As a simple initial test I have created a simple Java class library with a single class Person with one method public String GetName() { return "NoBody"; }. From here I have been following along with the samples given in the JNI download to edit the generateProxies.cmd to create the DLL wrapper of the jar.
I didn't have much luck with this so I decided to try to perform the same action but with the sample, specifically the sample entitled myJavaDemoCalc. When executed generateProxies.cmd in the sample folder an error is thrown.
(I will transcribe this picture if need be)
I have followed the link in the exception though while I somewhat understand what it means I am not sure if it is necessarily safe to enable loading from remote sources as it suggests at the end of the linked article.
I am also confused why the exception is being thrown seeing that the generateProxies.cmd and thus ProxyGen.exe is being run from my C: drive.
Anyone have an idea of what I could try next or know the issue here?
For reference here is the generateProxies.cmd source from myJavaDemoCalc
#echo off
copy ..\..\lib\*.* work
..\..\bin\proxygen.exe work\myJavaDemoCalc.jar -wd work
cd work
call build.cmd
cd ..
echo compiling usage
csc.exe /nologo /warn:0 /reference:work\jni4net.n-0.8.8.0.dll /reference:work\myJavaDemoCalc.j4n.dll /out:work\demo.exe /target:exe MyCalcUsageInDotnet.cs
I assume you downloaded that zip file and then immediately Extracted all files.
However, because that zipfile did originate from an untrusted zone, being the internet, the files in it will also remain untrusted. It contains an alternate data stream with a zone identifier.
When those assemblies get loaded by the framework, it checks if they can be trusted. Assemblies with that zone identfier still present don't get loaded. That is the exception you get:
System.IO.FileLoadException: Could not load file or assembly 'file:///jni4net.n-0.8.8.0.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) --->
System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch.
The quickest solution to resolve this is to open the properties window of the downloaded zip file and tick unblock before you extract all files:
If you already extracted all the files to a folder you can use the powershell command unblock-file
Get-ChildItem -Path 'c:\path\to\files' -Recurse | Unblock-File
But if you're sure that you will always run proxygen.exe with trusted assemblies, you can add the suggestion offered in the MSDN article by adding the loadFromRemoteSources element in the existing proxygen.exe.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<!-- trust all the thingz -->
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>

How to get jar class is coming from

I am currently working on an API for a server software so users can extend my software by programming plugins for it instead of modifying the software themselves, and allow other users without programming knowledge to easily change the software by adding these plugins. So far, everything is working fine. But, I am running into a problem with configuration.
You see, each plugin has a plugin.yml file stored with these 4 attributes:
Main: The main class is stored here
Name: This is where the plugin name is stored
Version: This is where the plugin version is stored
Author: This is where the plugin author is stored
Now, in order for the plugin to print something to the console, they use a function called: this.getServer().getLogger().info("MESSAGE); (They extend another class for plugins, thats why they use "this" instead of another class to log)
But, I do not have any idea on how to get which plugin is which when they are calling the function. I have a ArrayList of PluginSessions which event handlers use to cycle through to run Event Functions.
My solution is to get the jar from which a class is being called so I can then get the plugin.yml from there. But, I have NO idea on how to get that, I have tried using Class.forName(); and some other code. But because the class is non-existent within the jar/project running the code, It will throw a ClassNotFoundException.
Does anyone here know how to get the jar from which a class is coming from without using Class.forName()? Thanks! -Trent
Take a look at Class.getResource.
If you call MyClass.getResource("plugin.yml") (or "/plugin.yml" with leading slash, I forget) you get back a file URL pointing to the plugin.yml file in the same jar as MyClass. (Or null if the path is wrong or the jar doesn't contain a "plugin.yml" file.) You can then open an InputStream to that resource. In a plugin framework you may want to use myPluginInstance.getClass().getResource.
Assuming jar for 'PluginSessions' is already added in you classpath by eclipse then you can try the following trick -
Select/highlight PluginSessions by double clicking on it
Now press CTRL+SHIFT+T
A dialog named Open Type is appeared. Here you found from where the PluginSessions class is coming from. If you have more than one jar containing PluginSessions class than you have a list of them.
To benefited from this CTRL+SHIFT+T trick you need to add all of your jar need by the project to be added in your classpath.

How do I modify a Jenkins plugin to stop it from putting a link on build pages?

I'm trying to modify the existing EnvInject plugin so that the Environment Variables link it puts on a build's page is hidden. If I'm understanding the Jenkins API correctly, I should be able to do this by finding where the Action interface is implemented and having getIconFileName() return null.
I found that method implemented in EnvInjectAction.java and modified it to return null, but this had no effect--the link is still visible on build pages. I even tried modifying getDisplayName() and getUrlName() to also return null, but this also had no effect. Here is the modified method:
public String getIconFileName() {
return null;
}
I've taken care to follow the instructions for deploying a custom build of a core plugin from the Jenkins plugin tutorial, and I've also tried rebooting the machine that Jenkins is running on, all to no avail.
I'm clearly missing something vital, but I can't figure out what it could be. What else do I need to do to make the plugin not display the Environment Variables link?
Why do you want to do that? To hide sensitive information?
Are you aware of that even if you remove the link the variables can be displayed via:
http://jenkins/job/YourJob/1/injectedEnvVars?
Or according to the EnvInjectPlugin-VariablesTraceability:
"You can also get build environment variables by the following
HTTP GET URL: <jenkins_url>/job/<job_name>/<build_number>/injectedEnvVars/export"
However, if it's just to remove the link and modifying the plugin is not a must add the following to Jenkins' run/jenkins/war/css/style.css:
a[href*='/injectedEnvVars'] {
display: none;
}
Make a backup copy of the adapted style.css since it might get overwritten with a:
$ sudo service jenkins --full-restart
UPDATE
You can use a custom CSS with the following:
Manage Jenkins → Configure System → Theme → URL of theme CSS: ...
As answer to overcome comment limitations.
I looked into the source of the plugin and I can say that I'd chosen EnvInjectAction.java's getDisplayName() to apply the changes, as well. Since it contains return "Environment Variables"; and is the only file in the entire project that contains exactly that string.
I noticed that EnvIinjectAction is deprecated but that shouldn't do any harm anyway.
Have you tried to return an empty or an arbitrary string for testing rather than null. Maybe Jenkins itself doesn't like null being returned by this method. (But the next question is, why does it still display the original string of the plugin then.)
I even downloaded the jenkins-1.585 core sources and searched for invocations of getDisplayName() to check what is done with the value returned but there are 332 of them in src/main/java. I'm still trying to find the proper one.
Did you try the changed plugin on a local Jenkins on your machine? Maybe something went wrong while installing the plugin on the servers that are not maintained by yourself.
Have you considered contacting the maintainer Gregory Boissinot?

SVN revision number accessible in compiled GWT package

I have a GWT project which has its source managed in SVN, is packaged using Maven and has its builds managed via Hudson. I want to get the SVN revision number of the latest check-in/build to be visible in a comment at the bottom of the application root HTML file. I don't care where in the development process this happens!
Here are the options I've Googled for so far, with no success:
Can I get Hudson to, after building, write the build/revision number
to one of its build output files (namely the application root HTML
file)? I've seen no way to do this.
Can I get Maven to write the SVN revision number to one of its build
output files (namely the application root HTML file)? I've seen ways
of Maven writing this to a JAR/WAR manifest file (which can then be
accessed in the Java code), but I'm not sure that this works in GWT
(I'm not particularly knowledgeable about the internals of GWT).
Can I get SubVersion to, as a pre-commit hook, write the version number to a particular file? I know it's easy to write the version number to the file you're editing, but not so sure about writing to a totally separate file (so that it's updated on every commit, regardless of whether it was changed in that commit).
Does anyone have a complete, end-to-end example of how to get any of these working? I keep finding little snippets of code/config which do one part of the job, but not anything that is exactly what I'm looking for.
Thanks!
You can achieve what you're looking for with a combination of Maven and Hudson. In this example let's imagine you want the file version.txt at the root of your web app to contain the revision.
version.txt:
${SVN_REVISION}
In your project's pom.xml enable filtering in the maven-war-plugin:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<webResources>
<webResource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>version.txt</include>
</includes>
</webResource>
</webResources>
</configuration>
</plugin>
Make sure that Hudson is building your project via. Subversion checkout and it will set the SVN_REVISION environment variable for every build and Maven will fill it in.
This solution is for those who keep getting {SVN_REVISION} instead of the actual SVN_REVISION value inside the target file.
My solution was to also use filtering. However since I wanted the SVN_REVISION to appear inside my gwt app's main html page (as a means of "fighting" the user's cache, making sure that if we carry out a new build, then the user downloads the latest html file), I wasn't able to use Jason Terk's solution. The html file simply printed {SVN_REVISION} instead of the actual SVN_REVISION value.
So I defined a property inside <properties>:
<properties>
...
<buildVersion>${SVN_REVISION}</buildVersion>
...
</properties>
I then made sure I was filtering the appropriate html file (like described in Jason's solution), and then "extracted" the SVN_REVISION in the html file like so:
<script type="text/javascript">
...
var versionIdSuffix = '?v=${buildVersion}';
....
</script>
In a nutshell - I wasn't able to directly reference the {SVN_REVISION} property from inside the html file, so I "wrapped" it through <properties>, letting maven reference it instead.

Categories