-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathCheckSezpoz.java
More file actions
192 lines (177 loc) · 6.28 KB
/
CheckSezpoz.java
File metadata and controls
192 lines (177 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* #%L
* SciJava Common shared library for SciJava software.
* %%
* Copyright (C) 2009 - 2016 Board of Regents of the University of
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
* Institute of Molecular Cell Biology and Genetics.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.util;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.scijava.annotations.EclipseHelper;
import org.w3c.dom.Document;
/**
* Deprecated class.
*
* @author Johannes Schindelin
*/
@Deprecated
public final class CheckSezpoz {
@Deprecated
public static boolean verbose;
@Deprecated
public static final String FILE_NAME = "latest-sezpoz-check.txt";
@Deprecated
private CheckSezpoz() {
// NB: Prevent instantiation of utility class.
}
/**
* Checks the annotations of all CLASSPATH components. Optionally, it only
* checks the non-.jar components of the CLASSPATH. This is for Eclipse.
* Eclipse fails to run the annotation processor at each incremental build. In
* contrast to Maven, Eclipse usually does not build .jar files, though, so we
* can have a very quick check at startup if the annotation processor was not
* run correctly and undo the damage.
*
* @param checkJars whether to inspect .jar components of the CLASSPATH
* @return false, when the annotation processor had to be run
* @throws IOException
* @see EclipseHelper
*/
@Deprecated
public static boolean check(final boolean checkJars) throws IOException {
EclipseHelper.main();
return false;
}
/**
* Checks the annotations of a CLASSPATH component.
*
* @param file the CLASSPATH component (.jar file or directory)
* @return false, when the annotation processor had to be run
* @throws IOException
* @see EclipseHelper
*/
@Deprecated
public static boolean check(final File file) throws IOException {
System.err.println("Warning: Deprecated CheckSezpoz class was called!");
EclipseHelper.updateAnnotationIndex(new URLClassLoader(new URL[] { file.toURI().toURL() }));
return false;
}
/**
* Checks the annotations of a directory in the CLASSPATH.
*
* @param classes the CLASSPATH component directory
* @return false, when the annotation processor had to be run
* @throws IOException
* @see EclipseHelper
*/
@Deprecated
public static boolean checkDirectory(final File classes) throws IOException {
return check(classes);
}
/**
* Checks whether the annotations are possibly out-of-date.
* <p>
* This method looks whether there are any <i>.class</i> files older than
* their corresponding <i>.java</i> files, or whether there are <i>.class</i>
* files that were generated since last time we checked.
* </p>
*
* @param classes the <i>classes/</i> directory where Maven puts the
* <i>.class</i> files
* @param source the <i>src/main/java/<i> directory where Maven expects the
* <i>.java</i> files
* @param youngerThan the date/time when we last checked
* @see EclipseHelper
*/
@Deprecated
public static boolean checkDirectory(final File classes, final File source,
final long youngerThan) throws IOException
{
return check(classes);
}
/**
* Checks a <i>.jar</i> file for stale annotations.
* <p>
* This method is broken at the moment since there is no good way to verify
* that SezPoz ran before the <i>.jar</i> file was packaged.
* </p>
*
* @param file the <i>.jar</i> file
* @see EclipseHelper
*/
@Deprecated
public static void checkJar(final File file) throws IOException {
check(file);
}
/**
* Runs SezPoz on the sources, writing the annotations into the classes'
* {@code META-INF/annotations/} directory.
*
* @param classes the output directory
* @param sources the directory containing the source files
* @return whether anything in {@code META-INF/annotations/*} changed
* @see EclipseHelper
*/
@Deprecated
public static boolean fix(final File classes, final File sources) {
try {
return check(classes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* Writes out a DOM as <i>.xml</i> file.
*
* @param xml the DOM
* @param file the file to write
* @throws TransformerException
*/
@Deprecated
public static void writeXMLFile(final Document xml, final File file)
throws TransformerException
{
final Source source = new DOMSource(xml);
final Result result = new StreamResult(file);
final TransformerFactory factory = TransformerFactory.newInstance();
final Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
"4");
transformer.transform(source, result);
}
}