Skip to content

Commit

Permalink
Return error information if code generation fails, fixes eclipse-vort…
Browse files Browse the repository at this point in the history
…o#331

Signed-off-by: Ying Shaodong <[email protected]>
  • Loading branch information
gavinying committed Jul 12, 2016
1 parent deec1f3 commit 8fb54a6
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public ManifestFileModule(ITemplate<ProjectMetaData> template) {
}

public void generate(ProjectMetaData metaData, InvocationContext invocationContext, IGeneratedWriter outputter) {
Generated generatedPom = new Generated(FILE_NAME, FOLDER_NAME,
template.getContent(metaData,invocationContext));
outputter.write(generatedPom);
Generated generatedPom;
try {
generatedPom = new Generated(FILE_NAME, FOLDER_NAME, template.getContent(metaData,invocationContext));
outputter.write(generatedPom);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public PluginBuildFileModule(ITemplate<Context> template) {
}

public void generate(Context metaData, InvocationContext invocationContext, IGeneratedWriter outputter) {
Generated generatedBuildFile = new Generated(FILE_NAME, null,
template.getContent(metaData,invocationContext));
outputter.write(generatedBuildFile);
Generated generatedBuildFile;
try {
generatedBuildFile = new Generated(FILE_NAME, null, template.getContent(metaData,invocationContext));
outputter.write(generatedBuildFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ public PomFileModule(ITemplate<Context> template) {
}

public void generate(Context model, InvocationContext invocationContext, IGeneratedWriter outputter) {
Generated generatedPom = new Generated(FILE_NAME, null,
template.getContent(model,invocationContext));

outputter.write(generatedPom);
Generated generatedPom;
try {
generatedPom = new Generated(FILE_NAME, null, template.getContent(model,invocationContext));
outputter.write(generatedPom);
} catch (Exception e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public abstract class AbstractTemplateGeneratorTask<InformationModelFragment> im

public void generate(final InformationModelFragment fragmentModel, final InvocationContext context, final IGeneratedWriter writer) {

Generated generated = new Generated(getFileName(fragmentModel), getPath(fragmentModel), getTemplate().getContent(fragmentModel,context));
Generated generated;
try {
generated = new Generated(getFileName(fragmentModel), getPath(fragmentModel), getTemplate().getContent(fragmentModel,context));
} catch (Exception e) {
generated = new Generated("error.log", getPath(fragmentModel), e.getMessage());
}
writer.write(generated);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ public void generate(InformationModel ctx, InvocationContext context, IGenerated

for (Type type : allTypesUsedInModel) {
if (type instanceof Entity) {
writer.write(new Generated(entityTemplate.getFileName((Entity)type),entityTemplate.getPath((Entity)type),entityTemplate.getContent((Entity)type,context)));
try {
writer.write(new Generated(entityTemplate.getFileName((Entity)type),entityTemplate.getPath((Entity)type),entityTemplate.getContent((Entity)type,context)));
} catch (Exception e) {
e.printStackTrace();
}
} else if (type instanceof Enum) {
writer.write(new Generated(enumTemplate.getFileName((Enum)type),enumTemplate.getPath((Enum)type),enumTemplate.getContent((Enum)type,context)));
try {
writer.write(new Generated(enumTemplate.getFileName((Enum)type),enumTemplate.getPath((Enum)type),enumTemplate.getContent((Enum)type,context)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public interface ITemplate<Element> {
* @param context
* @return generated content for the specified context
*/
String getContent(Element element, InvocationContext context);
String getContent(Element element, InvocationContext context) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel
*/
class FunctionBlockLeshanTemplate extends LWM2MConstants implements ITemplate<FunctionblockModel> {

override getContent(FunctionblockModel model,InvocationContext context) {
override getContent(FunctionblockModel model,InvocationContext context) throws Exception {

'''
package examples.leshan.client;
Expand All @@ -37,6 +37,8 @@ import org.eclipse.leshan.core.response.ReadResponse;
public class «model.name» extends BaseInstanceEnabler {
«IF model.functionblock.status != null»
«FOR statusProperty : model.functionblock.status.properties»
/**
* «statusProperty.description»
Expand Down Expand Up @@ -101,6 +103,8 @@ public class «model.name» extends BaseInstanceEnabler {
}

}

«ENDIF»

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public final class ModuleUtil {
private static final String XML_SRC_LOCATION = "/objects/";
private static final String LESHAN_SRC_LOCATION = "/leshan";
private static final String LESHAN_SRC_LOCATION = "/leshan/";

private ModuleUtil() {
}
Expand Down

0 comments on commit 8fb54a6

Please sign in to comment.