Skip to content

Commit

Permalink
feat: add commnads eclipse:live and eclipse:repository
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Nov 11, 2024
1 parent 928157d commit d5bb012
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/main/java/bee/task/Eclipse.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bee.api.Command;
import bee.api.Library;
import bee.api.Project;
import bee.api.Repository;
import bee.api.Scope;
import bee.task.AnnotationProcessor.ProjectInfo;
import bee.util.Config;
Expand Down Expand Up @@ -279,6 +280,53 @@ private Directory relative(Directory path) {
return project.getRoot().relativize(path);
}

/**
* Rewrite sibling eclipse projects to use the current project directly.
*/
@Command("Rewrite sibling eclipse projects to use the current project directly.")
public void live() {
syncProject(true);
}

/**
* Rewrite sibling eclipse projects to use the repository.
*/
@Command("Rewrite sibling eclipse projects to use the current project in repository.")
public void repository() {
syncProject(false);
}

/**
* Rewrite sibling eclipse projects.
*/
private void syncProject(boolean live) {
String jar = I.make(Repository.class).resolveJar(project.asLibrary()).toString();
String currentProjectName = project.getRoot().base();

String oldPath = live ? jar.substring(0, jar.lastIndexOf(java.io.File.separator + project.getVersion() + java.io.File.separator))
: "/" + currentProjectName;
String newPath = live ? "/" + currentProjectName : jar;

for (File file : project.getRoot().parent().walkFile("*/.classpath").toList()) {
if (!file.parent().equals(project.getRoot())) {
String targetProjectName = file.parent().base();

XML root = I.xml(file.newBufferedReader());
XML classpath = root.find("classpathentry[path^=\"" + oldPath + "\"]");

if (classpath.size() != 0) {
// use project source directly
classpath.attr("kind", live ? "src" : "lib").attr("path", newPath);

// rewrite
root.to(file.newBufferedWriter());

ui.info("Project ", targetProjectName, " references ", currentProjectName, live ? " directly." : " in repository.");
}
}
}
}

/**
* {@inheritDoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions src/project/java/bee/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public class Project extends bee.api.Project {
require("org.eclipse.jgit", "org.eclipse.jgit").atProvided();
require("org.eclipse.jdt", "ecj").atProvided();
require("io.github.classgraph", "classgraph").atProvided();
require("org.graalvm.polyglot", "polyglot").atProvided();
require("org.graalvm.polyglot", "java-community").atProvided().byPom();
require("org.graalvm.polyglot", "js-community").atProvided().byPom();
require("org.graalvm.polyglot", "python-community").atProvided().byPom();
require("org.graalvm.espresso", "java").atProvided().byPom();
require("org.graalvm.espresso", "espresso-runtime-resources-jdk21").atProvided();

// TEST
require("com.github.teletha", "antibug").atTest();
Expand Down

0 comments on commit d5bb012

Please sign in to comment.