homebrew-core/Formula/pmd.rb
2017-06-24 21:56:14 -07:00

80 lines
2.6 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/5.8.0/pmd-src-5.8.0.zip"
sha256 "05f8a326b997216cf4be90bb860c8f6e2bd844ac8ba2951b15330bdf9b2b5801"
bottle do
cellar :any_skip_relocation
sha256 "1b4be1e4bcab74131f1f96ea564dd4b92c9548c8c65c1dc7eb1e48885f78f971" => :sierra
sha256 "3f30e2864ef789a9f5059fc994044733eecb3adf465f4a3fc14223866ff7c2c4" => :el_capitan
sha256 "9be258257e39bee11869372e0aef2422ffb09e250de0d9fd477f6db86125814e" => :yosemite
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.undent
<?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.undent
Run with `pmd` (instead of `run.sh` as described in the documentation).
EOS
end
test do
(testpath/"java/testClass.java").write <<-EOS.undent
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