Skip to content

Commit

Permalink
Version 4.3.1-p1
Browse files Browse the repository at this point in the history
* Introduces code quality checks in plugin source via detekt
* Code formatting
* Sets earliest supported JetBrains products to version 193.4778.7
  • Loading branch information
jimschubert committed Jul 2, 2020
1 parent 2e813ef commit abce023
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 112 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies {
}
testCompile("junit:junit:4.12")

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.10.0-RC1")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.10.0")
}

// Configure gradle-intellij-plugin plugin.
Expand Down
82 changes: 79 additions & 3 deletions detekt-config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
# Default detekt configuration:
# https://github.com/detekt/detekt/blob/master/detekt-cli/src/main/resources/default-detekt-config.yml
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml

formatting:
Indentation:
active: true
active: true
android: false
autoCorrect: true
ImportOrdering:
active: false
autoCorrect: true
layout: 'idea'
NoConsecutiveBlankLines:
active: true
autoCorrect: true
SpacingAroundComma:
active: true
autoCorrect: true

performance:
active: true
ArrayPrimitive:
active: true
ForEachOnRange:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
UnnecessaryTemporaryInstantiation:
active: true


potential-bugs:
active: true
Deprecation:
active: false
DuplicateCaseInWhenExpression:
active: true
EqualsAlwaysReturnsTrueOrFalse:
active: true
EqualsWithHashCodeExist:
active: true
ExplicitGarbageCollectionCall:
active: true
HasPlatformType:
active: false
IgnoredReturnValue:
active: false
restrictToAnnotatedMethods: true
returnValueAnnotations: ['*.CheckReturnValue', '*.CheckResult']
ImplicitDefaultLocale:
active: false
InvalidRange:
active: true
IteratorHasNextCallsNextMethod:
active: true
IteratorNotThrowingNoSuchElementException:
active: true
LateinitUsage:
active: false
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
excludeAnnotatedProperties: []
ignoreOnClassesPattern: ''
MapGetWithNotNullAssertionOperator:
active: false
MissingWhenCase:
active: true
RedundantElseInWhen:
active: true
UnconditionalJumpStatementInLoop:
active: false
UnnecessaryNotNullOperator:
active: false
UnnecessarySafeCall:
active: false
UnreachableCode:
active: true
UnsafeCallOnNullableType:
active: true
UnsafeCast:
active: false
UselessPostfixExpression:
active: false
WrongEqualsTypeParameter:
active: true
6 changes: 2 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name = "intellij-openapi-generator"

version = 4.0
buildNumber = 1

openapiGeneratorVersion=4.3.1
pluginVersion = 1

slf4jVersion=1.7.12

