Skip to content

Commit

Permalink
WINDUP-593 Report all unparsable XML file issues in one report - Repo…
Browse files Browse the repository at this point in the history
…rtService#getReportByName()
  • Loading branch information
OndraZizka authored and jsight committed Jan 18, 2016
1 parent bb31a1a commit 69d2f8a
Show file tree
Hide file tree
Showing 33 changed files with 711 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.ocpsoft.rewrite.event.Rewrite;

import com.google.common.collect.Iterables;
import org.jboss.windup.util.exception.WindupException;

/**
* Used to iterate over an implicit or explicit variable defined within the corresponding {@link ConfigurationRuleBuilder#when(Condition)} clause in
Expand Down Expand Up @@ -239,6 +240,7 @@ public void perform(GraphRewrite event, EvaluationContext context)
try
{
for (WindupVertexFrame frame : frames)
try
{
variables.push();
getPayloadManager().setCurrentPayload(variables, frame);
Expand All @@ -251,10 +253,10 @@ public void perform(GraphRewrite event, EvaluationContext context)
((GraphCondition) condition).setInputVariablesName(getPayloadVariableName(event, context));
}
conditionResult = condition.evaluate(event, context);
/*
* Add special clear layer for perform, because condition used one and could have added new variables. The condition result put into
* variables is ignored.
*/
/*
* Add special clear layer for perform, because condition used one and could have added new variables. The condition result put into
* variables is ignored.
*/
variables.push();
getPayloadManager().setCurrentPayload(variables, frame);
}
Expand Down Expand Up @@ -283,6 +285,10 @@ else if (condition != null)
variables.pop();
}
}
catch (Exception ex)
{
throw new WindupException("Failed when iterating " + frame.toPrettyString() + ":\n\t" + ex.getMessage(), ex);
}
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jboss.windup.config.query;


import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
import org.jboss.windup.config.GraphRewrite;

/**
* A Pipes step which gets the vertices behind outgoing edges of given label.
*/
public class InCriterion implements QueryGremlinCriterion
{
private final String edgeLabel;


public InCriterion(String edgeLabel)
{
this.edgeLabel = edgeLabel;
}


@Override
public void query(GraphRewrite event, GremlinPipeline<Vertex, Vertex> pipeline)
{
pipeline.in(edgeLabel);
}


@Override
public String toString()
{
return ".in(" + edgeLabel + ')';
}

}
20 changes: 13 additions & 7 deletions config/api/src/main/java/org/jboss/windup/config/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ public Boolean compute(Vertex argument)
/**
* Begin this {@link Query} with results of a prior {@link Query}, read from the variable with the given name.
*/
public static QueryBuilderFrom from(final String name)
public static QueryBuilderFrom from(final String sourceVarName)
{
final Query query = new Query();
query.setInputVariablesName(name);
query.setInputVariablesName(sourceVarName);
return query;
}

@Override
public ConditionBuilder as(String name)
public ConditionBuilder as(String outputVarName)
{
outputVar = name;
outputVar = outputVarName;
return this;
}

Expand Down Expand Up @@ -190,16 +190,22 @@ public QueryBuilderWith withProperty(String property)
return this;
}

@Override
public QueryBuilderWith withoutProperty(String property)
{
pipelineCriteria.add(new QueryPropertyCriterion(property, QueryPropertyComparisonType.NOT_DEFINED, null));
return this;
}

