Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ant XML imports break the "List Targets" feature #15

Open
ZaLiTHkA opened this issue Nov 20, 2014 · 2 comments
Open

Ant XML imports break the "List Targets" feature #15

ZaLiTHkA opened this issue Nov 20, 2014 · 2 comments

Comments

@ZaLiTHkA
Copy link
Contributor

I'm running ST3 x86 build 3065 under Windows 8.1 Pro x64, having issues trying to get this extension to read a Netbeans-generated Ant build script correctly. And fair warning: I don't do Python very well, I know enough to get by with debugging, but that's about it.

I hate Netbeans with the fire of a thousand burning suns, but other devs at work use it, so I'm trying to get this to work with Netbeans-generated Ant build scripts.

The specific problem I'm having is with regards to opening imported files.. Netbeans starts off with a build.xml file in the root of the project, which imports build-impl.xml from the nbprojects folder. For web app projects, this last file also imports a ant-deploy.xml file.

First I had an issue with the fact that Netbeans stores all paths Unix-style (separators are forward slashes), so I included a step to replace / with os.sep. The idea here is that if it's Unix, / will be replaced with /, if it's NT based, / becomes \. All good there.

Then I had an issue getting SuperAnt to grab the correct path for the imported file. After reading the line nbprojects/build-impl.xml from my build script, it would try and open that as an absolute path and fail. I got around this with os.path.join(self-working_dir, importFile) after my separator replacement line above.

To clarify, this is where I stand currently with SuperAnt_exec.py, lines 131-146:

if followImports:
    imports = dom.getElementsByTagName('import');
    for imp in imports:

        importFile = imp.getAttributeNode("file").nodeValue;
        print("Debug - importFile: initial string: " + importFile)

        # Windows-specific use case, Ant files use unix-style path formatting by default
        importFile = importFile.replace('/',os.sep);
        print("Debug - importFile: after string.replace: " + importFile)

        importFile = os.path.join(self.working_dir, importFile);
        print("Debug - importFile: self.working_dir: " + self.working_dir)
        print("Debug - importFile: string.join: " + importFile)

        projects = projects + self._get_projects_from_file(importFile, followImports);

The issue I have now is that build-impl.xml imports ant-deploy.xml from the same dir. Looking at the console output, when I run the "List Targets" task, I see the following:

Project detected searching folders for buildfile
Project folder search found buildfile at "D:\Dev Stuff\Java\Tests\My Project\build.xml".
Opening D:\Dev Stuff\Java\Tests\My Project\build.xml
Debug - importFile: initial string: nbproject/build-impl.xml
Debug - importFile: after string.replace: nbproject\build-impl.xml
Debug - importFile: self.working_dir: D:\Dev Stuff\Java\Tests\My Project
Debug - importFile: string.join: D:\Dev Stuff\Java\Tests\My Project\nbproject\build-impl.xml
Opening D:\Dev Stuff\Java\Tests\My Project\nbproject\build-impl.xml
Debug - importFile: initial string: ant-deploy.xml
Debug - importFile: after string.replace: ant-deploy.xml
Debug - importFile: self.working_dir: D:\Dev Stuff\Java\Tests\My Project
Debug - importFile: string.join: D:\Dev Stuff\Java\Tests\My Project\ant-deploy.xml
Opening D:\Dev Stuff\Java\Tests\My Project\ant-deploy.xml
The file: "D:\Dev Stuff\Java\Tests\My Project\ant-deploy.xml" could not be opened

Thing is, my ant-deploy.xml is inside the nbproject folder, so I actually need the followImports loop to remember the directory of the currently processed xml file. Basically the last import needs to be D:\Dev Stuff\Java\Tests\My Project\nbproject\ant-deploy.xml.

Any advice on how to fix this? Not knowing very much about Python leaves me a bit stuck here..

@aphex
Copy link
Owner

aphex commented Nov 20, 2014

Can you try replacing line 138 with the following and see if this gets you where you want to be?

if importFile.find(“${basedir}”) > -1
    importFile = importFile.replace("${basedir}", self.working_dir);
else
    importFile = os.path.abspath(file.name) + os.sep + importFile;

@ZaLiTHkA
Copy link
Contributor Author

Thanks, that seems to have set me on the right path, but I had to make a few changes before it would work..

Instead of replacing line 138 (in my file that's the initial imp.getAttributeNode(...) line), so I added the following just after it:

    if importFile.find("${basedir}") > -1:
        importFile = importFile.replace("${basedir}", self.working_dir)
    else:
        importFile = os.path.dirname(file) + os.sep + importFile

Checking the start of the function, file is a string, while f is a reference to the open file, so using either file or f.name seems to work here.

Either way though, I'm definitely getting the correct file path for the imports, now I just need to work out why it's not showing my the targets from within my ant-deploy.xml file. Pretty intense crash course in learning Python hey... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants