Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Javadocs #50

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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