javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/midp2/install/steps/PrepareInstallation.java
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2009 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;
       
    33 import com.nokia.mj.impl.installer.utils.FileRoots;
    32 import com.nokia.mj.impl.installer.utils.FileRoots;
    34 import com.nokia.mj.impl.installer.utils.FileUtils;
    33 import com.nokia.mj.impl.installer.utils.FileUtils;
    35 import com.nokia.mj.impl.installer.utils.InstallerException;
    34 import com.nokia.mj.impl.installer.utils.InstallerException;
    36 import com.nokia.mj.impl.installer.utils.Log;
    35 import com.nokia.mj.impl.installer.utils.Log;
    37 import com.nokia.mj.impl.installer.utils.MidpAttributeValidator;
    36 import com.nokia.mj.impl.installer.utils.MidpAttributeValidator;
    38 import com.nokia.mj.impl.installer.utils.SysUtil;
    37 import com.nokia.mj.impl.installer.utils.SysUtil;
    39 import com.nokia.mj.impl.security.midp.authentication.AuthenticationModule;
    38 import com.nokia.mj.impl.security.midp.authentication.AuthenticationModule;
    40 import com.nokia.mj.impl.security.midp.authentication.OcspSettings;
    39 import com.nokia.mj.impl.security.midp.authentication.OcspSettings;
    41 import com.nokia.mj.impl.fileutils.FileURL;
       
    42 import com.nokia.mj.impl.utils.Uid;
    40 import com.nokia.mj.impl.utils.Uid;
    43 
       
    44 import java.util.Vector;
       
    45 
    41 
    46 public class PrepareInstallation extends ExeStep
    42 public class PrepareInstallation extends ExeStep
    47 {
    43 {
    48 
    44 
    49     public void execute(ExeBall aBall)
    45     public void execute(ExeBall aBall)
   172         {
   168         {
   173             if (Downloader.isDownloadUrl(jarArg))
   169             if (Downloader.isDownloadUrl(jarArg))
   174             {
   170             {
   175                 aBall.iJarUrl = jarArg;
   171                 aBall.iJarUrl = jarArg;
   176             }
   172             }
   177             else if (isFileUrl(jarArg))
       
   178             {
       
   179                 aBall.iJarFilename = getFileFromUrl(jarArg);
       
   180                 Log.log("Jar " + aBall.iJarFilename + " from URL " + jarArg);
       
   181             }
       
   182             else
   173             else
   183             {
   174             {
   184                 aBall.iJarFilename = jarArg;
   175                 aBall.iJarFilename = jarArg;
   185             }
   176             }
   186         }
   177         }
   187         if (jadArg != null)
   178         if (jadArg != null)
   188         {
   179         {
   189             if (Downloader.isDownloadUrl(jadArg))
   180             if (Downloader.isDownloadUrl(jadArg))
   190             {
   181             {
   191                 aBall.iJadUrl = jadArg;
   182                 aBall.iJadUrl = jadArg;
   192             }
       
   193             else if (isFileUrl(jadArg))
       
   194             {
       
   195                 aBall.iJadFilename = getFileFromUrl(jadArg);
       
   196                 Log.log("Jad " + aBall.iJadFilename + " from URL " + jadArg);
       
   197             }
   183             }
   198             else
   184             else
   199             {
   185             {
   200                 aBall.iJadFilename = jadArg;
   186                 aBall.iJadFilename = jadArg;
   201             }
   187             }
   278         // be used to override the target installation drive.
   264         // be used to override the target installation drive.
   279         arg = args.get("drive");
   265         arg = args.get("drive");
   280         if (arg != null)
   266         if (arg != null)
   281         {
   267         {
   282             aBall.iInstallationDrive = args.parseDrive(arg);
   268             aBall.iInstallationDrive = args.parseDrive(arg);
   283             checkInstallationDrive(aBall.iInstallationDrive);
       
   284         }
   269         }
   285     }
   270     }
   286 
   271 
   287     private static void checkForPreinstallation(InstallBall aBall)
   272     private static void checkForPreinstallation(InstallBall aBall)
   288     {
   273     {
   359             new OcspSettings(ocspMode, ocspWarning, aBall.isSilent(),
   344             new OcspSettings(ocspMode, ocspWarning, aBall.isSilent(),
   360                              aBall.iIap, aBall.iSnap);
   345                              aBall.iIap, aBall.iSnap);
   361         Log.log("ocspSettings: " + ocspSettings);
   346         Log.log("ocspSettings: " + ocspSettings);
   362         return ocspSettings;
   347         return ocspSettings;
   363     }
   348     }
   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     }
       
   420 }
   349 }