Mercurial > hg > release > icedtea-web-1.7
changeset 1477:84cebefe259d
made OmegaT run - Made ITW to load resources from j2se/java tag too
* netx/net/sourceforge/jnlp/Parser.java: constructors/methods made public to help unittests
* netx/net/sourceforge/jnlp/ShortcutDesc.java: same
* netx/net/sourceforge/jnlp/ResourcesDesc.java: getJars made to iterate recursively over content of j2se
* tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java: added testcase
* tests/netx/unit/net/sourceforge/jnlp/jarsInJreDesc.jnlp: testfile copied form omegat which have this strange resources
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 02 Mar 2018 10:23:59 +0100 |
parents | f8fc55ba5af6 |
children | 2a9ff9f6ed44 |
files | ChangeLog netx/net/sourceforge/jnlp/Parser.java netx/net/sourceforge/jnlp/ResourcesDesc.java netx/net/sourceforge/jnlp/ShortcutDesc.java tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java tests/netx/unit/net/sourceforge/jnlp/jarsInJreDesc.jnlp |
diffstat | 6 files changed, 160 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Mar 02 10:22:31 2018 +0100 +++ b/ChangeLog Fri Mar 02 10:23:59 2018 +0100 @@ -1,3 +1,12 @@ +2018-02-03 Jiri Vanek <jvanek@redhat.com> + + Made ITW to load resources from j2se/java tag too + * netx/net/sourceforge/jnlp/Parser.java: constructors/methods made public to help unittests + * netx/net/sourceforge/jnlp/ShortcutDesc.java: same + * netx/net/sourceforge/jnlp/ResourcesDesc.java: getJars made to iterate recursively over content of j2se + * tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java: added testcase + * tests/netx/unit/net/sourceforge/jnlp/jarsInJreDesc.jnlp: testfile copied form omegat which have this strange resources + 2018-02-03 Jiri Vanek <jvanek@redhat.com> nosecurity switch made extendable also for certificate issues
--- a/netx/net/sourceforge/jnlp/Parser.java Fri Mar 02 10:22:31 2018 +0100 +++ b/netx/net/sourceforge/jnlp/Parser.java Fri Mar 02 10:23:59 2018 +0100 @@ -127,7 +127,7 @@ * @param settings the parser settings to use when parsing the JNLP file * @throws ParseException if the JNLP file is invalid */ - Parser(JNLPFile file, URL base, Node root, ParserSettings settings) throws ParseException { + public Parser(JNLPFile file, URL base, Node root, ParserSettings settings) throws ParseException { this(file, base, root, settings, null); } @@ -280,7 +280,7 @@ * @param j2se true if the resources are located under a j2se or java node * @throws ParseException if the JNLP file is invalid */ - List<ResourcesDesc> getResources(Node parent, boolean j2se) + public List<ResourcesDesc> getResources(Node parent, boolean j2se) throws ParseException { List<ResourcesDesc> result = new ArrayList<>(); Node resources[] = getChildNodes(parent, "resources"); @@ -509,7 +509,7 @@ * @param parent the parent node (jnlp) * @throws ParseException if the JNLP file is invalid */ - List<InformationDesc> getInfo(Node parent) + public List<InformationDesc> getInfo(Node parent) throws ParseException { List<InformationDesc> result = new ArrayList<>(); Node info[] = getChildNodes(parent, "information"); @@ -641,7 +641,7 @@ * @param parent the parent node * @throws ParseException if the JNLP file is invalid */ - SecurityDesc getSecurity(Node parent) throws ParseException { + public SecurityDesc getSecurity(Node parent) throws ParseException { Node nodes[] = getChildNodes(parent, "security"); // test for too many security elements @@ -700,7 +700,7 @@ * @param parent the parent node * @throws ParseException if the JNLP file is invalid */ - LaunchDesc getLauncher(Node parent) throws ParseException { + public LaunchDesc getLauncher(Node parent) throws ParseException { // check for other than one application type if (1 < getChildNodes(parent, "applet-desc").length + getChildNodes(parent, "application-desc").length @@ -1379,7 +1379,7 @@ * * @throws ParseException if the JNLP file is invalid */ - static Node getRootNode(InputStream input, ParserSettings settings) throws ParseException { + public static Node getRootNode(InputStream input, ParserSettings settings) throws ParseException { try { Object parser = getParserInstance(settings); Method m = parser.getClass().getMethod("getRootNode", InputStream.class);
--- a/netx/net/sourceforge/jnlp/ResourcesDesc.java Fri Mar 02 10:22:31 2018 +0100 +++ b/netx/net/sourceforge/jnlp/ResourcesDesc.java Fri Mar 02 10:23:59 2018 +0100 @@ -213,15 +213,34 @@ */ public <T> List<T> getResources(Class<T> type) { List<T> result = new ArrayList<>(); - for (Object resource : resources) { - if (type.isAssignableFrom(resource.getClass())) - result.add(type.cast(resource)); + if (resource instanceof JREDesc) { + JREDesc jre = (JREDesc) resource; + List<ResourcesDesc> descs = jre.getResourcesDesc(); + for (ResourcesDesc desc : descs) { + result.addAll(desc.getResources(type)); + } + } + if (isWontedResource(resource, type)) { + result.add(getWontedResource(resource, type)); + } } return result; } + private static <T> boolean isWontedResource(Object resource, Class<T> type) { + T l = getWontedResource(resource, type); + return l != null; + } + + private static <T> T getWontedResource(Object resource, Class<T> type) { + if (type.isAssignableFrom(resource.getClass())) { + return type.cast(resource); + } + return null; + } + /** * Add a resource. * @param resource to be added
--- a/netx/net/sourceforge/jnlp/ShortcutDesc.java Fri Mar 02 10:22:31 2018 +0100 +++ b/netx/net/sourceforge/jnlp/ShortcutDesc.java Fri Mar 02 10:23:59 2018 +0100 @@ -74,7 +74,7 @@ * For testing purposes. Verify if it have been parsed out correctly. * @return whether the shortcut requires being online. */ - boolean isOnlineValue() { + public boolean isOnlineValue() { return requiresOnline; }
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java Fri Mar 02 10:22:31 2018 +0100 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java Fri Mar 02 10:23:59 2018 +0100 @@ -33,8 +33,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. -*/ - + */ package net.sourceforge.jnlp; import java.io.InputStream; @@ -46,8 +45,10 @@ import org.junit.BeforeClass; import org.junit.Test; -/** Test that the parser works with basic jnlp files */ -public class ParserBasic extends NoStdOutErrTest{ +/** + * Test that the parser works with basic jnlp files + */ +public class ParserBasic extends NoStdOutErrTest { private static Node root; private static Parser parser; @@ -214,6 +215,22 @@ } @Test + public void testResourcesInsideJava() throws ParseException { + ClassLoader cl = ParserBasic.class.getClassLoader(); + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + ParserSettings defaultParser = new ParserSettings(); + InputStream jnlpStream = cl.getResourceAsStream("net/sourceforge/jnlp/jarsInJreDesc.jnlp"); + Node omega = Parser.getRootNode(jnlpStream, defaultParser); + Parser omegaParser = new Parser(new DummyJNLPFile(), null, omega, defaultParser); + ResourcesDesc resources = omegaParser.getResources(omega, false).get(0); + JARDesc[] r = resources.getJARs(); + // we ensures that also in j2se hars ar eloaded.it is 7 withutt them. + Assert.assertTrue(r.length>30); + } + + @Test public void testResourcesJar() throws ParseException { ResourcesDesc resources = parser.getResources(root, false).get(0); @@ -276,7 +293,7 @@ ApplicationDesc app = (ApplicationDesc) parser.getLauncher(root); Assert.assertNotNull(app); Assert.assertEquals("MainClass", app.getMainClass()); - Assert.assertArrayEquals(new String[] { "arg1", "arg2" }, app.getArguments()); + Assert.assertArrayEquals(new String[]{"arg1", "arg2"}, app.getArguments()); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/jarsInJreDesc.jnlp Fri Mar 02 10:23:59 2018 +0100 @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- +exmaple of "bad" jnlp file with resources inside j2sa +--> +<jnlp spec="1.0+" codebase="http://localhost/" href="jnlp.jnlp"> + <information> + <title>OmegaT</title> + <vendor>OmegaT development team</vendor> + <homepage href="http://www.omegat.org" /> + <shortcut online="false"> + <desktop /> + <menu submenu="OmegaT from WebStart" /> + </shortcut> + <offline-allowed /> + <association mime-type="application/x-omegat-project" extensions="project" /> + +<!-- + <related-content href="readme.html"> + <title>README</title> + <description> + The README file contains additional information about + the product + </description> + </related-content> +--> + </information> + + <security> + <all-permissions /> + </security> + + <resources> + <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"> + <resources> + <jar href="OmegaT.jar" /> + <jar href="docs.jar" /> + <jar href="htmlparser.jar" /> + <jar href="jmyspell-core-1.0.0-beta-2.jar" /> + <jar href="jna.jar" /> + <jar href="lib-mnemonics.jar" /> + <jar href="swing-layout-1.0.4.jar" /> + <jar href="vldocking-3.0.5-SNAPSHOT.jar" /> + <jar href="svnkit-1.8.5.jar" /> + <jar href="antlr-runtime-3.4.jar" /> + <jar href="sqljet-1.1.10.jar" /> + <jar href="sequence-library-1.0.2.jar" /> + <jar href="org.eclipse.jgit-3.7.1.201504261725-r.jar" /> + <jar href="jsch-0.1.49.jar" /> + <jar href="lucene-analyzers-3.6.2.jar" /> + <jar href="lucene-core-3.6.2.jar" /> + <jar href="lucene-kuromoji-3.6.2.jar" /> + <jar href="lucene-smartcn-3.6.2.jar" /> + <jar href="tinysegmenter.jar" /> + <jar href="commons-lang-2.4.jar" /> + <jar href="commons-io-2.4.jar" /> + <jar href="commons-logging-1.1.1.jar" /> + <jar href="jwordsplitter-3.4.jar" /> + <jar href="KoreanAnalyzer-3x-120223.jar" /> + <jar href="LanguageTool-data.jar" /> + <jar href="languagetool-core-2.2.jar" /> + <jar href="morfologik-fsa-1.5.4.jar" /> + <jar href="morfologik-speller-1.5.4.jar" /> + <jar href="morfologik-stemming-1.5.4.jar" /> + <jar href="cjftransform-1.0.1.jar" /> + <jar href="ictclas4j-1.0.1.jar" /> + <jar href="segment-1.4.1.jar" /> + <jar href="lucene-gosen-2.0.2-ipadic.jar" /> + <jar href="pdfbox-app-1.8.1.jar" /> + <jar href="groovy-all-2.2.2.jar" /> + <jar href="diff.jar" /> + <jar href="SuperTMXMerge-for_OmegaT.jar" /> + <jar href="slf4j-api-1.7.7.jar" /> + <jar href="slf4j-jdk14-1.7.7.jar" /> + <jar href="trilead-ssh2-1.0.0-build217.jar" /> + <jar href="juniversalchardet-1.0.3.jar" /> + </resources> + <resources os="Linux" arch="amd64"> + <nativelib href="hunspell-linux64.jar" /> + </resources> + <resources os="Linux" arch="i386"> + <nativelib href="hunspell-linux32.jar" /> + </resources> + <resources os="MacOS" arch="x86_64"> + <nativelib href="hunspell-macos64.jar" /> + </resources> + <resources os="MacOS" arch="i386"> + <nativelib href="hunspell-macos32.jar" /> + </resources> + <resources os="Windows" arch="amd64"> + <nativelib href="hunspell-win64.jar" /> + </resources> + <resources os="Windows" arch="x86"> + <nativelib href="hunspell-win32.jar" /> + </resources> + </j2se> + <property name="javaws.cfg.jauthenticator" value="true" /> + </resources> + <application-desc main-class="org.omegat.Main" /> +</jnlp> \ No newline at end of file