Skip to content

Commit

Permalink
Merge pull request #207 from jsight/WINDUP-214
Browse files Browse the repository at this point in the history
WINDUP-214: Add Story Points to Windup 2 application report
  • Loading branch information
jsight committed Aug 19, 2014
2 parents 43e2c94 + 5c4439c commit 961ca4b
Show file tree
Hide file tree
Showing 19 changed files with 453 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.nio.file.Paths;

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.service.GraphService;

import com.thinkaurelius.titan.core.attribute.Cmp;
import com.thinkaurelius.titan.core.attribute.Text;
import com.thinkaurelius.titan.util.datastructures.IterablesUtil;

Expand Down Expand Up @@ -48,7 +46,7 @@ public FileModel findByPath(String filePath)
{
// make the path absolute (as we only store absolute paths)
filePath = Paths.get(filePath).toAbsolutePath().toString();
return getUniqueByProperty(FileModel.PROPERTY_FILE_PATH, filePath);
return getUniqueByProperty(FileModel.FILE_PATH, filePath);
}

public Iterable<FileModel> findArchiveEntryWithExtension(String... values)
Expand Down Expand Up @@ -78,6 +76,6 @@ public Iterable<FileModel> findArchiveEntryWithExtension(String... values)
}

return getGraphContext().getQuery().type(FileModel.class)
.has("filePath", Text.REGEX, regex).vertices(FileModel.class);
.has("filePath", Text.REGEX, regex).vertices(FileModel.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@
@TypeValue("ProjectModel")
public interface ProjectModel extends WindupVertexFrame
{
public static final String PROPERTY_SOURCE_BASED = "sourceBased";
public static final String PROPERTY_DESCRIPTION = "description";
public static final String PROPERTY_NAME = "name";
public static final String PROPERTY_VERSION = "version";
public static final String PROPERTY_PROJECT_TYPE = "projectType";
public static final String DEPENDENCY = "dependency";
public static final String PARENT_PROJECT = "parentProject";
public static final String ROOT_FILE_MODEL = "rootFileModel";
public static final String PROJECT_MODEL_TO_FILE = "projectModelToFile";
public static final String SOURCE_BASED = "sourceBased";
public static final String DESCRIPTION = "description";
public static final String NAME = "name";
public static final String VERSION = "version";
public static final String PROJECT_TYPE = "projectType";

/**
* This represents the root directory (in the case of a source-based analysis) or root archive (for binary analysis)
* containing this particular project.
*
*/
@Adjacency(label = "rootFileModel", direction = Direction.OUT)
@Adjacency(label = ROOT_FILE_MODEL, direction = Direction.OUT)
public void setRootFileModel(FileModel fileModel);

@Adjacency(label = "rootFileModel", direction = Direction.OUT)
@Adjacency(label = ROOT_FILE_MODEL, direction = Direction.OUT)
public FileModel getRootFileModel();

/**
Expand All @@ -42,76 +46,76 @@ public interface ProjectModel extends WindupVertexFrame
* analysis).
*
*/
@Property(PROPERTY_SOURCE_BASED)
@Property(SOURCE_BASED)
void setSourceBased(boolean sourceBased);

@Property(PROPERTY_SOURCE_BASED)
@Property(SOURCE_BASED)
boolean isSourceBased();

/**
* Indicates the project's artifact type (jar, war, ear, etc)
*/
@Property(PROPERTY_PROJECT_TYPE)
@Property(PROJECT_TYPE)
void setProjectType(String projectType);

@Property(PROPERTY_PROJECT_TYPE)
@Property(PROJECT_TYPE)
String getProjectType();

@Property(PROPERTY_VERSION)
@Property(VERSION)
public String getVersion();

@Property(PROPERTY_VERSION)
@Property(VERSION)
public void setVersion(String version);

@Property(PROPERTY_NAME)
@Property(NAME)
public String getName();

@Property(PROPERTY_NAME)
@Property(NAME)
public void setName(String name);

@Property(PROPERTY_DESCRIPTION)
@Property(DESCRIPTION)
public String getDescription();

@Property(PROPERTY_DESCRIPTION)
@Property(DESCRIPTION)
public void setDescription(String description);

/**
* The parent ProjectModel, or null if no parent is present
*
*/
@Adjacency(label = "parentProject", direction = Direction.OUT)
@Adjacency(label = PARENT_PROJECT, direction = Direction.OUT)
public void setParentProject(ProjectModel maven);

@Adjacency(label = "parentProject", direction = Direction.OUT)
@Adjacency(label = PARENT_PROJECT, direction = Direction.OUT)
public ProjectModel getParentProject();

/**
* A list of child projects
*/
@Adjacency(label = "parentProject", direction = Direction.IN)
@Adjacency(label = PARENT_PROJECT, direction = Direction.IN)
public void addChildProject(ProjectModel maven);

@Adjacency(label = "parentProject", direction = Direction.IN)
@Adjacency(label = PARENT_PROJECT, direction = Direction.IN)
public Iterable<ProjectModel> getChildProjects();

/**
* Project dependencies, as well as metadata about those deps.
*/
@Adjacency(label = "dependency", direction = Direction.OUT)
@Adjacency(label = DEPENDENCY, direction = Direction.OUT)
public void addDependency(ProjectDependencyModel maven);

@Adjacency(label = "dependency", direction = Direction.OUT)
@Adjacency(label = DEPENDENCY, direction = Direction.OUT)
public Iterable<ProjectDependencyModel> getDependencies();

@Adjacency(label = "projectModelToFile", direction = Direction.OUT)
@Adjacency(label = PROJECT_MODEL_TO_FILE, direction = Direction.OUT)
public Iterable<FileModel> getFileModels();

@Adjacency(label = "projectModelToFile", direction = Direction.OUT)
@Adjacency(label = PROJECT_MODEL_TO_FILE, direction = Direction.OUT)
public void addFileModel(FileModel fileModel);

/**
* Gets all contained files that are not directories
*/
@GremlinGroovy("it.out('projectModelToFile').has('isDirectory', false)")
@GremlinGroovy("it.out('" + PROJECT_MODEL_TO_FILE + "').has('" + FileModel.IS_DIRECTORY + "', false)")
public Iterable<FileModel> getFileModelsNoDirectories();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,74 +26,82 @@
@TypeValue(FileModel.TYPE)
public interface FileModel extends ResourceModel
{
public static final String ARCHIVE_FILES = "archiveFiles";

public static final String PARENT_FILE = "parentFile";

public static final String SHA1_HASH = "sha1Hash";

public static final String MD5_HASH = "md5Hash";

public static final String FILE_TO_PROJECT_MODEL = "fileToProjectModel";

public static final String TYPE = "FileResource";

public static final String PROPERTY_FILE_NAME = "fileName";
public static final String PROPERTY_FILE_PATH = "filePath";
public static final String PROPERTY_IS_DIRECTORY = "isDirectory";
public static final String FILE_NAME = "fileName";
public static final String FILE_PATH = "filePath";
public static final String IS_DIRECTORY = "isDirectory";

@Property(PROPERTY_FILE_NAME)
@Property(FILE_NAME)
public String getFileName();

@Property(PROPERTY_FILE_NAME)
@Property(FILE_NAME)
public void setFileName(String filename);

@Property(PROPERTY_FILE_PATH)
@Property(FILE_PATH)
public String getFilePath();

// implemented via a handler that makes sure the isDirectory property is set as well
@JavaHandler
public void setFilePath(String filePath);

@Property(PROPERTY_IS_DIRECTORY)
@Property(IS_DIRECTORY)
public boolean isDirectory();

@Property("md5Hash")
@Property(MD5_HASH)
public String getMD5Hash();

@Property("md5Hash")
@Property(MD5_HASH)
public void setMD5Hash(String md5Hash);

@Property("sha1Hash")
@Property(SHA1_HASH)
public String getSHA1Hash();

@Property("sha1Hash")
@Property(SHA1_HASH)
public void setSHA1Hash(String sha1Hash);

/**
* Parent directory
*/
@Adjacency(label = "parentFile", direction = Direction.OUT)
@Adjacency(label = PARENT_FILE, direction = Direction.OUT)
public FileModel getParentFile();

@Adjacency(label = "parentFile", direction = Direction.OUT)
@Adjacency(label = PARENT_FILE, direction = Direction.OUT)
public void setParentFile(FileModel parentFile);

/**
* Files contained within this directory
*
* @return
*/
@Adjacency(label = "parentFile", direction = Direction.IN)
@Adjacency(label = PARENT_FILE, direction = Direction.IN)
public Iterable<FileModel> getContainedFiles();

/**
* Add a file to this directory
*/
@Adjacency(label = "parentFile", direction = Direction.IN)
@Adjacency(label = PARENT_FILE, direction = Direction.IN)
public void addContainedFiles(FileModel fileModel);

/**
* Indicates the archive that contained this file
*
* @return
*/
@Adjacency(label = "archiveFiles", direction = Direction.IN)
@Adjacency(label = ARCHIVE_FILES, direction = Direction.IN)
public ArchiveModel getParentArchive();

@Adjacency(label = "archiveFiles", direction = Direction.IN)
@Adjacency(label = ARCHIVE_FILES, direction = Direction.IN)
public void setParentArchive(ArchiveModel parentArchive);

@Adjacency(label = FILE_TO_PROJECT_MODEL, direction = Direction.OUT)
Expand Down Expand Up @@ -203,9 +211,9 @@ public void setFilePath(String filePath)
{
File file = new File(filePath);
// set the isDirectory attribute
it().setProperty(PROPERTY_IS_DIRECTORY, file.isDirectory());
it().setProperty(PROPERTY_FILE_PATH, file.getAbsolutePath());
it().setProperty(PROPERTY_FILE_NAME, file.getName());
it().setProperty(IS_DIRECTORY, file.isDirectory());
it().setProperty(FILE_PATH, file.getAbsolutePath());
it().setProperty(FILE_NAME, file.getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
* an XML file may be classified as a "XYZ Configuration File".) A {@link ClassificationModel} may also contain links to
* additional information, or auto-translated/generated/updated versions of the source file.
*/
@TypeValue("ClassificationModel")
@TypeValue(ClassificationModel.TYPE)
public interface ClassificationModel extends WindupVertexFrame
{
public static final String PROPERTY_RULE_ID = "PROP_RULE_ID";
public static final String PROPERTY_CLASSIFICATION = "PROP_CLASSIFICATION";
public static final String PROPERTY_DESCRIPTION = "PROP_DESCRIPTION";
public static final String PROPERTY_EFFORT = "PROP_EFFORT";
public static final String PROPERTY_LINKS = "PROP_LINKS";
public static final String TYPE = "ClassificationModel";
public static final String PROPERTY_RULE_ID = "ruleID";
public static final String PROPERTY_CLASSIFICATION = "classification";
public static final String PROPERTY_DESCRIPTION = "description";
public static final String PROPERTY_EFFORT = "effort";
public static final String PROPERTY_LINKS = "links";

public static final String FILE_MODEL = "classificationModelToFileModel";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jboss.windup.reporting.service;

import javax.inject.Inject;

import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.reporting.model.ClassificationModel;

import com.thinkaurelius.titan.core.attribute.Text;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;

public class ClassificationService extends GraphService<ClassificationModel>
{
@Inject
public ClassificationService(GraphContext context)
{
super(context, ClassificationModel.class);
}

/**
* Returns the total effort points in all of the {@link ClassificationModel}s associated with the files in this
* project.
*
* If set to recursive, then also include the effort points from child projects.
*
*/
public int getMigrationEffortPoints(ProjectModel projectModel, boolean recursive)
{
// 1. Get all classification models
GremlinPipeline<Vertex, Vertex> classificationPipeline = new GremlinPipeline<>(projectModel.asVertex());
classificationPipeline.out(ProjectModel.PROJECT_MODEL_TO_FILE).in(ClassificationModel.FILE_MODEL);
classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ClassificationModel.TYPE);

int classificationEffort = 0;
for (Vertex v : classificationPipeline)
{
classificationEffort += (Integer) v.getProperty(ClassificationModel.PROPERTY_EFFORT);
}
if (recursive)
{
for (ProjectModel childProject : projectModel.getChildProjects())
{
classificationEffort += getMigrationEffortPoints(childProject, recursive);
}
}
return classificationEffort;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.jboss.windup.reporting.service;

import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.reporting.model.InlineHintModel;

import com.thinkaurelius.titan.core.attribute.Text;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;

/**
* This provides helper functions for finding and creating BlackListModels within the graph.
*
Expand All @@ -22,4 +28,32 @@ public InlineHintService(GraphContext context)
{
super(context, InlineHintModel.class);
}

/**
* Returns the total effort points in all of the {@link InlineHintModel}s associated with the files in this project.
*
* If set to recursive, then also include the effort points from child projects.
*
*/
public int getMigrationEffortPoints(ProjectModel projectModel, boolean recursive)
{
GremlinPipeline<Vertex, Vertex> inlineHintPipeline = new GremlinPipeline<>(projectModel.asVertex());
inlineHintPipeline.out(ProjectModel.PROJECT_MODEL_TO_FILE).in(InlineHintModel.FILE_MODEL);
inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, InlineHintModel.TYPE);

int hintEffort = 0;
for (Vertex v : inlineHintPipeline)
{
hintEffort += (Integer) v.getProperty(InlineHintModel.PROPERTY_EFFORT);
}

if (recursive)
{
for (ProjectModel childProject : projectModel.getChildProjects())
{
hintEffort += getMigrationEffortPoints(childProject, recursive);
}
}
return hintEffort;
}
}
Loading

0 comments on commit 961ca4b

Please sign in to comment.