homebrew-core/Formula/pmd.rb
2018-02-25 22:56:50 -08: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.1.0/pmd-src-6.1.0.zip"
sha256 "43ed003b62854f7f979c3f0444dc75e494f75b0ab91d45af4866683d1f36d2e5"
bottle do
cellar :any_skip_relocation
sha256 "37df85f9e243892c9e64ef0ad1a8723fa69c9aabbe376d3aa551a0107a8fed71" => :high_sierra
sha256 "922fd4bcdbee1fb84e9499c1208ad70b56292d76c77fe0d2694532081362f018" => :sierra
sha256 "16684ba9d0df50905562445e85005956f6bd4c5323b92157656d2ad55439d30a" => :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