homebrew-core/Formula/pmd.rb
2017-12-15 20:04:42 +01:00

80 lines
2.5 KiB
Ruby

class Pmd < Formula
desc "Source code analyzer for Java, JavaScript, and more"
homepage "https://pmd.github.io"
url "https://github.com/pmd/pmd/releases/download/pmd_releases/6.0.0/pmd-src-6.0.0.zip"
sha256 "8b635fcc99f347c1c2dc5374719c2e3813516ce82a09843551e1ce0068b532da"
bottle do
cellar :any_skip_relocation
sha256 "92a283d6461a59d682b25770fd4aca0684014c0b994a37e191ac11e92428afe7" => :high_sierra
sha256 "ba1a84f493c0e053359910c6daaa90354046a35fc7dca80dad6f98bda9951a81" => :sierra
sha256 "ae9edf319e8394038b2f3d73fe60ec30579be37b6673f6f48e77d639322958c7" => :el_capitan
end
depends_on :java => "1.8+"
depends_on "maven" => :build
def install
java_user_home = buildpath/"java_user_home"
ENV["_JAVA_OPTIONS"] = "-Duser.home=#{buildpath}/java_user_home"
java_cache_repo = HOMEBREW_CACHE/"java_cache/.m2/repository"
java_cache_repo.mkpath
(java_user_home/".m2").install_symlink java_cache_repo
(java_user_home/".m2/toolchains.xml").write <<~EOS
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>#{ENV["JAVA_HOME"][/((\d\.?)+)\.\d/, 1]}</version>
</provides>
<configuration>
<jdkHome>#{ENV["JAVA_HOME"]}</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
</provides>
<configuration>
<jdkHome>#{ENV["JAVA_HOME"]}</jdkHome>
</configuration>
</toolchain>
</toolchains>
EOS
system "mvn", "clean", "package"
doc.install "LICENSE", "NOTICE", "README.md"
# The mvn package target produces a .zip with all the jars needed for PMD
safe_system "unzip", buildpath/"pmd-dist/target/pmd-bin-#{version}.zip"
libexec.install "pmd-bin-#{version}/bin", "pmd-bin-#{version}/lib"
bin.install_symlink "#{libexec}/bin/run.sh" => "pmd"
inreplace "#{libexec}/bin/run.sh", "${script_dir}/../lib", "#{libexec}/lib"
end
def caveats; <<~EOS
Run with `pmd` (instead of `run.sh` as described in the documentation).
EOS
end
test do
(testpath/"java/testClass.java").write <<~EOS
public class BrewTestClass {
// dummy constant
public String SOME_CONST = "foo";
public boolean doTest () {
return true;
}
}
EOS
system "#{bin}/pmd", "pmd", "-d", "#{testpath}/java", "-R",
"rulesets/java/basic.xml", "-f", "textcolor", "-l", "java"
end
end