Skip to content

Commit

Permalink
feat(core): Support multiple inputs
Browse files Browse the repository at this point in the history
- Add --directory, --classpath as JAR inputs
- All inputs are repeatable and may be mixed
- Add split-package command

Resolves #10
  • Loading branch information
aalmiray committed Feb 21, 2023
1 parent a7935ee commit 6b20104
Show file tree
Hide file tree
Showing 35 changed files with 1,245 additions and 317 deletions.
161 changes: 117 additions & 44 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ bytecode version; an ordered list of total versioned classes.

[source]
----
$ jarviz bytecode show --gav org.kordamp.maven:pomchecker-toolprovider:1.4.0
$ jarviz bytecode show --gav org.kordamp.maven:pomchecker-toolprovider:1.8.0
subject: pomchecker-toolprovider-1.8.0.jar
Unversioned classes. Bytecode version: 47 total: 9
Unversioned classes. Bytecode version: 48 total: 239
Unversioned classes. Bytecode version: 49 total: 358
Unversioned classes. Bytecode version: 49 total: 314
Unversioned classes. Bytecode version: 50 total: 896
Unversioned classes. Bytecode version: 51 total: 2089
Unversioned classes. Bytecode version: 52 total: 3366
Unversioned classes. Bytecode version: 53 total: 1
Unversioned classes. Bytecode version: 51 total: 595
Unversioned classes. Bytecode version: 52 total: 4,571
Unversioned classes. Bytecode version: 53 total: 2
----

Use the `--details` flag to list all classes per bytecode version

[source]
----
$ jarviz bytecode show --gav org.kordamp.maven:pomchecker-toolprovider:1.4.0 \
$ jarviz bytecode show --gav org.kordamp.maven:pomchecker-toolprovider:1.8.0 \
--bytecode-version 47 --details
subject: pomchecker-toolprovider-1.8.0.jar
Unversioned classes. Bytecode version: 47 total: 9
org.aopalliance.aop.Advice
org.aopalliance.aop.AspectException
Expand All @@ -82,11 +84,13 @@ org.aopalliance.intercept.MethodInvocation
[source]
----
$ jarviz bytecode show --gav com.fasterxml.jackson.core:jackson-core:2.14.1
subject: jackson-core-2.14.1.jar
Unversioned classes. Bytecode version: 52 total: 160
Versioned classes 9. Bytecode version: 53 total: 1
$ jarviz bytecode show --gav com.fasterxml.jackson.core:jackson-core:2.14.1 \
--bytecode-version 53 --details
subject: jackson-core-2.14.1.jar
Versioned classes 9. Bytecode version: 53 total: 1
module-info
----
Expand All @@ -100,6 +104,7 @@ Show the JAR's manifest.
[source]
----
$ jarviz manifest show --gav org.kordamp.maven:pomchecker-toolprovider:1.4.0
subject: pomchecker-toolprovider-1.4.0.jar
Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 11
Expand All @@ -122,7 +127,8 @@ Query manifest attributes.
----
$ jarviz manifest query --gav org.kordamp.maven:pomchecker-toolprovider:1.4.0 \
--attribute-name Automatic-Module-Name
org.kordamp.maven.pomchecker
subject: pomchecker-toolprovider-1.4.0.jar
Automatic-Module-Name: org.kordamp.maven.pomchecker
----

=== Module
Expand All @@ -137,6 +143,7 @@ Will show the module name, whether it's automatic or not, and if the name is val
[source]
----
$ jarviz module name --gav org.slf4j:slf4j-api:1.7.36
subject: slf4j-api-1.7.36.jar
name: org.slf4j
source: manifest
automatic: true
Expand All @@ -148,6 +155,7 @@ valid: true
[source]
----
$ jarviz module name --gav org.slf4j:slf4j-api:2.0.6
subject: slf4j-api-2.0.6.jar
name: org.slf4j
source: explicit
automatic: false
Expand All @@ -159,6 +167,7 @@ This JAR filename is invalid
[source]
----
$ jarviz module name --file foo-1-TAG.jar
subject: foo-1-TAG.jar
name: foo.1.TAG
source: filename
automatic: true
Expand All @@ -173,6 +182,7 @@ Show the module descriptor in detail.
[source]
----
$ jarviz module descriptor --gav jakarta.activation:jakarta.activation-api:2.1.1
subject: jakarta.activation-api-2.1.1.jar
name: jakarta.activation
version: 2.1.1
open: false
Expand All @@ -189,6 +199,44 @@ uses:
jakarta.activation.spi.MimeTypeRegistryProvider
----

