Skip to content

Commit 230c111

Browse files
committed
AppletDesc now accept also class.class suffixed entry point in its applet-desc xml element
#36 Added integration test for applet-desc.class suffixed main-class
1 parent 3e8e24d commit 230c111

File tree

8 files changed

+318
-1
lines changed

8 files changed

+318
-1
lines changed

core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/application/AppletDesc.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,28 @@ public String getName() {
127127
*/
128128
@Override
129129
public String getMainClass() {
130-
return mainClass;
130+
return cleanMainClass();
131+
}
132+
133+
/**
134+
* https://github.com/AdoptOpenJDK/IcedTea-Web/issues/361
135+
* appelts can have class specified both pkg.myclass and pkg.myclass.class
136+
* There are several places in ITW where this can be applied
137+
* I had decided to go eith direct getter from AppletDesc for several reasons:
138+
* - it is applet-desc specific, and application-desc should not be crippeld by this
139+
* - in checkForMain is palce where .class is appended, that would need to be adjsuted
140+
* - checkEntryPoint is comparin main class against record in manifest.
141+
* -- classes in manifest are supposed to be suffix .class free. Although you can smuggle class.class into manifest, that is usually bringing you toubles.
142+
* -- eg. java -jar willnot load such main-class
143+
* - I can be wrong with the manifest usage
144+
* @return mainclass striped of tailing .class if any
145+
*/
146+
private String cleanMainClass() {
147+
if (mainClass == null) {
148+
return mainClass;
149+
} else {
150+
return mainClass.replaceAll("\\.class$", "");
151+
}
131152
}
132153

133154
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package net.adoptopenjdk.icedteaweb.jnlp.element.application;
2+
3+
import net.sourceforge.jnlp.util.logging.NoStdOutErrTest;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
import java.net.URL;
8+
import java.util.HashMap;
9+
10+
11+
public class AppletDescTest extends NoStdOutErrTest {
12+
13+
@Test
14+
public void testClassIsNotStrippedAccidentally() throws Exception {
15+
Assert.assertEquals("mainClass", createAppletWithMain("mainClass").getMainClass());
16+
Assert.assertEquals("main.Class", createAppletWithMain("main.Class").getMainClass());
17+
Assert.assertEquals("mainclass", createAppletWithMain("mainclass").getMainClass());
18+
Assert.assertEquals("mainAclass", createAppletWithMain("mainAclass").getMainClass());
19+
Assert.assertEquals("mainclassa", createAppletWithMain("mainclassa").getMainClass());
20+
Assert.assertEquals("main.classa", createAppletWithMain("main.classa").getMainClass());
21+
}
22+
23+
@Test
24+
public void testClassIsStrippedProperly() throws Exception {
25+
Assert.assertEquals("main", createAppletWithMain("main.class").getMainClass());
26+
}
27+
28+
private static AppletDesc createAppletWithMain(String mainClass) throws Exception {
29+
return new AppletDesc("appler", mainClass, new URL("http", "localhost", "doc"), 100, 100, new HashMap<>());
30+
}
31+
32+
private static ApplicationDesc createApplicationWithMain(String mainClass) throws Exception {
33+
return new ApplicationDesc(mainClass, new String[0]);
34+
}
35+
36+
@Test
37+
public void testClassIsNotStrippedAccidentallyApplication() throws Exception {
38+
Assert.assertEquals("mainClass", createApplicationWithMain("mainClass").getMainClass());
39+
Assert.assertEquals("main.Class", createApplicationWithMain("main.Class").getMainClass());
40+
Assert.assertEquals("mainclass", createApplicationWithMain("mainclass").getMainClass());
41+
Assert.assertEquals("mainAclass", createApplicationWithMain("mainAclass").getMainClass());
42+
Assert.assertEquals("mainclassa", createApplicationWithMain("mainclassa").getMainClass());
43+
Assert.assertEquals("main.classa", createApplicationWithMain("main.classa").getMainClass());
44+
Assert.assertEquals("main.class", createApplicationWithMain("main.class").getMainClass());
45+
}
46+
47+
}

integration/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@
164164
</outputDirectory>
165165
</configuration>
166166
</execution>
167+
168+
<execution>
169+
<id>appletDescMainClassWithClass</id>
170+
<goals>
171+
<goal>jar</goal>
172+
</goals>
173+
<phase>process-test-classes</phase>
174+
<configuration>
175+
<includes>
176+
<include>**/common/*.class</include>
177+
<include>**/reproducers/appletDescMainClassWithClass/**/*.class</include>
178+
</includes>
179+
<finalName>App</finalName>
180+
<classifier>appletDescMainClassWithClass</classifier>
181+
<outputDirectory>
182+
${project.build.directory}/test-classes/net/adoptopenjdk/icedteaweb/integration/reproducers/appletDescMainClassWithClass/resources
183+
</outputDirectory>
184+
</configuration>
185+
</execution>
167186
</executions>
168187
</plugin>
169188

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.adoptopenjdk.icedteaweb.integration.reproducers.appletDescMainClassWithClass;
2+
3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
4+
import net.adoptopenjdk.icedteaweb.client.parts.downloadindicator.DefaultDownloadIndicator;
5+
import net.adoptopenjdk.icedteaweb.integration.IntegrationTest;
6+
import net.adoptopenjdk.icedteaweb.integration.TemporaryItwHome;
7+
import net.adoptopenjdk.icedteaweb.integration.reproducers.appletDescMainClassWithClass.applications.AppletDescMainClassWithClass;
8+
import net.adoptopenjdk.icedteaweb.integration.reproducers.progressclass.applications.ProgressClassManagedApplication;
9+
import net.sourceforge.jnlp.runtime.Boot;
10+
import net.sourceforge.jnlp.runtime.JNLPRuntime;
11+
import org.junit.Ignore;
12+
import org.junit.Rule;
13+
import org.junit.Test;
14+
15+
import java.io.IOException;
16+
17+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
18+
import static net.adoptopenjdk.icedteaweb.integration.reproducers.progressclass.applications.ProgressClassManagedApplication.PROGRESS_CLASS_OUTPUT_FILE;
19+
import static org.hamcrest.MatcherAssert.assertThat;
20+
import static org.hamcrest.Matchers.containsString;
21+
import static org.hamcrest.Matchers.is;
22+
23+
24+
public class AppletDescMainClassWithClassTest1 implements IntegrationTest {
25+
private static final String JAR_NAME = "App-appletDescMainClassWithClass.jar";
26+
27+
@Rule
28+
public TemporaryItwHome tmpItwHome = new TemporaryItwHome();
29+
@Rule
30+
public WireMockRule wireMock = new WireMockRule(wireMockConfig().dynamicPort());
31+
32+
33+
@Test(timeout = 100_000)
34+
public void appletWithNormallMainClass() throws IOException {
35+
// given
36+
final String jnlpUrl = setupServer(wireMock, "AppletDescMainClassWithClass1.jnlp", AppletDescMainClassWithClass.class, JAR_NAME);
37+
tmpItwHome.createTrustSettings(jnlpUrl);
38+
39+
// when
40+
final String[] args = {"-jnlp", jnlpUrl, "-nosecurity", "-Xnofork", "-headless"};
41+
Boot.main(args);
42+
43+
// then
44+
assertThat(hasCachedFile(tmpItwHome, JAR_NAME), is(true));
45+
//assertThat(getCachedFileAsString(tmpItwHome, AppletDescMainClassWithClass.ID), containsString("init AppletDescMainClassWithClass"));
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package net.adoptopenjdk.icedteaweb.integration.reproducers.appletDescMainClassWithClass;
2+
3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
4+
import net.adoptopenjdk.icedteaweb.integration.IntegrationTest;
5+
import net.adoptopenjdk.icedteaweb.integration.TemporaryItwHome;
6+
import net.adoptopenjdk.icedteaweb.integration.reproducers.appletDescMainClassWithClass.applications.AppletDescMainClassWithClass;
7+
import net.sourceforge.jnlp.runtime.Boot;
8+
import org.junit.Rule;
9+
import org.junit.Test;
10+
11+
import java.io.IOException;
12+
13+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
14+
import static org.hamcrest.MatcherAssert.assertThat;
15+
import static org.hamcrest.Matchers.is;
16+
17+
18+
public class AppletDescMainClassWithClassTest2 implements IntegrationTest {
19+
private static final String JAR_NAME = "App-appletDescMainClassWithClass.jar";
20+
21+
@Rule
22+
public TemporaryItwHome tmpItwHome = new TemporaryItwHome();
23+
@Rule
24+
public WireMockRule wireMock = new WireMockRule(wireMockConfig().dynamicPort());
25+
26+
27+
@Test(timeout = 100_000)
28+
public void appletWithDotClassSuffixedMainClass() throws IOException {
29+
// given
30+
final String jnlpUrl = setupServer(wireMock, "AppletDescMainClassWithClass2.jnlp", AppletDescMainClassWithClass.class, JAR_NAME);
31+
tmpItwHome.createTrustSettings(jnlpUrl);
32+
33+
// when
34+
final String[] args = {"-jnlp", jnlpUrl, "-nosecurity", "-Xnofork", "-headless"};
35+
Boot.main(args);
36+
37+
// then
38+
assertThat(hasCachedFile(tmpItwHome, JAR_NAME), is(true));
39+
//assertThat(getCachedFileAsString(tmpItwHome, AppletDescMainClassWithClass.ID), containsString("init AppletDescMainClassWithClass"));
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.adoptopenjdk.icedteaweb.integration.reproducers.appletDescMainClassWithClass.applications;
2+
3+
import java.applet.Applet;
4+
5+
import static net.adoptopenjdk.icedteaweb.integration.common.ManagedApplicationFileWriter.writeFile;
6+
7+
public class AppletDescMainClassWithClass extends Applet {
8+
9+
public static String ID = "AppletDescMainClassWithClass";
10+
11+
public void init() {
12+
System.out.println("init AppletDescMainClassWithClass");
13+
try {
14+
// writeFile(ID, writer -> writer.write("init AppletDescMainClassWithClass"));
15+
} catch (Exception ex) {
16+
throw new RuntimeException(ex);
17+
}
18+
}
19+
20+
public void start() {
21+
System.out.println("start AppletDescMainClassWithClass");
22+
try {
23+
// writeFile(ID , writer -> writer.write("start AppletDescMainClassWithClass"));
24+
} catch (Exception ex) {
25+
throw new RuntimeException(ex);
26+
}
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!--
2+
3+
This file is part of IcedTea.
4+
5+
IcedTea is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2, or (at your option)
8+
any later version.
9+
10+
IcedTea is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with IcedTea; see the file COPYING. If not, write to the
17+
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
02110-1301 USA.
19+
20+
Linking this library statically or dynamically with other modules is
21+
making a combined work based on this library. Thus, the terms and
22+
conditions of the GNU General Public License cover the whole
23+
combination.
24+
25+
As a special exception, the copyright holders of this library give you
26+
permission to link this library with independent modules to produce an
27+
executable, regardless of the license terms of these independent
28+
modules, and to copy and distribute the resulting executable under
29+
terms of your choice, provided that you also meet, for each linked
30+
independent module, the terms and conditions of the license of that
31+
module. An independent module is a module which is not derived from
32+
or based on this library. If you modify this library, you may extend
33+
this exception to your version of the library, but you are not
34+
obligated to do so. If you do not wish to do so, delete this
35+
exception statement from your version.
36+
37+
-->
38+
<?xml version="1.0" encoding="utf-8"?>
39+
<jnlp spec="1.0" href="AppletDescMainClassWithClass1.jnlp" codebase="http://localhost:${PORT}">
40+
<information>
41+
<title>main class of applet-desc</title>
42+
<vendor>IcedTea</vendor>
43+
<homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
44+
<description>percents in width/height</description>
45+
<offline/>
46+
</information>
47+
<resources>
48+
<j2se version="1.4+"/>
49+
<jar href="resources/App-appletDescMainClassWithClass.jar"/>
50+
</resources>
51+
<applet-desc
52+
name="normal"
53+
main-class="${MAIN_CLASS}">
54+
</applet-desc>
55+
</jnlp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--
2+
3+
This file is part of IcedTea.
4+
5+
IcedTea is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2, or (at your option)
8+
any later version.
9+
10+
IcedTea is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with IcedTea; see the file COPYING. If not, write to the
17+
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
02110-1301 USA.
19+
20+
Linking this library statically or dynamically with other modules is
21+
making a combined work based on this library. Thus, the terms and
22+
conditions of the GNU General Public License cover the whole
23+
combination.
24+
25+
As a special exception, the copyright holders of this library give you
26+
permission to link this library with independent modules to produce an
27+
executable, regardless of the license terms of these independent
28+
modules, and to copy and distribute the resulting executable under
29+
terms of your choice, provided that you also meet, for each linked
30+
independent module, the terms and conditions of the license of that
31+
module. An independent module is a module which is not derived from
32+
or based on this library. If you modify this library, you may extend
33+
this exception to your version of the library, but you are not
34+
obligated to do so. If you do not wish to do so, delete this
35+
exception statement from your version.
36+
37+
-->
38+
39+
<?xml version="1.0" encoding="utf-8"?>
40+
<jnlp spec="1.0" href="AppletDescMainClassWithClass2.jnlp" codebase="http://localhost:${PORT}">
41+
<information>
42+
<title>main class of applet-desc</title>
43+
<vendor>IcedTea</vendor>
44+
<homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
45+
<description>percents in width/height</description>
46+
<offline/>
47+
</information>
48+
<resources>
49+
<j2se version="1.4+"/>
50+
<jar href="resources/App-appletDescMainClassWithClass.jar"/>
51+
</resources>
52+
<applet-desc
53+
name="notnormal"
54+
main-class="${MAIN_CLASS}.class">
55+
</applet-desc>
56+
</jnlp>

0 commit comments

Comments
 (0)