Skip to content

Commit

Permalink
concept cloud plugin 2.0.0 213-231
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghanzheng committed Jun 10, 2023
1 parent 4cd5d0f commit b78bad4
Show file tree
Hide file tree
Showing 32 changed files with 962 additions and 314 deletions.
2 changes: 1 addition & 1 deletion concept-cloud/concept-cloud-plugin-intellij/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tasks {

patchPluginXml {
sinceBuild.set("213.5744.223")
untilBuild.set("")
untilBuild.set("232.0")
//sinceBuild.set("212")
//untilBuild.set("222.*")
//sinceBuild.set("223")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

@SuppressWarnings("all")
public class ConceptCloudWebModuleBuilder extends ConceptWebStarterModuleBuilder {

private final Key<Map<String, ConceptFrameworkVersion>> CONCEPT_CLOUD_CFV_KEY = new Key<>("CONCEPT_CLOUD_CFV_KEY");
Expand All @@ -29,7 +28,7 @@ public class ConceptCloudWebModuleBuilder extends ConceptWebStarterModuleBuilder
@Override
protected Url composeGeneratorUrl(@NotNull String s, @NotNull ConceptWebStarterContext webStarterContext) {
ConceptWebStarterFrameworkVersion frameworkVersion = webStarterContext.getFrameworkVersion();
String version = frameworkVersion.getId();
String version = frameworkVersion == null ? "VERSION_NULL" : frameworkVersion.getId();
String location = "java/" + version + "/template.zip";
String url;
if (s.endsWith("/")) {
Expand Down Expand Up @@ -117,6 +116,9 @@ private void handleConceptGradle(File file) throws IOException {

private String handleVersions(String content) {
Versions versions = getVersions();
if (versions == null) {
return content;
}
return content
.replaceAll("\\$V_GRADLE\\$", versions.gradle)
.replaceAll("\\$V_SPRING_BOOT\\$", versions.springBoot)
Expand All @@ -143,19 +145,19 @@ private ConceptFrameworkVersion getConceptFrameworkVersion() {
private void createDir(String name, File parent) {
File file = new File(parent, name);
if (!file.exists()) {
file.mkdirs();
boolean mkdirs = file.mkdirs();
}
}

private File createFile(String name, File parent) throws IOException {
File file = new File(parent, name);
File parentFile = new File(transform(file.getParent(), true));
if (!parentFile.exists()) {
parentFile.mkdirs();
boolean mkdirs = parentFile.mkdirs();
}
File create = new File(parentFile, file.getName());
if (!create.exists()) {
create.createNewFile();
boolean newFile = create.createNewFile();
}
return create;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.github.linyuzai.cloud.plugin.intellij.domain.DomainFileGenerator;
import com.github.linyuzai.cloud.plugin.intellij.domain.DomainModel;
import com.github.linyuzai.cloud.plugin.intellij.util.ConceptDialog;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.ui.RecentsManager;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
package com.github.linyuzai.cloud.plugin.intellij

import com.github.linyuzai.cloud.plugin.intellij.ConceptCompoundParallelOperationTrace.Companion.task
import com.intellij.openapi.Disposable
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.Disposer
import com.intellij.util.containers.DisposableWrapperList
import org.jetbrains.annotations.NonNls
import java.util.concurrent.atomic.AtomicInteger

class ConceptAnonymousParallelOperationTrace private constructor(
private val delegate: ConceptCompoundParallelOperationTrace<Nothing?>
) : ConceptObservableOperationTrace by delegate {
constructor(@NonNls debugName: String? = null) : this(ConceptCompoundParallelOperationTrace<Nothing?>(debugName))

fun startTask() = delegate.startTask(null)
fun finishTask() = delegate.finishTask(null)

companion object {
fun <R> ConceptAnonymousParallelOperationTrace.task(action: () -> R): R = delegate.task(null, action)
}
}

interface ConceptObservableOperationTrace {
/**
* Checks that operations is completed.
*/
fun isOperationCompleted(): Boolean

/**
* Subscribes listener with TTL on operation start event.
* Subscribed listener will be automatically unsubscribed when [ttl] is out or when [parentDisposable] is disposed.
* [parentDisposable] uses for early unsubscription when listener is called less than [ttl] times.
*
* @param ttl is a number of listener calls which should be passed to unsubscribe listener.
* @param listener is a listener function that will be called [ttl] times.
* @param parentDisposable is a subscription disposable.
*/
fun beforeOperation(ttl: Int, listener: () -> Unit, parentDisposable: Disposable)

/**
* Subscribes listener on operation start event that will never been unsubscribed.
*/
fun beforeOperation(listener: () -> Unit)

/**
* Subscribes listener on operation start event that unsubscribed when [parentDisposable] is disposed.
*/
fun beforeOperation(listener: () -> Unit, parentDisposable: Disposable)

/**
* Subscribes listener with TTL on operation finish event.
*
* @see beforeOperation(Int, () -> Unit, Disposable)
*/
fun afterOperation(ttl: Int, listener: () -> Unit, parentDisposable: Disposable)

/**
* Subscribes listener on operation finish event that will never been unsubscribed.
*/
fun afterOperation(listener: () -> Unit)

/**
* Subscribes listener on operation finish event that unsubscribed when [parentDisposable] is disposed.
*/
fun afterOperation(listener: () -> Unit, parentDisposable: Disposable)
}

class ConceptCompoundParallelOperationTrace<Id>(private val debugName: String? = null) :
ConceptAbstractObservableOperationTrace() {

private val traces = LinkedHashMap<Id, Int>()

override fun isOperationCompleted(): Boolean {
synchronized(this) {
return traces.isEmpty()
}
}

fun startTask(taskId: Id) {
val isOperationCompletedBeforeStart: Boolean
synchronized(this) {
isOperationCompletedBeforeStart = traces.isEmpty()
addTask(taskId)
}
if (isOperationCompletedBeforeStart) {
debug("Operation is started")
fireOperationStarted()
}
}

fun finishTask(taskId: Id) {
val isOperationCompletedAfterFinish: Boolean
synchronized(this) {
if (!removeTask(taskId)) return
isOperationCompletedAfterFinish = traces.isEmpty()
}
if (isOperationCompletedAfterFinish) {
debug("Operation is finished")
fireOperationFinished()
}
}

private fun addTask(taskId: Id) {
val taskCounter = traces.getOrPut(taskId) { 0 }
traces[taskId] = taskCounter + 1
debug("Task is started with id `$taskId`")
}

private fun removeTask(taskId: Id): Boolean {
debug("Task is finished with id `$taskId`")
val taskCounter = traces[taskId] ?: return false
when (taskCounter) {
1 -> traces.remove(taskId)
else -> traces[taskId] = taskCounter - 1
}
return taskCounter == 1
}

private fun debug(message: String) {
if (LOG.isDebugEnabled) {
val debugPrefix = if (debugName == null) "" else "$debugName: "
LOG.debug("$debugPrefix$message")
}
}

companion object {
private val LOG = Logger.getInstance(ConceptCompoundParallelOperationTrace::class.java)

fun <Id, R> ConceptCompoundParallelOperationTrace<Id>.task(taskId: Id, action: () -> R): R {
startTask(taskId)
try {
return action()
} finally {
finishTask(taskId)
}
}
}
}

abstract class ConceptAbstractObservableOperationTrace : ConceptObservableOperationTrace {

private val beforeOperationListeners = DisposableWrapperList<() -> Unit>()
private val afterOperationListeners = DisposableWrapperList<() -> Unit>()

protected fun fireOperationStarted() {
beforeOperationListeners.forEach { it() }
}

protected fun fireOperationFinished() {
afterOperationListeners.forEach { it() }
}

override fun beforeOperation(ttl: Int, listener: () -> Unit, parentDisposable: Disposable) {
subscribe(ttl, listener, ::beforeOperation, parentDisposable)
}

override fun beforeOperation(listener: () -> Unit) {
beforeOperationListeners.add(listener)
}

override fun beforeOperation(listener: () -> Unit, parentDisposable: Disposable) {
beforeOperationListeners.add(listener, parentDisposable)
}

override fun afterOperation(ttl: Int, listener: () -> Unit, parentDisposable: Disposable) {
subscribe(ttl, listener, ::afterOperation, parentDisposable)
}

override fun afterOperation(listener: () -> Unit) {
afterOperationListeners.add(listener)
}

override fun afterOperation(listener: () -> Unit, parentDisposable: Disposable) {
afterOperationListeners.add(listener, parentDisposable)
}
}

@JvmName("subscribe0")
fun subscribe(
ttl: Int,
listener: () -> Unit,
subscribe: (() -> Unit, Disposable) -> Unit,
parentDisposable: Disposable
) {
val ttlCounter = ConceptTTLCounter(ttl, parentDisposable)
subscribe({
ttlCounter.update()
listener()
}, ttlCounter)
}

private class ConceptTTLCounter(ttl: Int, parentDisposable: Disposable) : Disposable {
private val ttlCounter = AtomicInteger(ttl)

fun update() {
if (ttlCounter.decrementAndGet() == 0) {
Disposer.dispose(this)
}
}

override fun dispose() {}

init {
require(ttl > 0)
Disposer.register(parentDisposable, this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import com.intellij.openapi.actionSystem.ex.ActionButtonLook
import com.intellij.openapi.actionSystem.impl.ActionButton
import com.intellij.openapi.actionSystem.impl.ActionButtonWithText
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.util.NlsActions
import java.awt.Dimension
import java.awt.Insets
import java.util.function.Supplier
import kotlin.math.max

fun <T> ConceptRow.buttonSelector(options: Collection<T>, property: GraphProperty<T>, renderer: (T) -> String): ConceptButtonSelectorToolbar {
fun <T> ConceptRow.buttonSelector(options: Collection<T>, property: ConceptGraphProperty<T>, renderer: (T) -> String): ConceptButtonSelectorToolbar {
val actionGroup = DefaultActionGroup(options.map { ButtonSelectorAction(it, property, renderer(it)) })
val toolbar = ConceptButtonSelectorToolbar("ButtonSelector", actionGroup, true)
toolbar.targetComponent = null // any data context is supported, suppress warning
Expand All @@ -22,14 +21,14 @@ fun <T> ConceptRow.buttonSelector(options: Collection<T>, property: GraphPropert
}

class ButtonSelectorAction<T> @JvmOverloads constructor(private val option: T,
private val property: GraphProperty<T>,
private val property: ConceptGraphProperty<T>,
optionText: Supplier<@NlsActions.ActionText String>,
optionDescription: Supplier<@NlsActions.ActionText String>? = null)
: ToggleAction(optionText, optionDescription ?: Supplier { null }, null), DumbAware {

@JvmOverloads
constructor(option: T,
property: GraphProperty<T>,
property: ConceptGraphProperty<T>,
@NlsActions.ActionText optionText: String,
@NlsActions.ActionDescription optionDescription: String? = null) :
this(option, property, Supplier { optionText }, optionDescription?.let { Supplier { optionDescription } })
Expand Down
Loading

0 comments on commit b78bad4

Please sign in to comment.