// Path: pie-core/src/main/java/com/coverity/security/pie/web/PieAdminFilter.java
// public class PieAdminFilter implements Filter {
// 
//     public static final String ADMIN_FILTER_URI = "/c0bd580ddcb4666b1PIEec61812f3cdf305";
// 
//     private final PieInitializer pieInitializer;
//     
//     public PieAdminFilter(PieInitializer pieInitializer) {
//         this.pieInitializer = pieInitializer;
//     }
//     
//     @Override
//     public void init(FilterConfig filterConfig) throws ServletException {
//     }
// 
//     @Override
//     public void doFilter(ServletRequest request, ServletResponse response,
//             FilterChain chain) throws IOException, ServletException {
//         if (request instanceof HttpServletRequest) {
//             HttpServletRequest httpServletRequest = (HttpServletRequest)request;
//             String path = null;
//             if (httpServletRequest.getRequestURI().length() >= httpServletRequest.getContextPath().length()) {
//                 path = httpServletRequest.getRequestURI().substring(httpServletRequest.getContextPath().length());
//             }
//             if (ADMIN_FILTER_URI.equals(path)) {
//                 
//                 PolicyEnforcer policyEnforcer = pieInitializer.getPolicyEnforcer(httpServletRequest.getParameter("policyEnforcer"));
//                 String startTimeStr = httpServletRequest.getParameter("startTime");
//                 Long startTime = (startTimeStr == null ? null : Long.parseLong(startTimeStr));
//                 
//                 if (policyEnforcer != null) {
//                     PrintWriter writer = response.getWriter();
//                     writer.write("=== PIE REPORT ===\n");
//                     
//                     String[][] violations;
//                     if (startTime == null) {
//                         violations = policyEnforcer.getPolicy().getViolations();
//                     } else {
//                         violations = policyEnforcer.getPolicy().getViolations(startTime);
//                     }
//                     
//                     for (String[] violation : violations) {
//                         if (violation.length > 0) {
//                             writer.write(violation[0]);
//                         }
//                         for (int i = 1; i < violation.length; i++) {
//                             writer.write("\t");
//                             if (violation[i] != null) {
//                                 writer.write(violation[i]);
//                             }
//                         }
//                         writer.write("\n");
//                     }
//                     
//                     writer.close();
//                     return;
//                 }
//                
//             }
//         }
//         
//         chain.doFilter(request, response);
//     }
// 
//     @Override
//     public void destroy() {
//     }
// 
// }


import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import com.coverity.security.pie.web.PieAdminFilter;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.sonatype.aether.RepositorySystemSession;
                    throw new RuntimeException(e);
                }

                PolicyConfig policyConfig = new PolicyConfig(policy.getName(), pieConfig);
                if (!policyConfig.isEnabled()) {
                    continue;
                }
                policy.setPolicyConfig(policyConfig);
                getLog().info("Creating policy for " + policy.getName());
                
                final URL policyUrl = policyConfig.getPolicyFile();
                if (!policyUrl.getProtocol().equals("file")) {
                    throw new MojoFailureException("Cannot update a non-file policy: " + policyUrl.toString());
                }
                final File policyFile = new File(policyUrl.getPath());
                
                if (policyFile.exists()) {
                    Reader fr = null;
                    try {
                        fr = new InputStreamReader(new FileInputStream(policyFile), StandardCharsets.UTF_8);
                        policy.parsePolicy(fr);
                    } catch (IOException e) {
                        throw new MojoExecutionException("Could not parse policy file: " + policyConfig.getPolicyFile().toString());
                    } finally {
                        IOUtils.closeQuietly(fr);
                    }
                }
                
                URIBuilder uriBuilder;
                try {
// Path: pie-core/src/main/java/com/coverity/security/pie/web/PieAdminFilter.java
// public class PieAdminFilter implements Filter {
// 
//     public static final String ADMIN_FILTER_URI = "/c0bd580ddcb4666b1PIEec61812f3cdf305";
// 
//     private final PieInitializer pieInitializer;
//     
//     public PieAdminFilter(PieInitializer pieInitializer) {
//         this.pieInitializer = pieInitializer;
//     }
//     
//     @Override
//     public void init(FilterConfig filterConfig) throws ServletException {
//     }
// 
//     @Override
//     public void doFilter(ServletRequest request, ServletResponse response,
//             FilterChain chain) throws IOException, ServletException {
//         if (request instanceof HttpServletRequest) {
//             HttpServletRequest httpServletRequest = (HttpServletRequest)request;
//             String path = null;
//             if (httpServletRequest.getRequestURI().length() >= httpServletRequest.getContextPath().length()) {
//                 path = httpServletRequest.getRequestURI().substring(httpServletRequest.getContextPath().length());
//             }
//             if (ADMIN_FILTER_URI.equals(path)) {
//                 
//                 PolicyEnforcer policyEnforcer = pieInitializer.getPolicyEnforcer(httpServletRequest.getParameter("policyEnforcer"));
//                 String startTimeStr = httpServletRequest.getParameter("startTime");
//                 Long startTime = (startTimeStr == null ? null : Long.parseLong(startTimeStr));
//                 
//                 if (policyEnforcer != null) {
//                     PrintWriter writer = response.getWriter();
//                     writer.write("=== PIE REPORT ===\n");
//                     
//                     String[][] violations;
//                     if (startTime == null) {
//                         violations = policyEnforcer.getPolicy().getViolations();
//                     } else {
//                         violations = policyEnforcer.getPolicy().getViolations(startTime);
//                     }
//                     
//                     for (String[] violation : violations) {
//                         if (violation.length > 0) {
//                             writer.write(violation[0]);
//                         }
//                         for (int i = 1; i < violation.length; i++) {
//                             writer.write("\t");
//                             if (violation[i] != null) {
//                                 writer.write(violation[i]);
//                             }
//                         }
//                         writer.write("\n");
//                     }
//                     
//                     writer.close();
//                     return;
//                 }
//                
//             }
//         }
//         
//         chain.doFilter(request, response);
//     }
// 
//     @Override
//     public void destroy() {
//     }
// 
// }


// Path: pie-maven-plugin/src/main/java/com/coverity/security/pie/core/BuildPolicyMojo.java
import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import com.coverity.security.pie.web.PieAdminFilter;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.sonatype.aether.RepositorySystemSession;

                    throw new RuntimeException(e);
                }

                PolicyConfig policyConfig = new PolicyConfig(policy.getName(), pieConfig);
                if (!policyConfig.isEnabled()) {
                    continue;
                }
                policy.setPolicyConfig(policyConfig);
                getLog().info("Creating policy for " + policy.getName());
                
                final URL policyUrl = policyConfig.getPolicyFile();
                if (!policyUrl.getProtocol().equals("file")) {
                    throw new MojoFailureException("Cannot update a non-file policy: " + policyUrl.toString());
                }
                final File policyFile = new File(policyUrl.getPath());
                
                if (policyFile.exists()) {
                    Reader fr = null;
                    try {
                        fr = new InputStreamReader(new FileInputStream(policyFile), StandardCharsets.UTF_8);
                        policy.parsePolicy(fr);
                    } catch (IOException e) {
                        throw new MojoExecutionException("Could not parse policy file: " + policyConfig.getPolicyFile().toString());
                    } finally {
                        IOUtils.closeQuietly(fr);
                    }
                }
                
                URIBuilder uriBuilder;
                try {
                    uriBuilder = new URIBuilder(serverUrl.toString() + PieAdminFilter.ADMIN_FILTER_URI);