Skip to content

Commit

Permalink
WINDUP-502: EJB report should link class names to Java source files
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight authored and lincolnthree committed Feb 12, 2015
1 parent ed7e233 commit 08913bf
Show file tree
Hide file tree
Showing 29 changed files with 359 additions and 89 deletions.
Expand Up @@ -62,6 +62,36 @@ public void addTypeToRegistry(Class<? extends WindupVertexFrame> wvf)
}
}

/**
* Remove the given type from the provided {@link Element}.
*/
public void removeTypeFromElement(Class<? extends VertexFrame> kind, Element element)
{
StandardVertex v = GraphTypeManager.asTitanVertex(element);
Class<?> typeHoldingTypeField = typeRegistry.getTypeHoldingTypeField(kind);
if (typeHoldingTypeField == null)
return;

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

String typeFieldName = typeHoldingTypeField.getAnnotation(TypeField.class).value();
String typeValue = typeValueAnnotation.value();
v.removeProperty(typeFieldName);

for (TitanProperty existingType : v.getProperties(typeFieldName))
{
if (!existingType.getValue().toString().equals(typeValue))
{
v.addProperty(typeFieldName, existingType.getValue());
}
}

v.addProperty(typeFieldName, typeValue);
addSuperclassType(kind, element);
}

/**
* Adds the type value to the field denoting which type the element represents.
*/
Expand All @@ -79,9 +109,9 @@ public void addTypeToElement(Class<? extends VertexFrame> kind, Element element)
String typeFieldName = typeHoldingTypeField.getAnnotation(TypeField.class).value();
String typeValue = typeValueAnnotation.value();

for (TitanProperty existingTypes : v.getProperties(typeFieldName))
for (TitanProperty existingType : v.getProperties(typeFieldName))
{
if (existingTypes.getValue().toString().equals(typeValue))
if (existingType.getValue().toString().equals(typeValue))
{
// this is already in the list, so just exit now
return;
Expand Down
Expand Up @@ -24,6 +24,10 @@
import com.tinkerpop.frames.modules.AbstractModule;
import com.tinkerpop.frames.modules.Module;

/**
* This is used to provide a registry of {@link WindupVertexFrame} subclasses for integration with Tinkerpop Frames.
*
*/
@Singleton
public class GraphTypeRegistry
{
Expand All @@ -35,11 +39,22 @@ public class GraphTypeRegistry
@Inject
private GraphTypeManager graphTypeManager;

/**
* Add the provided type to the given {@link Element}.
*/
public void addTypeToElement(Class<? extends VertexFrame> kind, Element element)
{
graphTypeManager.addTypeToElement(kind, element);
}

/**
* Remove the provided type from the given {@link Element}.
*/
public void removeTypeFromElement(Class<? extends WindupVertexFrame> kind, Element element)
{
graphTypeManager.removeTypeFromElement(kind, element);
}

@PostConstruct
public void init()
{
Expand Down
Expand Up @@ -2,6 +2,7 @@

import org.jboss.windup.graph.model.WindupVertexFrame;

import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

/**
Expand All @@ -13,5 +14,17 @@
public interface SourceFileModel extends WindupVertexFrame
{
public static final String TYPE = "SourceFileModel";
public static final String GENERATE_SOURCE_REPORT = "generateSourceReport";

/**
* Contains a boolean indicating that the reporting system should generate a source report for this {@link SourceFileModel}.
*/
@Property(GENERATE_SOURCE_REPORT)
Boolean isGenerateSourceReport();

/**
* Contains a boolean indicating that the reporting system should generate a source report for this {@link SourceFileModel}.
*/
@Property(GENERATE_SOURCE_REPORT)
void setGenerateSourceReport(boolean generateSourceReport);
}
Expand Up @@ -79,8 +79,7 @@ public T createInMemory()
}

/**
* Create a new instance of the given {@link WindupVertexFrame} type. The ID is generated by the underlying graph
* database.
* Create a new instance of the given {@link WindupVertexFrame} type. The ID is generated by the underlying graph database.
*/
@Override
public T create()
Expand Down Expand Up @@ -314,6 +313,17 @@ public static <T extends WindupVertexFrame> T addTypeToModel(GraphContext graphC
return graphContext.getFramed().frame(vertex, type);
}

/**
* Removes the specified type from the frame.
*/
public static <T extends WindupVertexFrame> T removeTypeFromModel(GraphContext graphContext, WindupVertexFrame frame,
Class<T> type)
{
Vertex vertex = frame.asVertex();
graphContext.getGraphTypeRegistry().removeTypeFromElement(type, vertex);
return graphContext.getFramed().frame(vertex, type);
}

@Override
public void remove(final T model)
{
Expand Down

This file was deleted.

@@ -0,0 +1,15 @@
package org.jboss.windup.graph.service;

import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;

/**
* Provides useful methods for querying, creating, and updating {@link ProjectModel} instances.
*/
public class ProjectService extends GraphService<ProjectModel>
{
public ProjectService(GraphContext context)
{
super(context, ProjectModel.class);
}
}
Expand Up @@ -8,6 +8,7 @@
import org.jboss.forge.furnace.util.Assert;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.parameters.ParameterizedIterationOperation;
import org.jboss.windup.graph.model.resource.SourceFileModel;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.LinkModel;
Expand Down Expand Up @@ -95,6 +96,8 @@ public void performParameterized(GraphRewrite event, EvaluationContext context,
hintModel.addLink(linkModel);
}

if (locationModel.getFile() instanceof SourceFileModel)
((SourceFileModel) locationModel.getFile()).setGenerateSourceReport(true);
log.info("Hint added to " + locationModel.getFile().getPrettyPathWithinProject() + " [" + this + "] ");
}

Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.graph.model.resource.SourceFileModel;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.reporting.config.Link;
import org.jboss.windup.reporting.model.ClassificationModel;
Expand Down Expand Up @@ -158,6 +159,8 @@ public void performParameterized(GraphRewrite event, EvaluationContext context,
return;
}
}
if (payload instanceof SourceFileModel)
((SourceFileModel) payload).setGenerateSourceReport(true);
classification.addFileModel(payload);
log.info("Classification added to " + payload.getPrettyPathWithinProject() + " [" + this + "] ");
}
Expand Down
Expand Up @@ -5,6 +5,7 @@
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.graph.model.resource.SourceFileModel;
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.TechnologyTagLevel;
Expand All @@ -16,10 +17,10 @@
import com.tinkerpop.gremlin.java.GremlinPipeline;

/**
* This provides a helper class that can be used in a Windup Query call to execute a Gremlin search returning all
* FileModels that have associated {@link FileLocationModel}s or @{link ClassificationModel}s.
* This provides a helper class that can be used in a Windup Query call to execute a Gremlin search returning all FileModels that have associated
* {@link FileLocationModel}s or @{link ClassificationModel}s.
*/
public class FindClassifiedFilesGremlinCriterion implements QueryGremlinCriterion
public class FindSourceReportFilesGremlinCriterion implements QueryGremlinCriterion
{
@SuppressWarnings("unchecked")
@Override
Expand Down Expand Up @@ -48,7 +49,13 @@ public void query(GraphRewrite event, GremlinPipeline<Vertex, Vertex> pipeline)
.has(TechnologyTagModel.LEVEL, TechnologyTagLevel.IMPORTANT.toString())
.back("fileModel3");

// Also return SourceFileModel results with the generate source flag set to true
GremlinPipeline<Vertex, Vertex> generateSourceReportPropertyPipeline = new GremlinPipeline<Vertex, Vertex>(
context.getQuery().type(SourceFileModel.class).vertices());
generateSourceReportPropertyPipeline
.has(SourceFileModel.GENERATE_SOURCE_REPORT, true);

// combine these to get all file models that have either classifications or blacklists
pipeline.or(hintPipeline, classificationPipeline, technologyTagPipeline);
pipeline.or(hintPipeline, classificationPipeline, technologyTagPipeline, generateSourceReportPropertyPipeline);
}
}
Expand Up @@ -58,8 +58,7 @@ public Object exec(@SuppressWarnings("rawtypes") List arguments) throws Template
}
StringModel stringModelArg = (StringModel) arguments.get(0);
FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
SourceReportModel result = sourceReportService
.getSourceReportForFileModel(fileModel);
SourceReportModel result = sourceReportService.getSourceReportForFileModel(fileModel);
ExecutionStatistics.get().end(NAME);
return result;
}
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.jboss.windup.reporting.model.ReportFileModel;
import org.jboss.windup.reporting.model.TemplateType;
import org.jboss.windup.reporting.model.source.SourceReportModel;
import org.jboss.windup.reporting.query.FindClassifiedFilesGremlinCriterion;
import org.jboss.windup.reporting.query.FindSourceReportFilesGremlinCriterion;
import org.jboss.windup.reporting.service.ApplicationReportService;
import org.jboss.windup.reporting.service.ReportService;
import org.jboss.windup.reporting.service.SourceReportModelService;
Expand Down Expand Up @@ -62,8 +62,7 @@ public Configuration getConfiguration(GraphContext context)
/*
* Find all files for which there is at least one classification or blacklist
*/
Condition finder = Query.fromType(SourceFileModel.class)
.piped(new FindClassifiedFilesGremlinCriterion());
Condition finder = Query.fromType(SourceFileModel.class).piped(new FindSourceReportFilesGremlinCriterion());

