Skip to content

Commit

Permalink
Added bld project panel with commands display
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jul 16, 2024
1 parent 8bd2858 commit 3af2a5e
Show file tree
Hide file tree
Showing 24 changed files with 849 additions and 124 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repositories {
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
implementation(libs.bld)
implementation(libs.json)
}

//configurations.all {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
# libraries
bld = "2.0.0-SNAPSHOT"
json = "20240303"

# plugins
kotlin = "1.9.24"
Expand All @@ -11,6 +12,7 @@ kover = "0.8.1"

[libraries]
bld = { group = "com.uwyn.rife2", name = "bld", version.ref = "bld" }
json = { group = "org.json", name = "json", version.ref = "json" }

[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/rife/bld/idea/ProjectOpenStartupActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,7 @@ public class ProjectOpenStartupActivity implements ProjectActivity {
@Nullable
@Override
public Object execute(@NotNull Project project, @NotNull Continuation<? super Unit> continuation) {
System.out.println("Startup");

BldExecution.listTasks(project);

/* Clear console window. */
// ApplicationManager.getApplication().invokeAndWait(() -> {
// ConsoleView executionConsole = BldConsoleManager.getConsole(project);
// executionConsole.getComponent().setVisible(true);
// executionConsole.clear();
// var console = ToolWindowManagerEx.getInstance(project).getToolWindow(BldConstants.BLD_CONSOLE_NAME);
// if (console != null) {
// console.activate(null);
// }
// }, ModalityState.nonModal());

return null;
}
}
27 changes: 27 additions & 0 deletions src/main/java/rife/bld/idea/config/BldBuildCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.config;

import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.util.NlsSafe;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface BldBuildCommand {
@Nullable
@NlsSafe
String getName();

@Nullable
@NlsSafe
String getDisplayName();

@Nullable
@Nls(capitalization = Nls.Capitalization.Sentence) String getNotEmptyDescription();

void run(DataContext dataContext, List<?> additionalProperties, BldBuildListener buildListener);
}
19 changes: 19 additions & 0 deletions src/main/java/rife/bld/idea/config/BldBuildListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.config;

public interface BldBuildListener {
int FINISHED_SUCCESSFULLY = 0;
int ABORTED = 1;
int FAILED_TO_RUN = 2;

BldBuildListener NULL = new BldBuildListener() {
@Override
public void buildFinished(int state, int errorCount) {
}
};

void buildFinished(int state, int errorCount);
}
79 changes: 79 additions & 0 deletions src/main/java/rife/bld/idea/config/BldConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.config;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SimpleModificationTracker;
import com.intellij.util.EventDispatcher;
import org.jdom.Element;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@Service(Service.Level.PROJECT)
public final class BldConfiguration implements Disposable {
private final Project project_;
private final List<BldBuildCommand> buildCommands_ = new CopyOnWriteArrayList<>();
private final EventDispatcher<BldConfigurationListener> myEventDispatcher = EventDispatcher.create(BldConfigurationListener.class);

private volatile boolean initialized_ = false;

public BldConfiguration(final Project project) {
project_ = project;

ApplicationManager.getApplication().invokeLater(
() -> myEventDispatcher.getMulticaster().configurationLoaded(),
ModalityState.any()
);
}

public static BldConfiguration getInstance(final @NotNull Project project) {
return project.getService(BldConfiguration.class);
}

@Override
public void dispose() {
// no-op
}

public boolean isInitialized() {
return initialized_;
}

public List<BldBuildCommand> getBuildCommandList() {
return buildCommands_;
}

public void setBuildCommandList(ArrayList<BldBuildCommand> commands) {
initialized_ = true;

buildCommands_.clear();
buildCommands_.addAll(commands);
ApplicationManager.getApplication().invokeLater(
() -> myEventDispatcher.getMulticaster().configurationChanged(),
ModalityState.any()
);
}

public void addBldConfigurationListener(final BldConfigurationListener listener) {
myEventDispatcher.addListener(listener);
}

public void removeBldConfigurationListener(final BldConfigurationListener listener) {
myEventDispatcher.removeListener(listener);
}
}
15 changes: 15 additions & 0 deletions src/main/java/rife/bld/idea/config/BldConfigurationListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.config;

import java.util.EventListener;

public interface BldConfigurationListener extends EventListener {
default void configurationLoaded() {
}

default void configurationChanged() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.config.explorer;

import com.intellij.ide.util.treeView.AbstractTreeStructure;
import com.intellij.ide.util.treeView.NodeDescriptor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.util.ArrayUtilRt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import rife.bld.idea.config.BldBuildCommand;
import rife.bld.idea.config.BldConfiguration;
import rife.bld.idea.config.explorer.nodeDescriptors.*;
import rife.bld.idea.utils.BldBundle;

import java.util.ArrayList;
import java.util.Comparator;

public final class BldExplorerTreeStructure extends AbstractTreeStructure {
private static final Logger LOG = Logger.getInstance(BldExplorerTreeStructure.class);

private final Project project_;

private final Object root_ = new Object();
private final Object commandsFolder_ = new Object();
private final Object dependenciesFolder_ = new Object();

private static final Comparator<BldBuildCommand> commandComparator = (command1, command2) -> {
final String name1 = command1.getDisplayName();
if (name1 == null) return -1;
final String name2 = command2.getDisplayName();
if (name2 == null) return 1;
return name1.compareToIgnoreCase(name2);
};

public BldExplorerTreeStructure(final Project project) {
project_ = project;
}

@Override
public boolean isToBuildChildrenInBackground(@NotNull final Object element) {
return true;
}

@Override
public boolean isAlwaysLeaf(@NotNull Object element) {
return element != root_ && element != commandsFolder_ && element != dependenciesFolder_;
}

@Override
@NotNull
public BldNodeDescriptor createDescriptor(@NotNull Object element, NodeDescriptor parentDescriptor) {
if (element == root_) {
return new BldRootNodeDescriptor(project_, parentDescriptor, root_);
}
if (element == commandsFolder_) {
return new BldFolderNodeDescriptor(project_, parentDescriptor, commandsFolder_, BldBundle.message("bld.project.commands"));
}
if (element == dependenciesFolder_) {
return new BldFolderNodeDescriptor(project_, parentDescriptor, dependenciesFolder_, BldBundle.message("bld.project.dependencies"));
}

if (element instanceof BldBuildCommand) {
return new BldCommandNodeDescriptor(project_, parentDescriptor, (BldBuildCommand)element);
}

if (element instanceof String) {
return new BldTextNodeDescriptor(project_, parentDescriptor, (String) element);
}

LOG.error("Unknown element for this tree structure " + element);
return new BldTextNodeDescriptor(project_, parentDescriptor, String.valueOf(element));
}

@Override
public Object @NotNull [] getChildElements(@NotNull Object element) {
final var configuration = BldConfiguration.getInstance(project_);
if (element == root_) {
if (!configuration.isInitialized()) {
return new Object[]{BldBundle.message("progress.text.loading.bld.config")};
}
return new Object[]{commandsFolder_, dependenciesFolder_};
}

if (element == commandsFolder_) {
final var commands = new ArrayList<>(configuration.getBuildCommandList());
commands.sort(commandComparator);
return commands.toArray(new BldBuildCommand[0]);
}

if (element == dependenciesFolder_) {
// todo
return ArrayUtilRt.EMPTY_OBJECT_ARRAY;
}

return ArrayUtilRt.EMPTY_OBJECT_ARRAY;
}

@Override
@Nullable
public Object getParentElement(@NotNull Object element) {
if (element instanceof BldBuildCommand) {
return commandsFolder_;
}

if (element == commandsFolder_) {
return root_;
}

if (element == dependenciesFolder_) {
return root_;
}

return null;
}

@Override
public void commit() {
PsiDocumentManager.getInstance(project_).commitAllDocuments();
}

@Override
public boolean hasSomethingToCommit() {
return PsiDocumentManager.getInstance(project_).hasUncommitedDocuments();
}

@NotNull
@Override
public ActionCallback asyncCommit() {
return asyncCommitDocuments(project_);
}

@NotNull
@Override
public Object getRootElement() {
return root_;
}

}
Loading

0 comments on commit 3af2a5e

Please sign in to comment.