pluginGroup = us.jimschubert.intellij.openapitools
pluginName = intellij_openapi_generator
pluginVersion = 0
pluginSinceBuild = 193.4778.7
pluginUntilBuild = 201.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import javax.swing.event.EventListenerList
internal class ActionButtonGroup : ButtonGroup() {
private val app = ApplicationManager.getApplication()
private val boundListeners = EventListenerList()
private val listener = Listener(this) {
e: ActionEvent? ->
private val listener = Listener(this) { e: ActionEvent? ->
onChange(e)
}

Expand Down Expand Up @@ -60,7 +59,8 @@ internal class ActionButtonGroup : ButtonGroup() {
}
}

private class Listener(@Suppress("unused") val owner: ActionButtonGroup, val callback: (ActionEvent?) -> Unit) : ActionListener {
private class Listener(@Suppress("unused") val owner: ActionButtonGroup, val callback: (ActionEvent?) -> Unit) :
ActionListener {
override fun actionPerformed(e: ActionEvent?) {
callback.invoke(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import java.awt.GridBagLayout
import javax.swing.JPanel
import javax.swing.JRadioButton

internal class ConstrainedOptionsPanel(options: List<CliConstrainedOption>, private val default: String? = null) : JPanel(GridBagLayout()) {
internal class ConstrainedOptionsPanel(options: List<CliConstrainedOption>, private val default: String? = null) :
JPanel(GridBagLayout()) {
private val defaultIdentifier = "<default>"
private val group: ActionButtonGroup = ActionButtonGroup()

Expand Down Expand Up @@ -53,7 +54,7 @@ internal class ConstrainedOptionsPanel(options: List<CliConstrainedOption>, priv
}
}
// avoid group.selection to be null when there is no default option
if (group.selection == null) group.elements.nextElement().isSelected = true
if (group.selection == null) group.elements.nextElement().isSelected = true
}

val value: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ import us.jimschubert.intellij.openapitools.Message
import us.jimschubert.intellij.openapitools.events.GenerationNotificationManager
import java.awt.BorderLayout
import java.io.File
import java.lang.IllegalStateException
import java.util.*
import javax.swing.*

class GenerateDialog(private val project: Project, val file: VirtualFile, private val notificationManager: GenerationNotificationManager) : DialogWrapper(project) {
class GenerateDialog(
private val project: Project,
val file: VirtualFile,
private val notificationManager: GenerationNotificationManager
) : DialogWrapper(project) {
companion object {
private var generatorTypeMap: MutableMap<CodegenType, MutableList<CodegenConfig>> = mutableMapOf()
// private val app = ApplicationManager.getApplication()
Expand All @@ -76,20 +79,21 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat

init {
outputBrowse.addBrowseFolderListener(
us.jimschubert.intellij.openapitools.Message of "dialog.generate.output-browse.title",
null,
project,
FileChooserDescriptorFactory.createSingleFolderDescriptor()
us.jimschubert.intellij.openapitools.Message of "dialog.generate.output-browse.title",
null,
project,
FileChooserDescriptorFactory.createSingleFolderDescriptor()
)

// TODO: Prior to building anything here, read and parse file. If that fails, bail immediately with error message.
if (generatorTypeMap.isEmpty()) {
val extensions: List<CodegenConfig> = ServiceLoader.load(CodegenConfig::class.java, CodegenConfig::class.java.classLoader).toList()
val extensions: List<CodegenConfig> =
ServiceLoader.load(CodegenConfig::class.java, CodegenConfig::class.java.classLoader).toList()
for (extension in extensions) {
if (!generatorTypeMap.containsKey(extension.tag)) {
generatorTypeMap[extension.tag] = mutableListOf(extension)
} else {
generatorTypeMap[extension.tag]!!.add(extension)
generatorTypeMap[extension.tag]?.add(extension)
}
}
}
Expand All @@ -112,38 +116,38 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat

private fun createPrimitivesPanel() {
primitivesPanel = ValuePropertiesPanel(
Message of "panel.primitive-types.value-column"
Message of "panel.primitive-types.value-column"
)
primitivesPanel.setEmptyMessage(Message of "panel.primitive-types.empty-message")
}

private fun createTypeMappingsPanel() {
typeMappingsPanel = KeyValuePropertiesPanel(
us.jimschubert.intellij.openapitools.Message of "panel.type-mappings.key-column",
us.jimschubert.intellij.openapitools.Message of "panel.type-mappings.value-column"
us.jimschubert.intellij.openapitools.Message of "panel.type-mappings.key-column",
us.jimschubert.intellij.openapitools.Message of "panel.type-mappings.value-column"
)
typeMappingsPanel.setEmptyMessage(Message of "panel.type-mappings.empty-message")
}

private fun createImportMappingsPanel() {
importMappingsPanel = KeyValuePropertiesPanel(
Message of "panel.import-mappings.key-column",
Message of "panel.import-mappings.value-column"
Message of "panel.import-mappings.key-column",
Message of "panel.import-mappings.value-column"
)
importMappingsPanel.setEmptyMessage(Message of "panel.import-mappings.empty-message")
}

private fun createAdditionalPropertiesPanel() {
additionalPropertiesPanel = KeyValuePropertiesPanel(
Message of "panel.additional-properties.key-column"
Message of "panel.additional-properties.key-column"
)
additionalPropertiesPanel.setEmptyMessage(Message of "panel.additional-properties.empty-message")
}

private fun createInstantiationTypesPanel() {
instantiationTypesPanel = KeyValuePropertiesPanel(
Message of "panel.instantiation-types.key-column",
Message of "panel.instantiation-types.value-column"
Message of "panel.instantiation-types.key-column",
Message of "panel.instantiation-types.value-column"
)
instantiationTypesPanel.setEmptyMessage(Message of "panel.instantiation-types.empty-message")
}
Expand All @@ -159,28 +163,28 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat
// valid OpenAPI file
SwaggerParser().readWithInfo(file.path) ?: return ValidationInfo("Specification file is invalid.", null)

if(outputBrowse.text.isEmpty()){
if (outputBrowse.text.isEmpty()) {
notificationManager.warn("Output directory is empty.")
return ValidationInfo("Output directory is empty.", outputBrowse)
} else {
val path = outputBrowse.text.replaceFirst("^~", System.getProperty("user.home"))
if(outputBrowse.text != path) {
if (outputBrowse.text != path) {
outputBrowse.text = path
}

val output = File(FileUtil.toSystemDependentName(path))
if(output.exists() && !output.isDirectory) {
if (output.exists() && !output.isDirectory) {
notificationManager.warn("Output directory is not a valid directory.")
return ValidationInfo("Output directory is not a valid directory.", outputBrowse)
}
if(!output.exists()) {
if(FileUtil.createDirectory(output)) {
if (!output.exists()) {
if (FileUtil.createDirectory(output)) {
notificationManager.warn("Could not create output directory.")
return ValidationInfo("Could not create output directory.", outputBrowse)
}
}

if(!output.canWrite()) {
if (!output.canWrite()) {
notificationManager.warn("Output directory is not writable.")
return ValidationInfo("Output directory is not writable.", outputBrowse)
}
Expand Down Expand Up @@ -214,11 +218,11 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat
currentConfigOptions = configOptions
val tabPane = langPanel.component.components.first() as? JBTabsImpl
if (currentConfigOptions != null) {
langPanel.setTitleAt(0, currentConfigOptions?.config?.name?:"")
tabPane?.tabs?.forEachIndexed { index, tabInfo -> if(index > 0) tabInfo.isHidden = false }
langPanel.setTitleAt(0, currentConfigOptions?.config?.name ?: "")
tabPane?.tabs?.forEachIndexed { index, tabInfo -> if (index > 0) tabInfo.isHidden = false }
} else {
langPanel.setTitleAt(0, "OpenAPI Generator")
tabPane?.tabs?.forEachIndexed { index, tabInfo -> if(index > 0) tabInfo.isHidden = true }
tabPane?.tabs?.forEachIndexed { index, tabInfo -> if (index > 0) tabInfo.isHidden = true }
}
langPanel.selectedIndex = 0
syncOptionsPanelOnChange(p)
Expand All @@ -233,7 +237,8 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat

val configurator = CodegenConfigurator.fromFile(settingsPanel.configurationFile) ?: CodegenConfigurator()

val generatorName = currentConfigOptions?.config?.javaClass?.typeName ?: throw IllegalStateException("Configuration options is unexpectedly inaccessible")
val generatorName = currentConfigOptions?.config?.javaClass?.typeName
?: throw IllegalStateException("Configuration options is unexpectedly inaccessible")
configurator.setInputSpec(file.path)
configurator.setGeneratorName(generatorName)
configurator.setOutputDir(outputBrowse.text)
Expand All @@ -248,7 +253,7 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat
configurator.setVerbose(settingsPanel.isVerbose)
configurator.setSkipOverwrite(settingsPanel.skipOverwrite)

if(settingsPanel.templateDirectory != null)
if (settingsPanel.templateDirectory != null)
configurator.setTemplateDir(settingsPanel.templateDirectory)

configurator.setLibrary(settingsPanel.library)
Expand Down Expand Up @@ -276,12 +281,12 @@ class GenerateDialog(private val project: Project, val file: VirtualFile, privat

try {
val files: MutableList<File> = DefaultGenerator()
.opts(configurator.toClientOptInput())
.generate()
.opts(configurator.toClientOptInput())
.generate()

logger.info("Generated $generatorName output in ${outputBrowse.text}.")

if(files.count() > 0) logger.debug("Generated files:")
if (files.count() > 0) logger.debug("Generated files:")
files.forEach { f -> logger.debug(f.canonicalPath) }

notificationManager.success(currentConfigOptions?.config?.name ?: generatorName, outputBrowse.text)
Expand Down

0 comments on commit abce023

Please sign in to comment.