• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ant;
18 
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.taskdefs.ExecTask;
21 import org.apache.tools.ant.types.Path;
22 
23 /**
24  * Custom task to execute lint
25  */
26 public class LintExecTask extends ExecTask {
27 
28     private String mExecutable;
29     private String mHtml;
30     private String mXml;
31     private Path mSourcePath;
32     private Path mClassPath;
33 
34     /**
35      * Sets the value of the "executable" attribute.
36      * @param executable the value.
37      */
setExecutable(Path executable)38     public void setExecutable(Path executable) {
39         mExecutable = TaskHelper.checkSinglePath("executable", executable);
40     }
41 
42     /** Sets the path where Java source code should be found */
setSrc(Path path)43     public void setSrc(Path path) {
44         mSourcePath = path;
45     }
46 
47     /** Sets the path where class files should be found */
setClasspath(Path path)48     public void setClasspath(Path path) {
49         mClassPath = path;
50     }
51 
52     /**
53      * Sets the value of the "html" attribute: a path to a file or directory name
54      * where the HTML report should be written.
55      *
56      * @param html path to the html report
57      */
setHtml(Path html)58     public void setHtml(Path html) {
59         mHtml = TaskHelper.checkSinglePath("html", html);
60     }
61 
62     /**
63      * Sets the value of the "xml" attribute: a path to a file or directory name
64      * where the XML report should be written.
65      *
66      * @param xml path to the xml report
67      */
setXml(Path xml)68     public void setXml(Path xml) {
69         mXml = TaskHelper.checkSinglePath("xml", xml);
70     }
71 
72     @Override
execute()73     public void execute() throws BuildException {
74 
75         ExecTask task = new ExecTask();
76         task.setProject(getProject());
77         task.setOwningTarget(getOwningTarget());
78         task.setExecutable(mExecutable);
79         task.setTaskName("lint");
80         task.setFailonerror(true);
81 
82         task.createArg().setValue("--text");
83         task.createArg().setValue("stdout");
84 
85         if (mHtml != null) {
86             task.createArg().setValue("--html");
87             task.createArg().setValue(mHtml);
88         }
89 
90         if (mXml != null) {
91             task.createArg().setValue("--xml");
92             task.createArg().setValue(mXml);
93         }
94 
95         if (mSourcePath != null) {
96             task.createArg().setValue("--sources");
97             task.createArg().setValue(mSourcePath.toString());
98         }
99 
100         if (mClassPath != null) {
101             task.createArg().setValue("--classpath");
102             task.createArg().setValue(mClassPath.toString());
103         }
104 
105         task.createArg().setValue(getProject().getBaseDir().getAbsolutePath());
106         task.execute();
107     }
108 }
109