GraphOperation addSourceReport = new AbstractIterationOperation<FileModel>()
{
Expand Down
Expand Up @@ -15,7 +15,7 @@
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.GraphContextFactory;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.service.ProjectModelService;
import org.jboss.windup.graph.service.ProjectService;
import org.jboss.windup.reporting.model.ApplicationReportModel;
import org.jboss.windup.reporting.model.ApplicationReportIndexModel;
import org.jboss.windup.reporting.service.ApplicationReportService;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void testGetApplicationReportsForProjectModelSortedByPriority() throws IO
{
try (GraphContext context = factory.create())
{
ProjectModel projectModel = new ProjectModelService(context).create();
ProjectModel projectModel = new ProjectService(context).create();
ApplicationReportService applicationReportService = new ApplicationReportService(context);

ApplicationReportModel m1 = applicationReportService.create();
Expand Down
Expand Up @@ -21,7 +21,7 @@
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.TechnologyTagLevel;
import org.jboss.windup.reporting.query.FindClassifiedFilesGremlinCriterion;
import org.jboss.windup.reporting.query.FindSourceReportFilesGremlinCriterion;
import org.jboss.windup.reporting.query.FindFilesNotClassifiedOrHintedGremlinCriterion;
import org.jboss.windup.reporting.service.TechnologyTagService;
import org.junit.After;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void testFindingClassifiedFiles() throws Exception
GraphRewrite event = new GraphRewrite(context);

// manually execute this criterion (this just adds things to the pipeline)
new FindClassifiedFilesGremlinCriterion().query(event, pipeline);
new FindSourceReportFilesGremlinCriterion().query(event, pipeline);

List<FileModel> fileModels = new ArrayList<>();
for (Vertex v : pipeline)
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.graph.model.resource.SourceFileModel;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.graph.service.Service;
import org.jboss.windup.rules.apps.java.condition.JavaClass;
Expand Down Expand Up @@ -100,6 +101,7 @@ public void perform(GraphRewrite event, EvaluationContext context, JavaTypeRefer

private void extractEJBMetadata(GraphRewrite event, JavaTypeReferenceModel javaTypeReference)
{
((SourceFileModel) javaTypeReference.getFile()).setGenerateSourceReport(true);
JavaAnnotationTypeReferenceModel annotationTypeReference = (JavaAnnotationTypeReferenceModel) javaTypeReference;

JavaClassModel ejbClass = getJavaClass(javaTypeReference);
Expand All @@ -116,6 +118,7 @@ private void extractEJBMetadata(GraphRewrite event, JavaTypeReferenceModel javaT

private void extractEntityBeanMetadata(GraphRewrite event, JavaTypeReferenceModel entityTypeReference)
{
((SourceFileModel) entityTypeReference.getFile()).setGenerateSourceReport(true);
JavaAnnotationTypeReferenceModel entityAnnotationTypeReference = (JavaAnnotationTypeReferenceModel) entityTypeReference;
JavaAnnotationTypeReferenceModel tableAnnotationTypeReference = null;
for (WindupVertexFrame annotationTypeReferenceBase : Variables.instance(event).findVariable(TABLE_ANNOTATIONS_LIST))
Expand Down Expand Up @@ -152,6 +155,7 @@ private void extractEntityBeanMetadata(GraphRewrite event, JavaTypeReferenceMode

private void extractMessageDrivenMetadata(GraphRewrite event, JavaTypeReferenceModel javaTypeReference)
{
((SourceFileModel) javaTypeReference.getFile()).setGenerateSourceReport(true);
JavaAnnotationTypeReferenceModel annotationTypeReference = (JavaAnnotationTypeReferenceModel) javaTypeReference;

JavaClassModel ejbClass = getJavaClass(javaTypeReference);
Expand Down

0 comments on commit 08913bf

Please sign in to comment.