Skip to content

Commit

Permalink
Removing dependency on checkstyle to remove guava for Android projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmook committed Mar 11, 2019
1 parent d7b861c commit 81620b6
Show file tree
Hide file tree
Showing 13 changed files with 594 additions and 27 deletions.
5 changes: 0 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21")
classpath("org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2")
classpath("com.novoda:bintray-release:0.9")
classpath("com.novoda:bintray-release:0.9")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Expand Down
2 changes: 0 additions & 2 deletions markdown/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ dependencies {
api("com.vladsch.flexmark:flexmark-ext-gfm-strikethrough:0.40.20")
api("com.vladsch.flexmark:flexmark-ext-autolink:0.40.20")

implementation("com.puppycrawl.tools:checkstyle:8.18")

testImplementation(kotlin("test"))
testImplementation(gradleTestKit())
testImplementation("junit:junit:4.12")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.appmattus.markdown.checkstyle

/**
* Raw event for audit.
*
* I'm not very satisfied about the design of this event since there are
* optional methods that will return null in most of the case. This will
* need some work to clean it up especially if we want to introduce
* a more sequential reporting action rather than a packet error
* reporting. This will allow for example to follow the process quickly
* in an interface or a servlet (yep, that's cool to run a check via
* a web interface in a source repository ;-)
*
* Creates a new `AuditEvent` instance.
*
* @param fileName file associated with the event
* @param localizedMessage the actual message
* @see AuditListener
*/
class AuditEvent(
val fileName: String,
private val localizedMessage: LocalizedMessage? = null
) {

/**
* Return the line number on the source file where the event occurred.
* This may be 0 if there is no relation to a file content.
*
* @return an integer representing the line number in the file source code.
*/
val line: Int
get() = localizedMessage!!.lineNo

/**
* Return the message associated to the event.
*
* @return the event message
*/
val message: String
get() = localizedMessage!!.message

/**
* Gets the column associated with the message.
*
* @return the column associated with the message
*/
val column: Int
get() = localizedMessage!!.columnNo

/**
* Gets the audit event severity level.
*
* @return the audit event severity level
*/
val severityLevel: SeverityLevel
get() = localizedMessage?.severityLevel ?: SeverityLevel.INFO

/**
* Gets the name of the source for the message.
*
* @return the name of the source for the message
*/
val sourceName: String
get() = localizedMessage!!.sourceName
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.appmattus.markdown.checkstyle

/**
* Listener in charge of receiving events from the Checker.
* Typical events sequence is:
*
* ```
* auditStarted
* (fileStarted
* (addError)
* fileFinished)
* auditFinished
* ```
*/
interface AuditListener {

/**
* Notify that the audit is about to start.
*/
fun auditStarted()

/**
* Notify that the audit is finished.
*/
fun auditFinished()

/**
* Notify that audit is about to start on a specific file.
*
* @param event the event details
*/
fun fileStarted(event: AuditEvent)

/**
* Notify that audit is finished on a specific file.
*
* @param event the event details
*/
fun fileFinished(event: AuditEvent)

/**
* Notify that an audit error was discovered on a specific file.
*
* @param event the event details
*/
fun addError(event: AuditEvent)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.appmattus.markdown.checkstyle

/**
* Represents a message that can be localised. The translations come from
* message.properties files. The underlying implementation uses
* java.text.MessageFormat.
*
* @param lineNo line number associated with the message
* @param columnNo column number associated with the message
* @param message the error message
* @param severityLevel severity level for the message
* @param sourceClass the Class that is the source of the message
*/
data class LocalizedMessage(
val lineNo: Int,
val columnNo: Int,
val message: String,
val severityLevel: SeverityLevel,
private val sourceClass: Class<*>
) : Comparable<LocalizedMessage> {

/**
* Gets the name of the source for this LocalizedMessage.
*
* @return the name of the source for this LocalizedMessage
*/
val sourceName: String = sourceClass.name

////////////////////////////////////////////////////////////////////////////
// Interface Comparable methods
////////////////////////////////////////////////////////////////////////////

@Suppress("ComplexMethod")
override fun compareTo(other: LocalizedMessage): Int {
return if (lineNo == other.lineNo) {
if (columnNo == other.columnNo) {
message.compareTo(other.message)
} else {
Integer.compare(columnNo, other.columnNo)
}
} else {
Integer.compare(lineNo, other.lineNo)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.appmattus.markdown.checkstyle

/**
* Enum to specify behaviour regarding ignored modules.
*/
enum class OutputStreamOptions {

/**
* Close stream in the end.
*/
CLOSE,

/**
* Do nothing in the end.
*/
NONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.appmattus.markdown.checkstyle

import java.util.Locale

/**
* Severity level for a check violation.
*
* Each violation of an audit check is assigned one of the severity levels
* defined here.
*
*/
enum class SeverityLevel {

/**
* Severity level ignore.
*/
IGNORE,
/**
* Severity level info.
*/
INFO,
/**
* Severity level warning.
*/
WARNING,
/**
* Severity level error.
*/
ERROR;

/**
* Returns name of severity level.
*
* @return the name of this severity level.
*/
val value: String
get() = name.toLowerCase(Locale.ENGLISH)

override fun toString(): String {
return value
}
}
Loading

0 comments on commit 81620b6

Please sign in to comment.