Skip to content

7.1.x - Simplify star imports check#15361

Merged
codeconsole merged 3 commits intoapache:7.1.xfrom
codeconsole:7.1.x-startImports-check
Feb 1, 2026
Merged

7.1.x - Simplify star imports check#15361
codeconsole merged 3 commits intoapache:7.1.xfrom
codeconsole:7.1.x-startImports-check

Conversation

@codeconsole
Copy link
Copy Markdown
Contributor

@codeconsole codeconsole commented Jan 29, 2026

Rather than searching the dependency hierarchy, just check to see if the class is in the classpath.

enabled by:

grails {
    importGrailsCommonAnnotations = true
}

Copy link
Copy Markdown
Contributor

@sbglasius sbglasius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When tests pass, then this PR is approved.

Comment on lines 273 to 296
protected boolean isClassOnClasspath(FileCollection classpath, String className) {
String classPath = className.replace('.', '/') + '.class'
for (File file : classpath.files) {
try {
if (file.isFile() && file.name.endsWith('.jar')) {
def zip = new java.util.zip.ZipFile(file)
try {
if (zip.getEntry(classPath) != null) {
return true
}
} finally {
zip.close()
}
} else if (file.isDirectory()) {
if (new File(file, classPath).exists()) {
return true
}
}
} catch (Exception ignored) {
}
} catch (Exception e) {
project.logger.debug("Failed to check for dependency ${group}:${name} in ${configurationName}: ${e.message}")
return false
}
return false
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected boolean isClassOnClasspath(FileCollection classpath, String className) {
String classPath = className.replace('.', '/') + '.class'
for (File file : classpath.files) {
try {
if (file.isFile() && file.name.endsWith('.jar')) {
def zip = new java.util.zip.ZipFile(file)
try {
if (zip.getEntry(classPath) != null) {
return true
}
} finally {
zip.close()
}
} else if (file.isDirectory()) {
if (new File(file, classPath).exists()) {
return true
}
}
} catch (Exception ignored) {
}
} catch (Exception e) {
project.logger.debug("Failed to check for dependency ${group}:${name} in ${configurationName}: ${e.message}")
return false
}
return false
}
private static boolean isClassOnClasspath(FileCollection classpath, String className) {
def classEntry = className.replace('.', '/') + '.class'
classpath.files.any { f ->
try {
if (f.file && f.name.endsWith('.jar')) {
new ZipFile(f).withCloseable { zip ->
zip.getEntry(classEntry) != null
}
} else if (f.directory) {
new File(f, classEntry).exists()
} else {
false
}
} catch (Exception ignored) {
false
}
}
}

@codeconsole codeconsole merged commit babbedc into apache:7.1.x Feb 1, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants