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

Robert Scholte updated MANTTASKS-254:
-------------------------------------
    Description: 
{code}
    /**
     * Execute the Java class against the specified Ant Project.
     * @param project the Project to use.
     * @throws BuildException on error.
     */
    public void execute(Project project) throws BuildException {
        final String classname = javaCommand.getExecutable();

        AntClassLoader loader = null;
        try {
            if (sysProperties != null) {
                sysProperties.setSystem();
            }
            Class<?> target = null;
            try {
                if (classpath == null) {
                    target = Class.forName(classname);
                } else {
                    loader = project.createClassLoader(classpath);
                    loader.setParent(project.getCoreLoader());
                    loader.setParentFirst(false);
                    loader.addJavaLibraries();
                    loader.setIsolated(true);
                    loader.setThreadContextLoader();
                    loader.forceLoadClass(classname);
                    target = Class.forName(classname, true, loader);
                }
            } catch (ClassNotFoundException e) {
                throw new BuildException("Could not find " + classname + "."
                                         + " Make sure you have it in your"
                                         + " classpath");
            }
            main = target.getMethod("main", new Class[] {String[].class});
            if (main == null) {
                throw new BuildException("Could not find main() method in "
                                         + classname);
            }
            if ((main.getModifiers() & Modifier.STATIC) == 0) {
                throw new BuildException("main() method in " + classname
                    + " is not declared static");
            }
            if (timeout == null) {
                run();
            } else {
                thread = new Thread(this, "ExecuteJava");
                Task currentThreadTask
                    = project.getThreadTask(Thread.currentThread());
                // XXX is the following really necessary? it is in the same 
thread group...
                project.registerThreadTask(thread, currentThreadTask);
                // if we run into a timeout, the run-away thread shall not
                // make the VM run forever - if no timeout occurs, Ant's
                // main thread will still be there to let the new thread
                // finish
                thread.setDaemon(true);
                Watchdog w = new Watchdog(timeout.longValue());
                w.addTimeoutObserver(this);
                synchronized (this) {
                    thread.start();
                    w.start();
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        // ignore
                    }
                    if (timedOut) {
                        project.log("Timeout: sub-process interrupted",
                                    Project.MSG_WARN);
                    } else {
                        thread = null;
                        w.stop();
                    }
                }
            }
            if (caught != null) {
                throw caught;
            }
        } catch (BuildException e) {
            throw e;
        } catch (SecurityException e) {
            throw e;
        } catch (ThreadDeath e) {
            // XXX could perhaps also call thread.stop(); not sure if anyone 
cares
            throw e;
        } catch (Throwable e) {
            throw new BuildException(e);
        } finally {
            if (loader != null) {
                loader.resetThreadContextLoader();
                loader.cleanup();
                loader = null;
            }
            if (sysProperties != null) {
                sysProperties.restoreSystem();
            }
        }
    }

    /**
     * Run this ExecuteJava in a Thread.
     * @since Ant 1.5
     * TODO: run() should throw BuildException for any compile error
     */
    public void run() {
        final Object[] argument = {javaCommand.getArguments()};
        try {
            if (perm != null) {
                perm.setSecurityManager();
            }
            main.invoke(null, argument);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (!(t instanceof InterruptedException)) {
                caught = t;
            } /* else { swallow, probably due to timeout } */
        } catch (Throwable t) {
            caught = t;
        } finally {
            if (perm != null) {
                perm.restoreSecurityManager();
            }
            synchronized (this) {
                notifyAll();
            }
        }
    }
{code}

  was:
    /**
     * Execute the Java class against the specified Ant Project.
     * @param project the Project to use.
     * @throws BuildException on error.
     */
    public void execute(Project project) throws BuildException {
        final String classname = javaCommand.getExecutable();

        AntClassLoader loader = null;
        try {
            if (sysProperties != null) {
                sysProperties.setSystem();
            }
            Class<?> target = null;
            try {
                if (classpath == null) {
                    target = Class.forName(classname);
                } else {
                    loader = project.createClassLoader(classpath);
                    loader.setParent(project.getCoreLoader());
                    loader.setParentFirst(false);
                    loader.addJavaLibraries();
                    loader.setIsolated(true);
                    loader.setThreadContextLoader();
                    loader.forceLoadClass(classname);
                    target = Class.forName(classname, true, loader);
                }
            } catch (ClassNotFoundException e) {
                throw new BuildException("Could not find " + classname + "."
                                         + " Make sure you have it in your"
                                         + " classpath");
            }
            main = target.getMethod("main", new Class[] {String[].class});
            if (main == null) {
                throw new BuildException("Could not find main() method in "
                                         + classname);
            }
            if ((main.getModifiers() & Modifier.STATIC) == 0) {
                throw new BuildException("main() method in " + classname
                    + " is not declared static");
            }
            if (timeout == null) {
                run();
            } else {
                thread = new Thread(this, "ExecuteJava");
                Task currentThreadTask
                    = project.getThreadTask(Thread.currentThread());
                // XXX is the following really necessary? it is in the same 
thread group...
                project.registerThreadTask(thread, currentThreadTask);
                // if we run into a timeout, the run-away thread shall not
                // make the VM run forever - if no timeout occurs, Ant's
                // main thread will still be there to let the new thread
                // finish
                thread.setDaemon(true);
                Watchdog w = new Watchdog(timeout.longValue());
                w.addTimeoutObserver(this);
                synchronized (this) {
                    thread.start();
                    w.start();
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        // ignore
                    }
                    if (timedOut) {
                        project.log("Timeout: sub-process interrupted",
                                    Project.MSG_WARN);
                    } else {
                        thread = null;
                        w.stop();
                    }
                }
            }
            if (caught != null) {
                throw caught;
            }
        } catch (BuildException e) {
            throw e;
        } catch (SecurityException e) {
            throw e;
        } catch (ThreadDeath e) {
            // XXX could perhaps also call thread.stop(); not sure if anyone 
cares
            throw e;
        } catch (Throwable e) {
            throw new BuildException(e);
        } finally {
            if (loader != null) {
                loader.resetThreadContextLoader();
                loader.cleanup();
                loader = null;
            }
            if (sysProperties != null) {
                sysProperties.restoreSystem();
            }
        }
    }

    /**
     * Run this ExecuteJava in a Thread.
     * @since Ant 1.5
     * TODO: run() should throw BuildException for any compile error
     */
    public void run() {
        final Object[] argument = {javaCommand.getArguments()};
        try {
            if (perm != null) {
                perm.setSecurityManager();
            }
            main.invoke(null, argument);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (!(t instanceof InterruptedException)) {
                caught = t;
            } /* else { swallow, probably due to timeout } */
        } catch (Throwable t) {
            caught = t;
        } finally {
            if (perm != null) {
                perm.restoreSecurityManager();
            }
            synchronized (this) {
                notifyAll();
            }
        }
    }



