Skip to content

Commit

Permalink
Merging FixingProxies onto release100
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Tulach authored and lkishalmi committed Dec 16, 2018
1 parent aff7fb4 commit 910bd74
Show file tree
Hide file tree
Showing 23 changed files with 433 additions and 1,085 deletions.
1 change: 0 additions & 1 deletion nbbuild/cluster.properties
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ nb.cluster.platform=\
libs.junit4,\
libs.junit5,\
libs.osgi,\
libs.rhino,\
libs.testng,\
masterfs,\
masterfs.linux,\
Expand Down
373 changes: 0 additions & 373 deletions nbbuild/licenses/MPL-2.0

This file was deleted.

12 changes: 11 additions & 1 deletion platform/core.network/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@
which clients are supposed to download and execute in order to find
out which proxy to use. This is known as <a href="https://en.wikipedia.org/wiki/Proxy_auto-config">Proxy Auto-Config</a>
(or PAC). This module provides a pluggable PAC evaluation environment
based on Rhino. Execution of the downloaded JavaScript code is sandboxed.
based on Nashorn. However, it will gracefully degrade to any other JavaScript
which may be installed in the JVM. Execution of the downloaded
JavaScript code is sandboxed. (only true for Nashorn)
</p>
<p>
If you don't like the PAC evaluation environment provided
Expand Down Expand Up @@ -730,6 +732,14 @@
</question>
-->
<answer id="exec-reflection">
<p>
Yes. It detects the presence of Nashorn (as opposed to say Rhino) by way
of reflection. In particular it needs to know if the Java version is
Java 8u40 as Nashorn was greatly enhanced in that update and was more
or less useless (for our purpose) before this time. The use of reflection
means the code will gracefully 'degrade' to whatever script engine is
available if we are not on Java 8u40 or later.
</p>
<p>
For testing only a dirty hack is used in our <code>FakeDns</code> class.
This installs itself as a preferred name service in Java. This is done
Expand Down
9 changes: 0 additions & 9 deletions platform/core.network/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@
<specification-version>1.16</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.rhino</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.7.10</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.keyring</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.core.NbLifecycleManager;
import org.netbeans.core.network.proxy.pac.PacParsingException;
import org.netbeans.core.network.proxy.pac.PacScriptEvaluator;
import org.netbeans.core.network.proxy.pac.PacScriptEvaluatorFactory;
Expand Down Expand Up @@ -77,6 +78,7 @@ private ProxyAutoConfig(final String pacURL) throws URISyntaxException {

@Override
public void run() {
NbLifecycleManager.advancePolicy();
initEngine();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static int getMonth(String month) throws PacDateTimeInputException {


private static int getInteger(Object obj) throws PacDateTimeInputException {
if (obj instanceof Number) {
if (obj instanceof Integer || obj instanceof Long) {
return ((Number) obj).intValue();
}
if (obj instanceof String) {
Expand Down Expand Up @@ -320,9 +320,8 @@ private static Calendar getCalendar(Date now, boolean useGMT) {
* {@link PacHelperMethodsNetscape#weekdayRange(java.lang.Object...) weekdayRange()}
*
* <p>
* Note: In Rhino, JavaScript function arguments that are not used in the
* call will have a type of {@code java.lang.String} and the value will be
* 'undefined'.
* Note: In Nashorn, JavaScript function arguments that are not used in the
* call will have a type of {@code Undefined}.
*
* @param objs
* @return
Expand All @@ -338,8 +337,7 @@ public static int getNoOfParams(Object... objs) {
}
// Only parameters of type CharSequence (String) and
// Number (Integer, Long, etc) are relevant.
// Rhino converts javascript undefined to the string "undefined"
if ((obj instanceof Number) || (obj instanceof CharSequence && (! "undefined".equals(obj)))) {
if ((obj instanceof Number) || (obj instanceof CharSequence)) {
params++;
}
}
Expand All @@ -353,9 +351,6 @@ public static int getNoOfParams(Object... objs) {
*/
public static boolean usesGMT(Object... args) {
int params = getNoOfParams(args);
if(params == 0) {
return false;
}
if (args[params - 1] instanceof CharSequence) {
String p = args[params - 1].toString();
if (p.equals("GMT")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.core.network.proxy.pac.impl;

import jdk.nashorn.api.scripting.ClassFilter;
import org.netbeans.core.network.proxy.pac.PacHelperMethods;

/**
* Nashorn class filter which helps us create a sandboxed JavaScript execution
* environment which only has access to the Helper methods, nothing more.
*
* <p>Note that the ClassFilter feature is specific to Nashorn (Rhino had the
* {@code ClassShutter} class for this purpose), but the feature did not appear
* until Java 8u40.
*
* @author lbruun
*/
class ClassFilterPacHelpers implements ClassFilter {

@Override
public boolean exposeToScripts(String string) {
// The only Java class the PAC script is allowed to
// make use of is the PAC Helpers, nothing more.
return string.equals(PacHelperMethods.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,27 @@ private HelperScriptFactory() {
/**
* Gets JavaScript source with PAC Helper function declarations.
*
* @param bridgeObjectName name of Java object which contains Java methods,
* named similarly to the JavaScript PAC helper functions and with
* similar arg list. This Java object acts as the bridge between the
* JavaScript world and the Java world and must be an instance
* of {@link org.netbeans.network.proxy.pac.PacHelperMethods PacHelperMethods}.
*
* @return JavaScript source code
* @return JavaScript source code that returns a function that delegates
* to its first argument
*/
public static String getPacHelperSource(String bridgeObjectName) {
public static String getPacHelperSource() {
StringBuilder sb = new StringBuilder(2000);
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_NS, bridgeObjectName);
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_MS, bridgeObjectName);
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_DEBUG, bridgeObjectName);
sb.append("(function(self) {\n");
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_NS);
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_MS);
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_DEBUG);
sb.append("})\n");
return sb.toString();
}


private static void addFunctionDecls(StringBuilder sb, JsHelperFunction[] jsHelperFunctions, String bridgeObjectName) {
private static void addFunctionDecls(StringBuilder sb, JsHelperFunction[] jsHelperFunctions) {
for (JsHelperFunction f : jsHelperFunctions) {
sb.append("function ");
sb.append("this['");
sb.append(f.functionName);
sb.append('(');
sb.append("'] = function(");
addArgList(sb, f.argList);
sb.append(") {");
sb.append('\n');
sb.append(") {\n");
sb.append(" return ");
boolean encloseReturnValue = false;
if (Number.class.isAssignableFrom(f.getClass())) {
Expand All @@ -98,8 +94,7 @@ private static void addFunctionDecls(StringBuilder sb, JsHelperFunction[] jsHelp
encloseReturnValue = true;
sb.append("String(");
}
sb.append(bridgeObjectName);
sb.append('.');
sb.append("self.");
sb.append(f.functionName);
sb.append('(');
addArgList(sb, f.argList);
Expand Down
Loading

0 comments on commit 910bd74

Please sign in to comment.