Skip to content

Commit

Permalink
Fix #77 : In test extension points are not always found
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Prouvost <[email protected]>
  • Loading branch information
opcoach committed Jan 2, 2019
1 parent cde207b commit 6dcf492
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public IWorkspaceRoot getWorkspaceRoot()
{
return root;
}

public boolean isInitDone() { return initDone; }

/** initialize the sample project only once */
public IProject getSampleProject()
Expand All @@ -95,7 +97,7 @@ public IProject getSampleProject()
initGenModel(PROJECT_GENMODEL, PROJECT_ANT_FILE);
initGenModel(PROJECT2_GENMODEL, PROJECT_ANT2_FILE, "{0}Impl", "G{0}", "src");
initGenModel(FANNOISE_GENMODEL, FANOISE_ANT_FILE);

System.out.println("Init finished");
} catch (Exception ex)
{
ex.printStackTrace();
Expand Down Expand Up @@ -178,7 +180,7 @@ private static GMAGenModel readSampleGenModel(IWorkspaceRoot root, String pathTo

}

/** This method initialize the test workspace with a sample project
/** This method initializes the test workspace with a sample project
* It calls the prepareTestWorkspace ant file that will unzip the sample project
* */
private IWorkspaceRoot initWorkspace() throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.opcoach.genmodeladdon.core.genmodel.GMAGenModel
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.text.MessageFormat
import java.util.ArrayList
import java.util.Collections
import java.util.HashMap
Expand All @@ -12,28 +13,29 @@ import java.util.stream.Collectors
import org.eclipse.ant.core.AntRunner
import org.eclipse.core.resources.IProject
import org.eclipse.core.resources.IResource
import org.eclipse.core.resources.IResourceChangeEvent
import org.eclipse.core.resources.IResourceChangeListener
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.CoreException
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.NullProgressMonitor
import org.eclipse.core.runtime.Path
import org.eclipse.core.runtime.Platform
import org.eclipse.emf.codegen.ecore.genmodel.GenClass
import org.eclipse.emf.codegen.ecore.genmodel.GenModel
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage
import org.eclipse.emf.ecore.EClass
import org.eclipse.jdt.core.IClasspathEntry
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import java.text.MessageFormat
import org.eclipse.pde.internal.core.PDECore

/** This class is used to proceed the different steps to generate the development structure
* A method is defined for each step :
* generateDevStructure : generate the development structure
* generateAntFile : generate the ant file to generate the code (usefull for automatic builder)
* generateGenModelCode : generate the EMF code using templates (calls the ant file)
*/
class GenerateDevStructure {
class GenerateDevStructure implements IResourceChangeListener {

String classPattern
String interfacePattern
Expand Down Expand Up @@ -88,6 +90,9 @@ class GenerateDevStructure {
// println("Project " + projectName + " is " + status + " when creating devStructure for " + modelName)
// Reset the files not generated... (they are kept to ask if they must override existing files)
filesNotGenerated.clear

// Listen to workspace to be notified on refresh...
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD)
}

new(GMAGenModel gm) {
Expand Down Expand Up @@ -265,6 +270,7 @@ class GenerateDevStructure {
// BUT AFTER THE EMF CODE GENERATION !!
generateExtensions

// Must refresh workspace
refreshWorkspace

}
Expand All @@ -281,15 +287,30 @@ class GenerateDevStructure {

def getInterfacePattern() { interfacePattern }

var waitingForRefresh = false;

def refreshWorkspace() {
try {
waitingForRefresh = true
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null)
// println("Waiting for refresh ")
Thread.sleep(2000); // Wait for refresh (important). MUST NOT BE LESS THAN 2 seconds for tycho build
// Thread.sleep(2000); // Wait for refresh (important). MUST NOT BE LESS THAN 2 seconds for tycho build
while (waitingForRefresh) {
//println("Waiting for refresh")
Thread.sleep(1000)
}
} catch (CoreException e) {
e.printStackTrace
}
finally {
PDECore.^default.modelManager.bundleRootChanged(project)
}

}

override resourceChanged(IResourceChangeEvent event) {
// println(" ---> Received the postbuild event")
waitingForRefresh = false
}

def generateOverriddenFactoryInterface(GenPackage gp, String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.opcoach.genmodeladdon.core

import java.util.ArrayList
import java.util.Map
import org.eclipse.core.resources.IProject
import org.eclipse.pde.core.plugin.IPluginBase
import org.eclipse.pde.core.plugin.IPluginElement
import org.eclipse.pde.core.plugin.IPluginExtension
import org.eclipse.pde.core.plugin.IPluginExtensionPoint
Expand Down Expand Up @@ -38,6 +40,12 @@ package class GenerateExtensions {

// The input project that contains the extensions to be updated/added
IProject project


// Temp for debug....
//static var sourceModels = new ArrayList<IPluginModelBase>
//static int ism = 0;
// End Temp for debug....

new(IProject p) {

Expand All @@ -54,12 +62,29 @@ package class GenerateExtensions {
// But these extensions can be found using the workspace models
// Search for the sourceModel from the project name
var IPluginModelBase sourceModel
//println(" ************* Start Looking for workspace project ")
for (m : PluginRegistry.getWorkspaceModels()) {
println("Project name : " + m.bundleDescription.symbolicName)
if (m.bundleDescription !== null && project.name.equals(m.bundleDescription.symbolicName))
{
//println("Keep it")
sourceModel = m
//sourceModels.add(sourceModel)
//ism++
}
}
//println(" ************* End Looking for workspace project ")


// Copy current extension points in the new plugin model.
/* val nbEp = sourceModel.extensions.extensionPoints.size
if (nbEp == 0)
{
println(" No extension point ... ???? ")
}else
{
println(" -------->>>>>>>> There is " + nbEp + " extensions points in the source model")
}*/
for (IPluginExtensionPoint ept : sourceModel.extensions.extensionPoints)
fModel.pluginBase.add(ept.copyExtensionPoint)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@

@SuppressWarnings("all")
public interface GMAConstants {
public final static String PLUGIN_ID = "com.opcoach.genmodeladdon.core";
public static final String PLUGIN_ID = "com.opcoach.genmodeladdon.core";

public final static QualifiedName PROP_INTERFACE_PATTERN = new QualifiedName(GMAConstants.PLUGIN_ID, "interfacePattern");
public static final QualifiedName PROP_INTERFACE_PATTERN = new QualifiedName(GMAConstants.PLUGIN_ID, "interfacePattern");

public final static QualifiedName PROP_CLASS_PATTERN = new QualifiedName(GMAConstants.PLUGIN_ID, "classPattern");
public static final QualifiedName PROP_CLASS_PATTERN = new QualifiedName(GMAConstants.PLUGIN_ID, "classPattern");

public final static QualifiedName PROP_SRCDIR = new QualifiedName(GMAConstants.PLUGIN_ID, "srcDir");
public static final QualifiedName PROP_SRCDIR = new QualifiedName(GMAConstants.PLUGIN_ID, "srcDir");

public final static String PARAM_DEBUG_MODE = "-gmaDebug";
public static final String PARAM_DEBUG_MODE = "-gmaDebug";

public final static QualifiedName PROP_GENEMFCODE = new QualifiedName(GMAConstants.PLUGIN_ID, "generateEMFCodeAfter");
public static final QualifiedName PROP_GENEMFCODE = new QualifiedName(GMAConstants.PLUGIN_ID, "generateEMFCodeAfter");

public final static QualifiedName PROP_GMA = new QualifiedName(GMAConstants.PLUGIN_ID, "genModelAddon");
public static final QualifiedName PROP_GMA = new QualifiedName(GMAConstants.PLUGIN_ID, "genModelAddon");

public final static String ADVISED_GEN_INTERFACE_PATTERN = "M{0}";
public static final String ADVISED_GEN_INTERFACE_PATTERN = "M{0}";

public final static String ADVISED_GEN_CLASS_IMPL_PATTERN = "M{0}Impl";
public static final String ADVISED_GEN_CLASS_IMPL_PATTERN = "M{0}Impl";

public final static String ADVISED_DEV_INTERFACE_PATTERN = "{0}";
public static final String ADVISED_DEV_INTERFACE_PATTERN = "{0}";

public final static String ADVISED_DEV_CLASS_IMPL_PATTERN = "{0}Impl";
public static final String ADVISED_DEV_CLASS_IMPL_PATTERN = "{0}Impl";

public final static String ADVISED_GEN_SRC_DIR = "src-gen";
public static final String ADVISED_GEN_SRC_DIR = "src-gen";

public final static String DEFAULT_SRC_DEV = "src";
public static final String DEFAULT_SRC_DEV = "src";

public final static String DEFAULT_GEN_INTERFACE_PATTERN = "{0}";
public static final String DEFAULT_GEN_INTERFACE_PATTERN = "{0}";

public final static String DEFAULT_GEN_CLASS_IMPL_PATTERN = "{0}Impl";
public static final String DEFAULT_GEN_CLASS_IMPL_PATTERN = "{0}Impl";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@SuppressWarnings("all")
public class GenerateAntFileForCodeGeneration {
public final static String ANT_FILENAME = "generateEMFCode.xml";
public static final String ANT_FILENAME = "generateEMFCode.xml";

private CharSequence generateAntFileContent(final String modelDir, final String modelName) {
StringConcatenation _builder = new StringConcatenation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -38,6 +40,7 @@
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Exceptions;
Expand All @@ -53,7 +56,7 @@
* generateGenModelCode : generate the EMF code using templates (calls the ant file)
*/
@SuppressWarnings("all")
public class GenerateDevStructure {
public class GenerateDevStructure implements IResourceChangeListener {
private String classPattern;

private String interfacePattern;
Expand Down Expand Up @@ -116,6 +119,7 @@ public GenerateDevStructure(final GMAGenModel gm, final String cPattern, final S
status = "closed";
}
this.filesNotGenerated.clear();
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
Expand Down Expand Up @@ -336,24 +340,36 @@ public String getInterfacePattern() {
return this.interfacePattern;
}

private boolean waitingForRefresh = false;

public void refreshWorkspace() {
try {
try {
this.waitingForRefresh = true;
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
Thread.sleep(2000);
while (this.waitingForRefresh) {
Thread.sleep(1000);
}
} catch (final Throwable _t) {
if (_t instanceof CoreException) {
final CoreException e = (CoreException)_t;
e.printStackTrace();
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
PDECore.getDefault().getModelManager().bundleRootChanged(this.project);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}

@Override
public void resourceChanged(final IResourceChangeEvent event) {
this.waitingForRefresh = false;
}

public Object generateOverriddenFactoryInterface(final GenPackage gp, final String path) {
Object _xblockexpression = null;
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
*/
@SuppressWarnings("all")
class GenerateExtensions {
private final static String EMF_GENERATED_PACKAGE = "org.eclipse.emf.ecore.generated_package";
private static final String EMF_GENERATED_PACKAGE = "org.eclipse.emf.ecore.generated_package";

private final static String FACTORY_OVERRIDE = "org.eclipse.emf.ecore.factory_override";
private static final String FACTORY_OVERRIDE = "org.eclipse.emf.ecore.factory_override";

private final static String PACKAGE_ELT = "package";
private static final String PACKAGE_ELT = "package";

private final static String FACTORY_ELT = "factory";
private static final String FACTORY_ELT = "factory";

private final static String URI_ATTR = "uri";
private static final String URI_ATTR = "uri";

private final static String CLASS_ATTR = "class";
private static final String CLASS_ATTR = "class";

private WorkspaceBundlePluginModel fModel;

Expand All @@ -56,8 +56,13 @@ public GenerateExtensions(final IProject p) {
IPluginModelBase sourceModel = null;
IPluginModelBase[] _workspaceModels = PluginRegistry.getWorkspaceModels();
for (final IPluginModelBase m : _workspaceModels) {
if (((m.getBundleDescription() != null) && this.project.getName().equals(m.getBundleDescription().getSymbolicName()))) {
sourceModel = m;
{
String _symbolicName = m.getBundleDescription().getSymbolicName();
String _plus = ("Project name : " + _symbolicName);
InputOutput.<String>println(_plus);
if (((m.getBundleDescription() != null) && this.project.getName().equals(m.getBundleDescription().getSymbolicName()))) {
sourceModel = m;
}
}
}
IPluginExtensionPoint[] _extensionPoints = sourceModel.getExtensions().getExtensionPoints();
Expand Down

0 comments on commit 6dcf492

Please sign in to comment.