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.7.0/pmd-src-5.7.0.zip" sha256 "8a35af54f608e51d6f6fc710f384301216c3292772516c7be2beef3de64650dd" bottle do cellar :any_skip_relocation sha256 "6ce2ff604079a0fdb9dfdf945674d5680e997b01c2d61ce000e8d7b7e220085a" => :sierra sha256 "5282754e33f0807e6cc31147438340cb00590c4085fbc75daf9a98227f653e23" => :el_capitan sha256 "09952694d20860d20f92c57b2da7d43d3015944ef2917ea5452fd67874fc5c34" => :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 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.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