~ubuntu-branches/ubuntu/trusty/bnd/trusty

« back to all changes in this revision

Viewing changes to biz.aQute.bnd/src/aQute/bnd/ant/PrepareTask.java

  • Committer: Package Import Robot
  • Author(s): Damien Raude-Morvan
  • Date: 2011-11-09 22:39:08 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111109223908-n6pohsonp4lc2kc6
Tags: 1.50.0-1
* New upstream release.
* d/control: Add Build-Depends on libbindex-java.
* d/{bootstrap,rules}: Add bindex.jar to classpath.
* d/patches/no_git_during_build.diff: Don't try to use GIT during build.
* d/patches/osgi43_fixes.diff: Some fixes for libosgi-core-java >= 4.3.
* d/patches/no_felix.diff: Drop dependency on felix-framework (to remove
  dependency cycle).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package aQute.bnd.ant;
2
 
 
3
 
/**
4
 
 * The idea of this task is to read all the properties as if bnd has read them.
5
 
 * This makes it easier to use bnd standalone on the same data.
6
 
 */
7
 
 
8
 
import java.io.*;
9
 
import java.util.*;
10
 
 
11
 
import org.apache.tools.ant.*;
12
 
 
13
 
import aQute.bnd.build.*;
14
 
import aQute.bnd.build.Project;
15
 
 
16
 
public class PrepareTask extends BaseTask {
17
 
    File    basedir;
18
 
    boolean print = false;
19
 
    String    top;
20
 
 
21
 
    public void execute() throws BuildException {
22
 
        try {
23
 
            if (basedir == null || !basedir.isDirectory())
24
 
                throw new BuildException("The given base dir does not exist "
25
 
                        + basedir);
26
 
 
27
 
            Project project = Workspace.getProject(basedir);
28
 
            project.setProperty("in.ant", "true");
29
 
            project.setProperty("environment", "ant");
30
 
            
31
 
            // Check if we are in a sub build, in that case
32
 
            // top will be set to the target directory at the
33
 
            // top project.
34
 
            if ( top!=null && top.length()>0 && !top.startsWith("$"))
35
 
                project.setProperty("top", top);
36
 
            
37
 
            project.setExceptions(true);
38
 
            Properties properties = project.getFlattenedProperties();
39
 
            if (report() || report(project))
40
 
                throw new BuildException(
41
 
                        "Errors during Eclipse Path inspection");
42
 
 
43
 
            copyProperties(properties);
44
 
        } catch (Exception e) {
45
 
            e.printStackTrace();
46
 
            throw new BuildException(e);
47
 
        }
48
 
    }
49
 
 
50
 
    private void copyProperties(Properties flattened) {
51
 
        for (Enumeration<?> k = flattened.propertyNames(); k.hasMoreElements();) {
52
 
            String key = (String) k.nextElement();
53
 
            String value = flattened.getProperty(key);
54
 
            if (isPrint())
55
 
                System.out.printf("%-20s = %s\n", key, value);
56
 
 
57
 
            // We override existing values.
58
 
            getProject().setProperty(key, value.trim());
59
 
        }
60
 
    }
61
 
 
62
 
    public boolean isPrint() {
63
 
        return print;
64
 
    }
65
 
 
66
 
    /**
67
 
     * Print out the properties when they are set in sorted order
68
 
     * 
69
 
     * @param print
70
 
     */
71
 
    public void setPrint(boolean print) {
72
 
        this.print = print;
73
 
    }
74
 
 
75
 
    /**
76
 
     * Set the base directory of the project. This property MUST be set.
77
 
     * 
78
 
     * @param basedir
79
 
     */
80
 
    public void setBasedir(File basedir) {
81
 
        this.basedir = basedir;
82
 
    }
83
 
    
84
 
    /**
85
 
     * Set the base directory of the project. This property MUST be set.
86
 
     * 
87
 
     * @param basedir
88
 
     */
89
 
    public void setTop(String top) {
90
 
        this.top = top;
91
 
    }
92
 
}
 
1
package aQute.bnd.ant;
 
2
 
 
3
/**
 
4
 * The idea of this task is to read all the properties as if bnd has read them.
 
5
 * This makes it easier to use bnd standalone on the same data.
 
6
 */
 
7
 
 
8
import java.io.*;
 
9
import java.util.*;
 
10
 
 
11
import org.apache.tools.ant.*;
 
12
 
 
13
import aQute.bnd.build.*;
 
14
import aQute.bnd.build.Project;
 
15
 
 
16
public class PrepareTask extends BaseTask {
 
17
    File    basedir;
 
18
    boolean print = false;
 
19
    String    top;
 
20
 
 
21
    public void execute() throws BuildException {
 
22
        try {
 
23
            if (basedir == null || !basedir.isDirectory())
 
24
                throw new BuildException("The given base dir does not exist "
 
25
                        + basedir);
 
26
 
 
27
            Project project = Workspace.getProject(basedir);
 
28
            project.setProperty("in.ant", "true");
 
29
            project.setProperty("environment", "ant");
 
30
            
 
31
            // Check if we are in a sub build, in that case
 
32
            // top will be set to the target directory at the
 
33
            // top project.
 
34
            if ( top!=null && top.length()>0 && !top.startsWith("$"))
 
35
                project.setProperty("top", top);
 
36
            
 
37
            project.setExceptions(true);
 
38
            Properties properties = project.getFlattenedProperties();
 
39
            if (report() || report(project))
 
40
                throw new BuildException(
 
41
                        "Errors during Eclipse Path inspection");
 
42
 
 
43
            copyProperties(properties);
 
44
        } catch (Exception e) {
 
45
            e.printStackTrace();
 
46
            throw new BuildException(e);
 
47
        }
 
48
    }
 
49
 
 
50
    private void copyProperties(Properties flattened) {
 
51
        for (Enumeration<?> k = flattened.propertyNames(); k.hasMoreElements();) {
 
52
            String key = (String) k.nextElement();
 
53
            String value = flattened.getProperty(key);
 
54
            if (isPrint())
 
55
                System.out.printf("%-20s = %s\n", key, value);
 
56
 
 
57
            // We override existing values.
 
58
            getProject().setProperty(key, value.trim());
 
59
        }
 
60
    }
 
61
 
 
62
    public boolean isPrint() {
 
63
        return print;
 
64
    }
 
65
 
 
66
    /**
 
67
     * Print out the properties when they are set in sorted order
 
68
     * 
 
69
     * @param print
 
70
     */
 
71
    public void setPrint(boolean print) {
 
72
        this.print = print;
 
73
    }
 
74
 
 
75
    /**
 
76
     * Set the base directory of the project. This property MUST be set.
 
77
     * 
 
78
     * @param basedir
 
79
     */
 
80
    public void setBasedir(File basedir) {
 
81
        this.basedir = basedir;
 
82
    }
 
83
    
 
84
    /**
 
85
     * Set the base directory of the project. This property MUST be set.
 
86
     * 
 
87
     * @param basedir
 
88
     */
 
89
    public void setTop(String top) {
 
90
        this.top = top;
 
91
    }
 
92
}