summaryrefslogtreecommitdiff
path: root/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/GeneratorFileSystemAccess.java
blob: 205a63508001030d95de95f3407ff34067bb14d7 (plain)
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
package org.genivi.commonapi.core.generator;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.xtext.generator.JavaIoFileSystemAccess;


/**
 * This class adds the feature to printout the generated files to the JavaIoFileSystemAccess implementation.
 */
public class GeneratorFileSystemAccess extends JavaIoFileSystemAccess {

	private Set<String> fileList = new HashSet<String>();
	
	public GeneratorFileSystemAccess() {
		super();
	}
	
	public void clearFileList() {
		fileList.clear();
	}
	
	/**
	 * Call the base class method and store the filename in the list
	 * @param fileName using '/' as file separator
	 * @param contents the to-be-written contents.
	 */	
	public void generateFile(String fileName, CharSequence contents) {
		// do not generate a file if the contents is empty (feature: suppress code generation)
		if(contents.length() > 0) {
			super.generateFile(fileName, contents);
		}
		addFilePath(fileName, "");
	}
	
	/**
	 * Call the base class method and store the filename in the list
	 * @param fileName using '/' as file separator
	 * @param outputConfigurationName the name of the output configuration
	 * @param contents the to-be-written contents.
	 */
	public void generateFile(String fileName, String outputConfigurationName, CharSequence contents) {
		if(contents.length() > 0) {
			super.generateFile(fileName, outputConfigurationName, contents);
		}
		addFilePath(fileName, outputConfigurationName);
	}
	
	public void dumpGeneratedFiles() {
		for(String name : fileList) {
			System.out.println(name);
		}
	}
	
	public void addFilePath(String fileName, String outputConfigurationName) {
		String dirName = "";
		if(!outputConfigurationName.isEmpty()) {
			dirName = super.getOutputConfig(outputConfigurationName).getOutputDirectory();
		}
		if(!dirName.endsWith("/")) {
			dirName += "/";
		}
		fileList.add(dirName + fileName);		
	}
}