Skip to content

Commit

Permalink
Issue #409: Update dependencies
Browse files Browse the repository at this point in the history
- qdox 1.12.1 -> 2.1.0
- guava 11.0.2 -> 33.2.0
- plexus-archiver -> 3.7.0
- junit -> 4.13.2 (for maven plugin testing harness)
  • Loading branch information
reckart committed Nov 18, 2024
1 parent 4c2843b commit b285c77
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 130 deletions.
11 changes: 5 additions & 6 deletions uimafit-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -81,12 +85,11 @@
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>1.12.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
<version>33.2.0-jre</version>
</dependency>
</dependencies>

Expand All @@ -104,10 +107,6 @@
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<goals>
<goal>clean</goal>
<goal>package</goal>
</goals>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -63,7 +60,6 @@
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtField;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
import javassist.bytecode.AnnotationsAttribute;
Expand All @@ -76,7 +72,12 @@
/**
* Enhance UIMA components with automatically generated uimaFIT annotations.
*/
@Mojo(name = "enhance", defaultPhase = PROCESS_CLASSES, requiresDependencyResolution = TEST, requiresDependencyCollection = TEST)
@Mojo( //
name = "enhance", //
defaultPhase = PROCESS_CLASSES, //
requiresDependencyResolution = TEST, //
requiresDependencyCollection = TEST, //
threadSafe = true)
public class EnhanceMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
Expand Down Expand Up @@ -202,19 +203,19 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

// Get the compiled classes from this project
String[] files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
var files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
new String[] { "class" });
componentLoader = Util.getClassloader(project, getLog(), includeScope);
componentLoader = Util.getClassloader(project, includeScope);

// Set up class pool with all the project dependencies and the project classes themselves
ClassPool classPool = new ClassPool(true);
var classPool = new ClassPool(true);
classPool.appendClassPath(new LoaderClassPath(componentLoader));

// Set up map to keep a report per class.
Multimap<String, String> reportData = LinkedHashMultimap.create();

