Skip to content

Commit

Permalink
馃Ъ Fix depecrations
Browse files Browse the repository at this point in the history
  • Loading branch information
yodamad committed May 19, 2023
1 parent f53fe4c commit e1787fe
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 45 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.yodamad.svn2git.aop.logging;

import org.springframework.core.env.Profiles;
import tech.jhipster.config.JHipsterConstants;

import org.aspectj.lang.JoinPoint;
Expand All @@ -16,7 +17,6 @@

/**
* Aspect for logging execution of service and repository Spring components.
*
* By default, it only runs with the "dev" profile.
*/
@Aspect
Expand Down Expand Up @@ -58,7 +58,7 @@ public void applicationPackagePointcut() {
*/
@AfterThrowing(pointcut = "applicationPackagePointcut() && springBeanPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
if (env.acceptsProfiles(Profiles.of(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT))) {
log.error("Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL", e.getMessage(), e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import java.util.stream.Collectors
*/
fun isForbiddenExtension(workUnit: WorkUnit, path: Path): Boolean {
if (workUnit.migration.forbiddenFileExtensions == null) return false
val extensions = Arrays.stream(workUnit.migration.forbiddenFileExtensions.split(",").toTypedArray()).map { obj: String -> obj.toLowerCase() }.collect(Collectors.toList())
val uppercaseExtensions = Arrays.stream(workUnit.migration.forbiddenFileExtensions.split(",").toTypedArray()).map { obj: String -> obj.toUpperCase() }.collect(Collectors.toList())
val extensions = Arrays.stream(workUnit.migration.forbiddenFileExtensions.split(",").toTypedArray()).map { obj: String -> obj.lowercase() }.collect(Collectors.toList())
val uppercaseExtensions = Arrays.stream(workUnit.migration.forbiddenFileExtensions.split(",").toTypedArray()).map { obj: String -> obj.uppercase() }.collect(Collectors.toList())
extensions.addAll(uppercaseExtensions)
return extensions.stream()
.anyMatch { ext: String -> path.toString().endsWith(ext.replaceFirst("\\*".toRegex(), "")) }
Expand All @@ -45,7 +45,7 @@ fun exceedsMaxSize(workUnit: WorkUnit, path: Path): Boolean {
"K" -> digits *= 1024
else -> { }
}
var isFileExceedsMaxSize: Boolean = false
var isFileExceedsMaxSize: Boolean
FileChannel.open(path).use { fileChannel -> isFileExceedsMaxSize = fileChannel.size() > digits }
return isFileExceedsMaxSize
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.apache.commons.lang3.StringUtils
import org.springframework.web.util.UriUtils.decode
import org.springframework.web.util.UriUtils.encode

val EMPTY = ""
const val EMPTY = ""

fun formattedOrEmpty(element: String?, container: String, windowsCase: String? = null) =
when {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/yodamad/svn2git/init/CheckUp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CheckUp {
private val EXPECT_VERSION = "expect"
private val EXPECT_ERROR = "鉀旓笍 expect binary is required on Linux. 馃憠 Run apt-get|yum install expect."

val isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows")
val isWindows = System.getProperty("os.name").lowercase().startsWith("windows")

@PostConstruct
fun atStartup() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/fr/yodamad/svn2git/io/Shell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fr.yodamad.svn2git.domain.Migration
import fr.yodamad.svn2git.service.util.CommandManager
import org.apache.commons.io.IOUtils
import org.slf4j.LoggerFactory
import org.springframework.util.StringUtils.hasLength
import org.springframework.util.StringUtils.isEmpty
import java.io.*
import java.nio.charset.Charset
Expand All @@ -17,7 +18,7 @@ import java.util.function.Consumer
*/
object Shell {
private val LOG = LoggerFactory.getLogger(Shell::class.java)
val isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows")
val isWindows = System.getProperty("os.name").lowercase().startsWith("windows")

/**
* Get working directory
Expand Down Expand Up @@ -79,7 +80,7 @@ object Shell {
LOG.debug(String.format("Exec command : %s", securedCommandToPrint))
LOG.debug(String.format("in %s", execDir))
val process = builder.start()
val streamGobbler = StreamGobbler(process.inputStream) { s: String? -> if (alwaysPrintOutput && !isEmpty(s) && !s!!.contains("password", true)) LOG.info(s) else LOG.debug(s) }
val streamGobbler = StreamGobbler(process.inputStream) { s: String? -> if (alwaysPrintOutput && hasLength(s) && !s!!.contains("password", true)) LOG.info(s) else LOG.debug(s) }
Executors.newSingleThreadExecutor().submit(streamGobbler)
val errorStreamGobbler = StreamGobbler(process.errorStream) { s: String? -> LOG.error(s) }
Executors.newSingleThreadExecutor().submit(errorStreamGobbler)
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/fr/yodamad/svn2git/service/Cleaner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ open class Cleaner(val historyMgr: HistoryManager,
val gitCommand = String.format("git checkout -b \"%s\" \"%s\"", branchName, b)
execCommand(workUnit.commandManager, workUnit.directory, gitCommand)
// listCleanedFilesInSvnLocation
val branches = if (workUnit.migration.uppercase) "branches".toUpperCase() else "branches"
val branches = if (workUnit.migration.uppercase) "branches".uppercase() else "branches"
val cleanedFilesBranch: CleanedFiles = listCleanedFilesInSvnLocation(workUnit, b.replace("origin", branches), SvnLayout.BRANCH)
cleanedFilesMap[b.replace("origin", branches)] = cleanedFilesBranch
// clean potential modification
Expand All @@ -111,7 +111,7 @@ open class Cleaner(val historyMgr: HistoryManager,
val gitCommand = String.format("git checkout -b tmp_tag \"%s\"", t)
execCommand(workUnit.commandManager, workUnit.directory, gitCommand)
// listCleanedFilesInSvnLocation
val tags = if (workUnit.migration.uppercase) "tags".toUpperCase() else "tags"
val tags = if (workUnit.migration.uppercase) "tags".uppercase() else "tags"
val cleanedFilesTag: CleanedFiles = listCleanedFilesInSvnLocation(workUnit, t.replace("origin", tags), TAG)
cleanedFilesMap[t.replace("origin", tags)] = cleanedFilesTag
// clean potential modification
Expand Down Expand Up @@ -314,10 +314,10 @@ open class Cleaner(val historyMgr: HistoryManager,
Arrays.stream(workUnit.migration.forbiddenFileExtensions.split(",").toTypedArray())
.forEach { s: String ->
val innerHistory = historyMgr.startStep(workUnit.migration, StepEnum.GIT_CLEANING,
"Remove files with extension : ${s.toLowerCase()} and ${s.toUpperCase()}")
"Remove files with extension : ${s.lowercase()} and ${s.uppercase()}")
try {
Main.main(arrayOf("--delete-files", s.toLowerCase(), "--no-blob-protection", workUnit.directory))
Main.main(arrayOf("--delete-files", s.toUpperCase(), "--no-blob-protection", workUnit.directory))
Main.main(arrayOf("--delete-files", s.lowercase(), "--no-blob-protection", workUnit.directory))
Main.main(arrayOf("--delete-files", s.lowercase(), "--no-blob-protection", workUnit.directory))
historyMgr.endStep(innerHistory, DONE, null)
} catch (exc: Throwable) {
historyMgr.endStep(innerHistory, StatusEnum.FAILED, exc.message)
Expand Down Expand Up @@ -390,8 +390,8 @@ open class Cleaner(val historyMgr: HistoryManager,
*/
open fun cleanElementsOn(workUnit: WorkUnit, tags: Boolean) {

val elements = if (tags) Pair(workUnit.migration.tags, if (workUnit.migration.uppercase) "tags".toUpperCase() else "tags")
else Pair(workUnit.migration.branches, if (workUnit.migration.uppercase) "branches".toUpperCase() else "branches")
val elements = if (tags) Pair(workUnit.migration.tags, if (workUnit.migration.uppercase) "tags".uppercase() else "tags")
else Pair(workUnit.migration.branches, if (workUnit.migration.uppercase) "branches".uppercase() else "branches")

if (elements.first != null) {
val history = historyMgr.startStep(workUnit.migration, StepEnum.BRANCH_CLEAN, "Clean removed SVN ${elements.second}")
Expand Down Expand Up @@ -463,12 +463,12 @@ open class Cleaner(val historyMgr: HistoryManager,
val svnUrl = if (workUnit.migration.svnUrl.endsWith("/")) workUnit.migration.svnUrl else String.format("%s/", workUnit.migration.svnUrl)
val svnBranchList: String = if (StringUtils.isEmpty(workUnit.migration.svnPassword)) {
String.format("svn ls %s%s%s/%s > %s", svnUrl, workUnit.migration.svnGroup, workUnit.migration.svnProject,
if (isTags && workUnit.migration.uppercase) "tags".toUpperCase() else if (isTags) "tags" else if (workUnit.migration.uppercase) "branches".toUpperCase() else "branches", SVN_LIST)
if (isTags && workUnit.migration.uppercase) "tags".uppercase() else if (isTags) "tags" else if (workUnit.migration.uppercase) "branches".uppercase() else "branches", SVN_LIST)
} else {
String.format("svn ls %s%s%s/%s %s %s > %s", svnUrl,
if (workUnit.migration.svnGroup.endsWith("/")) workUnit.migration.svnGroup else String.format("%s/", workUnit.migration.svnGroup),
workUnit.migration.svnProject,
if (isTags && workUnit.migration.uppercase) "tags".toUpperCase() else if (isTags) "tags" else if (workUnit.migration.uppercase) "branches".toUpperCase() else "branches",
if (isTags && workUnit.migration.uppercase) "tags".uppercase() else if (isTags) "tags" else if (workUnit.migration.uppercase) "branches".uppercase() else "branches",
"--username=" + workUnit.migration.svnUser, "--password=" + workUnit.migration.svnPassword.escape(),
SVN_LIST)
}
Expand All @@ -479,7 +479,7 @@ open class Cleaner(val historyMgr: HistoryManager,
.collect(Collectors.toList())

// ######### Switch elementsToKeep if necessary ##################################
if (keepListFromFilter != null && keepListFromFilter.isNotEmpty()) {
if (!keepListFromFilter.isNullOrEmpty()) {
elementsToKeep = keepListFromFilter
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/fr/yodamad/svn2git/service/GitManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import fr.yodamad.svn2git.domain.enumeration.StatusEnum
import fr.yodamad.svn2git.domain.enumeration.StepEnum
import fr.yodamad.svn2git.io.Shell.execCommand
import fr.yodamad.svn2git.io.Shell.isWindows
import fr.yodamad.svn2git.repository.MappingRepository
import fr.yodamad.svn2git.service.util.*
import org.apache.commons.lang3.StringEscapeUtils
import org.apache.commons.lang3.StringUtils
import org.apache.commons.lang3.StringUtils.isEmpty
import org.apache.commons.text.StringEscapeUtils
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import java.io.IOException
Expand All @@ -23,8 +22,6 @@ import java.nio.charset.Charset.defaultCharset
open class GitManager(val historyMgr: HistoryManager,
val gitCommandManager: GitCommandManager,
val repoFormatter: GitRepositoryFormatter,
val mappingMgr: MappingManager,
val mappingRepository: MappingRepository,
var applicationProperties: ApplicationProperties) {

private val LOG = LoggerFactory.getLogger(GitManager::class.java)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/fr/yodamad/svn2git/service/GitlabManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ open class GitlabManager(val historyMgr: HistoryManager,
* Create project in GitLab
*
* @param migration
* @param workUnit
* @throws GitLabApiException
*/
@Throws(GitLabApiException::class)
open fun createGitlabProject(migration: Migration) : Int {
val history: MigrationHistory = historyMgr.startStep(migration, StepEnum.GITLAB_PROJECT_CREATION, migration.gitlabUrl + migration.gitlabGroup)
var gitlabAdmin = getGitlabAdminPrototype()
var gitlabProjectId : Int


// If gitlabInfo.token is empty assure using values found in application.yml.
// i.e. those in default GitlabAdmin object
Expand All @@ -61,6 +60,7 @@ open class GitlabManager(val historyMgr: HistoryManager,
}
try {
val group = gitlabAdmin!!.groupApi().getGroup(migration.gitlabGroup)
val gitlabProjectId : Int

// If no svn project specified, use svn group instead
if (isEmpty(migration.svnProject) && isEmpty(migration.gitlabProject)) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/fr/yodamad/svn2git/service/HistoryManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ open class HistoryManager(private val migrationHistoryRepository: MigrationHisto
val execution = Instant.now().toEpochMilli() - history.startTime.toEpochMilli()
history.executionTime = DateFormatter.toNiceFormat(execution)
}
migrationHistoryRepository.save(history)
LOG.info("Finish step ${history?.step} with status $status in ${history?.executionTime}")
migrationHistoryRepository.save(history!!)
LOG.info("Finish step ${history.step} with status $status in ${history.executionTime}")
}

/**
Expand All @@ -65,7 +65,7 @@ open class HistoryManager(private val migrationHistoryRepository: MigrationHisto
*/
@Transactional
open fun loadMigration(migId: Long): Migration {
val migration = migrationRepository.getOne(migId)
val migration = migrationRepository.getById(migId)
Hibernate.initialize(migration)
Hibernate.initialize(migration.histories)
Hibernate.initialize(migration.mappings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.apache.commons.lang3.StringUtils
import java.util.*

class CommandManager(val migration: Migration) {
var rootDir = ""
/**
* This is set to true when the svn clone step (and svn cleanup) has finished.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ open class GitCommandManager(val historyMgr: HistoryManager,
* Set element (branch or tag)
*/
private fun setSvnElement(elementName: String, element: String?, workUnit: WorkUnit): String {
val elt = if (workUnit.migration.uppercase) elementName.toUpperCase() else elementName
val elt = if (workUnit.migration.uppercase) elementName.uppercase() else elementName
return if (element == null) EMPTY
else "--$elementName=${workUnit.migration.svnProject}/$elt"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ fun resetHead() = gitCommand(RESET, "--hard", "HEAD")
fun gitClean(commandManager: CommandManager, workUnit: WorkUnit) {
try {
execCommand(commandManager, workUnit.directory, gitCommand("reflog expire", "--expire=now --all"))
} catch (rEx: RuntimeException) { }
} catch (_: RuntimeException) { }
try {
execCommand(commandManager, workUnit.directory, gitCommand("gc", "--prune=now --aggressive"))
} catch (rEx: RuntimeException) { }
} catch (_: RuntimeException) { }
execCommand(commandManager, workUnit.directory, gitCommand("reset", target = "HEAD"))
execCommand(commandManager, workUnit.directory, gitCommand("clean", "-fd"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ open class GitRepositoryFormatter(val historyMgr: HistoryManager,
}
return@mapToInt execCommand(workUnit.commandManager, workUnit.directory,
String.format("git mv %s %s \"%s\" \"%s\"",
if (applicationProperties.getFlags().isGitMvFOption()) "-f" else "",
if (applicationProperties.getFlags().isGitMvKOption()) "-k" else "",
if (applicationProperties.getFlags().isGitMvFOption) "-f" else "",
if (applicationProperties.getFlags().isGitMvKOption) "-k" else "",
el, Paths.get(mapping.gitDirectory, el).toString()))
} catch (e: InterruptedException) {
return@mapToInt ERROR_CODE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import java.io.IOException

@Service
open class GitTagManager(val gitManager: GitManager,
val gitCommandManager: GitCommandManager,
val historyMgr: HistoryManager) {
private val gitCommandManager: GitCommandManager,
val historyMgr: HistoryManager) {

private val LOG = LoggerFactory.getLogger(GitTagManager::class.java)
private val FAILED_TO_PUSH_TAG = "Failed to push tag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ open class MarkdownGenerator(
open fun generateSummaryReadme(migration: Migration, cleanedFilesManager: CleanedFilesManager, workUnit: WorkUnit) {
val md = StringBuilder()
// Overview
md.append(Heading(migration.gitlabProject.toUpperCase().replace("/".toRegex(), ""), 1))
md.append(Heading(migration.gitlabProject.uppercase().replace("/".toRegex(), ""), 1))
.emptyLine()
.append(" migrated from ${migration.svnUrl}${migration.svnGroup}${migration.svnProject} to ${migration.gitlabUrl}${migration.gitlabGroup}")
.emptyLine()
.append(" gitlab user ${BoldText(ItalicText(if (migration.gitlabToken == null) applicationProperties.gitlab.account.toUpperCase() else migration.user.toUpperCase()))} on ${migration.date}")
.append(" gitlab user ${BoldText(ItalicText(if (migration.gitlabToken == null) applicationProperties.gitlab.account.uppercase() else migration.user.uppercase()))} on ${migration.date}")
.emptyLine()
.append(" subversion user ${BoldText(ItalicText(migration.svnUser.toUpperCase()))} on ${migration.date}")
.append(" subversion user ${BoldText(ItalicText(migration.svnUser.uppercase()))} on ${migration.date}")
.emptyLine()
if (migration.mappings.isNotEmpty()) {
// Mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ open class MigrationResource(val migrationRepository: MigrationRepository,
@Timed
@GetMapping("/{id}")
@JsonView(Public::class)
open fun getMigration(@PathVariable id: Long?): ResponseEntity<Migration>? {
open fun getMigration(@PathVariable id: Long): ResponseEntity<Migration>? {
log.debug("REST request to get Migration : {}", id)
val migration = migrationRepository.findById(id)
return ResponseUtil.wrapOrNotFound(migration)
Expand Down
Loading

0 comments on commit e1787fe

Please sign in to comment.