How to find orphan plugins in eclipse RCPs? - eclipse

Update sites with RCPs prohibits orphan plugins, otherwise plugins that are not in a feature.
If this condition is not filled, the update manager returns the following error:
Resulting configuration does not contain the platform.
Unfortunately, no way to determine which plugins are orphan.
How to find orphan plugins ?

Here's a starting point (this applies for Eclipse 3.4 and later, when the P2 repository was introduced, earlier versions store their configuration differently. IIRC you could see all the plugins and features in platform.xml).
Create a new plugin project (New->Other->Plug-in Development->Plug-in Project) with the "Hello World" template then drop this code into the run method of the SampleAction.
Run the plugin as a test Eclipse Application and select Sample Menu->Sample Action, the plugins that don't belong to a feature will be output to the parent workspace's console. When I ran this there were quite a few more than I expected, I've had a few looks through and can't spot the logic error.
Edit, found logic error, was using the wrong array index used in innermost loop. Still not quite right though.
Edit 2. (Facepalm moment) Found the problem. Be sure to run the target workspace with all workspace and enabled target plugins enabled, or it will skew your results, obviously. If you install the plugin and dress it up a little bit you won't have this problem.
//get all the plugins that belong to features
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
Map<Long, IBundleGroup> bundlesMap = new HashMap<Long, IBundleGroup>();
if (providers != null) {
for (int i = 0; i < providers.length; i++) {
IBundleGroup[] bundleGroups = providers[i].getBundleGroups();
System.out.println("Bundle groups:");
for (int j = 0; j < bundleGroups.length; j++) {
Bundle[] bundles = bundleGroups[j] == null ? new Bundle[0] : bundleGroups[j]
.getBundles();
System.out.println(bundleGroups[j].getIdentifier());
for (int k = 0; k < bundles.length; k++) {
bundlesMap.put(bundles[k].getBundleId(), bundleGroups[j]);
}
}
}
}
BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
if(bundleContext instanceof BundleContextImpl) {
Bundle[] bundles = ((BundleContextImpl)bundleContext).getBundles();
System.out.println("Orphan Bundles:");
for (int i = 0; i < bundles.length; i++) {
if(!bundlesMap.containsKey(bundles[i].getBundleId())) {
System.out.println(bundles[i].getSymbolicName());
}
}
}

Related

Eclipse stops running

Whenever I try to use decrement in wrong way Eclipse stops working. Seems it started to happen after I installed Lombok. The code is shown below:
public class Patterns {
public static void main(String[] args) {
pattern31(5);
}
static void pattern31(int n) {
n = 5;
for (int row = 1 ; row <= n; row++) {
int columns = row>n ? 2*n-row:row;
int space=n-columns;
int p='A';
for(int s=0; s<=space; s++) {
System.out.print(" ");
}
for(int col=1; col<columns; col++) {
System.out.print((char) p++ +" ");
}
for(int col=2; col<=columns; col--) {
System.out.print((char) p++ +" ");
}
System.out.println();
}
}
}
I also have this message in the log:
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'C:\Users\User'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.

Accessing chosen items

I created a jQuery chosen element.
Now I wanna step through all items and check for duplicates before adding new options.
With selects element it was quite easy.
found = false;
for (j = 0; j < list1.options.length; j++)
{
if (txtValue == list1.options[j].value)
{
found=true;
j = list1.options.length;
}
}
I have no idea how I can step through the existing option list.
Can someone provide me an example?
It would also be helpful when someone can provide me an example how I can retrieve the selected options of the chosen element

Unity script runs in editor but fails to build

