Skip to content

Commit

Permalink
[eclipse] Add the "is standalone SRE" flag in the SREInstall.
Browse files Browse the repository at this point in the history
see #233

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 26, 2014
1 parent b93867a commit dc87222
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 55 deletions.
2 changes: 2 additions & 0 deletions checkstyle/suppressions.xml
Expand Up @@ -47,6 +47,8 @@
<suppress checks="MethodLength" files="SREsPreferencePage.java"/>
<suppress checks="MethodCount" files="SREsPreferencePage.java"/>

<suppress checks="NPathComplexity" files="AbstractSREInstall.java"/>

<suppress checks="CyclomaticComplexity" files="StandardSREInstall.java"/>
<suppress checks="NPathComplexity" files="StandardSREInstall.java"/>
<suppress checks="MethodLength" files="StandardSREInstall.java"/>
Expand Down
Expand Up @@ -55,6 +55,7 @@ public abstract class AbstractSREInstall implements ISREInstall {
private String minimalSarlVersion;
private String maximalSarlVersion;
private String mainClass;
private boolean isStandalone;
private LibraryLocation[] libraryLocations;
private Map<String, String> attributeMap;
private boolean dirty = true;
Expand Down Expand Up @@ -155,15 +156,20 @@ public IStatus getValidity() {
}
IStatus s = null;
try {
s = getMainClassValidity();
if (!isStandalone()) {
return SARLEclipsePlugin.createStatus(IStatus.ERROR, CODE_STANDALONE_SRE, Messages.AbstractSREInstall_5);
}
String mainClass = getMainClass();
if (Strings.isNullOrEmpty(mainClass)) {
return SARLEclipsePlugin.createStatus(IStatus.ERROR, CODE_MAIN_CLASS, Messages.AbstractSREInstall_2);
}
String name = getName();
if (Strings.isNullOrEmpty(name)) {
return SARLEclipsePlugin.createStatus(IStatus.ERROR, CODE_NAME, Messages.AbstractSREInstall_3);
}
s = getLibraryLocationValidity();
if (s == null) {
s = getNameValidity();
if (s == null) {
s = getLibraryLocationValidity();
if (s == null) {
s = getSARLVersionValidity();
}
}
s = getSARLVersionValidity();
}
} catch (Throwable e) {
//
Expand All @@ -174,22 +180,6 @@ public IStatus getValidity() {
return s;
}

private IStatus getMainClassValidity() {
String mainClass = getMainClass();
if (Strings.isNullOrEmpty(mainClass)) {
return SARLEclipsePlugin.createStatus(IStatus.ERROR, CODE_MAIN_CLASS, Messages.AbstractSREInstall_2);
}
return null;
}

private IStatus getNameValidity() {
String name = getName();
if (Strings.isNullOrEmpty(name)) {
return SARLEclipsePlugin.createStatus(IStatus.ERROR, CODE_NAME, Messages.AbstractSREInstall_3);
}
return null;
}

private IStatus getLibraryLocationValidity() {
LibraryLocation[] locations = getLibraryLocations();
if (locations == null || locations.length == 0) {
Expand All @@ -209,16 +199,16 @@ private IStatus getSARLVersionValidity() {
return SARLEclipsePlugin.createStatus(IStatus.ERROR,
CODE_SARL_VERSION,
MessageFormat.format(
Messages.AbstractSREInstall_0,
sarlVersion.toString(),
minVersion.toString()));
Messages.AbstractSREInstall_0,
sarlVersion.toString(),
minVersion.toString()));
} else if (cmp > 0) {
return SARLEclipsePlugin.createStatus(IStatus.ERROR,
CODE_SARL_VERSION,
MessageFormat.format(
Messages.AbstractSREInstall_1,
sarlVersion.toString(),
maxVersion.toString()));
Messages.AbstractSREInstall_1,
sarlVersion.toString(),
maxVersion.toString()));
}
}
return null;
Expand Down Expand Up @@ -437,4 +427,33 @@ public void setMainClass(String mainClass) {
}
}

/** {@inheritDoc}
*/
@Override
public void setStandalone(boolean isStandalone) {
if (isDirty()) {
setDirty(false);
resolveDirtyFields(true);
}
if (isStandalone != this.isStandalone) {
PropertyChangeEvent event = new PropertyChangeEvent(
this, ISREInstallChangedListener.PROPERTY_STANDALONE_SRE, this.isStandalone, isStandalone);
this.isStandalone = isStandalone;
if (this.notify) {
SARLRuntime.fireSREChanged(event);
}
}
}

