Skip to main content
summaryrefslogtreecommitdiffstats
blob: 51cd8116c78319991a8acb72c6d9416f401858eb (plain) (blame)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*******************************************************************************
 * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.generator.ui.wizard

import org.eclipse.core.runtime.preferences.InstanceScope
import org.eclipse.etrice.core.etphys.util.ETPhysUtil
import org.eclipse.etrice.generator.ui.preferences.PreferenceConstants
import org.eclipse.ui.preferences.ScopedPreferenceStore

/**
 * @author Henrik Rentz-Reichert
 *
 */
class ProjectFileFragments {
	
	def static String getBasicRoomModel(String baseName) {
		'''
			RoomModel «baseName» {
				LogicalSystem «baseName» {
					SubSystemRef main: MainSubSystem
				}
				SubSystemClass MainSubSystem {
					ActorRef appl: Application
					LogicalThread defaultThread
				}
				ActorClass Application {
				}
			}
		'''
	}
	
	/**
	 * @see ETPhysUtil
	 */
	def static String getBasicPhysicalModel(String baseName) {
		'''
			PhysicalModel «baseName» {
				
				PhysicalSystem PhysSys1 {
					NodeRef nodeRef1 : NodeClass1
				}
				
				NodeClass NodeClass1 {
					runtime = RuntimeClass1
					priomin = -10
					priomax = 10
					
					DefaultThread PhysicalThread1 {
						execmode = mixed
						interval = 100ms
						prio = 0
						stacksize = 1024
						msgblocksize = 32
						msgpoolsize = 10
					}
				}
			
				RuntimeClass RuntimeClass1 {
					model = multiThreaded
				} 
			}
		'''
	}
	
	def static String getBasicMappingModel(String baseName) {
		'''
			MappingModel «baseName» {
				import «baseName».* from "«baseName».room"
				import «baseName».* from "«baseName».etphys"
				Mapping «baseName» -> PhysSys1 {
					SubSystemMapping main -> nodeRef1 {
						ThreadMapping defaultThread -> PhysicalThread1
					}
				}
			}
		'''
	}
	
	def static String getGeneratorLaunchConfig(String targetLanguage, String modelPath, String baseName, String[] addLines) {
		val prefStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.etrice.generator.ui");
		val useTranslation = prefStore.getBoolean(PreferenceConstants::GEN_USE_TRANSLATION)
		'''
			<?xml version="1.0" encoding="UTF-8" standalone="no"?>
			<launchConfiguration type="org.eclipse.etrice.generator.launch.«targetLanguage».launchConfigurationType">
			<booleanAttribute key="MSC" value="true"/>
			<booleanAttribute key="UseTranslation" value="«useTranslation»"/>
			<listAttribute key="ModelFiles">
			<listEntry value="${workspace_loc:«modelPath»/«baseName».etmap}"/>
			</listAttribute>
			<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
			<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
			</listAttribute>
			«FOR line : addLines»
				«line»
			«ENDFOR»
			</launchConfiguration>
		'''
	}
	
	def static String getLaunchJavaApplicationConfig(String project, String mdlName, String mainClass) {
		'''
			<?xml version="1.0" encoding="UTF-8" standalone="no"?>
			<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
			<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
			<listEntry value="/«project»/src-gen/«mdlName.replace('.', '/')»/«mainClass».java"/>
			</listAttribute>
			<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
			<listEntry value="1"/>
			</listAttribute>
			<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
			<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="«mdlName».«mainClass»"/>
			<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="«project»"/>
			</launchConfiguration>
		'''
	}
	
	def static String getLaunchCApplicationConfig(String project) {
		'''
			<?xml version="1.0" encoding="UTF-8" standalone="no"?>
			<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType">
			<booleanAttribute key="org.eclipse.cdt.debug.mi.core.verboseMode" value="false"/>
			<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
			<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/>
			<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/«project».exe"/>
			<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="«project»"/>
			<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/>
			<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
			<listEntry value="/«project»"/>
			</listAttribute>
			<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
			<listEntry value="4"/>
			</listAttribute>
			</launchConfiguration>
		'''
	}
	
