-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #522 Removal of jdt dependency from org.obeonetwork.m2doc.ide.ui.
- Loading branch information
Showing
11 changed files
with
424 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...beonetwork.m2doc.ide.jdt/src/org/obeonetwork/m2doc/ide/jdt/util/ClassPropertyUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...rg.obeonetwork.m2doc.ide.ui/schema/org.obeonetwork.m2doc.ide.ui.classpropertyupdater.exsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.