SAN FRANCISCO -- Matt Cain threw a one-hitter, allowing only a single by Pittsburgh pitcher James McDonald in the sixth inning during a near-perfect performance Friday as the San Francisco Giants beat the Pirates 5-0 in their home opener.