> org.apache.tools.ant.taskdefs.ExecuteJava$run method should throw 
> BuildException
> --------------------------------------------------------------------------------
>
>                 Key: MANTTASKS-254
>                 URL: https://issues.apache.org/jira/browse/MANTTASKS-254
>             Project: Maven Ant Tasks (RETIRED)
>          Issue Type: Bug
>          Components: deploy task
>    Affects Versions: 2.0.2
>         Environment: JDK 1.8
> ANT 2.0.2
>            Reporter: Martin Gainty
>            Priority: Major
>         Attachments: ExecuteJava.java
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> {code}
>     /**
>      * Execute the Java class against the specified Ant Project.
>      * @param project the Project to use.
>      * @throws BuildException on error.
>      */
>     public void execute(Project project) throws BuildException {
>         final String classname = javaCommand.getExecutable();
>         AntClassLoader loader = null;
>         try {
>             if (sysProperties != null) {
>                 sysProperties.setSystem();
>             }
>             Class<?> target = null;
>             try {
>                 if (classpath == null) {
>                     target = Class.forName(classname);
>                 } else {
>                     loader = project.createClassLoader(classpath);
>                     loader.setParent(project.getCoreLoader());
>                     loader.setParentFirst(false);
>                     loader.addJavaLibraries();
>                     loader.setIsolated(true);
>                     loader.setThreadContextLoader();
>                     loader.forceLoadClass(classname);
>                     target = Class.forName(classname, true, loader);
>                 }
>             } catch (ClassNotFoundException e) {
>                 throw new BuildException("Could not find " + classname + "."
>                                          + " Make sure you have it in your"
>                                          + " classpath");
>             }
>             main = target.getMethod("main", new Class[] {String[].class});
>             if (main == null) {
>                 throw new BuildException("Could not find main() method in "
>                                          + classname);
>             }
>             if ((main.getModifiers() & Modifier.STATIC) == 0) {
>                 throw new BuildException("main() method in " + classname
>                     + " is not declared static");
>             }
>             if (timeout == null) {
>                 run();
>             } else {
>                 thread = new Thread(this, "ExecuteJava");
>                 Task currentThreadTask
>                     = project.getThreadTask(Thread.currentThread());
>                 // XXX is the following really necessary? it is in the same 
> thread group...
>                 project.registerThreadTask(thread, currentThreadTask);
>                 // if we run into a timeout, the run-away thread shall not
>                 // make the VM run forever - if no timeout occurs, Ant's
>                 // main thread will still be there to let the new thread
>                 // finish
>                 thread.setDaemon(true);
>                 Watchdog w = new Watchdog(timeout.longValue());
>                 w.addTimeoutObserver(this);
>                 synchronized (this) {
>                     thread.start();
>                     w.start();
>                     try {
>                         wait();
>                     } catch (InterruptedException e) {
>                         // ignore
>                     }
>                     if (timedOut) {
>                         project.log("Timeout: sub-process interrupted",
>                                     Project.MSG_WARN);
>                     } else {
>                         thread = null;
>                         w.stop();
>                     }
>                 }
>             }
>             if (caught != null) {
>                 throw caught;
>             }
>         } catch (BuildException e) {
>             throw e;
>         } catch (SecurityException e) {
>             throw e;
>         } catch (ThreadDeath e) {
>             // XXX could perhaps also call thread.stop(); not sure if anyone 
> cares
>             throw e;
>         } catch (Throwable e) {
>             throw new BuildException(e);
>         } finally {
>             if (loader != null) {
>                 loader.resetThreadContextLoader();
>                 loader.cleanup();
>                 loader = null;
>             }
>             if (sysProperties != null) {
>                 sysProperties.restoreSystem();
>             }
>         }
>     }
>     /**
>      * Run this ExecuteJava in a Thread.
>      * @since Ant 1.5
>      * TODO: run() should throw BuildException for any compile error
>      */
>     public void run() {
>         final Object[] argument = {javaCommand.getArguments()};
>         try {
>             if (perm != null) {
>                 perm.setSecurityManager();
>             }
>             main.invoke(null, argument);
>         } catch (InvocationTargetException e) {
>             Throwable t = e.getTargetException();
>             if (!(t instanceof InterruptedException)) {
>                 caught = t;
>             } /* else { swallow, probably due to timeout } */
>         } catch (Throwable t) {
>             caught = t;
>         } finally {
>             if (perm != null) {
>                 perm.restoreSecurityManager();
>             }
>             synchronized (this) {
>                 notifyAll();
>             }
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to