Skip to content

Commit

Permalink
[sre] Add the Janus classpath library.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 9, 2016
1 parent da833bb commit 082c8ba
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 123 deletions.
Expand Up @@ -22,7 +22,10 @@
package io.sarl.eclipse.buildpath;

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

import javax.naming.NameNotFoundException;

Expand Down Expand Up @@ -73,60 +76,87 @@ public SARLClasspathContainer(IPath containerPath) {
this.containerPath = containerPath;
}

/** Replies the list of the symbolic names of the bundle dependencies.
*
* @return the bundle symbolic names of the dependencies.
*/
@SuppressWarnings("static-method")
public Set<String> getBundleDependencies() {
final Set<String> deps = new HashSet<>();
deps.addAll(Arrays.asList(SARL_REFERENCE_LIBRARIES));
return deps;
}

@Override
public synchronized IClasspathEntry[] getClasspathEntries() {
if (this.entries == null) {
try {
updateEntries();
final List<IClasspathEntry> newEntries = new ArrayList<>();
updateEntries(newEntries);
this.entries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return this.entries;
}

private void updateEntries() throws Exception {
final List<IClasspathEntry> newEntries = new ArrayList<>();
/** Compute the entries of the container.
*
* @param entries the list of entries to update..
* @throws Exception if something is going wrong.
*/
protected void updateEntries(List<IClasspathEntry> entries) throws Exception {
for (final String referenceLibrary : SARL_REFERENCE_LIBRARIES) {
// Retreive the bundle
final Bundle bundle = Platform.getBundle(referenceLibrary);
if (bundle == null) {
throw new NameNotFoundException("No bundle found for: " + referenceLibrary); //$NON-NLS-1$
}
entries.add(newLibrary(referenceLibrary));
}
}

final IPath bundlePath = BundleUtil.getBundlePath(bundle);
final IPath sourceBundlePath = BundleUtil.getSourceBundlePath(bundle, bundlePath);

IClasspathAttribute[] extraAttributes = null;
if (referenceLibrary.startsWith("io.sarl")) { //$NON-NLS-1$
final IPath javadocPath = BundleUtil.getJavadocBundlePath(bundle, bundlePath);
final IClasspathAttribute attr;
if (javadocPath == null) {
attr = JavaCore.newClasspathAttribute(
IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
JAVADOC_URL);
} else {
attr = JavaCore.newClasspathAttribute(
IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
javadocPath.makeAbsolute().toOSString());
}
extraAttributes = new IClasspathAttribute[] {attr};
}
/** Create the classpath library linked to the bundle with the given name.
*
* @param libraryName the bundle name.
* @return the classpath entry.
* @throws Exception if something is going wrong.
*/
@SuppressWarnings("static-method")
protected IClasspathEntry newLibrary(String libraryName) throws Exception {
// Retreive the bundle
final Bundle bundle = Platform.getBundle(libraryName);
if (bundle == null) {
throw new NameNotFoundException("No bundle found for: " + libraryName); //$NON-NLS-1$
}

newEntries.add(JavaCore.newLibraryEntry(
bundlePath,
sourceBundlePath,
null,
new IAccessRule[] {},
extraAttributes,
false));
final IPath bundlePath = BundleUtil.getBundlePath(bundle);
final IPath sourceBundlePath = BundleUtil.getSourceBundlePath(bundle, bundlePath);

IClasspathAttribute[] extraAttributes = null;
if (libraryName.startsWith("io.sarl")) { //$NON-NLS-1$
final IPath javadocPath = BundleUtil.getJavadocBundlePath(bundle, bundlePath);
final IClasspathAttribute attr;
if (javadocPath == null) {
attr = JavaCore.newClasspathAttribute(
IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
JAVADOC_URL);
} else {
attr = JavaCore.newClasspathAttribute(
IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
javadocPath.makeAbsolute().toOSString());
}
extraAttributes = new IClasspathAttribute[] {attr};
}
this.entries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);

return JavaCore.newLibraryEntry(
bundlePath,
sourceBundlePath,
null,
new IAccessRule[] {},
extraAttributes,
false);
}

/** Reset the container.
*/
synchronized void reset() {
public synchronized void reset() {
this.entries = null;
}

Expand Down
@@ -1,4 +1,4 @@
SARLClasspathContainer_0=SARL Libraries
SARLClasspathContainerInitializer_0=Classpath container update
SARLContainerWizardPage_0=This read-only container manages the SARL dependencies.
SARLContainerWizardPage_1=This library provides all required and convenient dependency for SARL projects.\n\nContainer includes:\n{0}\n
SARLContainerWizardPage_1=This library provides all required and convenient dependencies for SARL projects.\n\nContainer includes:\n{0}\n
10 changes: 8 additions & 2 deletions sre/io.janusproject/io.janusproject.plugin/META-INF/MANIFEST.MF
Expand Up @@ -17,11 +17,17 @@ Require-Bundle: io.sarl.core;bundle-version="0.4.0",
org.eclipse.jdt.launching;bundle-version="3.8.100",
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.ui.workbench;bundle-version="3.108.0",
org.eclipse.core.resources;bundle-version="3.11.0"
Bundle-Activator: io.janusproject.JANUSEclipsePlugin
org.eclipse.core.resources;bundle-version="3.11.0",
org.eclipse.jdt.ui;bundle-version="3.12.0",
org.eclipse.swt;bundle-version="3.105.0",
org.eclipse.jface;bundle-version="3.12.0"
Bundle-Activator: io.janusproject.eclipse.JanusEclipsePlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Export-Package: io.janusproject,
io.janusproject.eclipse,
io.janusproject.eclipse.buildpath,
io.janusproject.eclipse.sre,
io.janusproject.kernel,
io.janusproject.kernel.annotations,
io.janusproject.kernel.bic,
Expand Down
@@ -1,3 +1,4 @@
#Properties file for io.janusproject.plugin
Bundle-Vendor = janusproject.io
Bundle-Name = Janusproject
Bundle-Name = Janusproject
classpathContainerPage.name = Janus Libraries
17 changes: 16 additions & 1 deletion sre/io.janusproject/io.janusproject.plugin/plugin.xml
Expand Up @@ -4,8 +4,23 @@
<extension
point="io.sarl.eclipse.sreInstallations">
<sreInstallation
class="io.janusproject.JanusSREInstall">
class="io.janusproject.eclipse.sre.JanusSREInstall">
</sreInstallation>
</extension>

<extension point="org.eclipse.jdt.core.classpathContainerInitializer">
<classpathContainerInitializer
id="io.janusproject.plugin.launching.JANUS_SUPPORT"
class="io.janusproject.eclipse.buildpath.JanusClasspathContainerInitializer"/>
</extension>

<extension
point="org.eclipse.jdt.ui.classpathContainerPage">
<classpathContainerPage
name="%classpathContainerPage.name"
class="io.janusproject.eclipse.buildpath.JanusContainerWizardPage"
id="io.janusproject.plugin.launching.JANUS_SUPPORT">
</classpathContainerPage>
</extension>

</plugin>

This file was deleted.

This file was deleted.

0 comments on commit 082c8ba

Please sign in to comment.