Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Trying to use JavaIoFileSystemAccess directly(Noob)
Trying to use JavaIoFileSystemAccess directly [message #1220479] Thu, 12 December 2013 04:53 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I've written a Java program which calls my Xtend code generator. There is no grammar involved here. Rather, the Java program looks in a specific folder for Java files matching a specific name pattern and then generates unit test classes corresponding to those matching files (classes).

The example Xtend code generators feature "IFileSystemAccess fsa" as a parameter of the overloaded doGenerate() method. IFileSystemAccess being an Interface it can't be used directly, so I tried implementing class JavaIoFileSystemAccess instead. However I am getting the error:

Exception in thread "main" java.lang.IllegalArgumentException: A slot with name 'DEFAULT_OUTPUT' has not been configured.


Why did I do this? What led me to think this would work? Nothing at all. I'm just guessing! I know nothing of these slots you are talking about.

Here's my Java code:

package com.holycityaudio.spincad;

import java.io.File;
import java.io.FileFilter;

import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;

import com.holycityaudio.spincad.generator.*;

public class GenTestCases {

	public static void main(String[] args) {
		
		JavaIoFileSystemAccess fsa = new JavaIoFileSystemAccess();

		File dir = new File("C:\\Users\\path_to_the_files\\");
		FileFilter fileFilter = new WildcardFileFilter("*Pattern.java");
		File[] files = dir.listFiles(fileFilter);
		SpinCADGenerator sG = new SpinCADGenerator();
		for (int i = 0; i < files.length; i++) {
			
			String pkage = "\\com\\holycityaudio\\SpinCAD\\test\\";
					
			String fileName = files[i].getName().split("Pattern")[0];
			System.out.println(fileName);

			fsa.generateFile(pkage + fileName + "Test.java", sG.toTestCode(fileName));
		}
	}
}


"toTestCode()" lives in my Xtend generator class.
Re: Trying to use JavaIoFileSystemAccess directly [message #1220485 is a reply to message #1220479] Thu, 12 December 2013 06:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
You have to call setoutputconfiguations or setoutputpath

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trying to use JavaIoFileSystemAccess directly [message #1220876 is a reply to message #1220485] Sun, 15 December 2013 04:21 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
Hi Christian,

I could use a few more details.

Here's my modified Java code.

package com.holycityaudio.spincad;

import java.io.File;
import java.io.FileFilter;

import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.generator.OutputConfiguration;

import com.holycityaudio.spincad.generator.*;

public class GenTestCases {

	static String CADBlockPath = "C:\\long_path_to_files\\";

	public static void main(String[] args) {

		JavaIoFileSystemAccess fsa = new JavaIoFileSystemAccess();
		fsa.setOutputPath("outputPath");
		
		File dir = new File(CADBlockPath);
		FileFilter fileFilter = new WildcardFileFilter("*CADBlock.java");
		File[] files = dir.listFiles(fileFilter);
		SpinCADGenerator sG = new SpinCADGenerator();
		if(files != null) {
			for (int i = 0; i < files.length; i++) {

				String fileName = files[i].getName().split("CADBlock")[0];
				System.out.println(fileName);

				CharSequence cS = sG.toTestCode(fileName);

				String youAreI = dir.toURI().toString();
				fsa.generateFile(youAreI, cS);
			}
		}
	}
}


All of my matching source files are getting found properly. However I get the error:

Exception in thread "main" org.eclipse.xtext.util.RuntimeIOException: Could not create directory C:\long_path_to_files\outputPath\file:\C:\long_path_to_files


What am I doing wrong?

GW

[Updated on: Sun, 15 December 2013 04:23]

Report message to a moderator

Re: Trying to use JavaIoFileSystemAccess directly [message #1220879 is a reply to message #1220876] Sun, 15 December 2013 08:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i think it is time to use the debugger.
i know nothing about your machine situation/access restrictions ...

and you do strange things in your code.
the outputpath is the target dir.

so the path you generate to should be relative ...
and the outputpath should be absolute...


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trying to use JavaIoFileSystemAccess directly [message #1220880 is a reply to message #1220879] Sun, 15 December 2013 08:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
P.S: maybe you should use guice to get an instance as well since (depending on what you generate) you will need e.g. and encodingprovider injected.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trying to use JavaIoFileSystemAccess directly [message #1220881 is a reply to message #1220880] Sun, 15 December 2013 09:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
	public static void main(String[] args) {
		JavaIoFileSystemAccess fsa = new JavaIoFileSystemAccess();
		Guice.createInjector(new AbstractGenericModule() {
			
			public Class<? extends IEncodingProvider> bindIEncodingProvider() {
				return IEncodingProvider.Runtime.class;
			}
			
		}).injectMembers(fsa);
		fsa.setOutputPath("dummy");
		fsa.generateFile("xxxx.txt", "contents");

	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trying to use JavaIoFileSystemAccess directly [message #1220887 is a reply to message #1220881] Sun, 15 December 2013 13:53 Go to previous message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
Thank you very much! I don't think I ever would have figured this out by myself. I had been tracing through this with the debugger for a few days, but when you're tracing through a ".class" file it's not possible to see the values of any local variables.

Here's what ultimately worked:

package com.holycityaudio.spincad;

import java.io.File;
import java.io.FileFilter;

import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.parser.IEncodingProvider;
import org.eclipse.xtext.service.AbstractGenericModule;

import com.google.inject.Guice;
import com.holycityaudio.spincad.generator.*;

public class GenTestCases {

	static String CADBlockPath = "C:\\path_to_source_files\\";
	static String TestBlockPath = "C:\\path_to_output_files\\";

	public static void main(String[] args) {

		JavaIoFileSystemAccess fsa = new JavaIoFileSystemAccess();
		fsa.setOutputPath(TestBlockPath);
		
		File dir = new File(CADBlockPath);
		FileFilter fileFilter = new WildcardFileFilter("*CADBlock.java");
		File[] files = dir.listFiles(fileFilter);
		SpinCADGenerator sG = new SpinCADGenerator();
		
		Guice.createInjector(new AbstractGenericModule() {
			
			public Class<? extends IEncodingProvider> bindIEncodingProvider() {
				return IEncodingProvider.Runtime.class;
			}
			
		}).injectMembers(fsa);
		
		if(files != null) {
			for (int i = 0; i < files.length; i++) {

				String fileName = files[i].getName().split("CADBlock")[0];
				System.out.println(fileName);

				CharSequence cS = sG.toTestCode(fileName);

				fsa.generateFile(fileName + "Test.java", cS);
			}
		}
	}
}

[Updated on: Sun, 15 December 2013 13:54]

Report message to a moderator

Previous Topic:MWE generator can't find resource
Next Topic:More proxy resolving issues
Goto Forum:
  


Current Time: Thu Mar 28 15:09:18 GMT 2024

Powered by FUDForum. Page generated in 0.05485 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top