~ubuntu-branches/ubuntu/natty/icedtea-web/natty-security

« back to all changes in this revision

Viewing changes to netx/net/sourceforge/jnlp/Launcher.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-02-24 12:57:25 UTC
  • mto: (18.1.1 experimental) (19.1.1 natty-security)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20110224125725-8zq5v35r6o27w8ku
Tags: upstream-1.1~20110320
ImportĀ upstreamĀ versionĀ 1.1~20110320

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import java.applet.Applet;
22
22
import java.awt.Container;
23
23
import java.io.File;
24
 
import java.io.FileInputStream;
25
 
import java.io.FileOutputStream;
26
 
import java.io.IOException;
27
 
import java.lang.management.ManagementFactory;
28
 
import java.lang.management.ThreadMXBean;
29
24
import java.lang.reflect.Method;
30
25
import java.net.InetAddress;
31
26
import java.net.URL;
32
27
import java.net.UnknownHostException;
33
 
import java.nio.channels.FileChannel;
34
 
import java.nio.channels.FileLock;
35
28
import java.util.LinkedList;
36
29
import java.util.List;
37
30
import java.util.jar.JarFile;
42
35
import net.sourceforge.jnlp.runtime.AppThreadGroup;
43
36
import net.sourceforge.jnlp.runtime.AppletInstance;
44
37
import net.sourceforge.jnlp.runtime.ApplicationInstance;
45
 
import net.sourceforge.jnlp.runtime.DeploymentConfiguration;
46
38
import net.sourceforge.jnlp.runtime.JNLPClassLoader;
47
39
import net.sourceforge.jnlp.runtime.JNLPRuntime;
48
40
import net.sourceforge.jnlp.services.InstanceExistsException;
49
41
import net.sourceforge.jnlp.services.ServiceUtil;
50
 
import net.sourceforge.jnlp.util.FileUtils;
51
 
import net.sourceforge.jnlp.util.Reflect;
52
42
 
53
43
import javax.swing.SwingUtilities;
54
44
import javax.swing.text.html.parser.ParserDelegator;
86
76
    /** If the application should call System.exit on fatal errors */
87
77
    private boolean exitOnFailure = true;
88
78
 
89
 
    /** a lock which is held to indicate that an instance of netx is running */
90
 
    private FileLock fileLock;
91
79
 
92
80
    /**
93
81
     * Create a launcher with the runtime's default update policy
201
189
    public ApplicationInstance launch(JNLPFile file, Container cont) throws LaunchException {
202
190
        TgThread tg;
203
191
 
 
192
        JNLPRuntime.markNetxRunning();
 
193
 
204
194
        //First checks whether offline-allowed tag is specified inside the jnlp
205
195
        //file.
206
196
        if (!file.getInformation().isOfflineAllowed()) {
329
319
 
330
320
            List<String> commands = new LinkedList<String>();
331
321
 
332
 
            String pathToWebstartBinary = System.getProperty("java.home") +
333
 
                                      File.separatorChar +
334
 
                                      "bin" +
335
 
                                      File.separatorChar +
336
 
                                      "javaws";
 
322
            // this property is set by the javaws launcher to point to the javaws binary
 
323
            String pathToWebstartBinary = System.getProperty("icedtea-web.bin.location");
337
324
            commands.add(pathToWebstartBinary);
338
325
            // use -Jargument format to pass arguments to the JVM through the launcher
339
326
            for (String arg : vmArgs) {
393
380
        if (!file.isApplication())
394
381
            throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplication"), R("LNotApplicationInfo")));
395
382
 
396
 
        markNetxRunning();
397
 
        Runtime.getRuntime().addShutdownHook(new Thread() {
398
 
            public void run() {
399
 
                markNetxStopped();
400
 
            }
401
 
        });
402
 
 
403
383
        try {
404
384
 
405
385
            try {
423
403
                    IconDesc.SPLASH, preferredWidth, preferredHeight);
424
404
            if (splashImageURL != null) {
425
405
                ResourceTracker resourceTracker = new ResourceTracker(true);
426
 
                resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy);
 
406
                resourceTracker.addResource(splashImageURL, file.getFileVersion(), null, updatePolicy);
427
407
                splashScreen = new JNLPSplashScreen(resourceTracker, null, null);
428
408
                splashScreen.setSplashImageURL(splashImageURL);
429
409
                if (splashScreen.isSplashScreenValid()) {
705
685
    }
706
686
 
707
687
    /**
708
 
     * Indicate that netx is running by creating the {@link JNLPRuntime#INSTANCE_FILE} and
709
 
     * acquiring a shared lock on it
710
 
     */
711
 
    private void markNetxRunning() {
712
 
        try {
713
 
            String message = "This file is used to check if netx is running";
714
 
 
715
 
            File netxRunningFile = new File(JNLPRuntime.getConfiguration()
716
 
                    .getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE));
717
 
            if (!netxRunningFile.exists()) {
718
 
                netxRunningFile.getParentFile().mkdirs();
719
 
                FileUtils.createRestrictedFile(netxRunningFile, true);
720
 
                FileOutputStream fos = new FileOutputStream(netxRunningFile);
721
 
                try {
722
 
                    fos.write(message.getBytes());
723
 
                } finally {
724
 
                    fos.close();
725
 
                }
726
 
            }
727
 
 
728
 
            FileInputStream is = new FileInputStream(netxRunningFile);
729
 
            FileChannel channel = is.getChannel();
730
 
            fileLock = channel.tryLock(0, Long.MAX_VALUE, true);
731
 
            if (fileLock != null && fileLock.isShared()) {
732
 
                if (JNLPRuntime.isDebug()) {
733
 
                    System.out.println("Acquired shared lock on " +
734
 
                            netxRunningFile.toString() + " to indicate javaws is running");
735
 
                }
736
 
            } else {
737
 
                fileLock = null;
738
 
            }
739
 
        } catch (IOException e) {
740
 
            e.printStackTrace();
741
 
        }
742
 
 
743
 
    }
744
 
 
745
 
    /**
746
 
     * Indicate that netx is stopped by releasing the shared lock on
747
 
     * {@link JNLPRuntime#INSTANCE_FILE}.
748
 
     */
749
 
    private void markNetxStopped() {
750
 
        if (fileLock == null) {
751
 
            return;
752
 
        }
753
 
        try {
754
 
            fileLock.release();
755
 
            fileLock.channel().close();
756
 
            fileLock = null;
757
 
            if (JNLPRuntime.isDebug()) {
758
 
                String file = JNLPRuntime.getConfiguration()
759
 
                        .getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE);
760
 
                System.out.println("Release shared lock on " + file);
761
 
            }
762
 
        } catch (IOException e) {
763
 
            e.printStackTrace();
764
 
        }
765
 
    }
766
 
 
767
 
    /**
768
688
     * Do hacks on per-application level to allow different AppContexts to work
769
689
     *
770
690
     * @see JNLPRuntime#doMainAppContextHacks
840
760
                exception = ex;
841
761
                // Exit if we can't launch the application.
842
762
                if (exitOnFailure)
843
 
                    System.exit(0);
 
763
                    System.exit(1);
844
764
            }
845
765
        }
846
766