I am using Unity 2019.2.10f1 and have encountered a weird bug when trying to build the game. Error message I get is:
error CS0246: The type or namespace name 'StaticEditorFlags' could not be found (are you missing a using directive or an assembly reference?)
I tried to reimport all, and I definitely have UnityEditor use directive for that script.
The following code is used to mark objects as static for optimization purposes and is only executed from the Editor:
private StaticEditorFlags staticFlags = StaticEditorFlags.ContributeGI | StaticEditorFlags.OccluderStatic | StaticEditorFlags.BatchingStatic | StaticEditorFlags.NavigationStatic | StaticEditorFlags.OffMeshLinkGeneration | StaticEditorFlags.ReflectionProbeStatic;
public void StaticLock()
{
lockChanges = true;
Transform renderRoot = transform.Find("Renders");
Transform collidersRoot = transform.Find("Colliders");
if (renderRoot != null)
{
int count = renderRoot.childCount;
for (int i = 0; i < count; i++)
GameObjectUtility.SetStaticEditorFlags(renderRoot.GetChild(i).gameObject, staticFlags);
}
if (collidersRoot != null)
{
int count = collidersRoot.childCount;
for (int i = 0; i < count; i++)
GameObjectUtility.SetStaticEditorFlags(collidersRoot.GetChild(i).gameObject, staticFlags);
}
}
First, UnityEditor libraries are not included in the builds, so you should get that error.
But in order to not include that script to builds you should put that script in a folder called Editor, so Unity will automatically remove scripts inside that folder from builds.
You can create Editor folders everywhere. everything inside will be ignored.

Project Browser not updating with Package Deletion Script

The following method deletes a package. The problem is that the Project Browser is never refreshed. Calling Repository.RefreshModelView(0) forces the update, but it reopens the model and kills script execution.
Here is the method:
function clearPackage( pkg ) {
var parent as EA.Package;
parent = Repository.GetPackageByID(pkg.ParentID);
var pkgList as EA.Collection;
pkgList = parent.Packages;
for (var i = 0; i < pkgList.Count; i++) {
var p as EA.Package;
p = pkgList.GetAt(i);
if (p.PackageGUID == pkg.PackageGUID) {
pkgList.Delete(i);
pkgList.Refresh();
parent.Update(); // have tried with and without
return;
}
}
}
Inspecting pkgList.Count before and after pkgList.Refresh does show a change in size. Again, the problem seems limited to the Project Browser.
Any ideas on how to refresh the Project Browser?
Cross posted on Sparx Forums.
To delete a package you just need to delete the package itself. Sorry for the Perl, but thats my donkey :-)
my $p = $rep->GetTreeSelectedObject();
my $par = $rep->GetPackageByID ($p->ParentID);
my $idx = 0;
for my $sp (in $par->Packages) {
if ($sp->PackageID == $p->PackageID) {
$par->Packages->DeleteAt ($idx, 1);
last;
}
$idx++;
}
$rep->RefreshModelView ($par->PackageID);
Try
Repository.RefreshModelView(parent.PackageID);
That will refresh only the contents of the parent package, not the whole model.

How to change the order of entries in "order and export tab" of eclipse java build path programmatically?

I need to change the order of two jar files in java build path of eclipse.
There is some operation on which the junit3.jar will be set before junit4.jar, but I am not able to find any clue.
You can obtain the raw classpath for the project, then find each Junit entry based on its kind and path, if they're in the "wrong order", you can then modify the raw classpath and set the modified path on to the project.
The snippet below outlines how it can be done, note there's no exception handling in this example:
//get the project by name, you probably want to use another method to
//obtain it
IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("foo");
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] entries = javaProject.getRawClasspath();
// find the JUnit 3 and Junit 4 entry index
int junit3Index = -1;
int junit4Index = -1;
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
if (entries[i].getPath().equals(
JUnitContainerInitializer.JUNIT3_PATH)) {
junit3Index = i;
} else if (entries[i].getPath().equals(
JUnitContainerInitializer.JUNIT4_PATH)) {
junit4Index = i;
}
}
}
if (junit3Index != -1 && junit4Index != -1
&& junit3Index > junit4Index) {
// swap the two entries
IClasspathEntry temp = entries[junit4Index];
entries[junit4Index] = entries[junit3Index];
entries[junit3Index] = temp;
//update the project with the modified path
javaProject.setRawClasspath(entries, new NullProgressMonitor());
}