PostInstallFixupAppServerAction.java :  » IDE-Netbeans » installer » org » netbeans » installer » Java Open Source

Java Open Source » IDE Netbeans » installer 
installer » org » netbeans » installer » PostInstallFixupAppServerAction.java
/*
 * The contents of this file are subject to the terms of the Common Development
 * and Distribution License (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
 * or http://www.netbeans.org/cddl.txt.
 *
 * When distributing Covered Code, include this CDDL Header Notice in each file
 * and include the License file at http://www.netbeans.org/cddl.txt.
 * If applicable, add the following below the CDDL Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 *
 * The Original Software is NetBeans. The Initial Developer of the Original
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.installer;

import com.installshield.product.ProductAction;
import com.installshield.product.ProductActionSupport;
import com.installshield.product.ProductBuilderSupport;
import com.installshield.product.ProductException;
import com.installshield.product.service.product.ProductService;
import com.installshield.util.Log;
import com.installshield.wizard.service.file.FileService;

public class PostInstallFixupAppServerAction extends ProductAction {
    
    private String productURL = ProductService.DEFAULT_PRODUCT_SOURCE;
    
    private String nbInstallDir = null;
    private String rootInstallDir = null;
    private String configDir = null;
    
    private FileService fileService;
    private String psep;
    private String sep;
    
    public void build(ProductBuilderSupport support) {
        try {
            support.putClass(Util.class.getName());
            support.putRequiredService(FileService.NAME);
            support.putRequiredService(ProductService.NAME);
        } catch (Exception ex) {
            logEvent(this, Log.ERROR, ex);
        }
    }
    
    public void init(ProductActionSupport support) throws ProductException {
        try {
            // need to get absoluteInstallLocation because uninstaller doesn't know the system properties.
            fileService = (FileService) getServices().getService(FileService.NAME);
            ProductService productService = (ProductService) getService(ProductService.NAME);
            
            psep = fileService.getPathSeparator();
            sep = fileService.getSeparator();
            rootInstallDir = resolveString((String) productService.getProductBeanProperty(productURL,null,"absoluteInstallLocation"));
            if (Util.isMacOSX()) {
                nbInstallDir = rootInstallDir + sep 
                + resolveString("$L(org.netbeans.installer.Bundle,Product.nbLocationBelowInstallRoot)");
            } else {
                nbInstallDir = rootInstallDir;
            }
        } catch (Exception e) {
            logEvent(this, Log.ERROR, e);
        }
        
        logEvent(this, Log.DBG,"nbInstallDir is " + nbInstallDir);
        
        configDir = nbInstallDir + sep + "etc";
    }
    
    public void install(ProductActionSupport support) throws ProductException {
        logEvent(this, Log.DBG,"install, support is " + support +" ...");
        
        init(support);
        
        if (Names.INSTALLER_JBOSS_BUNDLE.equals(Util.getStringPropertyValue(Names.INSTALLER_TYPE))) {
            addASInstallDirToIDEConfigFile();
        }
        
    }
    
    public void uninstall(ProductActionSupport support) throws ProductException {
        logEvent(this, Log.DBG,"uninstall, support is " + support +" ...");
        
        try {
            init(support);
            
        } catch (Exception ex) {
            logEvent(this, Log.ERROR, ex);
        }
    }
    
    public void replace(ProductAction oldAction, ProductActionSupport support) throws ProductException {
        logEvent(this, Log.DBG,"replace, oldAction is " + oldAction +", support is " + support + " ...");
        
        // TODO might modify config file
    }
    
    /** Adds value for system property com.sun.aas.installRoot to netbeans.conf.
     * Path (property value) is surrounded by double quotes on Windows.
     */
    //-J-Dorg.netbeans.modules.j2ee.jboss4.installRoot=\"E:\software\jboss-4.0.4.GA\"
    private void addASInstallDirToIDEConfigFile() {
        //If not set do not do anything (eg. if JBoss AS installer was cancelled)
        String asInstallDir = Util.getASInstallDir();
        if (asInstallDir == null) {
            logEvent(this, Log.DBG, "AS install dir is not set");
            return;
        }
        try {
            String configFilename = configDir + sep + "netbeans.conf";
            logEvent(this, Log.DBG, "Patching: " + configFilename);
            
            int whereToReplace = -1;
            
            String[] content = fileService.readAsciiFile(configFilename);
            if (content != null ) {
                for (int i = 0; i < content.length; i++) {
                    if (content[i].trim().startsWith("netbeans_default_options")) {
                        whereToReplace = i;
                        break;
                    }
                }
            }
            
            if (whereToReplace >= 0) {
                String line = content[whereToReplace].trim();
                //Locate " from end of line
                int pos = line.lastIndexOf('"');
                String newLine = "";
                //Add " around path on Windows due to possible space(s) in path
                //It is for future as now JBoss AS installer does not support spaces in install path.
                if (Util.isWindowsOS()) {
                    newLine = line.substring(0, pos) + " " 
                    + "-J-Dorg.netbeans.modules.j2ee.jboss4.installRoot=\"" + asInstallDir + "\"\"";
                } else {
                    newLine = line.substring(0, pos) + " " 
                    + "-J-Dorg.netbeans.modules.j2ee.jboss4.installRoot=" + asInstallDir + "\"";
                }
                logEvent(this, Log.DBG, "newLine: " + newLine);
                fileService.updateAsciiFile(configFilename, new String[] {newLine}, whereToReplace);
            }
        } catch (Exception ex) {
            logEvent(this, Log.ERROR, ex);
        }
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.