Return-Path: X-Original-To: apmail-ant-dev-archive@www.apache.org Delivered-To: apmail-ant-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB918D166 for ; Sat, 21 Jul 2012 05:47:17 +0000 (UTC) Received: (qmail 64563 invoked by uid 500); 21 Jul 2012 05:47:16 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 64350 invoked by uid 500); 21 Jul 2012 05:47:15 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 64319 invoked by uid 99); 21 Jul 2012 05:47:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Jul 2012 05:47:14 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mgitman@gmail.com designates 209.85.220.173 as permitted sender) Received: from [209.85.220.173] (HELO mail-vc0-f173.google.com) (209.85.220.173) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Jul 2012 05:47:08 +0000 Received: by vcbfl15 with SMTP id fl15so3594172vcb.4 for ; Fri, 20 Jul 2012 22:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=1OKzwKFWLuMrq/gMXNF931wlRGiKD+mro+DbCkpg+xg=; b=Jc0+lBKp4QbR26bYDi9n2Nbh8vOV64pZXiL1Z7ixW5S5HZNm/iXP5zj8vuKLZzVAHl o5R1/GXbmfDE4GUz7hIgd8z6uG5J0uGeDjhfKdPIaH0RxHJ+r/lRHEjCrESlE6wOV/4r YUeq7cC1K8Os1fgIvP/JSywrLy+2HxpALrnKC1u+qg2F2uTeXGJEKMqJ2zaIN86vXoSj AN/WD4olL4X+0/eSpDqUsNlTaDahhF+oVf7Yzdkg1ynfpj5kvjgHHMUWcItMPOjdzFWu BqZzUcgdjyoSLJtG9rK1z6zC+9NisK9Z7E2gdS0KzalKM24YpUZ15IQfPPWxC6RRBW/G F86g== MIME-Version: 1.0 Received: by 10.52.98.101 with SMTP id eh5mr5704924vdb.8.1342849607661; Fri, 20 Jul 2012 22:46:47 -0700 (PDT) Received: by 10.220.7.15 with HTTP; Fri, 20 Jul 2012 22:46:47 -0700 (PDT) In-Reply-To: References: Date: Fri, 20 Jul 2012 22:46:47 -0700 Message-ID: Subject: Re: controlling ClassLoader when programmatically invoking Ant From: Mitch Gitman To: Ant Developers List Content-Type: multipart/alternative; boundary=20cf307f34e4d9f83404c55089c4 --20cf307f34e4d9f83404c55089c4 Content-Type: text/plain; charset=UTF-8 P.S. I'm going to give URLClassLoader a shot with the JARs in Ant lib: http://docs.oracle.com/javase/6/docs/api/java/net/URLClassLoader.html Almost sounds a little too easy... On Fri, Jul 20, 2012 at 10:37 PM, Mitch Gitman wrote: > Technically, this message is better suited for the ant-user list, but I'm > thinking I'm more apt to get an answer on this list. (I'm also thinking > this is the better place for me to cash in some chits for my having > submitted patches for three Ivy issues I mentioned recently on this list. > Subject: "extends and buildlist on 2.3.0-rc1....") > > Here's my problem. I'm trying to do a JUnit test of some Ivy functionality > (actually, relating to the aforementioned Ivy bugs) by programmatically > creating and executing an Ant Project object. Everything runs just fine. > I'm able to execute targets and even tie in a BuildListener and a > BuildLogger to tap into output and error and check if the build failed. > > The problem is, everything works a little too well. Take a look at the > following example build.xml: > default="build"> > > > > > > > > I've abbreviated the ivy:resolve call, but take it from me that everything > works, including running the test directly from within an IDE. It > shouldn't. Nowhere am I specifying the classpath containing the JAR for Ivy > itself. Nowhere am I even doing the taskdef for Ivy. > > And in fact, if I run this build.xml straight from the command line, it > fails like you would expect: > Problem: failed to create task or type antlib:org.apache.ivy.ant:settings > ... > > I can only think that the key method I want to take advantage of is this > in Project: > public void setCoreLoader(ClassLoader coreLoader) { > this.coreLoader = coreLoader; > } > > What's interesting is that the command-line entry point for Ant in > org.apache.tools.ant.Main ends up passing null to setCoreLoader, in which > case "the parent classloader should be used," according to the method's > Javadoc. At this point, I go take a look at the scripts that launch Ant and > my eyes get blurry. But I believe what I want to do is manually construct a > ClassLoader as if I were running "java -cp ..." with the contents of Ant's > lib directory. (I'm showing my ignorance of ClassLoaders here, I realize.) > Perhaps someone can point me to an elegant way to accomplish that. > > If someone's going to say, "Hey, check what antunit does," I'd appreciate > if you could pinpoint what it's doing. > > P.S. Perhaps somebody has a rational explanation too for why the taskdef > of Ivy is creeping in. > --20cf307f34e4d9f83404c55089c4--