https://issues.apache.org/bugzilla/show_bug.cgi?id=45739

           Summary: Problems with BaseDir when the ant is started as Java
                    library from Java Application
           Product: Ant
           Version: 1.7.1
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: Core
        AssignedTo: notifications@ant.apache.org
        ReportedBy: [EMAIL PROTECTED]


I try to start ant script using ant as java library from Java application. The
start is realized as follow:
    File buildXmlFile = new File("C:\a\b\z.xml");
    List<String> command = new ArrayList<String>();
    ...
    command.add(...);
    ...
    command.add("-buildfile");
    command.add(buildXmlFile.getAbsolutePath());
    Main ant = new Main();
    ant.startAnt(command.toArray(new String[command.size()]), null, null);

The content of build xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<project name="SSHAntScriptTest" default="default" basedir=".">
    <description>Build file for SSH Ant Script tests.</description>
    <scp file="test.txt" todir="${username}:[EMAIL PROTECTED]:/home/bc"/>
</project>

The xml build file location is different from the execution directory.
When that execution is initiated from the command prompt like that everything
is OK:
c:\somedir>ant -buildfile c:\anotherdir>buildfile.xml

When I try to start the same with the same parameters as java library the
text.txt file can not be founded. Ant looks for the file in execution directory
"c:\somedir\test.txt" instead in buildfile directory "c:\anotherdir\test.txt".

To fix this at the moment the following changes are made:
1. The user.dir is changed:
   File dir = buildXmlFile.getParentFile();
   System.getProperties().put("user.dir", dir.getAbsolutePath());
2. The method runBuild from the Main class is fixed as follow:
   private void runBuild(ClassLoader coreLoader) throws BuildException {
      ...
      project.init();

      // 2008-Sep-04: Bug Fix from Miro.
      project.getBaseDir();

I try to put that fix before project.init() without result.

If you need I can send you one small project as test case.

The big problem is that I do some changes in System Properties and that the
application is multi-thread and multi-tasking and because System Properties are
global (static) for all instances in the current JVM.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Reply via email to