diff --git a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/SARLClasspathContainer.java b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/SARLClasspathContainer.java index e70bc344ec..89c1f6c3f0 100644 --- a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/SARLClasspathContainer.java +++ b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/SARLClasspathContainer.java @@ -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; @@ -73,11 +76,24 @@ 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 getBundleDependencies() { + final Set 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 newEntries = new ArrayList<>(); + updateEntries(newEntries); + this.entries = newEntries.toArray(new IClasspathEntry[newEntries.size()]); } catch (Exception e) { throw new RuntimeException(e); } @@ -85,48 +101,62 @@ public synchronized IClasspathEntry[] getClasspathEntries() { return this.entries; } - private void updateEntries() throws Exception { - final List 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 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; } diff --git a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/messages.properties b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/messages.properties index 8a905524c9..ed3d189998 100644 --- a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/messages.properties +++ b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/buildpath/messages.properties @@ -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 diff --git a/sre/io.janusproject/io.janusproject.plugin/META-INF/MANIFEST.MF b/sre/io.janusproject/io.janusproject.plugin/META-INF/MANIFEST.MF index 642918fe66..501e15fa05 100644 --- a/sre/io.janusproject/io.janusproject.plugin/META-INF/MANIFEST.MF +++ b/sre/io.janusproject/io.janusproject.plugin/META-INF/MANIFEST.MF @@ -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, diff --git a/sre/io.janusproject/io.janusproject.plugin/OSGI-INF/l10n/bundle.properties b/sre/io.janusproject/io.janusproject.plugin/OSGI-INF/l10n/bundle.properties index fc2fc260ec..5680eccb84 100644 --- a/sre/io.janusproject/io.janusproject.plugin/OSGI-INF/l10n/bundle.properties +++ b/sre/io.janusproject/io.janusproject.plugin/OSGI-INF/l10n/bundle.properties @@ -1,3 +1,4 @@ #Properties file for io.janusproject.plugin Bundle-Vendor = janusproject.io -Bundle-Name = Janusproject \ No newline at end of file +Bundle-Name = Janusproject +classpathContainerPage.name = Janus Libraries \ No newline at end of file diff --git a/sre/io.janusproject/io.janusproject.plugin/plugin.xml b/sre/io.janusproject/io.janusproject.plugin/plugin.xml index 0611e2c34d..bc7c9ee31c 100644 --- a/sre/io.janusproject/io.janusproject.plugin/plugin.xml +++ b/sre/io.janusproject/io.janusproject.plugin/plugin.xml @@ -4,8 +4,23 @@ + class="io.janusproject.eclipse.sre.JanusSREInstall"> + + + + + + + + + diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JANUSEclipsePlugin.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JANUSEclipsePlugin.java deleted file mode 100644 index b0409366cf..0000000000 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JANUSEclipsePlugin.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2016 the original authors or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.janusproject; - -import org.eclipse.ui.plugin.AbstractUIPlugin; - - - -/** - * The eclipse plugin providing the JANUS platform as default SRE. - * @author $Author: ngaud$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - * - */ -public class JANUSEclipsePlugin extends AbstractUIPlugin { - - /** Identifier of the plugin. - */ - public static final String PLUGIN_ID = "io.janusproject.plugin"; //$NON-NLS-1$ - - private static JANUSEclipsePlugin instance; - - /** Construct an Eclipse plugin for SARL. - */ - public JANUSEclipsePlugin() { - setDefault(this); - } - - /** Set the default instance of the plugin. - * - * @param defaultInstance - the default plugin instance. - */ - public static void setDefault(JANUSEclipsePlugin defaultInstance) { - instance = defaultInstance; - } - - /** Replies the instance of the plugin. - * - * @return the default plugin instance. - */ - public static JANUSEclipsePlugin getDefault() { - return instance; - } -} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall.properties b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall.properties deleted file mode 100644 index 74d19ef5f5..0000000000 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall.properties +++ /dev/null @@ -1 +0,0 @@ -PLUGIN_NAME = JANUS integrated SRE plugin \ No newline at end of file diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusEclipsePlugin.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusEclipsePlugin.java new file mode 100644 index 0000000000..310fd84ad0 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusEclipsePlugin.java @@ -0,0 +1,161 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2016 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.janusproject.eclipse; + +import com.google.common.base.Strings; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; + + + +/** + * The eclipse plugin providing the JANUS platform as default SRE. + * @author $Author: ngaud$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * + */ +public class JanusEclipsePlugin extends AbstractUIPlugin { + + /** Identifier of the plugin. + */ + public static final String PLUGIN_ID = "io.janusproject.plugin"; //$NON-NLS-1$ + + private static JanusEclipsePlugin instance; + + /** Construct an Eclipse plugin for SARL. + */ + public JanusEclipsePlugin() { + setDefault(this); + } + + /** Set the default instance of the plugin. + * + * @param defaultInstance - the default plugin instance. + */ + public static void setDefault(JanusEclipsePlugin defaultInstance) { + instance = defaultInstance; + } + + /** Replies the instance of the plugin. + * + * @return the default plugin instance. + */ + public static JanusEclipsePlugin getDefault() { + return instance; + } + + /** Create a status. + * + * @param severity - the severity level, see {@link IStatus}. + * @param message - the message associated to the status. + * @param cause - the cause of the problem. + * @return the status. + */ + @SuppressWarnings("static-method") + public IStatus createStatus(int severity, String message, Throwable cause) { + return new Status(severity, PLUGIN_ID, message, cause); + } + + /** Create a status. + * + * @param severity - the severity level, see {@link IStatus}. + * @param code - the code of the error. + * @param message - the message associated to the status. + * @param cause - the cause of the problem. + * @return the status. + */ + @SuppressWarnings("static-method") + public IStatus createStatus(int severity, int code, String message, Throwable cause) { + return new Status(severity, PLUGIN_ID, code, message, cause); + } + + /** Create a status. + * + * @param severity - the severity level, see {@link IStatus}. + * @param cause - the cause of the problem. + * @return the status. + */ + public IStatus createStatus(int severity, Throwable cause) { + String message = cause.getLocalizedMessage(); + if (Strings.isNullOrEmpty(message)) { + message = cause.getMessage(); + } + if (Strings.isNullOrEmpty(message)) { + message = cause.getClass().getSimpleName(); + } + return createStatus(severity, message, cause); + } + + /** Create a status. + * + * @param severity - the severity level, see {@link IStatus}. + * @param code - the code of the error. + * @param cause - the cause of the problem. + * @return the status. + */ + public IStatus createStatus(int severity, int code, Throwable cause) { + String message = cause.getLocalizedMessage(); + if (Strings.isNullOrEmpty(message)) { + message = cause.getMessage(); + } + if (Strings.isNullOrEmpty(message)) { + message = cause.getClass().getSimpleName(); + } + return createStatus(severity, code, message, cause); + } + + /** Create a status. + * + * @param severity - the severity level, see {@link IStatus}. + * @param message - the message associated to the status. + * @return the status. + */ + @SuppressWarnings("static-method") + public IStatus createStatus(int severity, String message) { + return new Status(severity, PLUGIN_ID, message); + } + + /** Create a status. + * + * @param severity - the severity level, see {@link IStatus}. + * @param code - the code of the error. + * @param message - the message associated to the status. + * @return the status. + */ + @SuppressWarnings("static-method") + public IStatus createStatus(int severity, int code, String message) { + return new Status(severity, PLUGIN_ID, code, message, null); + } + + /** Create a ok status. + * + * @return the status. + */ + @SuppressWarnings("static-method") + public IStatus createOkStatus() { + return Status.OK_STATUS; + } + +} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusSREInstall.properties b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusSREInstall.properties new file mode 100644 index 0000000000..2bdd4675e2 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusSREInstall.properties @@ -0,0 +1 @@ +PLUGIN_NAME = Janus integrated SRE plugin \ No newline at end of file diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall_fr.properties b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusSREInstall_fr.properties similarity index 100% rename from sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall_fr.properties rename to sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/JanusSREInstall_fr.properties diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusClasspathContainer.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusClasspathContainer.java new file mode 100644 index 0000000000..052322bab8 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusClasspathContainer.java @@ -0,0 +1,85 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2016 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.janusproject.eclipse.buildpath; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IClasspathEntry; + +import io.sarl.eclipse.buildpath.SARLClasspathContainer; + +/** Classpath container dedicated to the Janus platform. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +public class JanusClasspathContainer extends SARLClasspathContainer { + + /** Names of the reference libraries that are required to compile the Janus + * code and the generated Java code. + */ + public static final String[] JANUS_REFERENCE_LIBRARIES = { + "org.arakhne.afc.core.vmutils", //$NON-NLS-1$ + "org.arakhne.afc.core.util", //$NON-NLS-1$ + "com.hazelcast", //$NON-NLS-1$ + "com.google.gson", //$NON-NLS-1$ + "org.zeromq.jeromq", //$NON-NLS-1$ + "com.google.inject", //$NON-NLS-1$ + "org.apache.commons.cli", //$NON-NLS-1$ + }; + + /** Constructor. + * + * @param containerPath - the path of the container, e.g. the project. + */ + public JanusClasspathContainer(IPath containerPath) { + super(containerPath); + } + + @Override + public Set getBundleDependencies() { + final Set deps = super.getBundleDependencies(); + deps.addAll(Arrays.asList(JANUS_REFERENCE_LIBRARIES)); + return deps; + } + + @Override + protected void updateEntries(List entries) throws Exception { + // Add the SARL dependencies. + super.updateEntries(entries); + // Add the Janus dependencies. + for (final String referenceLibrary : JANUS_REFERENCE_LIBRARIES) { + entries.add(newLibrary(referenceLibrary)); + } + } + + @Override + public String getDescription() { + return Messages.JanusClasspathContainer_0; + } + +} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusClasspathContainerInitializer.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusClasspathContainerInitializer.java new file mode 100644 index 0000000000..016d5fa9ae --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusClasspathContainerInitializer.java @@ -0,0 +1,94 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2016 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.janusproject.eclipse.buildpath; + +import io.janusproject.eclipse.JanusEclipsePlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.ClasspathContainerInitializer; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; + +/** Initializer of the classpath container dedicated to the Janus platform. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +public class JanusClasspathContainerInitializer extends ClasspathContainerInitializer { + + /** Identifier of the container. + */ + public static final IPath CONTAINER_ID = new Path(JanusEclipsePlugin.PLUGIN_ID + ".launching.JANUS_SUPPORT"); //$NON-NLS-1$ + + @Override + public void initialize(IPath containerPath, IJavaProject project) + throws CoreException { + if (CONTAINER_ID.equals(containerPath)) { + final IClasspathContainer container = new JanusClasspathContainer(containerPath); + JavaCore.setClasspathContainer(containerPath, + new IJavaProject[] {project}, + new IClasspathContainer[] {container}, + null); + } + } + + @Override + public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { + // always ok to return classpath container + return true; + } + + @Override + public void requestClasspathContainerUpdate( + final IPath containerPath, + final IJavaProject javaProject, + final IClasspathContainer containerSuggestion) throws CoreException { + if (containerSuggestion instanceof JanusClasspathContainer) { + ((JanusClasspathContainer) containerSuggestion).reset(); + } + super.requestClasspathContainerUpdate(containerPath, javaProject, containerSuggestion); + final Job job = new Job(Messages.JanusClasspathContainerInitializer_0) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + JavaCore.setClasspathContainer( + containerPath, + new IJavaProject[] {javaProject}, + new IClasspathContainer[] {containerSuggestion}, + monitor); + } catch (CoreException ex) { + return JanusEclipsePlugin.getDefault().createStatus(IStatus.ERROR, ex); + } + return JanusEclipsePlugin.getDefault().createOkStatus(); + } + }; + job.schedule(); + } + +} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusContainerWizardPage.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusContainerWizardPage.java new file mode 100644 index 0000000000..d30b3f5a5b --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/JanusContainerWizardPage.java @@ -0,0 +1,94 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2016 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.janusproject.eclipse.buildpath; + +import java.text.MessageFormat; + +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.ui.JavaPluginImages; +import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; +import org.eclipse.jdt.ui.wizards.NewElementWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import io.sarl.eclipse.buildpath.SARLClasspathContainer; + +/** Wizard page that permits to add the Janus libraries into a project. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +public class JanusContainerWizardPage extends NewElementWizardPage implements IClasspathContainerPage { + + private IClasspathEntry containerEntry; + + /** Construct a wizard page for defining the SARL library container. + */ + public JanusContainerWizardPage() { + super("JanusClassPathContainer"); //$NON-NLS-1$ + setTitle(Messages.JanusClasspathContainer_0); + setImageDescriptor(JavaPluginImages.DESC_WIZBAN_ADD_LIBRARY); + setDescription(Messages.JanusContainerWizardPage_0); + this.containerEntry = JavaCore.newContainerEntry( + JanusClasspathContainerInitializer.CONTAINER_ID); + } + + @Override + public void createControl(Composite parent) { + final Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new FillLayout()); + final Label label = new Label(composite, SWT.NONE); + final StringBuilder builder = new StringBuilder(); + for (final String bundleId : SARLClasspathContainer.SARL_REFERENCE_LIBRARIES) { + builder.append("\t").append(bundleId).append("\n"); //$NON-NLS-1$//$NON-NLS-2$ + } + for (final String bundleId : JanusClasspathContainer.JANUS_REFERENCE_LIBRARIES) { + builder.append("\t").append(bundleId).append("\n"); //$NON-NLS-1$//$NON-NLS-2$ + } + label.setText(MessageFormat.format( + Messages.JanusContainerWizardPage_1, + builder.toString())); + setControl(composite); + } + + @Override + public boolean finish() { + return true; + } + + @Override + public IClasspathEntry getSelection() { + return this.containerEntry; + + } + + @Override + public void setSelection(IClasspathEntry containerEntry) { + //do nothing + } + +} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/Messages.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/Messages.java new file mode 100644 index 0000000000..b6e316a8ef --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/Messages.java @@ -0,0 +1,47 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2016 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.janusproject.eclipse.buildpath; + +import org.eclipse.osgi.util.NLS; + +/** Messages. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +@SuppressWarnings("all") +public class Messages extends NLS { + private static final String BUNDLE_NAME = "io.janusproject.eclipse.buildpath.messages"; //$NON-NLS-1$ + public static String JanusClasspathContainer_0; + public static String JanusClasspathContainerInitializer_0; + public static String JanusContainerWizardPage_0; + public static String JanusContainerWizardPage_1; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/messages.properties b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/messages.properties new file mode 100644 index 0000000000..efbc1713a6 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/buildpath/messages.properties @@ -0,0 +1,4 @@ +JanusClasspathContainer_0=Janus Libraries +JanusClasspathContainerInitializer_0=Classpath container update +JanusContainerWizardPage_0=This read-only container manages the Janus dependencies. +JanusContainerWizardPage_1=This library provides all required and convenient dependencies for SARL projects with the Janus platform.\n\nContainer includes:\n{0} diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/sre/JanusSREInstall.java similarity index 95% rename from sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall.java rename to sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/sre/JanusSREInstall.java index b4ff0ac769..b234ebba2f 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JanusSREInstall.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/sre/JanusSREInstall.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package io.janusproject; +package io.janusproject.eclipse.sre; import java.io.File; import java.io.IOException; @@ -27,17 +27,17 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import com.google.common.collect.Maps; +import io.janusproject.eclipse.JanusEclipsePlugin; +import io.janusproject.eclipse.buildpath.JanusClasspathContainer; import org.arakhne.afc.vmutil.locale.Locale; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; @@ -72,7 +72,6 @@ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ -@SuppressWarnings("restriction") public class JanusSREInstall extends AbstractSREInstall { /** @@ -86,17 +85,10 @@ public class JanusSREInstall extends AbstractSREInstall { private static final String DOT_JAR_EXTENSION = "." + JAR_EXTENSION; //$NON-NLS-1$ - /** - * The set of dependencies of the Janus plugin that really useful the runtime configuration This a manual configuration that must be update each - * time you change the dependency FIXME Update this array if you change the dependency of the Janus plugin and if this dependency is required at - * runtime by the launch configuration. - */ - private static final Set RUNTIME_REQUIRED_DEPDENCIES = new HashSet<>(Arrays.asList("io.sarl.core", //$NON-NLS-1$ - "io.sarl.util", "org.arakhne.afc.core.vmutils", "com.hazelcast", "com.google.gson", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "com.google.inject", "org.zeromq.jeromq", "org.apache.commons.cli")); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - private static final String DEFAULT_PATH_TO_CLASSES_IN_MAVEN_PROJECT = "target/classes"; //$NON-NLS-1$ + private static Set janusBundleDependencies; + /** * The path where this SRE plugin jar is effectively installed. */ @@ -123,7 +115,7 @@ public int compare(Bundle o1, Bundle o2) { */ public JanusSREInstall() { super(JANUS_SRE_ID); - final Bundle bundle = Platform.getBundle(JANUSEclipsePlugin.PLUGIN_ID); + final Bundle bundle = Platform.getBundle(JanusEclipsePlugin.PLUGIN_ID); final IPath bundlePath = BundleUtil.getBundlePath(bundle); if (bundlePath.toFile().isDirectory()) { // we have a directory, we assume we are in debug mode of the @@ -179,6 +171,14 @@ public JanusSREInstall() { this.setClassPathEntries(new ArrayList<>(classpathEntries)); } + private static Set getJanusBundleDependencies() { + if (janusBundleDependencies == null) { + final JanusClasspathContainer container = new JanusClasspathContainer(null); + janusBundleDependencies = container.getBundleDependencies(); + } + return janusBundleDependencies; + } + /** * Recrusive function to get all the required runtime dependencies of this SRE plugin and adding the corresponding elements to the * {@code classpathEntries} collection. @@ -207,7 +207,7 @@ private void getAllBundleDependencies(Bundle bundle, boolean firstcall) { || dependency.getVersion().compareTo(existingDependencyCPE.getKey()) > 0) { if (firstcall) { // First level of dependencies that are filtered according to runtimeNecessaryDependencies - if (RUNTIME_REQUIRED_DEPDENCIES.contains(dependency.getSymbolicName())) { + if (getJanusBundleDependencies().contains(dependency.getSymbolicName())) { URL u = null; try { u = FileLocator.resolve(dependency.getEntry(ROOT_NAME)); diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JavaClasspathParser.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/sre/JavaClasspathParser.java similarity index 99% rename from sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JavaClasspathParser.java rename to sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/sre/JavaClasspathParser.java index 94328b5c18..a2f0c3f00b 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/JavaClasspathParser.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/eclipse/sre/JavaClasspathParser.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package io.janusproject; +package io.janusproject.eclipse.sre; import java.io.ByteArrayOutputStream; import java.io.File; @@ -75,7 +75,7 @@ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ -@SuppressWarnings({ "checkstyle:classdataabstractioncoupling", "restriction" }) +@SuppressWarnings("checkstyle:classdataabstractioncoupling") public final class JavaClasspathParser { /**