buildframework/helium/sf/java/legacy/src/com/nokia/ant/Database.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     3
 * All rights reserved.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     4
 * This component and the accompanying materials are made available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     6
 * which accompanies this distribution, and is available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     8
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     9
 * Initial Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    10
 * Nokia Corporation - initial contribution.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    11
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    12
 * Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    13
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    14
 * Description: 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    15
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    16
 */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    17
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.ant;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import info.bliki.wiki.model.WikiModel;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import java.io.BufferedReader;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import java.io.File;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import java.io.FileOutputStream;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import java.io.IOException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import java.io.OutputStream;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import java.io.StringReader;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import java.util.ArrayList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import java.util.Enumeration;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import java.util.HashMap;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import java.util.Hashtable;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
import java.util.Iterator;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import java.util.List;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
import java.util.Map;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
import java.util.regex.Matcher;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
import java.util.regex.Pattern;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
import org.apache.tools.ant.BuildException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
import org.apache.tools.ant.Project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
import org.apache.tools.ant.Target;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
import org.apache.tools.ant.Task;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
import org.apache.tools.ant.types.Reference;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
import org.apache.tools.ant.types.ResourceCollection;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
import org.apache.tools.ant.types.resources.FileResource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
import org.dom4j.Attribute;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
import org.dom4j.CDATA;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
import org.dom4j.Comment;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
import org.dom4j.Document;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
import org.dom4j.DocumentException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
import org.dom4j.DocumentHelper;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
import org.dom4j.Element;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
import org.dom4j.Node;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
import org.dom4j.Text;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
import org.dom4j.Visitor;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
import org.dom4j.VisitorSupport;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
import org.dom4j.XPath;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
import org.dom4j.io.OutputFormat;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
import org.dom4j.io.SAXReader;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
import org.dom4j.io.XMLWriter;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
 * Reads the current ant project and a fileset and generates a xml file with a summary of targets,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
 * macros and properties.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
 */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    65
