javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/midp2/install/steps/PrepareInstallation.java
changeset 61 bf7ee68962da
parent 21 2a9601315dfc
child 83 26b2b12093af
equal deleted inserted replaced
48:e0d6e9bd3ca7 61:bf7ee68962da
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    27 import com.nokia.mj.impl.installer.exetable.ExeStep;
    27 import com.nokia.mj.impl.installer.exetable.ExeStep;
    28 import com.nokia.mj.impl.installer.integrityservice.IntegrityService;
    28 import com.nokia.mj.impl.installer.integrityservice.IntegrityService;
    29 import com.nokia.mj.impl.installer.jsrpluginnotifier.JsrPluginNotifier;
    29 import com.nokia.mj.impl.installer.jsrpluginnotifier.JsrPluginNotifier;
    30 import com.nokia.mj.impl.installer.storagehandler.StorageHandler;
    30 import com.nokia.mj.impl.installer.storagehandler.StorageHandler;
    31 import com.nokia.mj.impl.installer.utils.Args;
    31 import com.nokia.mj.impl.installer.utils.Args;
       
    32 import com.nokia.mj.impl.installer.utils.DriveInfo;
    32 import com.nokia.mj.impl.installer.utils.FileRoots;
    33 import com.nokia.mj.impl.installer.utils.FileRoots;
    33 import com.nokia.mj.impl.installer.utils.FileUtils;
    34 import com.nokia.mj.impl.installer.utils.FileUtils;
    34 import com.nokia.mj.impl.installer.utils.InstallerException;
    35 import com.nokia.mj.impl.installer.utils.InstallerException;
    35 import com.nokia.mj.impl.installer.utils.Log;
    36 import com.nokia.mj.impl.installer.utils.Log;
    36 import com.nokia.mj.impl.installer.utils.MidpAttributeValidator;
    37 import com.nokia.mj.impl.installer.utils.MidpAttributeValidator;
    37 import com.nokia.mj.impl.installer.utils.SysUtil;
    38 import com.nokia.mj.impl.installer.utils.SysUtil;
    38 import com.nokia.mj.impl.security.midp.authentication.AuthenticationModule;
    39 import com.nokia.mj.impl.security.midp.authentication.AuthenticationModule;
    39 import com.nokia.mj.impl.security.midp.authentication.OcspSettings;
    40 import com.nokia.mj.impl.security.midp.authentication.OcspSettings;
       
    41 import com.nokia.mj.impl.fileutils.FileURL;
    40 import com.nokia.mj.impl.utils.Uid;
    42 import com.nokia.mj.impl.utils.Uid;
       
    43 
       
    44 import java.util.Vector;
    41 
    45 
    42 public class PrepareInstallation extends ExeStep
    46 public class PrepareInstallation extends ExeStep
    43 {
    47 {
    44 
    48 
    45     public void execute(ExeBall aBall)
    49     public void execute(ExeBall aBall)
   168         {
   172         {
   169             if (Downloader.isDownloadUrl(jarArg))
   173             if (Downloader.isDownloadUrl(jarArg))
   170             {
   174             {
   171                 aBall.iJarUrl = jarArg;
   175                 aBall.iJarUrl = jarArg;
   172             }
   176             }
       
   177             else if (isFileUrl(jarArg))
       
   178             {
       
   179                 aBall.iJarFilename = getFileFromUrl(jarArg);
       
   180                 Log.log("Jar " + aBall.iJarFilename + " from URL " + jarArg);
       
   181             }
   173             else
   182             else
   174             {
   183             {
   175                 aBall.iJarFilename = jarArg;
   184                 aBall.iJarFilename = jarArg;
   176             }
   185             }
   177         }
   186         }
   178         if (jadArg != null)
   187         if (jadArg != null)
   179         {
   188         {
   180             if (Downloader.isDownloadUrl(jadArg))
   189             if (Downloader.isDownloadUrl(jadArg))
   181             {
   190             {
   182                 aBall.iJadUrl = jadArg;
   191                 aBall.iJadUrl = jadArg;
       
   192             }
       
   193             else if (isFileUrl(jadArg))
       
   194             {
       
   195                 aBall.iJadFilename = getFileFromUrl(jadArg);
       
   196                 Log.log("Jad " + aBall.iJadFilename + " from URL " + jadArg);
   183             }
   197             }
   184             else
   198             else
   185             {
   199             {
   186                 aBall.iJadFilename = jadArg;
   200                 aBall.iJadFilename = jadArg;
   187             }
   201             }
   264         // be used to override the target installation drive.
   278         // be used to override the target installation drive.
   265         arg = args.get("drive");
   279         arg = args.get("drive");
   266         if (arg != null)
   280         if (arg != null)
   267         {
   281         {
   268             aBall.iInstallationDrive = args.parseDrive(arg);
   282             aBall.iInstallationDrive = args.parseDrive(arg);
       
   283             checkInstallationDrive(aBall.iInstallationDrive);
   269         }
   284         }
   270     }
   285     }
   271 
   286 
   272     private static void checkForPreinstallation(InstallBall aBall)
   287     private static void checkForPreinstallation(InstallBall aBall)
   273     {
   288     {
   344             new OcspSettings(ocspMode, ocspWarning, aBall.isSilent(),
   359             new OcspSettings(ocspMode, ocspWarning, aBall.isSilent(),
   345                              aBall.iIap, aBall.iSnap);
   360                              aBall.iIap, aBall.iSnap);
   346         Log.log("ocspSettings: " + ocspSettings);
   361         Log.log("ocspSettings: " + ocspSettings);
   347         return ocspSettings;
   362         return ocspSettings;
   348     }
   363     }
       
   364 
       
   365     /**
       
   366      * Returns true if given URL is a file URL, false otherwise.
       
   367      */
       
   368     private static boolean isFileUrl(String aUrl)
       
   369     {
       
   370         if (aUrl == null || aUrl.length() == 0)
       
   371         {
       
   372             return false;
       
   373         }
       
   374         return aUrl.toLowerCase().startsWith("file://");
       
   375     }
       
   376 
       
   377     /**
       
   378      * Returns a file path from file URL.
       
   379      *
       
   380      * @throws InstallerException if URL is invalid.
       
   381      */
       
   382     private static String getFileFromUrl(String aUrl)
       
   383     {
       
   384         String filePath = null;
       
   385         try
       
   386         {
       
   387             FileURL fileUrl = new FileURL(aUrl);
       
   388             filePath = fileUrl.getFullPath();
       
   389         }
       
   390         catch (Throwable t)
       
   391         {
       
   392             InstallerException.internalError("Invalid file URL: " + aUrl, t);
       
   393         }
       
   394         return filePath;
       
   395     }
       
   396 
       
   397     /**
       
   398      * Checks that given installation drive is a valid one.
       
   399      *
       
   400      * @param aDrive installation drive
       
   401      * @throws InstallerException if installation drive is not valid
       
   402      */
       
   403     private static void checkInstallationDrive(int aDrive)
       
   404     {
       
   405         Vector drives = new Vector();
       
   406         SysUtil.getUserVisibleDrives(drives);
       
   407         for (int i = 0; i < drives.size(); i++)
       
   408         {
       
   409             DriveInfo driveInfo = (DriveInfo)drives.elementAt(i);
       
   410             if (driveInfo.getNumber() == aDrive)
       
   411             {
       
   412                 // Installation drive found from user visible drives.
       
   413                 return;
       
   414             }
       
   415         }
       
   416         InstallerException.internalError(
       
   417             "Invalid installation drive: " + aDrive +
       
   418             " (" + (char)('A' + aDrive) + ")");
       
   419     }
   349 }
   420 }