-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Outline path model which will be used to differentiate detection item…
…s in rich detal Rework results model to use the new path system, begin layout of standard scanning.
- Loading branch information
Showing
27 changed files
with
692 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ dependencies { | |
api asm_util | ||
api cafedude | ||
api lljzip | ||
api collections | ||
api jackson | ||
api slf4jLogging | ||
|
||
|
14 changes: 1 addition & 13 deletions
14
concoction-lib/src/main/java/info/mmpa/concoction/Concoction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
package info.mmpa.concoction; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import info.mmpa.concoction.result.ArchiveScanResults; | ||
|
||
public class Concoction { | ||
public static Map<String, ArchiveScanResults> scanDirectory(File file) { | ||
HashMap<String, ArchiveScanResults> results = new HashMap<>(); | ||
// TODO | ||
return results; | ||
} | ||
} | ||
public class Concoction {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
concoction-lib/src/main/java/info/mmpa/concoction/input/NotAClassException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
package info.mmpa.concoction.input; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Exception to outline an input to {@link ClassesAndFiles#addClass(String, byte[])} was not actually a class. | ||
*/ | ||
public class NotAClassException extends Exception { | ||
private final String name; | ||
|
||
/** | ||
* @param name | ||
* File path that is not a class. | ||
* @param cause | ||
* Parent exception thrown by class validation. | ||
*/ | ||
public NotAClassException(Throwable cause) { | ||
public NotAClassException(@Nonnull String name, @Nonnull Throwable cause) { | ||
super(cause); | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* @return File path that is not a class. | ||
*/ | ||
@Nonnull | ||
public String getName() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
concoction-lib/src/main/java/info/mmpa/concoction/model/path/AbstractPathElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package info.mmpa.concoction.model.path; | ||
|
||
/** | ||
* Common outline of path elements, declaring shared behaviors. | ||
*/ | ||
public abstract class AbstractPathElement implements PathElement { | ||
@Override | ||
public int compareTo(PathElement o) { | ||
return fullDisplay().compareTo(o.fullDisplay()); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
concoction-lib/src/main/java/info/mmpa/concoction/model/path/ClassPathElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package info.mmpa.concoction.model.path; | ||
|
||
import info.mmpa.concoction.model.ModelSource; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* A path to a class within a {@link ModelSource}. | ||
*/ | ||
public class ClassPathElement extends AbstractPathElement { | ||
private final Map<String, MethodPathElement> children = new HashMap<>(); | ||
private final SourcePathElement parent; | ||
private final String className; | ||
|
||
/** | ||
* @param parent | ||
* Parent path element. | ||
* @param className | ||
* Name of the class. | ||
*/ | ||
public ClassPathElement(@Nonnull SourcePathElement parent, @Nonnull String className) { | ||
this.parent = parent; | ||
this.className = className; | ||
} | ||
|
||
/** | ||
* @param methodName | ||
* Method name. | ||
* @param methodDesc | ||
* Method desc. | ||
* | ||
* @return New child path to a method within this class. | ||
*/ | ||
@Nonnull | ||
public MethodPathElement child(@Nonnull String methodName, @Nonnull String methodDesc) { | ||
return children.computeIfAbsent(methodName + methodDesc, k -> new MethodPathElement(this, methodName, methodDesc)); | ||
} | ||
|
||
/** | ||
* @param method | ||
* Method declaration. | ||
* | ||
* @return New child path to a method within this class. | ||
*/ | ||
@Nonnull | ||
public MethodPathElement child(@Nonnull MethodNode method) { | ||
return child(method.name, method.desc); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public PathElement parent() { | ||
return parent; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Collection<MethodPathElement> children() { | ||
return children.values(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String fullDisplay() { | ||
return parent.fullDisplay() + " : " + localDisplay(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String localDisplay() { | ||
return className; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
ClassPathElement that = (ClassPathElement) o; | ||
|
||
return className.equals(that.className); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return className.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return localDisplay(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
concoction-lib/src/main/java/info/mmpa/concoction/model/path/MethodPathElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package info.mmpa.concoction.model.path; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* A path to a method within a class. | ||
*/ | ||
public class MethodPathElement extends AbstractPathElement { | ||
private final ClassPathElement parent; | ||
private final String methodName; | ||
private final String methodDesc; | ||
|
||
/** | ||
* @param parent | ||
* Parent path element. | ||
* @param methodName | ||
* Name of the method. | ||
* @param methodDesc | ||
* Descriptor of the method. | ||
*/ | ||
public MethodPathElement(@Nonnull ClassPathElement parent, @Nonnull String methodName, @Nonnull String methodDesc) { | ||
this.parent = parent; | ||
this.methodName = methodName; | ||
this.methodDesc = methodDesc; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public PathElement parent() { | ||
return parent; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Collection<? extends PathElement> children() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String fullDisplay() { | ||
return parent.fullDisplay() + "." + localDisplay(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String localDisplay() { | ||
return methodName + methodDesc; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
MethodPathElement that = (MethodPathElement) o; | ||
|
||
if (!methodName.equals(that.methodName)) return false; | ||
return methodDesc.equals(that.methodDesc); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = methodName.hashCode(); | ||
result = 31 * result + methodDesc.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return localDisplay(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
concoction-lib/src/main/java/info/mmpa/concoction/model/path/PathElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package info.mmpa.concoction.model.path; | ||
|
||
import info.mmpa.concoction.model.ApplicationModel; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Outline of a modular path to point to different locations in a {@link ApplicationModel}. | ||
*/ | ||
public interface PathElement extends Comparable<PathElement> { | ||
/** | ||
* @return Parent path element. Will be {@code null} for the root. | ||
*/ | ||
@Nullable | ||
PathElement parent(); | ||
|
||
/** | ||
* @return Collection of child paths. | ||
*/ | ||
@Nonnull | ||
Collection<? extends PathElement> children(); | ||
|
||
/** | ||
* @return Full path display, which includes all display parts of parents. | ||
*/ | ||
@Nonnull | ||
String fullDisplay(); | ||
|
||
/** | ||
* @return Local display of the current element. | ||
*/ | ||
@Nonnull | ||
String localDisplay(); | ||
} |
Oops, something went wrong.