Skip to content

Commit

Permalink
Add Javadocs (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: César Soto Valero <[email protected]>
  • Loading branch information
ABHAY0O7 and cesarsotovalero authored Mar 18, 2021
1 parent 9d906d2 commit c4daf6e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@
@Data
public class ArtifactTypes {

/**
* A HashSet to store the types.
*/
private Set<String> allTypes;

/**
* A HashSet to store the used types.
*/
private Set<String> usedTypes;

/**
* Ctor.
*
* @param allTypes All types in the artifact.
* @param usedTypes Thew used types in the artifact.
*/
public ArtifactTypes(Set<String> allTypes, Set<String> usedTypes) {
this.allTypes = allTypes;
this.usedTypes = usedTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,27 @@
import java.util.Set;

/**
* Gets the set of classes contained in a library given either as a jar file or an exploded directory.
* Gets the set of classes contained in an artifact given either
* as a jar file or an exploded directory.
*/
public interface ClassAnalyzer {

// fields -----------------------------------------------------------------

/**
* To store the name of the class.
*/
String ROLE = ClassAnalyzer.class.getName();

// public methods ---------------------------------------------------------

/**
* Analyze the classes of a given artifact.
*
* @param url The artifact.
* @return A set of classes.
* @throws IOException In case of IO issues.
*/
Set<String> analyze(URL url)
throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@
*/
public interface ClassFileVisitor {

/**
* To visit the classes.
*
* @param className Name of the class
* @param in To read the bytes.
*/
void visitClass(String className, InputStream in);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public static void accept(URL url, ClassFileVisitor visitor)
}
}

/**
* Accepts a jar to be analyzed.
*
* @param url URL of jar
* @param visitor A {@link ClassFileVisitor}.
* @throws IOException In case of IO issues.
*/
private static void acceptJar(URL url, ClassFileVisitor visitor)
throws IOException {
try (JarInputStream in = new JarInputStream(url.openStream())) {
Expand All @@ -89,6 +96,13 @@ private static void acceptJar(URL url, ClassFileVisitor visitor)
}
}

/**
* Accepts a directory to be analyzed.
*
* @param directory Directory or File to be analyzed.
* @param visitor A {@link ClassFileVisitor}.
* @throws IOException In case of IO issues.
*/
private static void acceptDirectory(File directory, ClassFileVisitor visitor)
throws IOException {
if (!directory.isDirectory()) {
Expand All @@ -108,6 +122,13 @@ private static void acceptDirectory(File directory, ClassFileVisitor visitor)
}
}

/**
* Visits the classes.
*
* @param path Path of the class.
* @param in read the input bytes.
* @param visitor A {@link ClassFileVisitor}.
*/
private static void visitClass(String path, InputStream in, ClassFileVisitor visitor) {
if (!path.endsWith(CLASS)) {
throw new IllegalArgumentException("Path is not a class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class CollectorClassFileVisitor
implements ClassFileVisitor {
// fields -----------------------------------------------------------------

/**
* Set of all classes.
*/
private final Set<String> classes;

// constructors -----------------------------------------------------------
Expand All @@ -42,16 +45,24 @@ public CollectorClassFileVisitor() {

// ClassFileVisitor methods -----------------------------------------------

/*
* @see org.apache.invoke.shared.dependency.analyzer.ClassFileVisitor#visitClass(java.lang.String,
* java.io.InputStream)
/**
* {@link ClassFileVisitor}.
*
* @param className Name of the class
* @param in To read the bytes.
*/
@Override
public void visitClass(String className, InputStream in) {
classes.add(className);
}

// public methods ---------------------------------------------------------

/**
* Getter for visited classes.
*
* @return A set of visited classes.
*/
public Set<String> getClasses() {
return classes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class DefaultClassAnalyzer implements ClassAnalyzer {
* Analyze the class members.
*
* @param url The class URL.
* @return The visited classes.
* @return A set of visited classes.
* @throws IOException If there is an error.
*/
public Set<String> analyze(URL url) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down

0 comments on commit c4daf6e

Please sign in to comment.