Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Target folder outside workspace in absolute path(Generation tweaks)
[Acceleo] Target folder outside workspace in absolute path [message #1095526] Tue, 27 August 2013 03:10 Go to next message
Johan Hardy is currently offline Johan Hardy
Messages: 27
Registered: December 2012
Junior Member
Dear all,

I have developed a C code generator based on UML2 (plus a functional C profile). The generator works very well and I also have a UI launcher with the classic popupmenu (proposed by OBEO).

In the method "run", performing the popupmenu action, I'm trying to change the target (IContainer) such that the code is generated outside the workspace. For instance, it can be "C:/", "D:/users/me/data" or a network drive.

The way to get the absolute path is solved with "browse" dialog I have implemented in a corner. My problem is to convert (in some way) the string of the absolute path such that the generator (GenerateCText) is able to generate text anywhere.

IContainer target = model.getProject().getFolder("generated_code");
GenerateCText generator = new GenerateCText(modelURI, target, getArguments());
generator.doGenerate(monitor);


	public void doGenerate(IProgressMonitor monitor) throws IOException {
		if (!targetFolder.getLocation().toFile().exists()) {
			targetFolder.getLocation().toFile().mkdirs();
		}
		
		monitor.subTask("Loading ...");
		com.spacebel.acceleo.uml.to.c.main.GenerateC generatorC = new com.spacebel.acceleo.uml.to.c.main.GenerateC(modelURI, targetFolder.getLocation().toFile(), arguments);
		monitor.worked(1);
		String generationID = org.eclipse.acceleo.engine.utils.AcceleoLaunchingUtil.computeUIProjectID("com.spacebel.acceleo.uml.to.c", "com.spacebel.acceleo.uml.to.c.main.GenerateC", modelURI.toString(), targetFolder.getFullPath().toString(), new ArrayList<String>());
		generatorC.setGenerationID(generationID);
		generatorC.doGenerate(BasicMonitor.toMonitor(monitor));
	}


I have tried to change the GenerateCText constructor with a IPath instead of a IContainer for the target without success. I hope that it doesn't require to change the AbstractAcceleoGenerator.

In advance, thanks for any propositions;
Re: [Acceleo] Target folder outside workspace in absolute path [message #1095986 is a reply to message #1095526] Tue, 27 August 2013 16:19 Go to previous message
Johan Hardy is currently offline Johan Hardy
Messages: 27
Registered: December 2012
Junior Member
I finally found the solution myselft. Not sure it is the best ..

	public void run(IAction action) {
		if (files != null) {
			IRunnableWithProgress operation = new IRunnableWithProgress() {
				public void run(IProgressMonitor monitor) {
					try {
						Iterator<IFile> filesIt = files.iterator();
						while (filesIt.hasNext()) {
							IFile model = (IFile)filesIt.next();
							URI modelURI = URI.createPlatformResourceURI(model.getFullPath().toString(), true);
							try {
								IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(model.getFullPath().uptoSegment(1).toString());
								String targetLocation = project.getPersistentProperty(new QualifiedName("", C_DESTINATION_PROPERTY));
								GenerateCText generator = new GenerateCText(modelURI, targetLocation, getArguments());
								generator.doGenerate(monitor);
							} catch (IOException e) {
								IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
								Activator.getDefault().getLog().log(status);
							} finally {
								model.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
							}
						}
					} catch (CoreException e) {
						IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
						Activator.getDefault().getLog().log(status);
					}
				}
			};
			try {
				PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
			} catch (InvocationTargetException e) {
				IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
				Activator.getDefault().getLog().log(status);
			} catch (InterruptedException e) {
				IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
				Activator.getDefault().getLog().log(status);
			}
		}
	}

[Updated on: Wed, 28 August 2013 03:55]

Report message to a moderator

Previous Topic:[Xpand] Stereotype problem
Next Topic:[Acceleo] How to get the value of a property (tagged value)
Goto Forum:
  


Current Time: Wed Jul 30 01:09:44 EDT 2014

Powered by FUDForum. Page generated in 0.33642 seconds