public class Database {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    private Project project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    private ResourceCollection rc;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    private Task task;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    private boolean debug;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
    private boolean homeFilesOnly = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
    private HashMap<String, List<String>> globalSignalList = new HashMap<String, List<String>>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    private HashMap<String, String> map = new HashMap<String, String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    private Document signaldoc;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    74
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    75
    public Database(Project project, ResourceCollection rc, Task task) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        this.project = project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        this.rc = rc;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        this.task = task;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        map.put("hlm", "http://www.nokia.com/helium");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
    public Project getProject() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        return project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    public void setDebug(boolean debug) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        this.debug = debug;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
    public void setHomeFilesOnly(boolean homeFilesOnly) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        this.homeFilesOnly = homeFilesOnly;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
    public void log(String msg, int level) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        if (task != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
            task.log(msg, level);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    97
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    98
        else if (debug) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
            project.log(msg, level);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   103
    public void setRefid(Reference r) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   104
        Object object = r.getReferencedObject();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   105
        if (!(object instanceof ResourceCollection)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
            throw new BuildException(r.getRefId() + " doesn\'t denote a ResourceCollection");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   108
        rc = (ResourceCollection) object;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
    public Document createDOM() throws DocumentException, IOException {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   112
        // log("Building Ant project database", Project.MSG_DEBUG);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
        Element root = DocumentHelper.createElement("antDatabase");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        Document outDoc = DocumentHelper.createDocument(root);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        ArrayList<String> antFiles = getAntFiles(getProject(), homeFilesOnly);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   116
        for (String antFile : antFiles) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   117
            readSignals(antFile);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   119
        for (String antFile : antFiles) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
            parseAntFile(root, antFile);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        buildTaskDefs(root);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        return outDoc;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
    public void createXMLFile(File outputFile) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
            Document outDoc = createDOM();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
            OutputStream outStream = System.out;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
            if (outputFile != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
                outStream = new FileOutputStream(outputFile);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
            XMLWriter out = new XMLWriter(outStream, OutputFormat.createPrettyPrint());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
            out.write(outDoc);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   137
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   138
        catch (DocumentException e) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
            throw new BuildException(e.getMessage());
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   140
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   141
        catch (IOException e) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
            throw new BuildException(e.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   147
    private void readSignals(String antFile) throws DocumentException, IOException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
        SAXReader xmlReader = new SAXReader();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
        Document antDoc = xmlReader.read(new File(antFile));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        XPath xpath = DocumentHelper.createXPath("//hlm:signalListenerConfig");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        xpath.setNamespaceURIs(map);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
        List<Element> signalNodes = xpath.selectNodes(antDoc);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   154
        for (Element propertyNode : signalNodes) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
            signaldoc = antDoc;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
            String signalid = propertyNode.attributeValue("id");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
            String signaltarget = propertyNode.attributeValue("target");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            List<String> existinglist = globalSignalList.get(signaltarget);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
            String failbuild = signalType(signalid, signaldoc);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   161
            if (existinglist == null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
                existinglist = new ArrayList<String>();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   163
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
            existinglist.add(signalid + "," + failbuild);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
            globalSignalList.put(signaltarget, existinglist);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   170
    private String signalType(String signalid, Document antDoc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   171
        XPath xpath2 = DocumentHelper.createXPath("//hlm:signalListenerConfig[@id='" + signalid
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   172
            + "']/signalNotifierInput/signalInput");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
        xpath2.setNamespaceURIs(map);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
        List<Element> signalNodes3 = xpath2.selectNodes(antDoc);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   176
        for (Element propertyNode3 : signalNodes3) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
            String signalinputid = propertyNode3.attributeValue("refid");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   179
            XPath xpath3 = DocumentHelper.createXPath("//hlm:signalInput[@id='" + signalinputid
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   180
                + "']");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
            xpath3.setNamespaceURIs(map);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
            List<Element> signalNodes4 = xpath3.selectNodes(antDoc);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   183
            for (Element propertyNode4 : signalNodes4) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
                return propertyNode4.attributeValue("failbuild");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        return null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
     * @param root
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
     * @param antFile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
     * @throws DocumentException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
     * @throws IOException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   197
    private void parseAntFile(Element root, String antFile) throws DocumentException, IOException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
        log("Processing Ant file: " + antFile, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        SAXReader xmlReader = new SAXReader();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
        Document antDoc = xmlReader.read(new File(antFile));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
        // Element targetElement =
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        // DocumentHelper.createElement("target");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
        Element projectElement = root.addElement("project");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
        Element nameElement = projectElement.addElement("name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
        String projectName = antDoc.valueOf("/project/@name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
        nameElement.setText(projectName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
        // Element descriptionElement =
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        // projectElement.addElement("description");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
        String description = antDoc.valueOf("/project/description");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
        insertDocumentation(projectElement, description);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
        // descriptionElement.setText(description);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   217
        if (!antFile.contains("antlib.xml") && description.equals("")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
            log("Project has no comment: " + projectName, Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        Element defaultElement = projectElement.addElement("default");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
        defaultElement.setText(antDoc.valueOf("/project/@default"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
        // Project import statements
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
        List importNodes = antDoc.selectNodes("//import");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   226
        for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
            Element importCurrentNode = (Element) iterator.next();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   228
            addTextElement(projectElement, "fileDependency", importCurrentNode.attributeValue("file"));
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
        projectElement.addElement("pythonDependency");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        // Project exec statements
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
        List<Element> execNodes = antDoc.selectNodes("//exec//arg");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   235
        for (Element argNode : execNodes) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
            String argValue = argNode.attributeValue("value");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   238
            if (argValue == null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
                argValue = argNode.attributeValue("line");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   240
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   242
            if (argValue != null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
                Pattern filePattern = Pattern.compile(".pl|.py|.bat|.xml|.txt");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
                Matcher fileMatcher = filePattern.matcher(argValue);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   245
                if (fileMatcher.find()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
                    addTextElement(projectElement, "fileDependency", argValue);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
        List<Element> targetNodes = antDoc.selectNodes("//target");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   252
        for (Element targetNode : targetNodes) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
            processTarget(targetNode, projectElement);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
        // Process macrodef and scriptdef tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
        // TODO - maybe scriptdefs should be separate?
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
        List macroNodes = antDoc.selectNodes("//macrodef | //scriptdef");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   259
        for (Iterator iterator = macroNodes.iterator(); iterator.hasNext();) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
            Element macroNode = (Element) iterator.next();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
            processMacro(macroNode, projectElement, antFile);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
        // Project properties
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
        List propertyNodes = antDoc.selectNodes("//property");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   266
        for (Iterator iterator = propertyNodes.iterator(); iterator.hasNext();) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
            Element propertyNode = (Element) iterator.next();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
            processProperty(propertyNode, projectElement);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   272
    public ArrayList<String> getAntFiles() {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
        return getAntFiles(getProject(), true);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   276
    public ArrayList<String> getAntFiles(Project project) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
        return getAntFiles(project, true);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   279
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   280
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   281
     * Get the list of all Ant files we want to process. These can be project and antlib files.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
     * @return antFiles a list of ant files to be processed
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   284
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   286
    public ArrayList<String> getAntFiles(Project project, boolean homeOnly) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
        ArrayList<String> antFiles = new ArrayList<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
        Map<String, Target> targets = project.getTargets();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
        Iterator<Target> targetsIter = targets.values().iterator();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   291
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
        String projectHome = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   294
            projectHome = new File(project.getProperty("helium.dir")).getCanonicalPath();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   295
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   296
            while (targetsIter.hasNext()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
                Target target = targetsIter.next();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   298
                String projectPath = new File(target.getLocation().getFileName()).getCanonicalPath();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   300
                if (!antFiles.contains(projectPath)) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   301
                    if (homeOnly) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   302
                        if (!projectPath.contains(projectHome)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
                            antFiles.add(projectPath);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
                        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   305
                    } else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   306
                        antFiles.add(projectPath);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   307
                    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   310
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   311
            if (rc != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   312
                Iterator extraFilesIter = rc.iterator();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   313
                while (extraFilesIter.hasNext()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   314
                    FileResource fileResource = (FileResource) extraFilesIter.next();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   315
                    String extrafile = fileResource.getFile().getCanonicalPath();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   316
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   317
                    if (!antFiles.contains(fileResource.toString())
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   318
                        && !fileResource.getFile().getName().startsWith("test_")) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   319
                        if (homeOnly) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   320
                            if (!extrafile.contains(projectHome)) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   321
                                antFiles.add(extrafile);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   322
                            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   323
                        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   324
                        else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   325
                            antFiles.add(extrafile);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   326
                        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   327
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   328
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   329
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   330
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   331
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   332
        catch (IOException e) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   333
            log(e.getMessage(), Project.MSG_ERR);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   334
            e.printStackTrace();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   335
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   336
        return antFiles;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   337
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   338
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   339
    // --------------------------------- PRIVATE METHODS ------------------------------------------
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   340
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   341
    @SuppressWarnings("unchecked")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   342
    private void processMacro(Element macroNode, Element outProjectNode, String antFile)
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   343
        throws IOException, DocumentException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   344
        String macroName = macroNode.attributeValue("name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   345
        log("Processing macro: " + macroName, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   346
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   347
        Element outmacroNode = outProjectNode.addElement("macro");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   348
        addTextElement(outmacroNode, "name", macroNode.attributeValue("name"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   349
        addTextElement(outmacroNode, "description", macroNode.attributeValue("description"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   350
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   351
        // Add location
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   352
        // Project project = getProject();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   353
        // Macro antmacro = (Macro) project.getTargets().get(macroName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   354
        // System.out.println(project.getMacroDefinitions());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   355
        // System.out.println(macroName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   356
        // MacroInstance antmacro = (MacroInstance)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   357
        // project.getMacroDefinitions().get("http://www.nokia.com/helium:" +
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   358
        // macroName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   359
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   360
        // Add the location with just the file path for now and a dummy line
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   361
        // number.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   362
        // TODO - Later we should find the line number from the XML input.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   363
        addTextElement(outmacroNode, "location", antFile + ":1:");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   364
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   365
        List<Node> statements = macroNode.selectNodes("//scriptdef[@name='" + macroName
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   366
            + "']/attribute | //macrodef[@name='" + macroName + "']/attribute");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   367
        String usage = "";
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   368
        for (Node statement : statements) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   369
            String defaultval = statement.valueOf("@default");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   370
            if (defaultval.equals("")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   371
                defaultval = "value";
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   372
            } else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   373
                defaultval = "<i>" + defaultval + "</i>";
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   374
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   375
            usage = usage + " " + statement.valueOf("@name") + "=\"" + defaultval + "\"";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   376
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   377
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   378
        String macroElements = "";
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   379
        statements = macroNode.selectNodes("//scriptdef[@name='" + macroName
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   380
            + "']/element | //macrodef[@name='" + macroName + "']/element");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   381
        for (Node statement : statements) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   382
            macroElements = "&lt;" + statement.valueOf("@name") + "/&gt;\n" + macroElements;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   383
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   384
        if (macroElements.equals("")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   385
            addTextElement(outmacroNode, "usage", "&lt;hlm:" + macroName + " " + usage + "/&gt;");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   386
        } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   387
            addTextElement(outmacroNode, "usage", "&lt;hlm:" + macroName + " " + usage + "&gt;\n"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   388
                + macroElements + "&lt;/hlm:" + macroName + "&gt;");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   389
        }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   390
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   391
        // Add dependencies
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   392
        // Enumeration dependencies = antmacro.getDependencies();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   393
        // while (dependencies.hasMoreElements())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   394
        // {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   395
        // String dependency = (String) dependencies.nextElement();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   396
        // Element dependencyElement = addTextElement(outmacroNode,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   397
        // "dependency", dependency);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   398
        // dependencyElement.addAttribute("type","direct");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   399
        // }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   400
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   401
        callAntTargetVisitor(macroNode, outmacroNode);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   402
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   403
        // Add documentation
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   404
        // Get comment element before the macro element to extract macro doc
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   405
        List<Node> children = macroNode.selectNodes("preceding-sibling::node()");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   406
        if (children.size() > 0) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   407
            // Scan past the text nodes, which are most likely whitespace
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   408
            int index = children.size() - 1;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   409
            Node child = (Node) children.get(index);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   410
            while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   411
                index--;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   412
                child = (Node) children.get(index);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   413
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   414
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   415
            // Check if there is a comment node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   416
            String commentText = null;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   417
            if (child.getNodeType() == Node.COMMENT_NODE) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   418
                Comment macroComment = (Comment) child;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   419
                commentText = macroComment.getStringValue().trim();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   420
                log(macroName + " comment: " + commentText, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   421
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   422
            else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   423
                log("Macro has no comment: " + macroName, Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   424
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   425
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   426
            insertDocumentation(outmacroNode, commentText);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   427
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   428
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   429
        // Get names of all properties used in this macro
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   430
        ArrayList properties = new ArrayList();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   431
        Visitor visitor = new AntPropertyVisitor(properties);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   432
        macroNode.accept(visitor);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   433
        for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   434
            String property = (String) iterator.next();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   435
            addTextElement(outmacroNode, "propertyDependency", property);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   436
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   437
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   438
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   439
    private void callAntTargetVisitor(Element targetNode, Element outTargetNode) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   440
        // Add antcall/runtarget dependencies
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   441
        ArrayList<String> antcallTargets = new ArrayList<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   442
        ArrayList<String> logs = new ArrayList<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   443
        ArrayList<String> signals = new ArrayList<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   444
        ArrayList<String> executables = new ArrayList<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   445
        Visitor visitorTarget = new AntTargetVisitor(antcallTargets, logs, signals, executables);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   446
        targetNode.accept(visitorTarget);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   447
        for (String antcallTarget : antcallTargets) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   448
            Element dependencyElement = addTextElement(outTargetNode, "dependency", antcallTarget);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   449
            dependencyElement.addAttribute("type", "exec");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   450
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   451
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   452
        for (String log : logs) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   453
            addTextElement(outTargetNode, "log", log);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   454
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   455
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   456
        if (globalSignalList.get(targetNode.attributeValue("name")) != null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   457
            signals.addAll(globalSignalList.get(targetNode.attributeValue("name")));
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   458
        }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   459
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   460
        for (String signal : signals) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   461
            addTextElement(outTargetNode, "signal", signal);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   462
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   463
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   464
        for (String executable : executables) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   465
            addTextElement(outTargetNode, "executable", executable);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   466
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   467
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   468
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   469
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   470
    private void processTarget(Element targetNode, Element outProjectNode) throws IOException,
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   471
        DocumentException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   472
        String targetName = targetNode.attributeValue("name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   473
        log("Processing target: " + targetName, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   474
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   475
        // Add documentation
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   476
        // Get comment element before the target element to extract target doc
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   477
        String commentText = "";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   478
        List<Node> children = targetNode.selectNodes("preceding-sibling::node()");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   479
        if (children.size() > 0) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   480
            // Scan past the text nodes, which are most likely whitespace
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   481
            int index = children.size() - 1;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   482
            Node child = children.get(index);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   483
            while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   484
                index--;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   485
                child = (Node) children.get(index);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   486
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   487
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   488
            // Check if there is a comment node
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   489
            if (child.getNodeType() == Node.COMMENT_NODE) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   490
                Comment targetComment = (Comment) child;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   491
                commentText = targetComment.getStringValue().trim();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   492
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   493
                log(targetName + " comment: " + commentText, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   494
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   495
            else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   496
                log("Target has no comment: " + targetName, Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   497
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   498
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   499
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   500
        if (!commentText.contains("Private:")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   501
            Element outTargetNode = outProjectNode.addElement("target");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   502
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   503
            addTextElement(outTargetNode, "name", targetNode.attributeValue("name"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   504
            addTextElement(outTargetNode, "ifDependency", targetNode.attributeValue("if"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   505
            addTextElement(outTargetNode, "unlessDependency", targetNode.attributeValue("unless"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   506
            addTextElement(outTargetNode, "description", targetNode.attributeValue("description"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   507
            addTextElement(outTargetNode, "tasks", String.valueOf(targetNode.elements().size()));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   508
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   509
            // Add location
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   510
            Project project = getProject();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   511
            Target antTarget = (Target) project.getTargets().get(targetName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   512
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   513
            if (antTarget == null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   514
                return;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   515
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   516
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   517
            addTextElement(outTargetNode, "location", antTarget.getLocation().toString());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   518
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   519
            // Add dependencies
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   520
            Enumeration dependencies = antTarget.getDependencies();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   521
            while (dependencies.hasMoreElements()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   522
                String dependency = (String) dependencies.nextElement();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   523
                Element dependencyElement = addTextElement(outTargetNode, "dependency", dependency);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   524
                dependencyElement.addAttribute("type", "direct");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   525
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   526
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   527
            callAntTargetVisitor(targetNode, outTargetNode);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   528
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   529
            // Process the comment text as MediaWiki syntax and convert to HTML
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   530
            insertDocumentation(outTargetNode, commentText);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   531
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   532
            // Get names of all properties used in this target
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   533
            ArrayList properties = new ArrayList();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   534
            Visitor visitor = new AntPropertyVisitor(properties);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   535
            targetNode.accept(visitor);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   536
            for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   537
                String property = (String) iterator.next();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   538
                addTextElement(outTargetNode, "propertyDependency", property);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   539
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   540
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   541
            // Add the raw XML content of the element
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   542
            String targetXml = targetNode.asXML();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   543
            // Replace the CDATA end notation to avoid nested CDATA sections
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   544
            targetXml = targetXml.replace("]]>", "] ]>");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   545
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   546
            addTextElement(outTargetNode, "source", targetXml, true);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   547
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   548
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   549
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   550
    private void processProperty(Element propertyNode, Element outProjectNode) throws IOException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   551
        String propertyName = propertyNode.attributeValue("name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   552
        log("Processing Property: " + propertyName, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   553
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   554
        Element outPropertyNode = outProjectNode.addElement("property");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   555
        addTextElement(outPropertyNode, "name", propertyNode.attributeValue("name"));
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   556
        if (propertyNode.attributeValue("value") == null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   557
            addTextElement(outPropertyNode, "defaultValue", propertyNode.attributeValue("location"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   558
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   559
        else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   560
            addTextElement(outPropertyNode, "defaultValue", propertyNode.attributeValue("value"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   561
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   562
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   563
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   564
    private void insertDocumentation(Element outNode, String commentText) throws IOException,
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   565
        DocumentException {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   566
        if (commentText != null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   567
            WikiModel wikiModel = new WikiModel("", "");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   568
            if (!commentText.contains("</pre>")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   569
                && (commentText.contains("**") || commentText.contains("==") || commentText.contains("- -"))) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   570
                commentText = commentText.replace("**", "").replace("==", "").replace("- -", "").trim();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   571
                log("Warning: Comment code has invalid syntax: " + commentText, Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   572
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   573
            if (commentText.startsWith("-")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   574
                commentText = commentText.replace("-", "");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   575
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   576
            commentText = commentText.trim();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   577
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   578
            String commentTextCheck = commentText.replace("deprecated>", "").replace("tt>", "").replace("todo>", "");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   579
            if (commentTextCheck.contains(">") && !commentTextCheck.contains("</pre>")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   580
                log("Warning: Comment code needs <pre> tags around it: " + commentText, Project.MSG_WARN);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   581
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   582
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   583
            commentText = filterTextNewlines(commentText);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   584
            commentText = wikiModel.render(commentText);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   585
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   586
            // If <deprecated> tag exists in the comment, then parse the
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   587
            // deprecated message.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   588
            if (commentText.indexOf("&#60;deprecated&#62;") != -1) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   589
                int deprecatedMsgStart = commentText.indexOf("&#60;deprecated&#62;") + 20;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   590
                int deprecatedMsgEnd = commentText.indexOf("&#60;/deprecated&#62;");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   591
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   592
                // Add deprecated element.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   593
                String deprecatedMsg = commentText.substring(deprecatedMsgStart, deprecatedMsgEnd);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   594
                addTextElement(outNode, "deprecated", deprecatedMsg);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   595
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   596
                // remove <deprecated> part from description field.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   597
                int commentTextLength = commentText.length();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   598
                String documentationMsgStart = commentText.substring(1, deprecatedMsgStart - 20);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   599
                String documentationMsgEnd = commentText.substring(deprecatedMsgEnd + 21, commentTextLength);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   600
                String documentationMsg = documentationMsgStart.concat(documentationMsgEnd);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   601
                commentText = documentationMsg.trim();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   602
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   603
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   604
        else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   605
            commentText = "";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   606
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   607
        // Get the documentation element as a document
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   608
        String documentationText = "<documentation>" + commentText + "</documentation>";
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   609
        Document docDoc = DocumentHelper.parseText(documentationText);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   610
        outNode.add(docDoc.getRootElement());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   611
        log("HTML comment: " + commentText, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   612
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   613
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   614
    private Element addTextElement(Element parent, String name, String text) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   615
        Element element = addTextElement(parent, name, text, false);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   616
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   617
        return element;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   618
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   619
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   620
    private Element addTextElement(Element parent, String name, String text, boolean escape) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   621
        Element element = parent.addElement(name);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   622
        if (text != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   623
            if (escape) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   624
                element.addCDATA(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   625
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   626
            else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   627
                element.setText(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   628
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   629
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   630
        return element;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   631
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   632
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   633
    private String filterTextNewlines(String text) throws IOException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   634
        BufferedReader in = new BufferedReader(new StringReader(text));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   635
        StringBuilder out = new StringBuilder();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   636
        String line = in.readLine();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   637
        while (line != null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   638
            out.append(line.trim());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   639
            out.append("\n");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   640
            line = in.readLine();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   641
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   642
        return out.toString();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   643
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   644
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   645
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   646
     * Method adds taskdef nodes to the specified project.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   647
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   648
     * @param outProjectNode
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   649
     * @throws IOException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   650
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   651
    private void buildTaskDefs(Element root) throws DocumentException, IOException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   652
        Element projectElement = root.addElement("project");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   653
        projectElement.addElement("name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   654
        insertDocumentation(projectElement, "");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   655
        HashMap<String, String> tasks = getHeliumAntTasks();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   656
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   657
        for (String taskName : tasks.keySet()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   658
            String className = tasks.get(taskName);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   659
            log("Processing TaskDef: " + taskName, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   660
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   661
            Element outTaskDefNode = projectElement.addElement("taskdef");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   662
            addTextElement(outTaskDefNode, "name", taskName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   663
            addTextElement(outTaskDefNode, "classname", className);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   664
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   665
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   666
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   667
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   668
     * Method returns all the helium ant tasks in the project.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   669
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   670
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   671
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   672
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   673
    private HashMap<String, String> getHeliumAntTasks() {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   674
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   675
        // 1. Get all the task definitions from the project
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   676
        Hashtable<String, Class<?>> allTaskdefs = getProject().getTaskDefinitions();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   677
        // 2. Filter the list by applying criteria
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   678
        return filterTasks(allTaskdefs);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   679
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   680
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   681
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   682
     * Method is used to filter tasks.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   683
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   684
     * @param allTaskdefs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   685
     * @param criteria
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   686
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   687
    private HashMap<String, String> filterTasks(Hashtable<String, Class<?>> allTaskdefs) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   688
        HashMap<String, String> tasks = new HashMap<String, String>();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   689
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   690
        Enumeration<String> taskdefsenum = allTaskdefs.keys();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   691
        while (taskdefsenum.hasMoreElements()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   692
            String key = taskdefsenum.nextElement();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   693
            Class<?> clazz = allTaskdefs.get(key);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   694
            String className = clazz.getName();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   695
            if (key.contains("nokia.com") && className.startsWith("com.nokia")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   696
                && className.contains("ant.taskdefs")) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   697
                tasks.put(getTaskName(key), clazz.getName());
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   698
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   699
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   700
        return tasks;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   701
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   702
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   703
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   704
     * Returns the task name delimiting the helium namespace.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   705
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   706
     * @param text
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   707
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   708
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   709
    private String getTaskName(String text) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   710
        int lastIndex = text.lastIndexOf(':');
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   711
        return text.substring(lastIndex + 1);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   712
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   713
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   714
    // ----------------------------------- PRIVATE CLASSES -----------------------------------------
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   715
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   716
    private class AntPropertyVisitor extends VisitorSupport {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   717
        private List<String> propertyList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   718
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   719
        public AntPropertyVisitor(List<String> propertyList) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   720
            this.propertyList = propertyList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   721
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   722
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   723
        public void visit(Attribute node) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   724
            String text = node.getStringValue();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   725
            extractUsedProperties(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   726
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   727
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   728
        public void visit(CDATA node) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   729
            String text = node.getText();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   730
            extractUsedProperties(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   731
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   732
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   733
        public void visit(Text node) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   734
            String text = node.getText();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   735
            extractUsedProperties(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   736
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   737
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   738
        public void visit(Element node) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   739
            if (node.getName().equals("property")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   740
                String propertyName = node.attributeValue("name");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   741
                if (!propertyList.contains(propertyName)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   742
                    propertyList.add(propertyName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   743
                    log("property matches :" + propertyName, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   744
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   745
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   746
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   747
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   748
        private void extractUsedProperties(String text) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   749
            Pattern p1 = Pattern.compile("\\$\\{([^@$}]*)\\}");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   750
            Matcher m1 = p1.matcher(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   751
            log(text, Project.MSG_DEBUG);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   752
            while (m1.find()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   753
                String group = m1.group(1);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   754
                if (!propertyList.contains(group)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   755
                    propertyList.add(group);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   756
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   757
                log("property matches: " + group, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   758
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   759
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   760
            Pattern p2 = Pattern.compile("\\$\\{([^\n]*\\})\\}");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   761
            Matcher m2 = p2.matcher(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   762
            log(text, Project.MSG_DEBUG);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   763
            while (m2.find()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   764
                String group = m2.group(1);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   765
                if (!propertyList.contains(group)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   766
                    propertyList.add(group);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   767
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   768
                log("property matches: " + group, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   769
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   770
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   771
            Pattern p3 = Pattern.compile("\\$\\{(\\@\\{[^\n]*)\\}");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   772
            Matcher m3 = p3.matcher(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   773
            log(text, Project.MSG_DEBUG);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   774
            while (m3.find()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   775
                String group = m3.group(1);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   776
                if (!propertyList.contains(group)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   777
                    propertyList.add(group);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   778
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   779
                log("property matches: " + group, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   780
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   781
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   782
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   783
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   784
    private class AntTargetVisitor extends VisitorSupport {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   785
        private List<String> targetList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   786
        private List<String> logList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   787
        private List<String> signalList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   788
        private List<String> executableList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   789
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   790
        public AntTargetVisitor(List<String> targetList, List<String> logList,
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   791
            List<String> signalList, List<String> executableList) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   792
            this.targetList = targetList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   793
            this.logList = logList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   794
            this.signalList = signalList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   795
            this.executableList = executableList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   796
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   797
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   798
        public void visit(Element node) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   799
            String name = node.getName();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   800
            if (name.equals("antcall") || name.equals("runtarget")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   801
                String text = node.attributeValue("target");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   802
                extractTarget(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   803
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   804
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   805
            if (!name.equals("include") && !name.equals("exclude")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   806
                String text = node.attributeValue("name");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   807
                addLog(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   808
                text = node.attributeValue("output");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   809
                addLog(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   810
                text = node.attributeValue("value");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   811
                addLog(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   812
                text = node.attributeValue("log");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   813
                addLog(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   814
                text = node.attributeValue("line");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   815
                addLog(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   816
                text = node.attributeValue("file");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   817
                addLog(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   818
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   819
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   820
            if (name.equals("signal") || name.equals("execSignal")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   821
                String signalid = getProject().replaceProperties(node.attributeValue("name"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   822
                String failbuild = signalType(signalid, signaldoc);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   823
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   824
                if (signalList != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   825
                    if (failbuild != null) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   826
                        signalList.add(signalid + "," + failbuild);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   827
                    } else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   828
                        signalList.add(signalid);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   829
                    }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   830
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   831
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   832
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   833
            if (name.equals("exec") || name.equals("preset.exec")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   834
                String text = node.attributeValue("executable");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   835
                executableList.add(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   836
                log("Executable: " + text, Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   837
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   838
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   839
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   840
        private void addLog(String text) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   841
            if (text != null && logList != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   842
                for (String log : text.split(" ")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   843
                    String fulllogname = getProject().replaceProperties(log);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   844
                    if (!logList.contains(log)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   845
                        && (fulllogname.endsWith(".log") || fulllogname.endsWith(".html"))) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   846
                        log = log.replace("--log=", "");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   847
                        logList.add(log);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   848
                    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   849
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   850
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   851
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   852
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   853
        private void extractTarget(String text) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   854
            String iText = getProject().replaceProperties(text);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   855
            targetList.add(iText);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   856
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   857
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   858
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   859
}