[ 
https://issues.apache.org/jira/browse/MTOMCAT-270?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stefan Kopf updated MTOMCAT-270:
--------------------------------

    Description: 
Additional Web apps are exploded into a directory under the webapps folder in 
the Tomcat config directory - but only if this folder does not yet exist.

{code:title=org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java 
line 1443|borderStyle=solid}
        File webapps = new File( configurationDir, "webapps" );
        File artifactWarDir = new File( webapps, artifact.getArtifactId() );
        if ( !artifactWarDir.exists() )
        {
            //dont extract if exists
            artifactWarDir.mkdir();
            ...
{code}

If the artifact is changed (i.e. when deploying a snapshot), it is not 
redeployed since the directory does already exist.

Since the directory is just named after the artifact id and does not contain 
group id or version, it is also not re deployed even if the version of the 
dependency is changed.

Proposed fix (simple):
If the directory exists, it should be removed before exploding the web app.
Problem:
This does work correctly, but will cause some overhead since it will be always 
re-deploying.

Proposed optimal fix:
1. The deployment directory where the webapp is exploded to should consist of 
groupId, artifactId and version, and not just the artifact id.
For example:
{code:org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java suggested 
change|borderStyle=solid}
     private void addContextFromArtifact( Tomcat container, List<Context> 
contexts, Artifact artifact,
                                         String contextPath, File contextXml, 
boolean asWebApp )
        throws MojoExecutionException, ServletException, IOException
    {
        getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() 
) + " to contextPath: " + contextPath );
        File webapps = new File( configurationDir, "webapps" );
        File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" + 
artifact.getArtifactId() + "/" + artifact.getVersion() );
        if ( !artifactWarDir.exists() )
        ...
{code}
2. The timestamp of the directory should be compared against the timestamp of 
the war file. If the war file is newer, the directory is deleted and redeployed:
{code:title=org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java 
suggested change|borderStyle=solid}
        getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() 
) + " to contextPath: " + contextPath );
        File webapps = new File( configurationDir, "webapps" );
        File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" + 
artifact.getArtifactId() + "/" + artifact.getVersion() );
        if( artifactWarDir.exists() )
        {
            if( artifact.getFile().lastModified() > 
artifactWarDir.lastModified() )
            {
                FileUtils.deleteDirectory( artifactWarDir );
            }
        }
        if ( !artifactWarDir.exists() )
        {
            //dont extract if exists
            artifactWarDir.mkdir();
            try
            {
{code}

Please note that the changed directory layout proposed by this fix influences 
the fix proposed in MTOMCAT-269

  was:
Additional Web apps are exploded into a directory under the webapps folder in 
the Tomcat config directory - but only if this folder does not yet exist.

{code:org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java line 
1443|borderStyle=solid}
        File webapps = new File( configurationDir, "webapps" );
        File artifactWarDir = new File( webapps, artifact.getArtifactId() );
        if ( !artifactWarDir.exists() )
        {
            //dont extract if exists
            artifactWarDir.mkdir();
            ...
{code}

If the artifact is changed (i.e. when deploying a snapshot), it is not 
redeployed since the directory does already exist.

Since the directory is just named after the artifact id and does not contain 
group id or version, it is also not re deployed even if the version of the 
dependency is changed.

Proposed fix (simple):
If the directory exists, it should be removed before exploding the web app.
Problem:
This does work correctly, but will cause some overhead since it will be always 
re-deploying.

Proposed optimal fix:
1. The deployment directory where the webapp is exploded to should consist of 
groupId, artifactId and version, and not just the artifact id.
For example:
{code:org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java suggested 
change|borderStyle=solid}
     private void addContextFromArtifact( Tomcat container, List<Context> 
contexts, Artifact artifact,
                                         String contextPath, File contextXml, 
boolean asWebApp )
        throws MojoExecutionException, ServletException, IOException
    {
        getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() 
) + " to contextPath: " + contextPath );
        File webapps = new File( configurationDir, "webapps" );
        File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" + 
artifact.getArtifactId() + "/" + artifact.getVersion() );
        if ( !artifactWarDir.exists() )
        ...
{code}
2. The timestamp of the directory should be compared against the timestamp of 
the war file. If the war file is newer, the directory is deleted and redeployed:
{code:org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java suggested 
change|borderStyle=solid}
        getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() 
) + " to contextPath: " + contextPath );
        File webapps = new File( configurationDir, "webapps" );
        File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" + 
