Skip to content

Commit

Permalink
Fixed #522 Removal of jdt dependency from org.obeonetwork.m2doc.ide.ui.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Aug 26, 2024
1 parent 503d1ab commit 20a8c5e
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 77 deletions.
7 changes: 6 additions & 1 deletion plugins/org.obeonetwork.m2doc.ide.jdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
org.obeonetwork.m2doc;bundle-version="[3.0.0,4.0.0)",
org.obeonetwork.m2doc.ide;bundle-version="[3.0.0,4.0.0)",
org.obeonetwork.m2doc.ide.ui;bundle-version="[3.0.0,4.0.0)",
org.eclipse.jdt.core,
org.eclipse.jdt.launching
org.eclipse.jdt.launching,
org.eclipse.jdt.ui,
org.eclipse.ui.workbench,
org.eclipse.swt,
org.eclipse.jface
Export-Package: org.obeonetwork.m2doc.ide.jdt,
org.obeonetwork.m2doc.ide.jdt.util
Bundle-ActivationPolicy: lazy
Expand Down
6 changes: 6 additions & 0 deletions plugins/org.obeonetwork.m2doc.ide.jdt/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
class="org.obeonetwork.m2doc.ide.jdt.util.EclipseJDTClassProvider">
</classprovider>
</extension>
<extension
point="org.obeonetwork.m2doc.ide.ui.classpropertyupdater">
<classpropertyupdater
class="org.obeonetwork.m2doc.ide.jdt.util.ClassPropertyUpdater">
</classpropertyupdater>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Obeo - initial API and implementation
*
*******************************************************************************/
package org.obeonetwork.m2doc.ide.jdt.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.obeonetwork.m2doc.ide.ui.util.IClassPropertyUpdater;
import org.obeonetwork.m2doc.properties.TemplateCustomProperties;
import org.osgi.framework.Bundle;

/**
* Updates imported classes for the given {@link TemplateCustomProperties} using the JDT.
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
public class ClassPropertyUpdater implements IClassPropertyUpdater {

@Override
public boolean updatePropertyClasses(TemplateCustomProperties customProperties) {
final boolean res;

final IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
final FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
Display.getCurrent().getActiveShell(), true, PlatformUI.getWorkbench().getProgressService(), scope,
IJavaSearchConstants.CLASS);
if (dialog.open() == Dialog.OK && dialog.getResult() != null && dialog.getResult().length != 0) {
for (Object object : dialog.getResult()) {
IPath parentPath = ((IType) object).getParent().getPath();
if (parentPath.getFileExtension().equals("jar")) {
int indexOfUnderscore = parentPath.lastSegment().indexOf('_');
if (indexOfUnderscore > -1) {
final String pluginName = parentPath.lastSegment().substring(0, indexOfUnderscore);
customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(), pluginName);
} else {
customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(), "");
}
} else {
final String bundleName = getBundleName((IType) object);
if (bundleName != null) {
customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(), bundleName);
} else {
customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(),
((IType) object).getJavaProject().getProject().getName());
}
}
}
res = true;
} else {
res = false;
}

return res;
}

/**
* Gets the bundle name of the given {@link IType}.
*
* @param type
* the {@link IType}
* @return the bundle name of the given {@link IType} if any, <code>null</code> otherwise
*/
private String getBundleName(IType type) {
final String packageName = type.getParent().getParent().getElementName();
final List<String> segments = new ArrayList<>(Arrays.asList(packageName.split("\\.")));
while (!segments.isEmpty()) {
String bundleName = String.join(".", segments);
final Bundle bundle = Platform.getBundle(bundleName);
if (bundle != null) {
return bundle.getSymbolicName();
}
segments.remove(segments.size() - 1);
}

return null;
}
}
3 changes: 1 addition & 2 deletions plugins/org.obeonetwork.m2doc.ide.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Require-Bundle: org.eclipse.ui,
org.apache.poi;bundle-version="[5.2.3,5.2.4)",
org.obeonetwork.m2doc.ide;bundle-version="[3.0.0,4.0.0)",
org.eclipse.acceleo.query;bundle-version="[6.0.1,8.0.0)",
org.eclipse.jdt.ui,
org.eclipse.jdt.core,
org.eclipse.acceleo.annotations
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Expand All @@ -33,5 +31,6 @@ Export-Package: org.obeonetwork.m2doc.ide.ui,
org.obeonetwork.m2doc.ide.ui.propertyTester,
org.obeonetwork.m2doc.ide.ui.services,
org.obeonetwork.m2doc.ide.ui.services.configurator,
org.obeonetwork.m2doc.ide.ui.util,
org.obeonetwork.m2doc.ide.ui.wizard
Automatic-Module-Name: org.obeonetwork.m2doc.ide.ui
5 changes: 3 additions & 2 deletions plugins/org.obeonetwork.m2doc.ide.ui/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2016, 2020 Obeo.
# Copyright (c) 2016, 2024 Obeo.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
Expand All @@ -16,4 +16,5 @@ bin.includes = plugin.xml,\
.,\
plugin.properties,\
icons/,\
build.properties
build.properties,\
schema/
1 change: 1 addition & 0 deletions plugins/org.obeonetwork.m2doc.ide.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
-->

