diff options
2 files changed, 208 insertions, 185 deletions
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java index b2882a84d..a378f4ae4 100644 --- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java +++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/newwizard/ProjectCreator.java @@ -49,13 +49,8 @@ import org.eclipse.jface.resource.ImageDescriptor; */ public class ProjectCreator { - private static final String[] commonNatureIDs = { - JavaCore.NATURE_ID, - "org.eclipse.xtext.ui.shared.xtextNature" - }; - private static final String[] commonBuilderIDs = { - "org.eclipse.xtext.ui.shared.xtextBuilder", - }; + private static final String[] commonNatureIDs = { JavaCore.NATURE_ID, "org.eclipse.xtext.ui.shared.xtextNature" }; + private static final String[] commonBuilderIDs = { "org.eclipse.xtext.ui.shared.xtextBuilder", }; public static List<String> getCommonNatureIDs() { return Arrays.asList(commonNatureIDs); @@ -64,29 +59,18 @@ public class ProjectCreator { public static List<String> getCommonBuilderIDs() { return Arrays.asList(commonBuilderIDs); } - - public static IProject createETriceProject( - IPath javaSource, - IPath javaSourceGen, - URI projectLocationURI, - IProject runtimeProject, - List<String> naturesToAdd, - List<String> buildersToAdd, - Monitor monitor - ) { - IProgressMonitor progressMonitor = BasicMonitor - .toIProgressMonitor(monitor); + + public static IProject createETriceProject(IPath javaSource, IPath javaSourceGen, URI projectLocationURI, + IProject runtimeProject, List<String> naturesToAdd, List<String> buildersToAdd, Monitor monitor) { + IProgressMonitor progressMonitor = BasicMonitor.toIProgressMonitor(monitor); String projectName = javaSource.segment(0); IProject project = null; try { List<IClasspathEntry> classpathEntries = new UniqueEList<IClasspathEntry>(); progressMonitor.beginTask("", 10); - progressMonitor.subTask("Creating eTrice project " - + projectName - + " (" - + (projectLocationURI != null ? projectLocationURI - .toString() : projectName) + ")"); + progressMonitor.subTask("Creating eTrice project " + projectName + " (" + + (projectLocationURI != null ? projectLocationURI.toString() : projectName) + ")"); IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().getProject(projectName); @@ -95,36 +79,30 @@ public class ProjectCreator { if (!project.exists()) { URI location = projectLocationURI; if (location == null) { - location = URI.createFileURI(workspace.getRoot() - .getLocation().append(projectName).toOSString()); + location = URI.createFileURI(workspace.getRoot().getLocation().append(projectName).toOSString()); } location = location.appendSegment(".project"); File projectFile = new File(location.toString()); if (projectFile.exists()) { - projectFile - .renameTo(new File(location.toString() + ".old")); + projectFile.renameTo(new File(location.toString() + ".old")); } } IJavaProject javaProject = JavaCore.create(project); IProjectDescription projectDescription = null; if (!project.exists()) { - projectDescription = ResourcesPlugin.getWorkspace() - .newProjectDescription(projectName); + projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); if (projectLocationURI != null) { - projectDescription.setLocationURI(new java.net.URI( - projectLocationURI.toString())); + projectDescription.setLocationURI(new java.net.URI(projectLocationURI.toString())); } - project.create(projectDescription, new SubProgressMonitor( - progressMonitor, 1)); + project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1)); project.open(new SubProgressMonitor(progressMonitor, 1)); } else { projectDescription = project.getDescription(); project.open(new SubProgressMonitor(progressMonitor, 1)); if (project.hasNature(JavaCore.NATURE_ID)) { - classpathEntries.addAll(Arrays.asList(javaProject - .getRawClasspath())); + classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath())); } } @@ -132,19 +110,19 @@ public class ProjectCreator { { ArrayList<IProject> referencedProjects = new ArrayList<IProject>(); - if (runtimeProject!=null) + if (runtimeProject != null) referencedProjects.add(runtimeProject); if (!referencedProjects.isEmpty()) { - projectDescription.setReferencedProjects( - referencedProjects.toArray(new IProject[referencedProjects.size()])); + projectDescription.setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects + .size()])); for (IProject referencedProject : referencedProjects) { - IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry( - referencedProject.getFullPath()); + IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry(referencedProject + .getFullPath()); classpathEntries.add(referencedProjectClasspathEntry); } } } - + { String[] natureIds = projectDescription.getNatureIds(); if (natureIds == null) { @@ -164,55 +142,49 @@ public class ProjectCreator { } projectDescription.setBuildSpec(builders); - project.setDescription(projectDescription, - new SubProgressMonitor(progressMonitor, 1)); + project.setDescription(projectDescription, new SubProgressMonitor(progressMonitor, 1)); createSrcFolder(progressMonitor, project, classpathEntries, javaSource); createSrcFolder(progressMonitor, project, classpathEntries, javaSourceGen); if (isInitiallyEmpty) { - IClasspathEntry jreClasspathEntry = JavaCore - .newVariableEntry(new Path( - JavaRuntime.JRELIB_VARIABLE), new Path( - JavaRuntime.JRESRC_VARIABLE), new Path( + IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry( + new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE), new Path( JavaRuntime.JRESRCROOT_VARIABLE)); for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext();) { IClasspathEntry classpathEntry = i.next(); - if (classpathEntry.getPath().isPrefixOf( - jreClasspathEntry.getPath())) { + if (classpathEntry.getPath().isPrefixOf(jreClasspathEntry.getPath())) { i.remove(); } } String jreContainer = JavaRuntime.JRE_CONTAINER; jreContainer += "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"; - classpathEntries.add(JavaCore.newContainerEntry(new Path( - jreContainer))); + classpathEntries.add(JavaCore.newContainerEntry(new Path(jreContainer))); } - javaProject.setRawClasspath(classpathEntries - .toArray(new IClasspathEntry[classpathEntries.size()]), + javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(progressMonitor, 1)); } if (isInitiallyEmpty) { - javaProject.setOutputLocation( - new Path("/" + javaSource.segment(0) + "/bin"), - new SubProgressMonitor(progressMonitor, 1)); + javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"), new SubProgressMonitor( + progressMonitor, 1)); } - javaProject.setRawClasspath - (classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), - new SubProgressMonitor(progressMonitor, 1)); - - if (isInitiallyEmpty) - { - javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"), new SubProgressMonitor(progressMonitor, 1)); - } + javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), + new SubProgressMonitor(progressMonitor, 1)); + + if (isInitiallyEmpty) { + javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"), new SubProgressMonitor( + progressMonitor, 1)); + } - } catch (Exception e) { + } + catch (Exception e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); - } finally { + } + finally { progressMonitor.done(); } @@ -225,24 +197,20 @@ public class ProjectCreator { * @param projectDescription * @return */ - private static ICommand[] addBuilder(String manifestBuilder, - ICommand[] builders, IProjectDescription projectDescription) { + private static ICommand[] addBuilder(String manifestBuilder, ICommand[] builders, + IProjectDescription projectDescription) { boolean hasBuilder = false; for (int i = 0; i < builders.length; ++i) { - if (manifestBuilder.equals(builders[i] - .getBuilderName())) { + if (manifestBuilder.equals(builders[i].getBuilderName())) { hasBuilder = true; } } if (!hasBuilder) { ICommand[] oldBuilders = builders; builders = new ICommand[oldBuilders.length + 1]; - System.arraycopy(oldBuilders, 0, builders, 0, - oldBuilders.length); - builders[oldBuilders.length] = projectDescription - .newCommand(); - builders[oldBuilders.length] - .setBuilderName(manifestBuilder); + System.arraycopy(oldBuilders, 0, builders, 0, oldBuilders.length); + builders[oldBuilders.length] = projectDescription.newCommand(); + builders[oldBuilders.length].setBuilderName(manifestBuilder); } return builders; } @@ -254,13 +222,11 @@ public class ProjectCreator { * @return * @throws CoreException */ - private static String[] addNature(String natureId, String[] natureIds, - IProject project) throws CoreException { + private static String[] addNature(String natureId, String[] natureIds, IProject project) throws CoreException { if (!project.hasNature(natureId)) { String[] oldNatureIds = natureIds; natureIds = new String[oldNatureIds.length + 1]; - System.arraycopy(oldNatureIds, 0, natureIds, 0, - oldNatureIds.length); + System.arraycopy(oldNatureIds, 0, natureIds, 0, oldNatureIds.length); natureIds[oldNatureIds.length] = natureId; } return natureIds; @@ -273,30 +239,22 @@ public class ProjectCreator { * @param src * @throws CoreException */ - private static void createSrcFolder(IProgressMonitor progressMonitor, - IProject project, List<IClasspathEntry> classpathEntries, IPath src) - throws CoreException { + private static void createSrcFolder(IProgressMonitor progressMonitor, IProject project, + List<IClasspathEntry> classpathEntries, IPath src) throws CoreException { if (src.segmentCount() > 1) { - IPath sourceContainerPath = src.removeFirstSegments( - 1).makeAbsolute(); + IPath sourceContainerPath = src.removeFirstSegments(1).makeAbsolute(); IFolder sourceContainer = project.getFolder(sourceContainerPath); if (!sourceContainer.exists()) { for (int i = sourceContainerPath.segmentCount() - 1; i >= 0; i--) { - sourceContainer = project - .getFolder(sourceContainerPath - .removeLastSegments(i)); + sourceContainer = project.getFolder(sourceContainerPath.removeLastSegments(i)); if (!sourceContainer.exists()) { - ((IFolder) sourceContainer).create(false, true, - new SubProgressMonitor(progressMonitor, - 1)); + ((IFolder) sourceContainer).create(false, true, new SubProgressMonitor(progressMonitor, 1)); } } } - IClasspathEntry sourceClasspathEntry = JavaCore - .newSourceEntry(src); - for (Iterator<IClasspathEntry> i = classpathEntries - .iterator(); i.hasNext();) { + IClasspathEntry sourceClasspathEntry = JavaCore.newSourceEntry(src); + for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext();) { IClasspathEntry classpathEntry = i.next(); if (classpathEntry.getPath().isPrefixOf(src)) { i.remove(); @@ -306,112 +264,165 @@ public class ProjectCreator { } } - public static IContainer findOrCreateContainer - (IPath path, boolean forceRefresh, IPath localLocation, IProgressMonitor progressMonitor) throws CoreException - { - String projectName = path.segment(0); - IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); - projectDescription.setLocation(localLocation); - return findOrCreateContainer(path, forceRefresh, projectDescription, progressMonitor); - } - - public static IContainer findOrCreateContainer - (IPath path, boolean forceRefresh, IProjectDescription projectDescription, IProgressMonitor progressMonitor) throws CoreException - { - try - { - String projectName = path.segment(0); - progressMonitor.beginTask("", path.segmentCount() + 3); - progressMonitor.subTask("examine new project "+projectName); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject project = workspace.getRoot().getProject(path.segment(0)); - - if (forceRefresh) - { - project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(progressMonitor, 1)); - } - else - { - progressMonitor.worked(1); - } - - if (!project.exists()) - { - project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1)); - project.open(new SubProgressMonitor(progressMonitor, 1)); - } - else - { - project.open(new SubProgressMonitor(progressMonitor, 2)); - } - - IContainer container = project; - for (int i = 1, length = path.segmentCount(); i < length; ++ i) - { - IFolder folder = container.getFolder(new Path(path.segment(i))); - if (!folder.exists()) - { - folder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); - } - else - { - progressMonitor.worked(1); - } - - container = folder; - } - - return container; - } - finally - { - progressMonitor.done(); - } - } - - public static void createModel(URI uri, String baseName) { + public static IContainer findOrCreateContainer(IPath path, boolean forceRefresh, IPath localLocation, + IProgressMonitor progressMonitor) throws CoreException { + String projectName = path.segment(0); + IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); + projectDescription.setLocation(localLocation); + return findOrCreateContainer(path, forceRefresh, projectDescription, progressMonitor); + } + + public static IContainer findOrCreateContainer(IPath path, boolean forceRefresh, + IProjectDescription projectDescription, IProgressMonitor progressMonitor) throws CoreException { try { - PrintStream model = new PrintStream( - URIConverter.INSTANCE.createOutputStream(uri, null), - false, - "UTF-8"); - model.println("RoomModel "+baseName+" {"); - model.println("\t// TODO: add ROOM classes here..."); + String projectName = path.segment(0); + progressMonitor.beginTask("", path.segmentCount() + 3); + progressMonitor.subTask("examine new project " + projectName); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProject project = workspace.getRoot().getProject(path.segment(0)); + + if (forceRefresh) { + project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(progressMonitor, 1)); + } + else { + progressMonitor.worked(1); + } + + if (!project.exists()) { + project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1)); + project.open(new SubProgressMonitor(progressMonitor, 1)); + } + else { + project.open(new SubProgressMonitor(progressMonitor, 2)); + } + + IContainer container = project; + for (int i = 1, length = path.segmentCount(); i < length; ++i) { + IFolder folder = container.getFolder(new Path(path.segment(i))); + if (!folder.exists()) { + folder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); + } + else { + progressMonitor.worked(1); + } + + container = folder; + } + + return container; + } + finally { + progressMonitor.done(); + } + } + + public static void createModel(URI uri, String baseName) { + try { + PrintStream model = new PrintStream(URIConverter.INSTANCE.createOutputStream(uri, null), false, "UTF-8"); + model.println("RoomModel " + baseName + " {"); + model.println("\tLogicalSystem LogSys1 {"); + model.println("\t\tSubSystemRef subSysRef1:SubSysClass1"); + model.println("\t}"); + model.println("\tSubSystemClass SubSysClass1 {"); + model.println("\t\tActorRef actorRef1:ActorClass1"); + model.println("\t\tLogicalThread defaultThread"); + model.println("\t}"); + model.println("\tActorClass ActorClass1 {"); + model.println("\t}"); model.println("}"); model.close(); - } catch (UnsupportedEncodingException e) { + } + catch (UnsupportedEncodingException e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); - } catch (IOException e) { + } + catch (IOException e) { + Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); + } + } + + public static void createPhysicalModel(URI uri, String baseName) { + try { + PrintStream model = new PrintStream(URIConverter.INSTANCE.createOutputStream(uri, null), false, "UTF-8"); + model.println("PhysicalModel " + baseName + " {"); + model.println("\t"); + model.println("\tPhysicalSystem PhysSys1 {"); + model.println("\t\tNodeRef nodeRef1 : NodeClass1"); + model.println("\t}"); + model.println("\t"); + model.println("\tNodeClass NodeClass1 {"); + model.println("\t\truntime = RuntimeClass1"); + model.println("\t\tpriomin = -10"); + model.println("\t\tpriomax = 10"); + model.println("\t\t"); + model.println("\t\tDefaultThread PhysicalThread1 {"); + model.println("\t\t\texecmode = mixed"); + model.println("\t\t\tinterval = 100ms"); + model.println("\t\t\tprio = 0"); + model.println("\t\t\tstacksize = 1024"); + model.println("\t\t\tmsgblocksize = 32"); + model.println("\t\t\tmsgpoolsize = 10"); + model.println("\t\t}"); + model.println("\t}"); + model.println(""); + model.println("\tRuntimeClass RuntimeClass1 {"); + model.println("\t\tmodel = multiThreaded"); + model.println("\t} "); + model.println("}"); + model.close(); + } + catch (UnsupportedEncodingException e) { + Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); + } + catch (IOException e) { + Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); + } + } + + public static void createMappingModel(URI uri, String baseName) { + try { + PrintStream model = new PrintStream(URIConverter.INSTANCE.createOutputStream(uri, null), false, "UTF-8"); + model.println("MappingModel " + baseName + " {"); + model.println("\timport "+baseName+".* from \""+baseName+".room\""); + model.println("\timport "+baseName+".* from \""+baseName+".etphys\""); + model.println("\tMapping LogSys1 -> PhysSys1 {"); + model.println("\t\tSubSystemMapping subSysRef1 -> nodeRef1 {"); + model.println("\t\t\tThreadMapping defaultThread -> PhysicalThread1"); + model.println("\t\t}"); + model.println("\t}"); + model.println("}"); + model.close(); + } + catch (UnsupportedEncodingException e) { + Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); + } + catch (IOException e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); } } public static void createBuildProperties(URI uri, String baseName) { try { - PrintStream prop = new PrintStream( - URIConverter.INSTANCE.createOutputStream(uri, null), - false, - "UTF-8"); + PrintStream prop = new PrintStream(URIConverter.INSTANCE.createOutputStream(uri, null), false, "UTF-8"); prop.println("source.. = src/,\\"); prop.println("src-gen/"); prop.close(); - } catch (UnsupportedEncodingException e) { + } + catch (UnsupportedEncodingException e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); - } catch (IOException e) { + } + catch (IOException e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); } } public static void createLaunchConfig(URI uri, String baseName, String[] addLines) { try { - PrintStream launch = new PrintStream( - URIConverter.INSTANCE.createOutputStream(uri, null), - false, - "UTF-8"); + PrintStream launch = new PrintStream(URIConverter.INSTANCE.createOutputStream(uri, null), false, "UTF-8"); launch.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); launch.println("<launchConfiguration type=\"org.eclipse.etrice.generator.launch.java.launchConfigurationType\">"); + launch.println("<booleanAttribute key=\"MSC\" value=\"true\"/>"); launch.println("<listAttribute key=\"ModelFiles\">"); - launch.println("<listEntry value=\"${workspace_loc:/"+baseName+"/model/"+baseName+".room}\"/>"); + launch.println("<listEntry value=\"${workspace_loc:/" + baseName + "/model/" + baseName + ".etmap}\"/>"); launch.println("</listAttribute>"); launch.println("<listAttribute key=\"org.eclipse.debug.ui.favoriteGroups\">"); launch.println("<listEntry value=\"org.eclipse.debug.ui.launchGroup.run\"/>"); @@ -421,9 +432,11 @@ public class ProjectCreator { } launch.println("</launchConfiguration>"); launch.close(); - } catch (UnsupportedEncodingException e) { + } + catch (UnsupportedEncodingException e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); - } catch (IOException e) { + } + catch (IOException e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); } } @@ -437,11 +450,9 @@ public class ProjectCreator { * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { - ImageDescriptor desc = RoomActivator.getInstance().getImageRegistry() - .getDescriptor(path); + ImageDescriptor desc = RoomActivator.getInstance().getImageRegistry().getDescriptor(path); if (desc == null) { - desc = RoomActivator.imageDescriptorFromPlugin( - "org.eclipse.etrice.core.room.ui", path); + desc = RoomActivator.imageDescriptorFromPlugin("org.eclipse.etrice.core.room.ui", path); if (desc == null) System.err.println("image not found: " + path); else { diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java index cc15c1f80..3e338b001 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/newwizard/EmptyProjectWizard.java @@ -122,6 +122,18 @@ public class EmptyProjectWizard extends Wizard implements INewWizard { ProjectCreator.createModel(modelURI, baseName); + URI physModelURI = URI.createPlatformResourceURI("/" + + baseName + + "/model/"+baseName+".etphys", true); + ProjectCreator.createPhysicalModel(physModelURI, + baseName); + + URI mapModelURI = URI.createPlatformResourceURI("/" + + baseName + + "/model/"+baseName+".etmap", true); + ProjectCreator.createMappingModel(mapModelURI, + baseName); + ProjectCreator.createBuildProperties(URI.createPlatformResourceURI("/" +baseName+"/build.properties", true), baseName); |