// Determine where to write the missing meta data report file
File reportFile = new File(project.getBuild().getDirectory(),
var reportFile = new File(project.getBuild().getDirectory(),
"uimafit-missing-meta-data-report.txt");

// Read existing report
Expand All @@ -223,13 +224,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

// Remember the names of all examined components, whether processed or not.
List<String> examinedComponents = new ArrayList<String>();
var examinedComponents = new ArrayList<String>();

int countAlreadyEnhanced = 0;
int countEnhanced = 0;

for (String file : files) {
String clazzName = Util.getClassName(project, file);
for (var file : files) {
var clazzName = Util.getClassName(project, file);

// Check if this is a UIMA component
Class<?> clazz;
Expand Down Expand Up @@ -271,7 +272,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

// Get the source file
String sourceFile = getSourceFile(clazzName);
var sourceFile = getSourceFile(clazzName);

// Try to extract parameter descriptions from JavaDoc in source file
if (sourceFile != null) {
Expand Down Expand Up @@ -319,7 +320,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

if (generateMissingMetaDataReport) {
// Remove any classes from the report that are no longer part of the build
List<String> deletedClasses = new ArrayList<String>(reportData.keySet());
var deletedClasses = new ArrayList<String>(reportData.keySet());
deletedClasses.removeAll(examinedComponents);
reportData.removeAll(deletedClasses);

Expand Down Expand Up @@ -354,8 +355,7 @@ private void markAsEnhanced(CtClass aCtClazz) {
ClassFile classFile = aCtClazz.getClassFile();
ConstPool constPool = classFile.getConstPool();

AnnotationsAttribute annoAttr = (AnnotationsAttribute) classFile
.getAttribute(AnnotationsAttribute.visibleTag);
var annoAttr = (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag);

// Create annotation attribute if it does not exist
if (annoAttr == null) {
Expand All @@ -377,19 +377,18 @@ private void markAsEnhanced(CtClass aCtClazz) {
*/
private void enhanceResourceMetaData(JavaSource aAST, Class<?> aClazz, CtClass aCtClazz,
Multimap<String, String> aReportData) {
ClassFile classFile = aCtClazz.getClassFile();
ConstPool constPool = classFile.getConstPool();
var classFile = aCtClazz.getClassFile();
var constPool = classFile.getConstPool();

AnnotationsAttribute annoAttr = (AnnotationsAttribute) classFile
.getAttribute(AnnotationsAttribute.visibleTag);
var annoAttr = (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag);

// Create annotation attribute if it does not exist
if (annoAttr == null) {
annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
}

// Create annotation if it does not exist
Annotation a = annoAttr.getAnnotation(ResourceMetaData.class.getName());
var a = annoAttr.getAnnotation(ResourceMetaData.class.getName());
if (a == null) {
a = new Annotation(ResourceMetaData.class.getName(), constPool);
// Add a name, otherwise there will be none in the generated descriptor.
Expand All @@ -398,7 +397,7 @@ private void enhanceResourceMetaData(JavaSource aAST, Class<?> aClazz, CtClass a
}

// Update description from JavaDoc
String doc = Util.getComponentDocumentation(aAST, aClazz.getName());
var doc = Util.getComponentDocumentation(aAST, aClazz.getName());
enhanceMemberValue(a, "description", doc, overrideComponentDescription,
ResourceMetaDataFactory.getDefaultDescription(aClazz), constPool, aReportData, aClazz);

Expand Down Expand Up @@ -439,9 +438,9 @@ private void enhanceResourceMetaData(JavaSource aAST, Class<?> aClazz, CtClass a
private void enhanceMemberValue(Annotation aAnnotation, String aName, String aNewValue,
boolean aOverride, String aDefault, ConstPool aConstPool,
Multimap<String, String> aReportData, Class<?> aClazz) {
String value = getStringMemberValue(aAnnotation, aName);
boolean isEmpty = value.length() == 0;
boolean isDefault = value.equals(aDefault);
var value = getStringMemberValue(aAnnotation, aName);
var isEmpty = value.length() == 0;
var isDefault = value.equals(aDefault);

if (isEmpty || isDefault || aOverride) {
if (aNewValue != null) {
Expand Down Expand Up @@ -479,7 +478,7 @@ private void enhanceConfigurationParameter(JavaSource aAST, Class<?> aClazz, CtC
// Fetch configuration parameters from the @ConfigurationParameter annotations in the
// compiled class. We only need the fields in the class itself. Superclasses should be
// enhanced by themselves.
for (Field field : aClazz.getDeclaredFields()) {
for (var field : aClazz.getDeclaredFields()) {
final String pname;
final String type;
final String pdesc;
Expand Down Expand Up @@ -507,24 +506,22 @@ else if (ExternalResourceFactory.isExternalResourceField(field)) {
}

if (pdesc == null) {
String msg = "No description found for " + type + " [" + pname + "]";
var msg = "No description found for " + type + " [" + pname + "]";
getLog().debug(msg);
aReportData.put(aClazz.getName(), msg);
continue;
}

// Update the "description" field of the annotation
try {
CtField ctField = aCtClazz.getField(field.getName());
AnnotationsAttribute annoAttr = (AnnotationsAttribute) ctField.getFieldInfo()
var ctField = aCtClazz.getField(field.getName());
var annoAttr = (AnnotationsAttribute) ctField.getFieldInfo()
.getAttribute(AnnotationsAttribute.visibleTag);

// Locate and update annotation
if (annoAttr != null) {
Annotation[] annotations = annoAttr.getAnnotations();

// Update existing annotation
for (Annotation a : annotations) {
for (Annotation a : annoAttr.getAnnotations()) {
if (a.getTypeName()
.equals(org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName())
|| a.getTypeName()
Expand Down Expand Up @@ -562,11 +559,11 @@ else if (ExternalResourceFactory.isExternalResourceField(field)) {
*/
private Map<String, String> getParameterConstants(Class<?> aClazz, String[] aPrefixes) {
Map<String, String> result = new HashMap<String, String>();
for (Field f : aClazz.getFields()) {
for (var field : aClazz.getFields()) {
boolean hasPrefix = false;
// Check if any of the registered prefixes matches
for (String prefix : aPrefixes) {
if (f.getName().startsWith(prefix)) {
if (field.getName().startsWith(prefix)) {
hasPrefix = true;
break;
}
Expand All @@ -579,10 +576,10 @@ private Map<String, String> getParameterConstants(Class<?> aClazz, String[] aPre

// If one matched, record the field
try {
String parameterName = (String) f.get(null);
result.put(parameterName, f.getName());
var parameterName = (String) field.get(null);
result.put(parameterName, field.getName());
} catch (IllegalAccessException e) {
getLog().warn("Unable to access name constant field [" + f.getName() + "]: "
getLog().warn("Unable to access name constant field [" + field.getName() + "]: "
+ ExceptionUtils.getRootCauseMessage(e), e);
}
}
Expand All @@ -603,12 +600,11 @@ private JavaSource parseSource(String aSourceFile) throws MojoExecutionException
*
* @return The path to the source file or {@code null} if no source file was found.
*/
@SuppressWarnings("unchecked")
private String getSourceFile(String aClassName) {
String sourceName = aClassName.replace('.', '/') + ".java";
var sourceName = aClassName.replace('.', '/') + ".java";

for (String root : (List<String>) project.getCompileSourceRoots()) {
File f = new File(root, sourceName);
for (var root : (List<String>) project.getCompileSourceRoots()) {
var f = new File(root, sourceName);
if (f.exists()) {
return f.getPath();
}
Expand All @@ -621,18 +617,16 @@ private String getSourceFile(String aClassName) {
*/
private void writeMissingMetaDataReport(File aReportFile, Multimap<String, String> aReportData)
throws MojoExecutionException {
String[] classes = aReportData.keySet().toArray(new String[aReportData.keySet().size()]);
var classes = aReportData.keySet().toArray(String[]::new);
Arrays.sort(classes);

PrintWriter out = null;
FileUtils.mkdir(aReportFile.getParent());
try {
out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(aReportFile), encoding));

try (var out = new PrintWriter(
new OutputStreamWriter(new FileOutputStream(aReportFile), encoding))) {
if (classes.length > 0) {
for (String clazz : classes) {
for (var clazz : classes) {
out.printf("%s %s%n", MARK_CLASS, clazz);
Collection<String> messages = aReportData.get(clazz);
var messages = aReportData.get(clazz);
if (messages.isEmpty()) {
out.printf(" No problems");
} else {
Expand All @@ -648,8 +642,6 @@ private void writeMissingMetaDataReport(File aReportFile, Multimap<String, Strin
} catch (IOException e) {
throw new MojoExecutionException("Unable to write missing meta data report to [" + aReportFile
+ "]" + ExceptionUtils.getRootCauseMessage(e), e);
} finally {
IOUtils.closeQuietly(out);
}
}

Expand All @@ -663,12 +655,10 @@ private void readMissingMetaDataReport(File aReportFile, Multimap<String, String
return;
}

LineIterator i = null;
try {
try (var i = IOUtils.lineIterator(new FileInputStream(aReportFile), encoding)) {
String clazz = null;
i = IOUtils.lineIterator(new FileInputStream(aReportFile), encoding);
while (i.hasNext()) {
String line = i.next();
var line = i.next();
// Report say there is no missing meta data
if (line.startsWith(MARK_NO_MISSING_META_DATA)) {
return;
Expand All @@ -690,8 +680,6 @@ private void readMissingMetaDataReport(File aReportFile, Multimap<String, String
throw new MojoExecutionException(
"Unable to read missing meta data report: " + ExceptionUtils.getRootCauseMessage(e),
e);
} finally {
LineIterator.closeQuietly(i);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
/**
* Generate descriptor files for uimaFIT-based UIMA components.
*/
@Mojo(name = "generate", defaultPhase = PROCESS_CLASSES, requiresDependencyResolution = TEST, requiresDependencyCollection = TEST)
@Mojo( //
name = "generate", //
defaultPhase = PROCESS_CLASSES, //
requiresDependencyResolution = TEST, //
requiresDependencyCollection = TEST, //
threadSafe = true)
public class GenerateDescriptorsMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
Expand Down Expand Up @@ -141,7 +146,7 @@ public void execute() throws MojoExecutionException {
String[] files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
new String[] { "class" });

componentLoader = Util.getClassloader(project, getLog(), includeScope);
componentLoader = Util.getClassloader(project, includeScope);

// List of components that is later written to META-INF/org.apache.uima.fit/components.txt
StringBuilder componentsManifest = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

/**
* Maven Mojos for uimaFIT.
*/
Expand Down
Loading

0 comments on commit b285c77

Please sign in to comment.