protected void extract()

in tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java [585:690]


    protected void extract()
        throws Exception
    {

        if ( extractDirectoryFile.exists() )
        {
            debugMessage( "delete extractDirectory:" + extractDirectoryFile.getAbsolutePath() );
            FileUtils.deleteDirectory( extractDirectoryFile );
        }

        if ( !this.extractDirectoryFile.exists() )
        {
            boolean created = this.extractDirectoryFile.mkdirs();
            if ( !created )
            {
                throw new Exception( "FATAL: impossible to create directory:" + this.extractDirectoryFile.getPath() );
            }
        }

        // ensure webapp dir is here
        boolean created = new File( extractDirectory, "webapps" ).mkdirs();
        if ( !created )
        {
            throw new Exception(
                "FATAL: impossible to create directory:" + this.extractDirectoryFile.getPath() + "/webapps" );

        }

        String wars = runtimeProperties.getProperty( WARS_KEY );
        populateWebAppWarPerContext( wars );

        for ( Map.Entry<String, String> entry : webappWarPerContext.entrySet() )
        {
            debugMessage( "webappWarPerContext entry key/value: " + entry.getKey() + "/" + entry.getValue() );
            InputStream inputStream = null;
            try
            {
                File expandFile = null;
                inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( entry.getValue() );
                if ( !useServerXml() )
                {
                    if ( entry.getKey().equals( "/" ) )
                    {
                        expandFile = new File( extractDirectory, "webapps/ROOT.war" );
                    }
                    else
                    {
                        expandFile = new File( extractDirectory, "webapps/" + entry.getValue() );
                    }
                }
                else
                {
                    expandFile = new File( extractDirectory, "webapps/" + entry.getValue() );
                }

                debugMessage( "expand to file:" + expandFile.getPath() );

                // MTOMCAT-211 ensure parent directories created
                File parentFile = expandFile.getParentFile();
                if ( !parentFile.mkdirs() && !parentFile.isDirectory() )
                {
                    throw new Exception( "FATAL: impossible to create directories:" + parentFile );
                }

                expand( inputStream, expandFile );

            }
            finally
            {
                if ( inputStream != null )
                {
                    inputStream.close();
                }
            }
        }

        //Copy code source to webapps folder
        if ( codeSourceWar != null )
        {
            FileInputStream inputStream = null;
            try
            {
                File expandFile = new File( extractDirectory, "webapps/" + codeSourceContextPath + ".war" );
                inputStream = new FileInputStream( codeSourceWar );
                debugMessage( "move code source to file:" + expandFile.getPath() );
                expand( inputStream, expandFile );
            }
            finally
            {
                if ( inputStream != null )
                {
                    inputStream.close();
                }
            }
        }

        // expand tomcat configuration files if there
        expandConfigurationFile( "catalina.properties", extractDirectoryFile );
        expandConfigurationFile( "logging.properties", extractDirectoryFile );
        expandConfigurationFile( "tomcat-users.xml", extractDirectoryFile );
        expandConfigurationFile( "catalina.policy", extractDirectoryFile );
        expandConfigurationFile( "context.xml", extractDirectoryFile );
        expandConfigurationFile( "server.xml", extractDirectoryFile );
        expandConfigurationFile( "web.xml", extractDirectoryFile );

    }