=== Packages

*split*

Display split packages

[source]
----
$ jarviz packages split --directory ~/.sdkman/candidates/maven/current/lib/
subject: maven-artifact-3.9.0.jar
org.apache.maven.artifact
org.apache.maven.artifact.handler
org.apache.maven.artifact.metadata
org.apache.maven.artifact.repository
org.apache.maven.artifact.repository.layout
org.apache.maven.artifact.repository.metadata
org.apache.maven.artifact.resolver
org.apache.maven.artifact.resolver.filter
org.apache.maven.artifact.versioning
org.apache.maven.repository
org.apache.maven.repository.legacy.metadata
subject: maven-compat-3.9.0.jar
org.apache.maven.artifact
org.apache.maven.artifact.repository
org.apache.maven.artifact.repository.layout
org.apache.maven.artifact.repository.metadata
org.apache.maven.artifact.resolver
org.apache.maven.artifact.resolver.filter
org.apache.maven.artifact.versioning
org.apache.maven.execution
org.apache.maven.project
org.apache.maven.project.path
org.apache.maven.repository
...
----

=== Services

*list*
Expand All @@ -197,11 +245,12 @@ Display registered services.

[source]
----
$ jarviz services list --gav org.kordamp.maven:pomchecker-toolprovider:1.4.0
org.slf4j.spi.SLF4JServiceProvider
$ jarviz services list --gav org.kordamp.maven:pomchecker-toolprovider:1.8.0
subject: pomchecker-toolprovider-1.8.0.jar
java.util.spi.ToolProvider
javax.annotation.processing.Processor
org.apache.commons.logging.LogFactory
org.slf4j.spi.SLF4JServiceProvider
----

*show*
Expand All @@ -210,8 +259,10 @@ Display service implementations for a given service.

[source]
----
$ jarviz services show --gav org.kordamp.maven:pomchecker-toolprovider:1.4.0 \
$ jarviz services show --gav org.kordamp.maven:pomchecker-toolprovider:1.8.0 \
--service-name java.util.spi.ToolProvider
subject: pomchecker-toolprovider-1.8.0.jar
service: java.util.spi.ToolProvider
org.kordamp.maven.checker.toolprovider.Pomchecker
----

Expand Down Expand Up @@ -239,6 +290,7 @@ $ jarviz module name --gav com.sun.mail:jakarta.mail:2.0.1 \
--report-format xml \
--report-format json \
--report-format yaml
subject: jakarta.mail-2.0.1.jar
name: jakarta.mail
source: explicit
automatic: false
Expand All @@ -248,60 +300,81 @@ valid: true
[source]
.jakarta.mail.txt
----
subject:
file: jakarta.mail-2.0.1.jar
size: 689294
sha256: 8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23
name: jakarta.mail
source: explicit
automatic: false
valid: true
subjects:
subject:
command: module name
jar:
file: jakarta.mail-2.0.1.jar
size: 689294
sha256: 8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23
result:
name: jakarta.mail
source: explicit
automatic: false
valid: true
----

[source,xml]
[subs="verbatim"]
.jakarta.mail.xml
----
<jarviz>
<subject>
<file>jakarta.mail-2.0.1.jar</file>
<size>689294</size>
<sha256>8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23</sha256>
</subject>
<name>jakarta.mail</name>
<source>explicit</source>
<automatic>false</automatic>
<valid>true</valid>
<subjects>
<subject>
<command>module name</command>
<jar>
<file>jakarta.mail-2.0.1.jar</file>
<size>689294</size>
<sha256>8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23</sha256>
</jar>
<result>
<name>jakarta.mail</name>
<source>explicit</source>
<automatic>false</automatic>
<valid>true</valid>
</result>
</subject>
</subjects>
</jarviz>
----

[source,json]
.jakarta.mail.json
----
{
"subject": {
"file": "jakarta.mail-2.0.1.jar",
"size": 689294,
"sha256": "8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23"
},
"name": "jakarta.mail",
"source": "explicit",
"automatic": false,
"valid": true
"subjects": [
{
"command": "module name",
"jar": {
"file": "jakarta.mail-2.0.1.jar",
"size": 689294,
"sha256": "8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23"
},
"result": {
"name": "jakarta.mail",
"source": "explicit",
"automatic": false,
"valid": true
}
}
]
}
----

