How can I share global configuration fields when writing a jenkins plugin? - plugins

I'm currently writing a jenkins plug-in that has multiple builders. I wanted to share the fields in the descriptor/global.jelly across all builders. How can I share this information? Can I use inheritance or encapsulation?

A good place to start is to search the Jenkins github repository
The code you want is
Jenkins.getInstance().getDescriptor( MyPluginWithGlobalConfig.class )
Which will give you the descriptor back you want (as there is only one instance of the descriptor)
Here is one I used in a plugin (in groovy) which fetches a descriptor then calls a method on it source file
#Override
public List<String> rebuild(List<String> list){
SeleniumDynamicCapability.DescriptorImpl sdcd = Jenkins.getInstance().getDescriptor(SeleniumDynamicCapability.class)
List<SeleniumCapabilityRO> sc = sdcd.loadDefaultItems()
if (sc.size() == 0)
throw(new SeleniumException("No selenium capabilities detected"))
setSeleniumCapabilities(sc)
sc.each{list.add(it.toString())}
return list;
}

Related

How to customize addContentItemDialog to restrict files over 10mb upload in IBM Content Navigator

I am customizing ICN (IBM Content Navigator) 2.0.3 and my requirement is to restrict user to upload files over 10mb and only allowed files are .pdf or .docx.
I know I have to extend / customize the AddContentItemDialog but there is very less detail on exactly how to do it, or any video on it. I'd appreciate if someone could guide.
Thanks
I installed the development environment but I am not sure how to extend the AddContentItemDialog.
public void applicationInit(HttpServletRequest request,
PluginServiceCallbacks callbacks) throws Exception {
}
I want to also know how to roll out the changes to ICN.
This can be easily extended. I would suggest to read the ICN red book for the details on how to do it. But it is pretty standard code.
Regarding rollout the code to ICN, there are two ways:
- If you are using plugin: just replace the Jar file on the server location and restart WAS.
- If you are using EDS: you need to redeploy the web service and restart WAS.
Hope this helps.
thanks
Although there are many ways to do this, one way indeed is tot extend, or augment the AddContentItemDialog as you qouted. After looking at the (rather poor IBM documentation) i figured you could probably use the onAdd event/method
Dojo/Aspect#around allows you to do exactly that, example:
require(["dojo/aspect", "ecm/widget/dialog/AddContentItemDialog"], function(aspect, AddContentItemDialog) {
aspect.around(AddContentItemDialog.prototype, "onAdd", function advisor(original) {
return function around() {
var files = this.addContentItemGeneralPane.getFileInputFiles();
var containsInvalidFiles = dojo.some(files, function isInvalid(file) {
var fileName = file.name.toLowerCase();
var extensionOK = fileName.endsWith(".pdf") || fileName.endsWith(".docx");
var fileSizeOK = file.size <= 10 * 1024 * 1024;
return !(extensionOK && fileSizeOK);
});
if (containsInvalidFiles) {
alert("You can't add that :)");
}else{
original.apply(this, arguments);
}
}
});
});
Just make sure this code gets executed before the actual dialog is opened. The best way to achieve this, is by wrapping this code in a new plugin.
Now on creating/deploying plugins -> The easiest way is this wizard for Eclipse (see also a repackaged version for newer eclipse versions). Just create a new arbitrary plugin, and paste this javascript code in the generated .js file.
Additionally it might be good to note that you're only limiting "this specific dialog" to upload specific files. It would probably be a good idea to also create a requestFilter to limit all possible uses of the addContent api...

Is it possible to use Autofac somehow within Unity3d?

