1 /* 
2  * Copyright 2005 Paul Hinds
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.runtime.exe;
17
18import org.tp23.antinstaller.InstallException;
19import org.tp23.antinstaller.InstallerContext;
20import org.tp23.antinstaller.Installer;
21import org.tp23.antinstaller.runtime.VersionHelper;
22
23
24/**
25 * Executes the Screens part of the build
26 * @author Paul Hinds
27 * @version $Id: ExecuteRunnerFilter.java,v 1.3 2006/12/21 01:48:51 teknopaul Exp $
28 */
29public class ExecuteRunnerFilter implements ExecuteFilter {
30
31    /**
32     * @see org.tp23.antinstaller.runtime.exe.ExecuteFilter#exec(org.tp23.antinstaller.InstallerContext)
33     */
34    public void exec(InstallerContext ctx) throws InstallException {
35
36        checkInstallerRuntimeEnvironment( ctx.getInstaller() );
37        
38        if(ctx.getInstaller().isVerbose()){
39            ctx.log("Starting UI Screens");
40        }
41        boolean ok = ctx.getRunner().runInstaller();
42        if(!ok){
43            throw new AbortException("Install Aborted");
44        }
45        ctx.log("Install screens rendered");
46    }
47
48    public static class AbortException extends InstallException{
49        public AbortException(String message){
50            super(message);
51        }
52    }
53
54    /*
55     * Perform checks on installer runtime environment.
56     */
57    private void checkInstallerRuntimeEnvironment( Installer installer )
58        throws InstallException {
59
60        String minJavaVersion = installer.getMinJavaVersion();
61        if(minJavaVersion != null && ! "".equals(minJavaVersion) ) {
62            VersionHelper helper = new VersionHelper();
63            if( ! helper.equalOrHigher(System.getProperty("java.version"), minJavaVersion, true) ) {
64                throw new InstallException("Incorrect Java version, installer requires java runtime version of '" + minJavaVersion +"' or higher");
65            }
66        }
67
68    }
69}
70