Javaファイルの文字コードが UTF-8(BOM付き)、UTF-8(BOMなし)、Shift_JIS が混在している状態になっていたので、それらをすべて UTF-8(BOMなし)に一括変換したい
Powershell
$folder = "C:\Your\Target\Directory" # ←変換対象のパスに変更!
$extensions = @("*.java", "*.xml", "*.properties")
# UTF-8かどうか判定する関数
function IsUTF8([byte[]]$bytes) {
try {
[System.Text.Encoding]::UTF8.GetString($bytes) | Out-Null
return $true
} catch {
return $false
}
}
foreach ($ext in $extensions) {
Get-ChildItem -Path $folder -Recurse -Filter $ext | ForEach-Object {
$path = $_.FullName
$bytes = [System.IO.File]::ReadAllBytes($path)
$encoding = New-Object System.Text.UTF8Encoding $false # UTF-8 (BOMなし)
$text = ""
if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
$text = [System.Text.Encoding]::UTF8.GetString($bytes, 3, $bytes.Length - 3)
Write-Host "[UTF-8 with BOM] → $path"
}
elseif (IsUTF8 $bytes) {
$text = [System.Text.Encoding]::UTF8.GetString($bytes)
Write-Host "[UTF-8 no BOM] → $path"
}
else {
$sjis = [System.Text.Encoding]::GetEncoding("shift_jis")
$text = $sjis.GetString($bytes)
Write-Host "[Shift_JIS] → $path"
}
[System.IO.File]::WriteAllText($path, $text, $encoding)
}
}
eclipse {
classpath {
plusConfigurations += [configurations.testRuntimeClasspath]
file {
whenMerged { classpath ->
classpath.entries.each { entry ->
if (entry instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency) {
entry.entryAttributes.remove("without_test_code")
}
}
}
}
}
}