I am using Unity3d 2018.1.0f3 which is using .net 4.6x and has netstandard 2.0. Does anyone know if its possible to get Autofac working within Unity? Currently, I get an error saying that it unloaded the assemblies due to possible runtime issues.
Thanks,
MH
I have no idea about the other stuff, and I use an older version of it, but I use AutoFac (3.5.2) with Unity with no issues at all. I think it needs slightly different setup for unity but not really sure. but I have an editor window system that uses ScriptableObjects for databases and seperate pages for different item types, and use autofac to inject the databases, and find all the sub pages and auto load them.
this is how I do it if this helps:
private ISWeaponDatabase weaponDb;
private ISQualityDatabase qualityDb;
private ISArmorDatabase armorDb;
private int currentTab;
private ContainerBuilder builder;
private BasePage[] pages;
DatabaseConfig dbConfig = Resources.Load<DatabaseConfig>("DatabaseConfig");
if (dbConfig == null) return;
if (weaponDb == null) weaponDb = ISWeaponDatabase.GetDatase<ISWeaponDatabase>(dbConfig.DataFolder, dbConfig.WeaponDatabase.DatabaseFile);
if (qualityDb == null) qualityDb = ISWeaponDatabase.GetDatase<ISQualityDatabase>(dbConfig.DataFolder, dbConfig.QualityDatabase.DatabaseFile);
if (armorDb == null) armorDb = ISArmorDatabase.GetDatase<ISArmorDatabase>(dbConfig.DataFolder, dbConfig.ArmorDatabase.DatabaseFile);
builder = new ContainerBuilder();
builder.RegisterInstance(weaponDb).As<ISWeaponDatabase>();
builder.RegisterInstance(armorDb).As<ISArmorDatabase>();
builder.RegisterInstance(qualityDb).As<ISQualityDatabase>();
builder.RegisterAssemblyTypes(Assembly.GetAssembly(GetType())).Where(t => t.Name.EndsWith("EditorPage")).As<BasePage>().SingleInstance();
IContainer container = builder.Build();
pages = container.Resolve<IEnumerable<BasePage>>().ToArray();
Yes, it is possible, would be nice to know what you tried until now, but basically, you'll import it as you'd import every other 3rd party library.
I assume you are on an up-to-date Windows Machine and you are using VS because you didn't give us any information on that.
Fire up your NuGet PM in VS (Tools > NuGet Package Manager > Console)
Command: Install-Package Autofac -Version 4.8.1
Or your preferred way to get a NuGet package https://www.nuget.org/packages/Autofac/ (VS is of course also working)
Now you should have a package in /Packages/Autofac.4.8.1/lib/net45
Copy the DLL over to your assets/lib folder (or wherever you want to have it)
If you go back to Unity it will load Autofac now
Now you can go to any class you have and type "using Autofac" and get started.

Extracting data from owl file using java,gwt,eclipse

I have to display content from the owl file namely the class names.. onto my browser, I am using GWT,eclipse to do so, could some one tell me the following :-
1)how do I integrate the owl file with the eclipse project?
2)How do I run queries from my java project to extract class names from the owl file?
3)Where can I get the protege api to nclude into my project?!
You could just store your .owl file anywhere inside your project or on any other location on your harddrive. You just provide a path to it, when you load/store it (see code below).
Take a look at the OWLAPI, it allows you to load an existing ontology and retrieve all classes from it. Your code could look like this:
private static void loadAndPrintEntities() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI documentIRI = IRI.create("file:///C:/folder/", "your_rontology.owl");
try {
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(documentIRI);
//Prints all axioms, not just classes
ontology.axioms().forEach(a -> System.out.println(a));
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
}
Rather than trying to integrate the Protegé API into your project, I suggest you write a plugin for Protegé. There are some great examples that should get you started. Import this project into Eclipse, modify the content, build your plugin and drop it into Protegé. That's it, you're ready to go!

RCP - Proper register Listener not from view