/** {@inheritDoc}
*/
@Override
public boolean isStandalone() {
if (isDirty()) {
setDirty(false);
resolveDirtyFields(true);
}
return this.isStandalone;
}

}
Expand Up @@ -69,6 +69,10 @@ public interface ISREInstall extends Cloneable {
*/
int CODE_SOURCE = 6;

/** Error code related to the standalone SRE.
*/
int CODE_STANDALONE_SRE = 7;

/** Clone this SRE.
* The clone has the same Id as the cloned object.
*
Expand Down Expand Up @@ -276,4 +280,22 @@ public interface ISREInstall extends Cloneable {
*/
boolean getNotify();

/** Replies if this SRE is a standalone SRE.
* A standalone SRE contains all the Java dependencies needed for
* running the SRE.
*
* @return <code>true</code> if the SRE Install corresponds to a
* standalone SRE; otherwise <code>false</code>.
*/
boolean isStandalone();

/** Set if this SRE is a standalone SRE.
* A standalone SRE contains all the Java dependencies needed for
* running the SRE.
*
* @param isStandalone - flag that is <code>true</code> if the SRE Install corresponds to a
* standalone SRE; otherwise <code>false</code>.
*/
void setStandalone(boolean isStandalone);

}
Expand Up @@ -89,6 +89,12 @@ public interface ISREInstallChangedListener extends EventListener {
String PROPERTY_PROGRAM_ARGUMENTS = SARLEclipsePlugin.PLUGIN_ID
+ ".PROPERTY_PROGRAM_ARGUMENTS"; //$NON-NLS-1$

/**
* Property constant indicating if a SRE is standalone.
*/
String PROPERTY_STANDALONE_SRE = SARLEclipsePlugin.PLUGIN_ID
+ ".STANDALONE_SRE"; //$NON-NLS-1$

/**
* Notification that the workspace default SRE install
* has changed.
Expand Down
Expand Up @@ -38,10 +38,13 @@ public class Messages extends NLS {
public static String AbstractSREInstall_2;
public static String AbstractSREInstall_3;
public static String AbstractSREInstall_4;
public static String AbstractSREInstall_5;
public static String StandardSREInstall_0;
public static String StandardSREInstall_1;
public static String StandardSREInstall_2;
public static String StandardSREInstall_3;
public static String StandardSREInstall_4;
public static String StandardSREInstall_5;
public static String SREConfigurationBlock_0;
public static String SREConfigurationBlock_1;
public static String SREConfigurationBlock_2;
Expand Down
106 changes: 106 additions & 0 deletions plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/SREConstants.java
@@ -0,0 +1,106 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* 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.sarl.eclipse.runtime;


/**
* Constants that are representing elements in the SRE's manifest file.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public final class SREConstants {

/** Field name in the manifest that provides the main class.
*/
public static final String MANIFEST_MAIN_CLASS = "Main-Class"; //$NON-NLS-1$

/** Field name for the class path in the manifest file.
*/
public static final String MANIFEST_CLASS_PATH = "Class-Path"; //$NON-NLS-1$

/** Section of the manifest file that is detected to SRE.
*/
public static final String MANIFEST_SECTION_SRE = "SARL-Runtime-Environment"; //$NON-NLS-1$

/** Field name for the SARL specification version in the SRE section of the manifest file.
*/
public static final String MANIFEST_SARL_SPEC_VERSION = "SARL-Spec-Version"; //$NON-NLS-1$

/** Field name for the SRE name in the SRE section of the manifest file.
*/
public static final String MANIFEST_SRE_NAME = "SRE-Name"; //$NON-NLS-1$

/** Field name for the VM arguments in the SRE section of the manifest file.
*/
public static final String MANIFEST_VM_ARGUMENTS = "VM-Arguments"; //$NON-NLS-1$

/** Field name for the program arguments in the SRE section of the manifest file.
*/
public static final String MANIFEST_PROGRAM_ARGUMENTS = "Program-Arguments"; //$NON-NLS-1$

/** Field name for the boolean flag in the manifest file that indicates if it is a standalone SRE.
*/
public static final String MANIFEST_STANDALONE_SRE = "Standalone-SRE"; //$NON-NLS-1$

/** Attribute name of the SRE's library path (the jar file).
*/
public static final String XML_LIBRARY_PATH = "libraryPath"; //$NON-NLS-1$

/** Attribute name of the SRE's name.
*/
public static final String XML_SRE_NAME = "name"; //$NON-NLS-1$

/** Attribute name of the SRE's main class.
*/
public static final String XML_MAIN_CLASS = "mainClass"; //$NON-NLS-1$

/** Node name of a library used by the SRE.
*/
public static final String XML_LIBRARY_LOCATION = "libraryLocation"; //$NON-NLS-1$

/** Attribute name of system path of the SRE's library.
*/
public static final String XML_SYSTEM_LIBRARY_PATH = "systemLibraryPath"; //$NON-NLS-1$

/** Attribute name of package root path of the SRE's library.
*/
public static final String XML_PACKAGE_ROOT_PATH = "packageRootPath"; //$NON-NLS-1$

/** Attribute name of source path of the SRE's library.
*/
public static final String XML_SOURCE_PATH = "sourcePath"; //$NON-NLS-1$

/** Attribute name of javadoc path of the SRE's library.
*/
public static final String XML_JAVADOC_PATH = "javadoc"; //$NON-NLS-1$

/** Attribute name indicating if the SRE is standalone.
*/
public static final String XML_STANDALONE_SRE = "standalone"; //$NON-NLS-1$

private SREConstants() {
//
}

}

0 comments on commit dc87222

Please sign in to comment.