Skip to content

Commit

Permalink
feat: Add dependency task.
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jan 5, 2023
1 parent 5d84277 commit 947212f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Add it into in the dependencies element like so:
<dependency>
<groupId>com.github.teletha</groupId>
<artifactId>bee</artifactId>
<version>0.34.1</version>
<version>0.35.0</version>
</dependency>
```
#### [Gradle](https://gradle.org/)
Expand All @@ -66,7 +66,7 @@ repositories {
Add it into the dependencies section like so:
```gradle
dependencies {
implementation 'com.github.teletha:bee:0.34.1'
implementation 'com.github.teletha:bee:0.35.0'
}
```
#### [SBT](https://www.scala-sbt.org/)
Expand All @@ -76,7 +76,7 @@ resolvers += "jitpack" at "https://jitpack.io"
```
Add it into the libraryDependencies section like so:
```scala
libraryDependencies += "com.github.teletha" % "bee" % "0.34.1"
libraryDependencies += "com.github.teletha" % "bee" % "0.35.0"
```
#### [Leiningen](https://leiningen.org/)
Add JitPack repository at the end of repositories in your project.clj:
Expand All @@ -85,12 +85,12 @@ Add JitPack repository at the end of repositories in your project.clj:
```
Add it into the dependencies section like so:
```clj
:dependencies [[com.github.teletha/bee "0.34.1"]]
:dependencies [[com.github.teletha/bee "0.35.0"]]
```
#### [Bee](https://teletha.github.io/bee)
Add it into your project definition class like so:
```java
require("com.github.teletha", "bee", "0.34.1");
require("com.github.teletha", "bee", "0.35.0");
```
<p align="right"><a href="#top">back to top</a></p>

Expand Down Expand Up @@ -120,11 +120,8 @@ If you think something might be a bug, but you're not sure, ask on StackOverflow
Bee depends on the following products on runtime.
* [asm-9.4](https://mvnrepository.com/artifact/org.ow2.asm/asm/9.4)
* [commons-lang3-3.12.0](https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.12.0)
* [httpclient-4.5.13](https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.13)
* [httpcore-4.4.15](https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.4.15)
* [javax.annotation-api-1.2](https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api/1.2)
* [javax.inject-1](https://mvnrepository.com/artifact/javax.inject/javax.inject/1)
* [jcl-over-slf4j-2.0.6](https://mvnrepository.com/artifact/org.slf4j/jcl-over-slf4j/2.0.6)
* [jul-to-slf4j-2.0.6](https://mvnrepository.com/artifact/org.slf4j/jul-to-slf4j/2.0.6)
* [maven-api-meta-4.0.0-alpha-2](https://mvnrepository.com/artifact/org.apache.maven/maven-api-meta/4.0.0-alpha-2)
* [maven-api-model-4.0.0-alpha-2](https://mvnrepository.com/artifact/org.apache.maven/maven-api-model/4.0.0-alpha-2)
Expand All @@ -141,15 +138,13 @@ Bee depends on the following products on runtime.
* [maven-resolver-named-locks-1.9.2](https://mvnrepository.com/artifact/org.apache.maven.resolver/maven-resolver-named-locks/1.9.2)
* [maven-resolver-provider-4.0.0-alpha-2](https://mvnrepository.com/artifact/org.apache.maven/maven-resolver-provider/4.0.0-alpha-2)
* [maven-resolver-spi-1.9.2](https://mvnrepository.com/artifact/org.apache.maven.resolver/maven-resolver-spi/1.9.2)
* [maven-resolver-transport-http-1.9.2](https://mvnrepository.com/artifact/org.apache.maven.resolver/maven-resolver-transport-http/1.9.2)
* [maven-resolver-util-1.9.2](https://mvnrepository.com/artifact/org.apache.maven.resolver/maven-resolver-util/1.9.2)
* [maven-xml-impl-4.0.0-alpha-2](https://mvnrepository.com/artifact/org.apache.maven/maven-xml-impl/4.0.0-alpha-2)
* [org.eclipse.sisu.plexus-0.3.5](https://mvnrepository.com/artifact/org.eclipse.sisu/org.eclipse.sisu.plexus/0.3.5)
* [plexus-interpolation-1.26](https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-interpolation/1.26)
* [plexus-utils-3.4.2](https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-utils/3.4.2)
* [plexus-utils-4.0.0-alpha-2](https://mvnrepository.com/artifact/org.apache.maven/plexus-utils/4.0.0-alpha-2)
* [psychopath-1.6.0](https://mvnrepository.com/artifact/com.github.teletha/psychopath/1.6.0)
* [sinobu-3.0.0](https://mvnrepository.com/artifact/com.github.teletha/sinobu/3.0.0)
* [plexus-utils-3.0.24](https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-utils/3.0.24)
* [psychopath-1.7.1](https://mvnrepository.com/artifact/com.github.teletha/psychopath/1.7.1)
* [sinobu-3.1.0](https://mvnrepository.com/artifact/com.github.teletha/sinobu/3.1.0)
* [slf4j-api-2.0.6](https://mvnrepository.com/artifact/org.slf4j/slf4j-api/2.0.6)
* [slf4j-nop-2.0.6](https://mvnrepository.com/artifact/org.slf4j/slf4j-nop/2.0.6)
<p align="right"><a href="#top">back to top</a></p>
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/bee/api/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,18 @@ private static final void addRemoteRepository(String name, String url) {
this.session = session;
}

/**
* Build the dependency graph for compile scope.
*
* @param project
* @return
*/
public DependencyNode buildDependencyGraph(Project project) {
try {
// collect dependency
CollectRequest request = new CollectRequest(null, remoteRepositories());
for (Library library : project.libraries) {
if (library.scope.accept("compile")) {
// spcify the latest version
Artifact artifact = library.artifact;
if (artifact.getVersion().equals("LATEST")) {
artifact = artifact.setVersion("[" + resolveLatestVersion(library) + ",)");
}
request.addDependency(new Dependency(artifact, library.scope.id));
if (library.scope.accept(Scope.Compile.id)) {
request.addDependency(new Dependency(library.artifact, library.scope.id));
}
}
request.setRootArtifact(project.asLibrary().artifact);
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/bee/task/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
package bee.task;

import java.util.Comparator;
import java.util.List;

import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.graph.DependencyNode;

import bee.Task;
Expand All @@ -20,13 +24,24 @@ public class Dependency extends Task {

@Command("Display the dependency tree.")
public void tree() {
Repository repo = I.make(Repository.class);
show(0, I.make(Repository.class).buildDependencyGraph(project));
}

/**
* Write out the dependency.
*
* @param depth
* @param node
*/
private void show(int depth, DependencyNode node) {
Artifact artifact = node.getArtifact();
ui.info("\t".repeat(depth) + artifact.getGroupId() + " : " + artifact.getArtifactId() + " : " + artifact.getVersion());

DependencyNode dependencies = repo.buildDependencyGraph(project);
System.out.println(dependencies);
List<DependencyNode> children = node.getChildren();
children.sort(Comparator.comparing(o -> o.getArtifact().getArtifactId()));

for (DependencyNode child : dependencies.getChildren()) {
System.out.println(child + " " + child.getChildren());
for (DependencyNode child : children) {
show(depth + 1, child);
}
}
}
5 changes: 3 additions & 2 deletions src/project/java/bee/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
package bee;

import static bee.api.License.*;
import static bee.api.License.MIT;

import javax.lang.model.SourceVersion;

Expand Down Expand Up @@ -45,8 +45,8 @@ public class Project extends bee.api.Project {

// LOGGER
require("org.slf4j", "slf4j-nop");
require("org.slf4j", "jcl-over-slf4j");
require("org.slf4j", "jul-to-slf4j");
// require("org.slf4j", "jcl-over-slf4j"); for maven-resolver-transport-http

// REQUIRED
require("com.github.teletha", "sinobu");
Expand All @@ -65,6 +65,7 @@ public class Project extends bee.api.Project {
require("com.github.teletha", "antibug").atTest();

unrequire("commons-codec", "commons-codec");
unrequire("org.apache.maven", "plexus-utils");
unrequire("org.eclipse.sisu", "org.eclipse.sisu.inject");
unrequire("org.codehaus.plexus", "plexus-classworlds");
unrequire("org.codehaus.plexus", "plexus-component-annotations");
Expand Down

0 comments on commit 947212f

Please sign in to comment.