private static FramesSelector createInitialFramesSelector(final Query query)
{
return new FramesSelector()
{
@Override
public Iterable<WindupVertexFrame> getFrames(GraphRewrite event, EvaluationContext context)
{
GremlinPipeline<Vertex, Vertex> pipeline;
Iterable<Vertex> startingVertices = getStartingVertices(event);
pipeline = new GremlinPipeline<>(startingVertices);
GremlinPipeline<Vertex, Vertex> pipeline = new GremlinPipeline<>(startingVertices);
Set<WindupVertexFrame> frames = new HashSet<>();
for (QueryGremlinCriterion c : query.getPipelineCriteria())
{
Expand Down Expand Up @@ -297,7 +303,7 @@ public String toString()
builder.append("Query");
if (searchType != null)
{
builder.append(".find(").append(searchType.getName()).append(")");
builder.append(".fromType(").append(searchType.getName()).append(")");
}

if (!pipelineCriteria.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public interface QueryBuilderPiped extends ConditionBuilder, QueryBuilderAs
public interface QueryBuilderPiped extends ConditionBuilder, QueryBuilderAs, QueryBuilderWith
{
/**
* Query the selected {@link WindupVertexFrame} instances via {@link Gremlin}. This method can be used to change the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface QueryBuilderWith extends ConditionBuilder, QueryBuilderAs
QueryBuilderWith withProperty(String property, QueryPropertyComparisonType searchType,
Object searchValue);

/**
* Narrow the query to {@link WindupVertexFrame} instances that satisfy the given property comparison.
*/
QueryBuilderWith withoutProperty(String property);

/**
* Narrow the query with the given {@link Predicate}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
public enum QueryPropertyComparisonType
{
EQUALS,
NOT_EQUALS,
CONTAINS_TOKEN,
CONTAINS_ANY_TOKEN,
REGEX,
DEFINED,
NOT_DEFINED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public void query(GraphRewrite event, GremlinPipeline<Vertex, Vertex> pipeline)
case EQUALS:
pipeline.has(this.propertyName, this.searchValue);
break;
case NOT_EQUALS:
pipeline.hasNot(this.propertyName, this.searchValue);
break;
case CONTAINS_TOKEN:
pipeline.has(this.propertyName, Text.CONTAINS, searchValue);
break;
Expand All @@ -43,6 +46,9 @@ public void query(GraphRewrite event, GremlinPipeline<Vertex, Vertex> pipeline)
case DEFINED:
pipeline.has(this.propertyName);
break;
case NOT_DEFINED:
pipeline.hasNot(this.propertyName);
break;
default:
throw new IllegalArgumentException("Unrecognized property query type: " + searchType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static GremlinPipeline<Vertex, Vertex> addPipeFor(GremlinPipeline<Vertex,

public String toString()
{
return ".find(" + searchedClass.getSimpleName() + ")";
return ".formType(" + searchedClass.getSimpleName() + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,21 @@ public TestIterationPayLoadPassProvider()
public Configuration getConfiguration(GraphContext context)
{
Configuration configuration = ConfigurationBuilder.begin()
.addRule()
.when(Query.fromType(TestPayloadModel.class).as("list_variable"))
.perform(Iteration
.over("list_variable").as("single_var")
.perform(new AbstractIterationOperation<TestPayloadModel>()
{
@Override
public void perform(GraphRewrite event, EvaluationContext context,
TestPayloadModel model)
{
modelCounter++;
Assert.assertNotNull(model);
}
})
.endIteration()
);
.addRule()
.when(Query.fromType(TestPayloadModel.class).as("list_variable"))
.perform(Iteration
.over("list_variable").as("single_var")
.perform(new AbstractIterationOperation<TestPayloadModel>()
{
@Override
public void perform(GraphRewrite event, EvaluationContext context, TestPayloadModel model)
{
modelCounter++;
Assert.assertNotNull(model);
}
})
.endIteration()
);
return configuration;
}
// @formatter:on
Expand All @@ -172,28 +171,27 @@ public TestIterationPayLoadNotPassProvider()
public Configuration getConfiguration(GraphContext context)
{
Configuration configuration = ConfigurationBuilder
.begin()
.addRule()
.when(Query.fromType(TestSimple2Model.class).as("do_not_perform")
.and(Query.fromType(TestPayloadModel.class).as("list_variable")))
.perform(Iteration //first iteration
.over("list_variable")
.as("single_var")
.perform(Iteration.over("do_not_perform") //second iteration
.perform(new AbstractIterationOperation<TestPayloadModel>("single_var")
{
@Override
public void perform(GraphRewrite event, EvaluationContext context,
TestPayloadModel model)
{
//should access the outer iteration, not the inner one
modelCounter++;
Assert.assertNotNull(model);
}
}).endIteration())

.endIteration()
);
.begin()
.addRule()
.when(Query.fromType(TestSimple2Model.class).as("do_not_perform")
.and(Query.fromType(TestPayloadModel.class).as("list_variable")))
.perform(Iteration //first iteration
.over("list_variable")
.as("single_var")
.perform(Iteration.over("do_not_perform") //second iteration
.perform(new AbstractIterationOperation<TestPayloadModel>("single_var")
{
@Override
public void perform(GraphRewrite event, EvaluationContext context, TestPayloadModel model)
{
//should access the outer iteration, not the inner one
modelCounter++;
Assert.assertNotNull(model);
}
}).endIteration())

.endIteration()
);
return configuration;
}
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ public void removeTypeFromElement(Class<? extends VertexFrame> kind, Element ele
Class<?> typeHoldingTypeField = getTypeRegistry().getTypeHoldingTypeField(kind);
if (typeHoldingTypeField == null)
return;
String typeFieldName = typeHoldingTypeField.getAnnotation(TypeField.class).value();


TypeValue typeValueAnnotation = kind.getAnnotation(TypeValue.class);
if (typeValueAnnotation == null)
return;

String typeFieldName = typeHoldingTypeField.getAnnotation(TypeField.class).value();
String typeValue = typeValueAnnotation.value();
///String typeValue = getTypeIdentifier(kind);

v.removeProperty(typeFieldName);

for (TitanProperty existingType : v.getProperties(typeFieldName))
Expand All @@ -126,6 +128,19 @@ public void removeTypeFromElement(Class<? extends VertexFrame> kind, Element ele
addSuperclassType(kind, element);
}

/**
* Returns the type identifier for given type - the value in the property discriminating this type.
*/
public static String getTypeIdentifier(Class<? extends VertexFrame> modelInterface)
{
TypeValue typeValueAnnotation = modelInterface.getAnnotation(TypeValue.class);
if (typeValueAnnotation == null)
return null;

return typeValueAnnotation.value();
}


/**
* Adds the type value to the field denoting which type the element represents.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ public interface ProjectModel extends WindupVertexFrame
@GremlinGroovy("it.out('" + PROJECT_MODEL_TO_FILE + "').has('" + FileModel.IS_DIRECTORY + "', false)")
Iterable<FileModel> getFileModelsNoDirectories();

/**
* Gets all contained files that are not directories
*/
@GremlinGroovy("it.out('" + PROJECT_MODEL_TO_FILE + "').has('" + FileModel.PARSE_ERROR + "')")
Iterable<FileModel> getUnparsableFiles();

/**
* Returns the project model that represents the whole application. If this projectModel is the root projectModel, it will return it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public interface FileModel extends ResourceModel
String FILE_PATH = "filePath";
String IS_DIRECTORY = "isDirectory";
String WINDUP_GENERATED = "windupGenerated";
String PRETTY_PATH = "fileModelPrettyPath";
String PRETTY_PATH_WITHIN_PROJECT = "fileModelPrettyPathWithinProject";
String PARSE_ERROR = "parseError";

/**
* Contains the File Name (the last component of the path). Eg, a file /tmp/foo/bar/file.txt would have fileName set to "file.txt"
Expand Down Expand Up @@ -93,6 +96,19 @@ public interface FileModel extends ResourceModel
@Property(SHA1_HASH)
void setSHA1Hash(String sha1Hash);

/**
* Did Windup encounter problems when parsing this file?
*/
@Property(PARSE_ERROR)
String getParseError();

/**
* Contains a SHA1 Hash of the file
*/
@Property(PARSE_ERROR)
void setParseError(String message);


/**
* Parent directory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

/**
* These reports are directly associated with an application, and that application's project model. These can include things like an Application
* Overview report (with various hints, etc) as well as more specific reports (hibernate reports, ejb reports, classloading reports, etc).
* These reports are directly associated with an application, and that application's project model.
* These can include things like an Application Overview report (with various hints, etc)
* as well as more specific reports (hibernate reports, ejb reports, classloading reports, etc).
*
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ public String getReportDirectory()
return path.toAbsolutePath().toString();
}

/**
* Returns the ReportModel with given name.
*/
public <T extends ReportModel> T getReportByName(String name, Class<T> clazz)
{
ReportModel reportM = this.getUniqueByProperty(ReportModel.REPORT_NAME, name);
//if (!(clazz.isAssignableFrom(reportM.getClass())))
try
{
return (T) reportM;
}
catch (ClassCastException ex)
{
throw new WindupException("The vertex is not of expected frame type "+clazz.getName()+": " + reportM.toPrettyString());
}
}

/**
* Gets a unique filename (that has not been used before in the output folder) for this report and sets it on the report model.
*/
Expand Down
Loading

0 comments on commit 69d2f8a

Please sign in to comment.