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.2.0/pmd-src-6.2.0.zip" sha256 "05050fc66fc05f7ce05da0e4d49c9e12a681d1a6bad0764a94c0874c556d0a9d" bottle do cellar :any_skip_relocation sha256 "3d39df025d87e96be861c0b5ff04c537981995988dc2134ddef8b3fcfa7eb42b" => :high_sierra sha256 "029e5ebb8b16fffc8239feaff2312d5e1b14cb28d4a4d41c05adfea8ae11c653" => :sierra sha256 "dbf599d9117d7606787743f15e083be40c8c65510d80c24ed9e972e92e4d12ac" => :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 jdk #{ENV["JAVA_HOME"][/((\d\.?)+)\.\d/, 1]} #{ENV["JAVA_HOME"]} jdk 1.7 #{ENV["JAVA_HOME"]} 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