[source,yaml]
.jakarta.mail.yaml
----
subject:
file: jakarta.mail-2.0.1.jar
size: 689294
sha256: 8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23
name: jakarta.mail
source: explicit
automatic: false
valid: true
subjects:
- command: module name
jar:
file: jakarta.mail-2.0.1.jar
size: 689294
sha256: 8988bdbde922ee173db7179e23393dd2258f3b64f708f41082e03f0e0494cc23
result:
name: jakarta.mail
source: explicit
automatic: false
valid: true
----

== Install
Expand Down
1 change: 1 addition & 0 deletions core/jarviz-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
exports org.kordamp.jarviz.core.bytecode;
exports org.kordamp.jarviz.core.model;
exports org.kordamp.jarviz.core.modules;
exports org.kordamp.jarviz.core.packages;
exports org.kordamp.jarviz.core.processors;
exports org.kordamp.jarviz.core.services;
exports org.kordamp.jarviz.reporting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
*/
package org.kordamp.jarviz.core;

import java.util.Set;
import java.util.jar.JarFile;

/**
* @author Andres Almiray
* @since 0.1.0
*/
public interface JarFileResolver<T> {
T getSource();

JarFile resolveJarFile();
public interface JarFileResolver {
Set<JarFile> resolveJarFiles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,69 @@
*/
package org.kordamp.jarviz.core;

import org.kordamp.jarviz.core.resolvers.ClasspathBasedJarFileResolver;
import org.kordamp.jarviz.core.resolvers.CompositeJarFileResolver;
import org.kordamp.jarviz.core.resolvers.DirectoryBasedJarFileResolver;
import org.kordamp.jarviz.core.resolvers.GavBasedJarFileResolver;
import org.kordamp.jarviz.core.resolvers.PathBasedJarFileResolver;
import org.kordamp.jarviz.core.resolvers.UrlBasedJarFileResolver;

import java.net.URL;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Set;

import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
import static org.kordamp.jarviz.util.StringUtils.isNotBlank;

/**
* @author Andres Almiray
* @since 0.1.0
*/
public class JarFileResolvers {
public static JarFileResolver<?> createJarFileResolver(Path file, String gav, URL url, Path cacheDirectory) {
public static JarFileResolver createJarFileResolver(Path file, String gav, URL url, Path cacheDirectory) {
if (file != null) return new PathBasedJarFileResolver(file);
if (isNotBlank(gav)) return new GavBasedJarFileResolver(cacheDirectory, gav);
return new UrlBasedJarFileResolver(cacheDirectory, url);
}

public static Set<JarFileResolver> classpathJarFileResolvers(Collection<String> classpaths) {
if (classpaths.isEmpty()) return emptySet();
return classpaths.stream()
.map(ClasspathBasedJarFileResolver::new)
.collect(toSet());
}

public static Set<JarFileResolver> directoryJarFileResolvers(Collection<Path> directories) {
if (directories.isEmpty()) return emptySet();
return directories.stream()
.map(DirectoryBasedJarFileResolver::new)
.collect(toSet());
}

public static Set<JarFileResolver> pathJarFileResolvers(Collection<Path> files) {
if (files.isEmpty()) return emptySet();
return files.stream()
.map(PathBasedJarFileResolver::new)
.collect(toSet());
}

public static Set<JarFileResolver> gavJarFileResolvers(Path cacheDirectory, Collection<String> gavs) {
if (gavs.isEmpty()) return emptySet();
return gavs.stream()
.map(gav -> new GavBasedJarFileResolver(cacheDirectory, gav))
.collect(toSet());
}

public static Set<JarFileResolver> urlJarFileResolvers(Path cacheDirectory, Collection<URL> urls) {
if (urls.isEmpty()) return emptySet();
return urls.stream()
.map(url -> new UrlBasedJarFileResolver(cacheDirectory, url))
.collect(toSet());
}

public static JarFileResolver compositeJarFileResolver(Set<JarFileResolver> resolvers) {
return new CompositeJarFileResolver(resolvers);
}
}
Loading

0 comments on commit 6b20104

Please sign in to comment.