artifact.getArtifactId() + "/" + artifact.getVersion() );
        if( artifactWarDir.exists() )
        {
            if( artifact.getFile().lastModified() > 
artifactWarDir.lastModified() )
            {
                FileUtils.deleteDirectory( artifactWarDir );
            }
        }
        if ( !artifactWarDir.exists() )
        {
            //dont extract if exists
            artifactWarDir.mkdir();
            try
            {
{code}

Please note that the changed directory layout proposed by this fix influences 
the fix proposed in MTOMCAT-269


> Additional web apps are not re-deployed properly
> ------------------------------------------------
>
>                 Key: MTOMCAT-270
>                 URL: https://issues.apache.org/jira/browse/MTOMCAT-270
>             Project: Apache Tomcat Maven Plugin
>          Issue Type: Bug
>          Components: tomcat6, tomcat7
>    Affects Versions: 2.2
>            Reporter: Stefan Kopf
>            Assignee: Olivier Lamy (*$^¨%`£)
>
> Additional Web apps are exploded into a directory under the webapps folder in 
> the Tomcat config directory - but only if this folder does not yet exist.
> {code:title=org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java 
> line 1443|borderStyle=solid}
>         File webapps = new File( configurationDir, "webapps" );
>         File artifactWarDir = new File( webapps, artifact.getArtifactId() );
>         if ( !artifactWarDir.exists() )
>         {
>             //dont extract if exists
>             artifactWarDir.mkdir();
>             ...
> {code}
> If the artifact is changed (i.e. when deploying a snapshot), it is not 
> redeployed since the directory does already exist.
> Since the directory is just named after the artifact id and does not contain 
> group id or version, it is also not re deployed even if the version of the 
> dependency is changed.
> Proposed fix (simple):
> If the directory exists, it should be removed before exploding the web app.
> Problem:
> This does work correctly, but will cause some overhead since it will be 
> always re-deploying.
> Proposed optimal fix:
> 1. The deployment directory where the webapp is exploded to should consist of 
> groupId, artifactId and version, and not just the artifact id.
> For example:
> {code:org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java 
> suggested change|borderStyle=solid}
>      private void addContextFromArtifact( Tomcat container, List<Context> 
> contexts, Artifact artifact,
>                                          String contextPath, File contextXml, 
> boolean asWebApp )
>         throws MojoExecutionException, ServletException, IOException
>     {
>         getLog().info( "Deploy warfile: " + String.valueOf( 
> artifact.getFile() ) + " to contextPath: " + contextPath );
>         File webapps = new File( configurationDir, "webapps" );
>         File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" 
> + artifact.getArtifactId() + "/" + artifact.getVersion() );
>         if ( !artifactWarDir.exists() )
>         ...
> {code}
> 2. The timestamp of the directory should be compared against the timestamp of 
> the war file. If the war file is newer, the directory is deleted and 
> redeployed:
> {code:title=org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java 
> suggested change|borderStyle=solid}
>         getLog().info( "Deploy warfile: " + String.valueOf( 
> artifact.getFile() ) + " to contextPath: " + contextPath );
>         File webapps = new File( configurationDir, "webapps" );
>         File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" 
> + artifact.getArtifactId() + "/" + artifact.getVersion() );
>         if( artifactWarDir.exists() )
>         {
>             if( artifact.getFile().lastModified() > 
> artifactWarDir.lastModified() )
>             {
>                 FileUtils.deleteDirectory( artifactWarDir );
>             }
>         }
>         if ( !artifactWarDir.exists() )
>         {
>             //dont extract if exists
>             artifactWarDir.mkdir();
>             try
>             {
> {code}
> Please note that the changed directory layout proposed by this fix influences 
> the fix proposed in MTOMCAT-269



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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

Reply via email to