I try to register my class as PostSelectionListener from separate plugin (this class is not a view, only simple class), I use this:
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService().
addPostSelectionListener(VIEWS_VISUALIZATION_TYP_ID, this);
It works fine, but I have a warning:
- Discouraged access: The method getActiveWorkbenchWindow()
from the type Workbench is not accessible due to restriction on required library F:
\elipseSource\plugins\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
- Discouraged access: The method getInstance()
from the type Workbench is not accessible due to restriction on required library F:\elipseSource\plugins
\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
- Discouraged access: The type Workbench is not accessible
due to restriction on required library F:\elipseSource\plugins
\org.eclipse.ui.workbench_3.5.1.M20090826-0800a.jar
How can I register listener in proper way ?
I have found a solution, instead of
Workbench.getInstance()
I should use:
PlatformUI.getWorkbench()
I am RCP beginner so it was not obvious for me
Check if this is a MANFEST.MF generation issue (see this thread)
Open the MANIFEST.MF of the base project and look at the Runtime tab.
The packages that are to be accessed in other plugins should be listed as Exported Packages.
Try to re-compute the right list of exported packages.
If this is not working, as described in this thread, you still have the option to de-activate the warning:
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
(or: Project) Properties -> Java Compiler -> Errors/Warnings
"Warning" or "Ignore" options will only hide the potential issue in the project, by allowing the project to use any classes ignoring predefined access rules.
To completely resolve this issue, analyze the project and located the use of restricted classes and take necessary actions (either remove those references or access rules).
For external jar (not your case), Potential workaround:
If I add the Jar file as an external jar and move it up before the JRE system Library (in order of export), I don't get this error.
Actually the OP slowik managed to avoid the dependency by accessing the Workbench services through the PlatformUI
PlatformUI.getWorkbench()
instead of Workbench.getInstance()
You can see this approach used in the rcp.util.RCPUtil class:
/**
* Returns wether the ViewPart with the given id is currently visble in
* one of the pages of the active Workbench window. Will also return
* true when the page-book containing this view is minimized.
*
* #param viewID The id of the view to be queried
* #return Wether the view is visible
*/
public static boolean isViewVisible(String JavaDoc viewID) {
// IWorkbenchPage[] pages = Workbench.getInstance().getActiveWorkbenchWindow().getPages();
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
for (int i = 0; i < pages.length; i++) {
IWorkbenchPart part = pages[i].findView(viewID);
if (part != null) {
return isPartVisible(part);
}
}
return false;
}

Eclipse RCP: How to access internal classes of plugins?

I want to use the default XML editor (org.eclipse.wst.xml.ui) of Eclipse in an RCP application. I need to read the DOM of the xml file currently open. The plugin doesn't offer any extension point, so I'm trying to access the internal classes. I am aware that the I should not access the internal classes, but I don't have another option.
My approach is to create a fragment and an extension point to be able to read data from the plugin. I'm trying not to recompile the plugin, that's why I thought that a fragment was necessary. I just want to load it and extract the data at runtime.
So, my question is: is there another way to access the classes of a plugin? if yes, how?
Any tutorial, doc page or useful link for any of the methods is welcome.
Since nobody answered my question and I found the answer after long searches, I will post the answer for others to use if they bump into this problem.
To access a plugin at runtime you must create and extension point and an extension attached to it into the plugin that you are trying to access.
Adding classes to a plugin using a fragment is not recommended if you want to access those classes from outside of the plugin.
So, the best solution for this is to get the plugin source from the CVS Repository and make the modifications directly into the source of the plugin. Add extension points, extensions and the code for functionality.
Tutorials:
Getting the plugin from the CVS Repository:
http://www.eclipse.org/webtools/community/tutorials/DevelopingWTP/DevelopingWTP.html
Creating extensions and extension points and accessing them:
http://www.vogella.de/articles/EclipseExtensionPoint/article.html
http://www.eclipsezone.com/eclipse/forums/t97608.rhtml
I ended up extending XMLMultiPageEditorPart like this:
public class MultiPageEditor extends XMLMultiPageEditorPart implements
IResourceChangeListener {
#Override
public void resourceChanged(IResourceChangeEvent event) {
// TODO Auto-generated method stub
setActivePage(3);
}
public Document getDOM() {
int activePageIndex = getActivePage();
setActivePage(1);
StructuredTextEditor fTextEditor = (StructuredTextEditor) getSelectedPage();
IDocument document = fTextEditor.getDocumentProvider().getDocument(
fTextEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager()
.getExistingModelForRead(document);
Document modelDocument = null;
try {
if (model instanceof IDOMModel) {
// cast the structured model to a DOM Model
modelDocument = (Document) (((IDOMModel) model).getDocument());
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
setActivePage(activePageIndex);
return modelDocument;
}
}
This is not a clean implementation, but it gets the job done.