Skip to content

Commit

Permalink
use Properties instead of PropertyResourceBundle for cleaner API
Browse files Browse the repository at this point in the history
  • Loading branch information
abelhegedus committed Feb 10, 2017
1 parent 404e6d1 commit 6ff3c24
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.google.common.collect.Lists
import java.util.ArrayList
import java.util.List
import java.util.PropertyResourceBundle
import java.util.Properties
import java.util.stream.Collectors
import org.eclipse.emf.codegen.ecore.genmodel.GenBase
import org.eclipse.emf.codegen.ecore.genmodel.GenClass
Expand Down Expand Up @@ -65,12 +65,13 @@ abstract class CoreDocGen extends DocGenUtil implements IDocGenerator{
protected GenPackage genPkg
protected StringBuilder builder
protected List<String> filter
protected PropertyResourceBundle options
protected Properties options

override generateDocument(StringBuilder sb, EObject root, List<String> filters, PropertyResourceBundle options) {
override generateDocument(StringBuilder sb, EObject root, List<String> filters, Properties options) {
this.builder = sb
this.filter = Lists::newArrayList(filters)
this.options = options

init

if (root instanceof GenModel) {
Expand Down Expand Up @@ -411,15 +412,15 @@ abstract class CoreDocGen extends DocGenUtil implements IDocGenerator{
def protected optionActive(String option){
var optVal = ""
if (options != null && options.containsKey(option)) {
optVal = options.getString(option)
optVal = options.getProperty(option)
}
optVal.trim.equals("true")
}

def protected optionValue(String option){
var optVal = ""
if (options != null) {
optVal = options.getString(option)
if (options != null && options.containsKey(option)) {
optVal = options.getProperty(option)
}
return optVal
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hu.bme.mit.documentation.generator.ecore;

import java.util.List;
import java.util.PropertyResourceBundle;
import java.util.Properties;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
Expand All @@ -24,5 +24,5 @@ public interface IDocGenerator {
* @param nameRefFilter
* @param options
*/
void generateDocument(final StringBuilder sb, final EObject root, final List<String> filter, final PropertyResourceBundle options);
void generateDocument(final StringBuilder sb, final EObject root, final List<String> filter, final Properties options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.PropertyResourceBundle;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
Expand Down Expand Up @@ -39,7 +39,7 @@ public static void generateDocForModel(URI modelPath, File outputFile, File opti

if (root != null) {
try (FileOutputStream fos = new FileOutputStream(outputFile, false)) {
PropertyResourceBundle options = getResourceBundle(optionFile);
Properties options = getProperties(optionFile);
List<String> filter = getFilters(options);
StringBuilder sb = new StringBuilder();
docGen.generateDocument(sb, root, filter, options);
Expand All @@ -62,10 +62,11 @@ private static EObject getRootEObject(URI modelPath) throws IOException {
return null;
}

private static PropertyResourceBundle getResourceBundle(File filterFile) {
private static Properties getProperties(File filterFile) {
if(filterFile!=null && filterFile.exists()){
try (InputStream fis = new FileInputStream(filterFile)) {
PropertyResourceBundle bundle = new PropertyResourceBundle(fis);
Properties bundle = new Properties();
bundle.load(fis);
return bundle;
}
catch (IOException e) {
Expand All @@ -76,8 +77,8 @@ private static PropertyResourceBundle getResourceBundle(File filterFile) {
return null;
}

private static List<String> getFilters(PropertyResourceBundle bundle) {
List<String> filter = getOptionValues(bundle != null ? bundle.getString("filters") : null);
private static List<String> getFilters(Properties bundle) {
List<String> filter = getOptionValues(bundle != null ? bundle.getProperty("filters") : null);
filter.add("http://www.eclipse.org/emf/2002/Ecore");
return filter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package hu.qgears.xtextdoc.generator;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import org.eclipse.emf.ecore.EClassifier;
Expand All @@ -23,8 +25,6 @@
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.resource.XtextResource;

import com.google.common.collect.ImmutableList;

import hu.bme.mit.documentation.generator.ecore.CoreDocGen;
import hu.bme.mit.documentation.generator.ecore.EPackageDocGenHtml;

Expand Down Expand Up @@ -67,11 +67,13 @@ private void generateOutput() throws IOException {
}
private void generateMetaModel()
{
Properties properties = new Properties();
properties.setProperty(CoreDocGen.SKIP_HEADER, "true");
for(EPackage p:packages)
{
EPackageDocGenHtml h=new EPackageDocGenHtml();
StringBuilder sb=new StringBuilder();
h.generateDocument(sb, p, ImmutableList.of(CoreDocGen.SKIP_HEADER), null);
h.generateDocument(sb, p, Collections.<String>emptyList(), properties);
rtcout.write(sb.toString());
System.out.println(""+p);
}
Expand Down

0 comments on commit 6ff3c24

Please sign in to comment.