<plugin>
<extension-point id="org.obeonetwork.m2doc.ide.ui.classpropertyupdater" name="M2Doc class property updater" schema="schema/org.obeonetwork.m2doc.ide.ui.classpropertyupdater.exsd"/>

<extension
point="org.eclipse.core.expressions.propertyTesters">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.obeonetwork.m2doc.ide" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.obeonetwork.m2doc.ide.ui" id="org.obeonetwork.m2doc.ide.ui.classpropertyupdater" name="M2Doc class property updater"/>
</appinfo>
<documentation>
Register an IClassPropertiesUpdater to update service classes in custom properties.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="classpropertyupdater"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="classpropertyupdater">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="org.obeonetwork.m2doc.ide.ui.util.IClassPropertyUpdater:"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
3.3.3
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Obeo.
* Copyright (c) 2016, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -14,11 +14,16 @@
import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.obeonetwork.m2doc.ide.services.configurator.ServicesConfiguratorRegistryListener;
import org.obeonetwork.m2doc.ide.ui.util.ClassPropertyUpdaterRegistryListener;
import org.obeonetwork.m2doc.ide.ui.util.IClassPropertyUpdater;
import org.osgi.framework.BundleContext;

/**
Expand Down Expand Up @@ -46,35 +51,38 @@ public class Activator extends AbstractUIPlugin {
*/
private static Activator plugin;

/**
* The {@link ClassPropertyUpdaterRegistryListener}.
*/
private static final ClassPropertyUpdaterRegistryListener classPropertyUpdaterRegistryListener = new ClassPropertyUpdaterRegistryListener();

/**
* The registered {@link IClassPropertyUpdater}.
*/
private static IClassPropertyUpdater classPropertyUpdater;

/**
* The constructor.
*/
public Activator() {
}

/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.
* BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
final IExtensionRegistry registry = Platform.getExtensionRegistry();
registry.addListener(classPropertyUpdaterRegistryListener,
ServicesConfiguratorRegistryListener.SERVICES_CONFIGURATOR_EXTENSION_POINT);
classPropertyUpdaterRegistryListener.parseInitialContributions();
}

/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.
* BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);

final IExtensionRegistry registry = Platform.getExtensionRegistry();
registry.removeListener(classPropertyUpdaterRegistryListener);
}

/**
Expand Down Expand Up @@ -109,4 +117,23 @@ protected void initializeImageRegistry(ImageRegistry reg) {
getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e));
}
}

/**
* Gets the registered {@link IClassPropertyUpdater}.
*
* @return the registered {@link IClassPropertyUpdater}
*/
public static IClassPropertyUpdater getClassPropertyUpdater() {
return classPropertyUpdater;
}

/**
* Registers the given {@link IClassPropertyUpdater}.
*
* @param updater
* the {@link IClassPropertyUpdater} to update
*/
public static void registerClassPropertyUpdater(IClassPropertyUpdater updater) {
classPropertyUpdater = updater;
}
}
Loading

0 comments on commit 20a8c5e

Please sign in to comment.