This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 83122 - Deployment.undeploy()
Summary: Deployment.undeploy()
Status: RESOLVED FIXED
Alias: None
Product: serverplugins
Classification: Unclassified
Component: Infrastructure (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: Petr Hejl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-21 23:38 UTC by Rich Unger
Modified: 2008-09-15 10:21 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Ant task for undeploying (2.61 KB, text/plain)
2006-08-23 00:11 UTC, Rich Unger
Details
patch for using UndeployTask.java (1.77 KB, patch)
2006-08-23 00:12 UTC, Rich Unger
Details | Diff
patch (16.98 KB, text/plain)
2008-09-10 15:32 UTC, Petr Hejl
Details
updated patch (minor fixes) (19.23 KB, text/plain)
2008-09-11 15:11 UTC, Petr Hejl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rich Unger 2006-08-21 23:38:59 UTC
There should be a way to programatically undeploy a webapp (like an undeploy
method to mirror the deploy method in
org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment).  This would
seem to make sense as part of the "clean" action for a web project.

Use case #1: There are web frameworks out there that parse configuration files
when the deployment occurs, but will not pick up changes to those files
automatically.  True, you can force a redeploy, but there's no way to return to
a "clean" state now without traversing the Runtime..Servers UI.

Use case #2: I'm working with a framework that uses log4j to output a log file
in the web context, and it maintains a lock on that file until the context is
undeployed.  So, 'ant clean' does not work because it fails to delete the file.
 I went to modify my 'clean' ant target to undeploy the webapp first, and found
no API to implement this.  My workaround is to shut down the server altogether,
which is much more time consuming.
Comment 1 Rich Unger 2006-08-22 01:39:42 UTC
Upon further searching, this is related to issue 32773.  I just wrote an ant
task that undeploys the current project's app.  It seems to work all right,
except that it will start up the server if it hasn't already launched, which is
undesirable, but I haven't figured out how to check if the target j2ee server is
running or not:

public class UndeployTask extends Task
{
    public void execute() throws BuildException
    {
        File baseDir = getProject().getBaseDir();
        Project proj = FileOwnerQuery.getOwner(FileUtil.toFileObject(baseDir));

        J2eeModuleProvider jmp = (J2eeModuleProvider)
            proj.getLookup().lookup(J2eeModuleProvider.class);
        DeploymentManager mgr = jmp.getInstanceProperties().getDeploymentManager();

        // for tomcat, this target contains all the webapps
        Target target = jmp.getInstanceProperties().getDefaultTarget();
        Target[] targets = { target };

        String contextUrl = jmp.getConfigSupport().getWebContextRoot(); // (e.g.
"/pizzaordering")

        try
        {
            TargetModuleID[] ids = mgr.getAvailableModules(ModuleType.WAR, targets);

            for (TargetModuleID id : ids)
            {
                String moduleId = id.getModuleID(); // (e.g.
"http://localhost:8084/pizzaordering")
                if (moduleId.endsWith(contextUrl))
                {
                    log("Undeploying old build of web context: " + contextUrl);
                    TargetModuleID[] toUndeploy = { id };
                    mgr.undeploy(toUndeploy);
                }
            }
        }
        catch (TargetException ex)
        {
            throw new BuildException(ex);
        }
        catch (IllegalStateException ex)
        {
            throw new BuildException(ex);
        }
    }
}
Comment 2 Pavel Buzek 2006-08-22 02:13:36 UTC
I agree it would be good to add this into Deployment class and also to into
nbdeploy task (or as a separate task). Not sure if you want to make it part of
clean by default - if you clean/build repeatedly or if you have never deployed
the module you do not want to be slowed down by undeploy (even connecting to the
server and checking if it has been deployed), but we would need to test how long
that takes. Maybe we can add a checkbox to Run tab in project properties.

Undeploy would need to fail nicely (just show a waning) if the server is not
running or if the module was not dpeloyed.

Once we do this we should also add Undeploy action to project popup menu.

I would then close 32773 as wontfix.
Comment 3 Rich Unger 2006-08-22 21:37:54 UTC
I added the following code at the beginning of the Task:

ServerInstance si =
ServerRegistry.getInstance().getServerInstance(jmp.getServerInstanceID());
StartServer ss = si.getStartServer();
if (ss == null || !ss.isRunning())
  return;

This required an impl dependency on j2eeserver (is there a way to check whether
ss.isRunning() using API classes?)

Clean is now very quick if the server isn't running at all.  If it is running,
but the webapp is not deployed, it is still very quick.  I didn't notice any
difference from the old behavior.

In V-Builder, I plan to ship this Task, and to call it from the clean target.  I
would recommend a similar solution to NB, as well as taking a look at whether
deploy should always force a redeploy (I think it should).

If you think you might implement this the way I did, I could provide a full
patch for web/project and j2eeserver.
Comment 4 Pavel Buzek 2006-08-22 21:57:31 UTC
Rich, yes please attach the diff. Stepan will take a look at this in 6.0.
Comment 5 Rich Unger 2006-08-23 00:11:49 UTC
Created attachment 33174 [details]
Ant task for undeploying
Comment 6 Rich Unger 2006-08-23 00:12:16 UTC
Created attachment 33175 [details]
patch for using UndeployTask.java
Comment 7 Sherold Dev 2006-08-23 10:06:14 UTC
Thanks for the patch. Unfortunately, NB 5.5 is already feature frozen, so I will
integrate your patch in the next release - 6.0.
Comment 8 Petr Hejl 2007-09-20 14:16:48 UTC
Partially related to issue 112529.
Comment 9 Petr Hejl 2008-09-10 15:31:19 UTC
Attaching the proper patch that should work for any J2EE module, doing nothing when app is not deployed or server is
stopped.
Comment 10 Petr Hejl 2008-09-10 15:31:54 UTC
Patch includes undeploy on clean.
Comment 11 Petr Hejl 2008-09-10 15:32:36 UTC
Created attachment 69547 [details]
patch
Comment 12 Petr Hejl 2008-09-11 15:11:06 UTC
Created attachment 69663 [details]
updated patch (minor fixes)
Comment 13 Petr Hejl 2008-09-15 10:21:27 UTC
Fixed in main 5d7eec56a42d.