	def static String getMavenPOM(String project, String mdlName, String mainClass) {
		'''
			<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
						xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
				<modelVersion>4.0.0</modelVersion>
				<groupId>«project»</groupId>
				<artifactId>«mdlName»</artifactId>
				<version>1.0.0</version>
				
				<repositories>
					<repository>
						<id>repo.eclipse.org-snapshots</id>
						<name>eTrice Repository - Snapshots</name>
						<url>https://repo.eclipse.org/content/repositories/etrice-snapshots/</url>
					</repository>
				</repositories>
				
				<pluginRepositories>
					<pluginRepository>
						<id>repo.eclipse.org-snapshots</id>
						<name>eTrice Repository - Snapshots</name>
						<url>https://repo.eclipse.org/content/repositories/etrice-snapshots/</url>
					</pluginRepository>
				</pluginRepositories>
				
				<build>
					<sourceDirectory>src-gen</sourceDirectory>
					<resources>
						<resource>
							<directory>src-gen</directory>
							<excludes>
								<exclude>**/*.java</exclude>
							</excludes>
						</resource>
					</resources>
					<plugins>
						<plugin>
							<groupId>org.codehaus.mojo</groupId>
							<artifactId>build-helper-maven-plugin</artifactId>
							<version>1.7</version>
							<executions>
								<execution>
									<id>add-source</id>
									<phase>generate-sources</phase>
									<goals>
										<goal>add-source</goal>
									</goals>
									<configuration>
										<sources>
											<source>src</source>
										</sources>
									</configuration>
								</execution>
							</executions>
						</plugin>
						<plugin>
							<groupId>org.eclipse.etrice</groupId>
							<artifactId>org.eclipse.etrice.generator.java.mvn</artifactId>
							<version>0.4.0-SNAPSHOT</version>
							<executions>
								<execution>
									<goals>
										<goal>eTriceJavaGenerator</goal>
									</goals>
							        <configuration>
							          <arguments>
										<!-- allowed switches for the generator (not complete) -->
										<!-- generate the store/restore interface using POJO data objects
										<param>-storeDataObj</param>
										-->
										<!-- generate MSC instrumentation
										<param>-msc_instr</param>
										-->
										<!-- generate the persistence interface for dynamic actors
										<param>-persistable</param>
										-->
										<!-- generate all ROOM classes as library
										<param>-lib</param>
										-->
										<!-- generate documentation
										<param>-genDocu</param>
										-->
										<!-- generate files incrementally (overwrite only if contents changed)
										<param>-inc</param>
										-->
							          	<param>model/«mdlName».etmap</param>
							          </arguments>
							        </configuration>
								</execution>
							</executions>
							<dependencies>
								<!-- put the modellib on the class path to allow resolution of models by the generator -->
								<dependency>
									<groupId>org.eclipse.etrice</groupId>
									<artifactId>org.eclipse.etrice.modellib.java</artifactId>
									<version>0.4.0-SNAPSHOT</version>
								</dependency>
							</dependencies>
						</plugin>
						<plugin>
							<artifactId>maven-compiler-plugin</artifactId>
							<version>3.1</version>
							<configuration>
								<source>1.6</source>
								<target>1.6</target>
							</configuration>
						</plugin>
						<plugin>
							<artifactId>maven-assembly-plugin</artifactId>
							<executions>
								<execution>
									<phase>package</phase>
									<goals>
										<goal>single</goal>
									</goals>
								</execution>
							</executions>
							<configuration>
								<descriptorRefs>
									<descriptorRef>jar-with-dependencies</descriptorRef>
								</descriptorRefs>
								<archive>
									<manifest>
										<mainClass>«mdlName».«mainClass»</mainClass>
									</manifest>
								</archive>
							</configuration>
						</plugin>
					</plugins>
					<pluginManagement>
						<plugins>
							<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
							<plugin>
								<groupId>org.eclipse.m2e</groupId>
								<artifactId>lifecycle-mapping</artifactId>
								<version>1.0.0</version>
								<configuration>
									<lifecycleMappingMetadata>
										<pluginExecutions>
											<pluginExecution>
												<pluginExecutionFilter>
													<groupId>
														org.eclipse.etrice
													</groupId>
													<artifactId>
														org.eclipse.etrice.generator.java.mvn
													</artifactId>
													<versionRange>
														[0.4.0-SNAPSHOT,)
													</versionRange>
													<goals>
														<goal>
															eTriceJavaGenerator
														</goal>
													</goals>
												</pluginExecutionFilter>
												<action>
													<ignore></ignore>
												</action>
											</pluginExecution>
											<pluginExecution>
												<pluginExecutionFilter>
													<groupId>
														org.codehaus.mojo
													</groupId>
													<artifactId>
														build-helper-maven-plugin
													</artifactId>
													<versionRange>
														[1.7,)
													</versionRange>
													<goals>
														<goal>add-source</goal>
													</goals>
												</pluginExecutionFilter>
												<action>
													<ignore></ignore>
												</action>
											</pluginExecution>
										</pluginExecutions>
									</lifecycleMappingMetadata>
								</configuration>
							</plugin>
						</plugins>
					</pluginManagement>
				</build>
				<dependencies>
					<dependency>
						<groupId>org.eclipse.etrice</groupId>
						<artifactId>org.eclipse.etrice.runtime.java</artifactId>
						<version>0.4.0-SNAPSHOT</version>
				  	</dependency>
				  	<dependency>
				  		<groupId>org.eclipse.etrice</groupId>
				  		<artifactId>org.eclipse.etrice.modellib.java</artifactId>
				  		<version>0.4.0-SNAPSHOT</version>
				  	</dependency>
				</dependencies>
			</project>
		'''
	}
	
	def static String getMavenBuilder(String project) {
		'''
			<?xml version="1.0" encoding="UTF-8" standalone="no"?>
			<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
			<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
			<stringAttribute key="M2_GOALS" value="package"/>
			<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
			<booleanAttribute key="M2_OFFLINE" value="false"/>
			<stringAttribute key="M2_PROFILES" value=""/>
			<listAttribute key="M2_PROPERTIES"/>
			<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
			<booleanAttribute key="M2_SKIP_TESTS" value="false"/>
			<intAttribute key="M2_THREADS" value="1"/>
			<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
			<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
			<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/«project»}"/>
			</launchConfiguration>
		'''
	}
	
	def static String getMavenLauncher(String project, String mdlName) {
		'''
			<?xml version="1.0" encoding="UTF-8" standalone="no"?>
			<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
			<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${env_var:JAVA_HOME}/bin/java.exe"/>
			<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-jar target/«mdlName»-1.0.0-jar-with-dependencies.jar"/>
			<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/«project»}"/>
			</launchConfiguration>
		'''
	}
}

Back to the top