/
GeneratedDerivedSourceFolder.java
172 lines (139 loc) · 5.23 KB
/
GeneratedDerivedSourceFolder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.opcoach.genmodeladdon.handlers;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Shell;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import com.opcoach.genmodeladdon.core.GenerateDevStructure;
import com.opcoach.genmodeladdon.core.genmodel.GMAGenModel;
import com.opcoach.genmodeladdon.ui.dialog.ConfirmFileSelectionDialog;
import com.opcoach.genmodeladdon.ui.dialog.DerivedSourceParametersDialog;
import jakarta.inject.Named;
public class GeneratedDerivedSourceFolder extends GenerateParentHandler
{
private Shell parentShell;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
@Named(IServiceConstants.ACTIVE_SELECTION) GMAGenModel gm)
{
parentShell = shell;
DerivedSourceParametersDialog dial = new DerivedSourceParametersDialog(shell);
dial.setGenModel(gm);
int status = dial.open();
if (status == Dialog.OK)
{
gm.setDevClassPattern(dial.getDevClassPattern());
gm.setDevInterfacePattern(dial.getDevInterfacePattern());
String src = dial.getSrcDir();
gm.setSrcDir(src);
boolean generateEMFModelCode = dial.getGenerateEMFModelCode();
gm.setGenerateEMFCode(generateEMFModelCode);
boolean generateXtendCode = dial.isOverridenImplAsXtend();
gm.setGenerateOverridenImplAsXtend(generateXtendCode);
final GenerateDevStructure gds = new GenerateDevStructure(gm);
// set some genModel convenient properties.
gds.initializeGenModelConvenientProperties();
// Try to generate to check the files that could be
// overridden
gds.generateDevStructure(false);
Map<String, Object> filesNotGenerated = gds.filesNotGenerated;
StringBuffer filesInError = new StringBuffer();
int confirmCode = ConfirmFileSelectionDialog.OK;
ConfirmFileSelectionDialog cfs = null;
if (!filesNotGenerated.isEmpty())
{
cfs = new ConfirmFileSelectionDialog(parentShell, filesNotGenerated, src);
confirmCode = cfs.open();
}
if (confirmCode == ConfirmFileSelectionDialog.OK)
{
// Now can generate really the files.
gds.generateDevStructure(true);
// Must ask if the not generated files can override
// existing files...
if (cfs != null)
{
for (String fn : cfs.getFilesToBeGenerated())
{
// Open the file and generate contents
try
{
FileWriter fw = new FileWriter(fn);
fw.write(filesNotGenerated.get(fn).toString());
fw.flush();
fw.close();
} catch (IOException e)
{
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
ILog log = Platform.getLog(bundle);
String mess = "Unable to generate the file : " + fn;
Status st = new Status(Status.WARNING, bundle.getSymbolicName(), Status.OK, mess, e);
log.log(st);
int pos = fn.indexOf(src);
filesInError.append(fn.substring(pos)).append("\n");
}
}
}
// Display a sum up dialog
if (filesInError.length() == 0)
MessageDialog.openInformation(parentShell, "Files generated",
"Files have been generated in this directory : \n\n" + gds.getSrcAbsolutePath());
else
{
MessageDialog.openWarning(parentShell, "Files generated with errors",
"Some errors occured during the generation.\n\n These files were not generated : \n"
+ filesInError
+ "\n\nThe other files have been generated without any error here : \n"
+ gds.getSrcAbsolutePath()
+ "\n\n---------------------------------------------------\nCheck the logs in : "
+ Platform.getLogFileLocation().toPortableString());
}
// Generate the next step : ant file and EMF code
if (generateEMFModelCode)
{
// Generate the ant file and call it with the ant Runner
// Generate the ant file to generate emf code
final File antFile = gds.generateAntFile();
// Once dev structure is generated and ant file too, can call it !
ProgressMonitorDialog pmd = new ProgressMonitorDialog(parentShell);
pmd.open();
try
{
pmd.run(true, false, new IRunnableWithProgress()
{
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
monitor.setTaskName("Generating EMF code");
gds.generateGenModelCode(antFile, monitor);
}
});
} catch (InvocationTargetException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Must generate and update extensions
gds.generateExtensions();
}
}
}
}