Skip to content

Commit a512026

Browse files
committed
Issue #37: Add documentation for Ant, add list of bundled signatures and also link from Maven docs.
1 parent 4050425 commit a512026

File tree

5 files changed

+175
-2
lines changed

5 files changed

+175
-2
lines changed

build.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@
280280

281281
<target name="documentation" depends="maven-descriptor,-get-cli-help">
282282
<mkdir dir="${documentation-dir}"/>
283+
<copy todir="${documentation-dir}">
284+
<fileset dir="src/main/docs" excludes="*.xsl" />
285+
</copy>
283286
<xslt basedir="${maven-build-dir}/generated-site/xdoc" includes="*.xml" destdir="${documentation-dir}" style="src/main/docs/xdoc2html.xsl" force="false">
284287
<mapper type="glob" from="*.xml" to="*.html"/>
285288
</xslt>

src/main/docs/ant-task.html

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<html>
2+
<head>
3+
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
4+
<title>Ant Task Documentation</title>
5+
<style type="text/css">
6+
table {
7+
border-collapse: collapse;
8+
}
9+
table, tr, th, td {
10+
border: 1px solid dimgray;
11+
vertical-align: top;
12+
text-align: left;
13+
}
14+
th, td {
15+
padding: .2em;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<h1>Ant Task Documentation</h1>
21+
22+
<h2>Description</h2>
23+
24+
<p>Task to check if a set of class files contains calls to forbidden APIs
25+
from a given classpath and list of API signatures (either inline or as pointer to files).
26+
In contrast to other ANT tasks, this tool does only visit the given classpath
27+
and the system classloader, not ANT's class loader.</p>
28+
29+
<h2>Parameters</h2>
30+
31+
<table>
32+
33+
<tr>
34+
<th>Name</th>
35+
<th>Type</th>
36+
<th>Default</th>
37+
<th>Description</th>
38+
</tr>
39+
40+
<tr>
41+
<td>dir</td>
42+
<td><code>File</code></td>
43+
<td></td>
44+
<td>Directory to scan for class files. This directory is automatically converted to a <code>FileSet</code> with <code>**/*.class</code> as include pattern.</td>
45+
</tr>
46+
47+
<tr>
48+
<td>signaturesfile</td>
49+
<td><code>File</code></td>
50+
<td></td>
51+
<td>A single signatures file.</td>
52+
</tr>
53+
54+
<tr>
55+
<td>bundledsignatures</td>
56+
<td><code>String</code></td>
57+
<td></td>
58+
<td>Name of a <a href="bundled-signatures.html">built-in signatures</a> file.</td>
59+
</tr>
60+
61+
<tr>
62+
<td>classpath</td>
63+
<td><code>Path</code></td>
64+
<td></td>
65+
<td>Classpath in ANT format. Should be identical to classpath used for compiling the class files.</td>
66+
</tr>
67+
68+
<tr>
69+
<td>classpathref</td>
70+
<td><code>Reference</code></td>
71+
<td></td>
72+
<td>Reference to a <code>path</code> defined anywhere else. Should be identical to classpath used for compiling the class files.</td>
73+
</tr>
74+
75+
<tr>
76+
<td>failOnUnsupportedJava</td>
77+
<td><code>boolean</code></td>
78+
<td><code>false</code></td>
79+
<td>Fail the build, if the bundled ASM library cannot read the class file format of the runtime library or the runtime library cannot be discovered.</td>
80+
</tr>
81+
82+
<tr>
83+
<td>failOnMissingClasses</td>
84+
<td><code>boolean</code></td>
85+
<td><code>true</code></td>
86+
<td>Fail the build, if a referenced class is missing. This requires that you pass the whole classpath including all dependencies.
87+
If you don't have all classes in the filesets, the application classes must be reachable through this classpath, too.</td>
88+
</tr>
89+
90+
<tr>
91+
<td>failOnUnresolvableSignatures</td>
92+
<td><code>boolean</code></td>
93+
<td><code>true</code></td>
94+
<td>Fail the build if a signature is not resolving. If this parameter is set to to false, then such signatures are silently ignored.</td>
95+
</tr>
96+
97+
<tr>
98+
<td>internalRuntimeForbidden</td>
99+
<td><code>boolean</code></td>
100+
<td><code>false</code></td>
101+
<td>Forbids calls to classes from the internal java runtime (like <code>sun.misc.Unsafe</code>).</td>
102+
</tr>
103+
104+
<tr>
105+
<td>restrictClassFilename</td>
106+
<td><code>boolean</code></td>
107+
<td><code>true</code></td>
108+
<td>Automatically restrict resource names included to files with a name ending in <code>'.class'</code>. This makes filesets easier, as the <code>includes="**/*.class"</code> is not needed.</td>
109+
</tr>
110+
111+
<tr>
112+
<td>ignoreEmptyFileset</td>
113+
<td><code>boolean</code></td>
114+
<td><code>false</code></td>
115+
<td>Ignore empty fileset/resource collection and print a warning instead.</td>
116+
</tr>
117+
118+
</table>
119+
120+
<h2>Parameters specified as nested elements</h2>
121+
122+
<p>This task supports all resource collections Ant provides (<code>fileset</code>, <code>filelist</code>,
123+
<code>file</code>, <code>tarfileset</code>, <code>zipfileset</code>,...)
124+
and uses all class files from them. It automatically adds an implcit filter to file names ending in <code>'.class'</code>,
125+
so you don't need to add this as include attribute to those collections.</p>
126+
127+
<p>You can also pass one or multiple <code>classpath</code> elements to form a classpath. Ideally use the same configuration like the <code>javac</code> task.</p>
128+
129+
<p>To pass in signatures, you have 3 possibilities:</p>
130+
131+
<ul>
132+
<li>Use <code>bundledSignatures</code> element to pass a <a href="bundled-signatures.html">built-in signatures</a> file, e.g. <code>&lt;bundledsignatures name=&quot;jdk-unsafe-1.7&quot;&gt;</code></li>
133+
<li>Use <code>signaturesFileSet</code>, <code>signaturesFileList</code>, <code>signaturesFile</code> elements to pass in collections of signatures files. Those elements behave like the corresponding standard Ant types.</li>
134+
<li>Place signatures as plain text (use CDATA sections) inside the <code>forbiddenapis</code> element.</li>
135+
</ul>
136+
137+
</body>
138+
</html>

src/main/docs/bundled-signatures.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<html>
2+
<head>
3+
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
4+
<title>Bundled Signatures Documentation</title>
5+
</head>
6+
<body>
7+
<h1>Bundled Signatures Documentation</h1>
8+
9+
<p>The JAR file contains the following signatures and can be used in Maven or Ant using <tt>&lt;bundledSignatures&gt;</tt>.
10+
All signatures are versioned against the specified JDK version: </p>
11+
12+
<ul>
13+
14+
<li><strong><tt>jdk-unsafe-*</tt>:</strong> Signatures
15+
of &quot;unsafe&quot; methods that use default charset, default locale, or default timezone. For server applications it is very
16+
stupid to call those methods, as the results will definitely not what the user wants
17+
(for Java <tt>*</tt> = 1.5, 1.6, 1.7, 1.8; Maven automatically adds the compile Java version).</li>
18+
19+
<li><strong><tt>jdk-deprecated-*</tt>:</strong> This disallows all deprecated
20+
methods from the JDK (for Java <tt>*</tt> = 1.5, 1.6, 1.7, 1.8; Maven automatically adds the compile Java version).</li>
21+
22+
<li><strong><tt>jdk-system-out</tt>:</strong> On server-side applications or libraries used by other programs, printing to
23+
<tt>System.out</tt> or <tt>System.err</tt> is discouraged and should be avoided (any java version, no specific version).</li>
24+
25+
<li><strong><tt>commons-io-unsafe-*</tt>:</strong> If your application uses the famous <i>Apache Common-IO</i> library,
26+
this adds signatures of all methods that depend on default charset
27+
(for versions <tt>*</tt> = 1.0, 1.1, 1.2, 1.3, 1.4, 2.0, 2.1, 2.2, 2.3, 2.4).</li>
28+
29+
</ul>
30+
31+
</body>
32+
</html>

src/main/docs/docindex.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</code>
4848
</p>
4949
<h2>Apache Ant</h2>
50-
<p>Coming soon!</p>
50+
<p><a href="ant-task.html">Task Documentation</a></p>
5151
<h2>Apache Maven: Mojo Goals</h2>
5252
<ul>
5353
<xsl:apply-templates select="mojos/mojo"/>

src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public abstract class AbstractCheckMojo extends AbstractMojo {
5757
private String signatures;
5858

5959
/**
60-
* Specifies built in signatures files (e.g., deprecated APIs for specific Java versions,
60+
* Specifies <a href="bundled-signatures.html">built-in signatures</a> files (e.g., deprecated APIs for specific Java versions,
6161
* unsafe method calls using default locale, default charset,...)
6262
* @since 1.0
6363
*/

0 commit comments

Comments
 (0)