fixed.
Thanks for review.

2012/4/29 Konstantin Kolinko <knst.koli...@gmail.com>:
> 2012/4/29  <ol...@apache.org>:
>> Author: olamy
>> Date: Sat Apr 28 21:11:01 2012
>> New Revision: 1331833
>>
>> URL: http://svn.apache.org/viewvc?rev=1331833&view=rev
>> Log:
>> for exec war extraction mode, generate a file containing the archive 
>> timestamp creation to force reextract when users regenerate it and miss to 
>> reset extract folder.
>>
>> Modified:
>>    
>> tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
>>    
>> tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
>>
>> Modified: 
>> tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
>> URL: 
>> http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java?rev=1331833&r1=1331832&r2=1331833&view=diff
>> ==============================================================================
>> --- 
>> tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
>>  (original)
>> +++ 
>> tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
>>  Sat Apr 28 21:11:01 2012
>> @@ -51,6 +51,7 @@ import java.io.InputStream;
>>  import java.io.OutputStream;
>>  import java.io.PrintWriter;
>>  import java.util.ArrayList;
>> +import java.util.Date;
>>  import java.util.Enumeration;
>>  import java.util.Iterator;
>>  import java.util.List;
>> @@ -293,6 +294,7 @@ public abstract class AbstractExecWarMoj
>>
>>             Properties properties = new Properties();
>>
>> +            properties.put( Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY, 
>> Long.toString( new Date().getTime() ) );
>
>
> The above "new Date().getTime()" call produces the same result as
> calling System.currentTimeMillis() directly, but creates an unneeded
> Date object.
>
>
>>             properties.put( Tomcat7Runner.ENABLE_NAMING_KEY, 
>> Boolean.toString( enableNaming ) );
>>             properties.put( Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY, 
>> accessLogValveFormat );
>>             properties.put( Tomcat7Runner.HTTP_PROTOCOL_KEY, 
>> connectorHttpProtocol );
>> @@ -369,7 +371,6 @@ public abstract class AbstractExecWarMoj
>>             IOUtils.copy( getClass().getResourceAsStream( "/conf/web.xml" ), 
>> os );
>>             os.closeArchiveEntry();
>>
>> -
>>             properties.store( tmpPropertiesFileOutputStream, "created by 
>> Apache Tomcat Maven plugin" );
>>
>>             tmpPropertiesFileOutputStream.flush();
>>
>> Modified: 
>> tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
>> URL: 
>> http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java?rev=1331833&r1=1331832&r2=1331833&view=diff
>> ==============================================================================
>> --- 
>> tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
>>  (original)
>> +++ 
>> tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
>>  Sat Apr 28 21:11:01 2012
>> @@ -33,6 +33,8 @@ import java.io.BufferedOutputStream;
>>  import java.io.File;
>>  import java.io.FileNotFoundException;
>>  import java.io.FileOutputStream;
>> +import java.io.FileReader;
>> +import java.io.FileWriter;
>>  import java.io.IOException;
>>  import java.io.InputStream;
>>  import java.lang.reflect.InvocationTargetException;
>> @@ -58,6 +60,8 @@ public class Tomcat7Runner
>>     // contains war name wars=foo.war,bar.war
>>     public static final String WARS_KEY = "wars";
>>
>> +    public static final String ARCHIVE_GENERATION_TIMESTAMP_KEY = 
>> "generationTimestamp";
>> +
>>     public static final String ENABLE_NAMING_KEY = "enableNaming";
>>
>>     public static final String ACCESS_LOG_VALVE_FORMAT_KEY = 
>> "accessLogValveFormat";
>> @@ -125,15 +129,48 @@ public class Tomcat7Runner
>>
>>         debugMessage( "use extractDirectory:" + 
>> extractDirectoryFile.getPath() );
>>
>> -        // do we have to extract content
>> -        if ( !extractDirectoryFile.exists() || resetExtract )
>> +        boolean archiveTimestampChanged = false;
>> +
>> +        // compare timestamp stored during previous run if exists
>> +        File timestampFile = new File( extractDirectoryFile, 
>> ".tomcat_executable_archive.timestamp" );
>> +
>> +        Properties timestampProps = new Properties();
>> +
>> +        if ( timestampFile.exists() )
>>         {
>> -            extract();
>> +            timestampProps.load( new FileReader( timestampFile ) );
>
> The above is bad coding. You should use FileInputStream to load a
> Properties file.
>
> Properties file uses ISO-8859-1, not system default encoding, and
> there are methods that use InputStream/OutputStream in the Properties
> class to deal with that.
>
>
>> +            String timestampValue = timestampProps.getProperty( 
>> Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY );
>> +            if ( timestampValue != null )
>> +            {
>> +                long timestamp = Long.parseLong( timestampValue );
>> +                archiveTimestampChanged =
>> +                    Long.parseLong( runtimeProperties.getProperty( 
>> Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY ) )
>> +                        > timestamp;
>> +
>> +                debugMessage( "read timestamp from file " + timestampValue 
>> + ", archiveTimestampChanged: "
>> +                                  + archiveTimestampChanged );
>> +            }
>> +
>>         }
>> -        else
>> +
>> +        // do we have to extract content
>>         {
>> -            String wars = runtimeProperties.getProperty( WARS_KEY );
>> -            populateWebAppWarPerContext( wars );
>> +            if ( !extractDirectoryFile.exists() || resetExtract )
>> +            {
>> +                extract();
>> +                // first run so create timestamp file
>> +                if ( !timestampFile.exists() )
>
> I do not get why you use the above exists() check. Shouldn't it be
> unconditional?
>
> With your followup fix in
> http://svn.apache.org/viewvc?diff_format=h&view=revision&revision=1331839
> you do perform extract() call if (archiveTimestampChanged) is true,
> but I do not see how the timestamp file is updated.  I have not looked
> into it, but does extract() call delete the file? That would be the
> reason to remove the above exists() check.
>
>> +                {
>> +                    timestampProps.put( 
>> Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY, 
>> runtimeProperties.getProperty(
>> +                        Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY ) );
>> +                    timestampProps.store( new FileWriter( timestampFile ), 
>> "Timestamp file for executable war/jar" );
>
>
> It needs FileOutputStream above.
>
>
>> +                }
>> +            }
>> +            else
>> +            {
>> +                String wars = runtimeProperties.getProperty( WARS_KEY );
>> +                populateWebAppWarPerContext( wars );
>> +            }
>>         }
>>
>>         // create tomcat various paths
>>
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>



-- 
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to