You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Blaise Gervais <ge...@gmail.com> on 2010/04/22 13:51:24 UTC

Custom task with classpath and exclusion

Hi everyone,

I'm writing one custom Ant Task who create a classpath. This task can also
exlued files from the class path. But I'm unable to excludes files from the
Path because the path t the excluded file is wrong.
Here is my code :

> FileSet exclusions = new FileSet();

System.out.println("Parent : "+classpathFile.getParentFile());

exclusions.setDir(new File(Path.translateFile(classpathFile.getParent())));

exclusions.setProject(getProject());

Path antClassPath = new Path(getProject());

for (InternalClassPathEntry entry : eclipseClassPath.getEntries(entryKinds))
> {

PathElement element = antClassPath.createPathElement();

element.setLocation(new File(classpathFile.getParentFile(),
> entry.path.getPath()));

if ( entry.exclusions!=null && !entry.exclusions.isEmpty() ) {

for (String exclusion : entry.exclusions) {

System.out.println("Exclude :
> "+entry.path.getPath()+File.separatorChar+exclusion);

exclusions.createExcludesFile().setName(entry.path.getPath()+File.separatorChar+exclusion);

}

}

}

System.out.println(antClassPath);

antClassPath.addFileset(exclusions);


And the output :

> Buildfile: C:\Dev\Perso\App\app-builder\build.xml

test:

[eclipseclasspath] Parent : C:\Dev\Perso\App\app-impl\app-manager

[eclipseclasspath] Exclude :
> src.main\be/me/app/manager/commons/components/OgTreeTable.java

[eclipseclasspath] Exclude :
> src.main\be/me/app/manager/commons/models/TreeTableModel.java

[eclipseclasspath] Exclude :
> src.main\be/me/app/manager/commons/models/TreeTableModelAdapter.java

[eclipseclasspath] Exclude :
> src.main\be/me/app/manager/commons/models/AbstractTreeTableModel.java

[eclipseclasspath] Exclude : modules\epublish\be/me/sics/**/*

[eclipseclasspath] Exclude :
> modules\epublish\com/sun/star/beans/LocalOfficeConnection.java


> BUILD FAILED

C:\Dev\Perso\App\app-builder\build.xml:39: Excludesfile
> C:\Dev\Perso\App\app-builder\src.main\be\gervaisb\ogam\manager\commons\components\OgTreeTable.java
> not found.


> Total time: 233 milliseconds


The "Parent" folder correctly point to the project folder and each "Exclude"
are also existing : Parent+File.separator+Exclude give me a path to a real
file.
But the build fail and tell me that the file is not found. In fact she is
not found bacause ANt try to find it from a wrong folder. It will not look
into "C:\...\app-builder\" but into "C:\...\app-impl\app-manager\" (the
"Parent")

Can you help me please ?

Thanks


-- 
Gervais Blaise
<ge...@gmail.com>

Re: Custom task with classpath and exclusion

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-04-22, Blaise Gervais <ge...@gmail.com> wrote:

> exclusions.createExcludesFile().setName(entry.path.getPath()+File.separatorChar+exclusion);

In a fileset an excludesfile is a text file that contains an exclusion
pattern per line.  I don't think you really want this but
createExclude(),

> And the output :

>> Buildfile: C:\Dev\Perso\App\app-builder\build.xml

> test:

> [eclipseclasspath] Parent : C:\Dev\Perso\App\app-impl\app-manager

> [eclipseclasspath] Exclude :
>> src.main\be/me/app/manager/commons/components/OgTreeTable.java

This is probably a good name for an exclude pattern which is resolved
relative to the fileset's dir.

> But the build fail and tell me that the file is not found. In fact she is
> not found bacause ANt try to find it from a wrong folder.

excludesfiles as opposed to exclude patterns are resolved relative to
the project's basedir, not the dir of the fileset.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org