Skip to content

Commit

Permalink
Merge pull request #239 from jsight/WINDUP-263
Browse files Browse the repository at this point in the history
WINDUP-263: Use dot (org.example.*) notation on JavaClass reports instea...
  • Loading branch information
jsight committed Sep 5, 2014
2 parents ef28bcb + c578222 commit 5d07b37
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
Expand Up @@ -23,6 +23,10 @@
import com.tinkerpop.frames.modules.javahandler.JavaHandlerContext;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

/**
* Represents a File on disk
*
*/
@TypeValue(FileModel.TYPE)
public interface FileModel extends ResourceModel
{
Expand All @@ -42,31 +46,60 @@ public interface FileModel extends ResourceModel
public static final String FILE_PATH = "filePath";
public static final String IS_DIRECTORY = "isDirectory";

/**
* 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"
*/
@Property(FILE_NAME)
public String getFileName();

/**
* 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"
*/
@Property(FILE_NAME)
public void setFileName(String filename);

/**
* Contains the full path to the file (eg, /tmp/foo/bar/file.txt)
*/
@Property(FILE_PATH)
public String getFilePath();

/**
* Contains the full path to the file (eg, /tmp/foo/bar/file.txt)
*/
// implemented via a handler that makes sure the isDirectory property is set as well
@JavaHandler
public void setFilePath(String filePath);

/**
* Indicates whether the file is a directory or not
*/
@Property(IS_DIRECTORY)
public boolean isDirectory();

/**
* Contains a MD5 Hash of the file
*/
@Property(MD5_HASH)
public String getMD5Hash();

/**
* Contains a MD5 Hash of the file
*/
@Property(MD5_HASH)
public void setMD5Hash(String md5Hash);

/**
* Contains a SHA1 Hash of the file
*/
@Property(SHA1_HASH)
public String getSHA1Hash();

/**
* Contains a SHA1 Hash of the file
*/
@Property(SHA1_HASH)
public void setSHA1Hash(String sha1Hash);

Expand All @@ -76,6 +109,9 @@ public interface FileModel extends ResourceModel
@Adjacency(label = PARENT_FILE, direction = Direction.OUT)
public FileModel getParentFile();

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

Expand All @@ -95,30 +131,49 @@ public interface FileModel extends ResourceModel

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

/**
* Sets the archive that contained this file
*/
@Adjacency(label = ARCHIVE_FILES, direction = Direction.IN)
public void setParentArchive(ArchiveModel parentArchive);

/**
* Gets the ProjectModel that this file is a part of
*/
@Adjacency(label = FILE_TO_PROJECT_MODEL, direction = Direction.OUT)
public ProjectModel getProjectModel();

/**
* Sets the ProjectModel that this file is a part of
*/
@Adjacency(label = FILE_TO_PROJECT_MODEL, direction = Direction.OUT)
public void setProjectModel(ProjectModel projectModel);

/**
* Gets a {@link File} object representing this file
*/
@JavaHandler
public File asFile() throws RuntimeException;

/**
* Returns an open {@link InputStream} for reading from this file
*/
@JavaHandler
public InputStream asInputStream() throws RuntimeException;

/**
* Returns the path of this file within the archive (including all subarchives, etc)
*/
@JavaHandler
public String getPrettyPath();

/**
* Returns the path of this file within the parent project (format suitable for reporting)
*/
@JavaHandler
public String getPrettyPathWithinProject();

Expand Down
@@ -0,0 +1,66 @@
package org.jboss.windup.rules.apps.java.reporting.freemarker;

import java.util.List;

import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.reporting.freemarker.WindupFreeMarkerMethod;
import org.jboss.windup.rules.apps.java.model.JavaClassFileModel;
import org.jboss.windup.rules.apps.java.model.JavaSourceFileModel;

import freemarker.ext.beans.StringModel;
import freemarker.template.TemplateModelException;

/**
* Returns a pretty path for the provided file. If the File appears to represent a Java File, this will attempt to
* determine the associated Java Class and return the name formatted as a package and class (eg, com.package.Foo).
*
* Called as follows:
*
* getPrettyPathForFile(fileModel)
*
* @author jsightler <jesse.sightler@gmail.com>
*
*/
public class GetPrettyPathForFile implements WindupFreeMarkerMethod
{

@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
if (arguments.size() != 1)
{
throw new TemplateModelException("Error, method expects one argument (FileModel)");
}
StringModel stringModelArg = (StringModel) arguments.get(0);
FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
if (fileModel instanceof JavaClassFileModel)
{
JavaClassFileModel jcfm = (JavaClassFileModel) fileModel;
return jcfm.getJavaClass().getQualifiedName();
}
else if (fileModel instanceof JavaSourceFileModel)
{
JavaSourceFileModel javaSourceModel = (JavaSourceFileModel) fileModel;
String filename = fileModel.getFileName();
String packageName = javaSourceModel.getPackageName();

if (filename.endsWith(".java"))
{
filename = filename.substring(0, filename.length() - 5);
}

return packageName == null || packageName.equals("") ? filename : packageName + "." + filename;
}
else
{
return fileModel.getPrettyPathWithinProject();
}
}

@Override
public String getMethodName()
{
return "getPrettyPathForFile";
}

}
Expand Up @@ -13,7 +13,7 @@
<tr>
<td>
<a href="${sourceReportModel.reportFilename}">
${fileModel.prettyPathWithinProject}
${getPrettyPathForFile(fileModel)}
</a>
</td>
<td>
Expand Down

0 comments on commit 5d07b37

Please sign in to comment.