Skip to content

Commit

Permalink
Merge pull request #62 from eMoflon/rkluge-dev
Browse files Browse the repository at this point in the history
NPE fix
  • Loading branch information
RolandKluge authored Mar 21, 2018
2 parents 5538ecc + f9fa922 commit 1e12767
Show file tree
Hide file tree
Showing 20 changed files with 668 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
import org.gervarro.eclipse.task.ITask;
import org.moflon.core.utilities.WorkspaceHelper;

/**
* Collects all cross references of a given {@link Resource}, which is
* configured in the constructor
*
* @author Gergely Varró - Initial implementation
* @author Roland Kluge - Docu
*/
public class CrossReferenceResolver implements ITask {
private static final String TASK_NAME = "Cross-reference resolving";

private final Resource resource;
private final UniqueEList<Resource> resources = new UniqueEList<Resource>();

/**
* Configures the original {@link Resource} from which all cross-references
* shall be explored.
*
* @param resource
* the {@link Resource} to explore
*/
public CrossReferenceResolver(final Resource resource) {
this.resource = resource;
}
Expand All @@ -35,39 +47,73 @@ public IStatus run(final IProgressMonitor monitor) {
resources.add(resource);
for (int i = 0; i < resources.size(); i++) {
final Resource resource = resources.get(i);
for (final TreeIterator<EObject> j = resource.getAllContents(); j.hasNext();) {
final EObject eObject = j.next();
if (eObject instanceof EDataType) {
j.prune();
}
for (final EObject eCrossReference : eObject.eCrossReferences()) {
if (eCrossReference instanceof EClass) {
if (eCrossReference.eIsProxy()) {
final String proxyURI = eCrossReference instanceof InternalEObject
? ((InternalEObject) eCrossReference).eProxyURI().toString() + " "
: "";
crossReferenceResolutionStatus.add(new Status(IStatus.ERROR,
WorkspaceHelper.getPluginId(getClass()),
"Unresolved cross reference " + proxyURI + "in " + EcoreUtil.getURI(eObject)));
} else {
final EPackage referencedEPackage = ((EClass) eCrossReference).getEPackage();
if (resource != referencedEPackage.eResource()) {
resources.add(referencedEPackage.eResource());
}
exploreResource(resource, crossReferenceResolutionStatus);
}
return crossReferenceResolutionStatus.isOK() ? Status.OK_STATUS : crossReferenceResolutionStatus;
}

/**
* Traverses the given {@link Resource} and adds all Resources to
* {@link #getResources()} that are cross-references by some {@link EClass} in
* the given resource
*
* @param anchorResource
* @param crossReferenceResolutionStatus
*/
private void exploreResource(final Resource anchorResource, final MultiStatus crossReferenceResolutionStatus) {
for (final TreeIterator<EObject> j = anchorResource.getAllContents(); j.hasNext();) {
final EObject eObject = j.next();
if (eObject instanceof EDataType) {
j.prune();
}
for (final EObject eCrossReference : eObject.eCrossReferences()) {
if (eCrossReference instanceof EClass) {
if (eCrossReference.eIsProxy()) {
final Status status = createProxyReportingStatus(eObject, eCrossReference);
crossReferenceResolutionStatus.add(status);
} else {
final EPackage referencedEPackage = ((EClass) eCrossReference).getEPackage();
if (anchorResource != referencedEPackage.eResource()) {
resources.add(referencedEPackage.eResource());
}
}
}
}
}
return crossReferenceResolutionStatus;
}

/**
* Returns the task name
*/
@Override
public final String getTaskName() {
return TASK_NAME;
return "Cross-reference resolving";
}

/**
* The set of all cross-referenced {@link Resource}s of the configured resource
*
* @return
*/
public final List<Resource> getResources() {
return resources;
}

/**
* Creates a {@link Status} that reports about an unresolved proxy
*
* @param eObject
* the object
* @param eCrossReference
* the unresolved proxy
* @return the status
*/
private Status createProxyReportingStatus(final EObject eObject, final EObject eCrossReference) {
final String proxyURI = eCrossReference instanceof InternalEObject
? ((InternalEObject) eCrossReference).eProxyURI().toString() + " "
: "";
Status status = new Status(IStatus.ERROR, WorkspaceHelper.getPluginId(getClass()),
"Unresolved cross reference " + proxyURI + "in " + EcoreUtil.getURI(eObject));
return status;
}
}
2 changes: 1 addition & 1 deletion org.moflon.core.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.moflon.core.feature"
label="eMoflon Core Components Feature"
version="1.0.0.qualifier"
version="1.1.0.qualifier"
provider-name="eMoflon Developers"
plugin="org.moflon.core.branding">

Expand Down
2 changes: 1 addition & 1 deletion org.moflon.core.preferences/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: eMoflon Preferences Infrastructure
Bundle-SymbolicName: org.moflon.core.preferences;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Version: 1.1.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: eMoflon Developers
Require-Bundle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@
* @author Roland Kluge - Initial implementation
*/
public class EMoflonPreferencesStorage {

/**
* Indicates unbounded adornment size for {@link #getMaximumAdornmentSize()}
*/
public static final int REACHABILITY_MAX_ADORNMENT_SIZE_INFINITY = 0;

/**
* Default value for {@link #getMaximumAdornmentSize()}
*/
public static final int DEFAULT_REACHABILITY_MAX_ADORNMENT_SIZE = REACHABILITY_MAX_ADORNMENT_SIZE_INFINITY;

/**
* Default value for {@link #getValidationTimeout()}
*/
public static final int DEFAULT_VALIDATION_TIMEOUT_MILLIS = 30000;

/**
* Default value for {@link #getReachabilityEnabled()}
*/
public static final boolean DEFAULT_REACHABILITIY_IS_ENABLED = true;

/**
* Default value for {@link #getPreferredGenModelPlatformUriType()}
*/
public static final PlatformUriType DEFAULT_PLATFORM_URI_TYPE = PlatformUriType.PLUGIN;

/**
* Stores the configured validation timeout in milliseconds. 'null' if not set.
Expand All @@ -29,6 +47,11 @@ public class EMoflonPreferencesStorage {
*/
private boolean reachabilityEnabled;

/**
* Stores the preferred {@link PlatformUriType}
*/
private PlatformUriType preferredPlatformUriType = DEFAULT_PLATFORM_URI_TYPE;

/**
* Sets the validation timeout in milliseconds
*
Expand All @@ -39,6 +62,10 @@ public void setValidationTimeout(final int validationTimeout) {
this.validationTimeout = validationTimeout;
}

/**
* Returns the timeout for the reachability validation (in milliseconds)
* @return the validation timeout
*/
public int getValidationTimeout() {
return this.validationTimeout;
}
Expand All @@ -54,6 +81,10 @@ public void setReachabilityMaximumAdornmentSize(final int maximumAdornmentSize)
this.maximumAdornmentSize = maximumAdornmentSize;
}

/**
* @return the maximum size of adornments to analyze using reachability analysis
* @see #setReachabilityMaximumAdornmentSize(int)
*/
public int getMaximumAdornmentSize() {
return this.maximumAdornmentSize;
}
Expand All @@ -69,7 +100,33 @@ public void setReachabilityEnabled(final boolean reachabilityEnabled) {
this.reachabilityEnabled = reachabilityEnabled;
}

/**
* @return true if the reachability analysis shall be enabled, false
* otherwise
* @see #setReachabilityEnabled(boolean)
*/
public boolean getReachabilityEnabled() {
return reachabilityEnabled;
}

/**
* Configures the preferred {@link PlatformUriType}
* @param preferredPlatformUriType the preferred {@link PlatformUriType}. Must not be <code>null</code>.
*/
public void setPreferredPlatformUriType(final PlatformUriType preferredPlatformUriType)
{
if (preferredPlatformUriType == null)
throw new IllegalArgumentException("Only non-null values allowed for preferred platform URI type.");

this.preferredPlatformUriType = preferredPlatformUriType;
}

/**
* Returns the {@link PlatformUriType} that shall be used by the build process to represent resources in workspace projects.
* @return the preferred URI type
*/
public PlatformUriType getPreferredGenModelPlatformUriType()
{
return this.preferredPlatformUriType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.moflon.core.preferences;

/**
* Lists all types of Ecore URIs.
* @author Roland Kluge - Initial implementation
*/
public enum PlatformUriType {
/**
* Placeholder for platform:/resource URIs
*/
RESOURCE,
/**
* Placeholder for platform:/plugin URIs
*/
PLUGIN;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.moflon.core.releng.updatesite/AntUtilitiesBuild.xml"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.moflon.core.releng.updatesite"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_PROPERTIES">
<mapEntry key="eclipse.home" value="C:\Users\rkluge\Documents\Programme\oxygen_L0_MoflonCore"/>
<mapEntry key="eclipse.pdebuild.home" value="C:\Users\rkluge\Documents\Programme\oxygen_L0_MoflonCore\plugins\org.eclipse.pde.build_3.9.300.v20170515-0912\."/>
<mapEntry key="eclipse.pdebuild.scripts" value="C:\Users\rkluge\Documents\Programme\oxygen_L0_MoflonCore\plugins\org.eclipse.pde.build_3.9.300.v20170515-0912\scripts"/>
<mapEntry key="eclipse.pdebuild.templates" value="C:\Users\rkluge\Documents\Programme\oxygen_L0_MoflonCore\plugins\org.eclipse.pde.build_3.9.300.v20170515-0912\templates"/>
<mapEntry key="eclipse.running" value="true"/>
<mapEntry key="emoflonCoreUpdateSiteProjectRoot" value="${workspace_loc:/emoflon-core-updatesite}"/>
</mapAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_TARGETS" value="copyFromStable,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.moflon.core.releng.updatesite/AntUtilitiesBuild.xml}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/org.moflon.core.releng.updatesite}"/>
<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
</launchConfiguration>
Loading

0 comments on commit 1e12767

Please sign in to comment.