Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Trying to use JavaIoFileSystemAccess directly(Noob)
Trying to use JavaIoFileSystemAccess directly [message #1220479] Wed, 11 December 2013 23:53 Go to next message
Eclipse UserFriend
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 01:46 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Trying to use JavaIoFileSystemAccess directly [message #1220876 is a reply to message #1220485] Sat, 14 December 2013 23:21 Go to previous messageGo to next message
Eclipse UserFriend
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: Sat, 14 December 2013 23:23] by Moderator

Re: Trying to use JavaIoFileSystemAccess directly [message #1220879 is a reply to message #1220876] Sun, 15 December 2013 03:55 Go to previous messageGo to next message
Eclipse UserFriend
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...
Re: Trying to use JavaIoFileSystemAccess directly [message #1220880 is a reply to message #1220879] Sun, 15 December 2013 03:58 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Trying to use JavaIoFileSystemAccess directly [message #1220881 is a reply to message #1220880] Sun, 15 December 2013 04:03 Go to previous messageGo to next message
Eclipse UserFriend
	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");

	}
Re: Trying to use JavaIoFileSystemAccess directly [message #1220887 is a reply to message #1220881] Sun, 15 December 2013 08:53 Go to previous message
Eclipse UserFriend
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 08:54] by Moderator

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


Current Time: Mon Jul 07 10:08:14 EDT 2025

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

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

Back to the top