@CheckForNull private static ProxyConfiguration _get() { JenkinsJVM.checkJenkinsJVM(); // this code could be called between the JVM flag being set and theInstance initialized Jenkins jenkins = Jenkins.getInstance(); return jenkins == null ? null : jenkins.proxy; }
/** * Verify that the classloader that loaded this class is the classloader from which {@link Jenkins} has been * started. * * @throws IllegalStateException if this is not the classloader on the JVM that started {@link Jenkins}. */ public static void checkJenkinsJVM() { if (!isJenkinsJVM()) { throw new IllegalStateException("Not running on the Jenkins master JVM"); } }
private static void _setJenkinsJVM(boolean jenkinsJVM) { JenkinsJVM.setJenkinsJVM(jenkinsJVM); } }
@CheckForNull private static ProxyConfiguration _get() { JenkinsJVM.checkJenkinsJVM(); // this code could be called between the JVM flag being set and theInstance initialized Jenkins jenkins = Jenkins.getInstance(); return jenkins == null ? null : jenkins.proxy; }
/** * Verify that the classloader that loaded this class is not the classloader from which {@link Jenkins} has been * started. * * @throws IllegalStateException if this is the classloader on the JVM that started {@link Jenkins}. */ public static void checkNotJenkinsJVM() { if (isJenkinsJVM()) { throw new IllegalStateException("Running on the Jenkins master JVM"); } }
private static void _setJenkinsJVM(boolean jenkinsJVM) { JenkinsJVM.setJenkinsJVM(jenkinsJVM); } }
private void pregenerateNote(String html) { if (!notes.containsKey(html)) { JenkinsJVM.checkJenkinsJVM(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { new SimpleHtmlNote(html).encodeTo(baos); } catch (IOException x) { // should be impossible throw new RuntimeException(x); } notes.put(html, baos.toByteArray()); } }
@CheckForNull private static ProxyConfiguration get() { if (JenkinsJVM.isJenkinsJVM()) { return _get(); } return null; }
private static void _setJenkinsJVM(boolean jenkinsJVM) { JenkinsJVM.setJenkinsJVM(jenkinsJVM); } }
static byte[][] createNotes() { JenkinsJVM.checkJenkinsJVM(); return Stream.of(new MavenMojoNote(), new Maven3MojoNote(), new MavenWarningNote(), new MavenErrorNote()).map(note -> { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { note.encodeTo(baos); } catch (IOException x) { // should be impossible throw new RuntimeException(x); } return baos.toByteArray(); }).toArray(byte[][]::new); }
/** * @return All ProcessKillingVeto extensions currently registered. An empty * list if Jenkins is not available, never null. */ public static List<ProcessKillingVeto> all() { if (JenkinsJVM.isJenkinsJVM()) { return _all(); } return Collections.emptyList(); }
private static void _setJenkinsJVM(boolean jenkinsJVM) { JenkinsJVM.setJenkinsJVM(jenkinsJVM); } }
@CheckForNull private static String tryGetValueFromContext(String key) { if (!JenkinsJVM.isJenkinsJVM()) { return null; } return doTryGetValueFromContext(key); }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (OutputStream gzos = new GZIPOutputStream(buf); ObjectOutputStream oos = JenkinsJVM.isJenkinsJVM() ? AnonymousClassWarnings.checkingObjectOutputStream(gzos) : new ObjectOutputStream(gzos)) { oos.writeObject(this); } ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); try { buf2.write(PREAMBLE); if (JenkinsJVM.isJenkinsJVM()) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE byte[] mac = MAC.mac(buf.toByteArray()); dos.writeInt(- mac.length); // negative to differentiate from older form dos.write(mac); } dos.writeInt(buf.size()); buf.writeTo(dos); } finally { dos.close(); } buf2.write(POSTAMBLE); return buf2; }
/** * This method should be used wherever {@link URL#openConnection()} to internet URLs is invoked directly. */ public static URLConnection open(URL url) throws IOException { final ProxyConfiguration p = get(); URLConnection con; if(p==null) { con = url.openConnection(); } else { Proxy proxy = p.createProxy(url.getHost()); con = url.openConnection(proxy); if(p.getUserName()!=null) { // Add an authenticator which provides the credentials for proxy authentication Authenticator.setDefault(p.authenticator); p.jenkins48775workaround(proxy, url); } } if(DEFAULT_CONNECT_TIMEOUT_MILLIS > 0) { con.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS); } if (JenkinsJVM.isJenkinsJVM()) { // this code may run on a slave decorate(con); } return con; }
if (JenkinsJVM.isJenkinsJVM()) { JenkinsJVMAccess._setJenkinsJVM(oldJenkinsJVM);
}) protected Jenkins(File root, ServletContext context, PluginManager pluginManager) throws IOException, InterruptedException, ReactorException { oldJenkinsJVM = JenkinsJVM.isJenkinsJVM(); // capture to restore in cleanUp() JenkinsJVMAccess._setJenkinsJVM(true); // set it for unit tests as they will not have gone through WebAppMain long start = System.currentTimeMillis();
/** * Verify that the classloader that loaded this class is the classloader from which {@link Jenkins} has been * started. * * @throws IllegalStateException if this is not the classloader on the JVM that started {@link Jenkins}. */ public static void checkJenkinsJVM() { if (!isJenkinsJVM()) { throw new IllegalStateException("Not running on the Jenkins master JVM"); } }
/** * Verify that the classloader that loaded this class is not the classloader from which {@link Jenkins} has been * started. * * @throws IllegalStateException if this is the classloader on the JVM that started {@link Jenkins}. */ public static void checkNotJenkinsJVM() { if (isJenkinsJVM()) { throw new IllegalStateException("Running on the Jenkins master JVM"); } }
@CheckForNull private static ProxyConfiguration get() { if (JenkinsJVM.isJenkinsJVM()) { return _get(); } return null; }