-
Notifications
You must be signed in to change notification settings - Fork 181
[MCOMPILER-538] Do not add target/generated-sources/annotations to the source roots #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MCOMPILER-538] Do not add target/generated-sources/annotations to the source roots #191
Conversation
1fb1448 to
a47f454
Compare
elharo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a test.
I need to think about the bug but I'm not 100% sure the issue is correct. This might be working as it should.
|
I have been checking the javac options, and testing with this change, it does seem that we don't need to specify the generated-sources/annotations in the -sourcepath argument, it should be more than enough to specify it on the -s option. |
slawekjaranowski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not confirm that fix resolve issue, IT will be appreciated
|
All my projects that test upgrades to 3.12.0 fail because of this line, looking forward to when it's removed! |
@Nthalk We need more details. There is a version 3.12.1 under vote, will be available in a few day. |
I'm using renovate for auto dependency upgrades on multiple projects, the simplest doesn't use any annotation processing and yields this error on The configuration I have is pretty simple, no funny business: Here is the output of |
|
@Nthalk version 3.12.1 is going to be released in a couple of days fixing that issue. |
a47f454 to
5910df7
Compare
|
I have rebased the PR and added a test case. I am not really happy with the hardcoded paths in |
5910df7 to
9b86939
Compare
9b86939 to
24847e5
Compare
|
Not sure why the CI failed before and the logs are gone now. I have rebased the PR and @elharo @slawekjaranowski There also is a test case now, as requested. |
elharo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to run mvn spotless:apply
|
@elharo I did that and there are no changes:
|
24847e5 to
5ff1b35
Compare
|
Nevermind, I was using Java 17 multiline string literals in the test-case. The CI should run now. |
|
Is the build working or is the CI borked again: Error: Failed to execute goal com.kohlschutter.mavenplugins:copy-rename-maven-plugin:2.0.0:copy (set-source) on project code: The plugin com.kohlschutter.mavenplugins:copy-rename-maven-plugin:2.0.0 requires Maven version 3.8.8 -> [Help 1] |
5ff1b35 to
d434ced
Compare
|
The current error is most likely because of the I have added |
|
looks like the CI is green now. |
slawekjaranowski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we try to add the same test to master branch?
Probably. It is desirable that the master contains most of the tests of the 3.x branch. |
0b8b00b
into
apache:maven-compiler-plugin-3.x
|
The PR description says
But this is not the case, the entire code related to source paths was removed. This means that downstream plugins no longer see the generated sources. For example, the source-jar will no longer contain the generated sources. I'm pretty sure that's not what you wanted and will upset anyone who relies on https://issues.apache.org/jira/browse/MCOMPILER-157. Wasn't the idea to only remove this line? That should have been enough to fix MCOMPILER-538 without any side effects. |
Looks like missing tests for MCOMPILER-157 ... |
|
Actually, I think there is a test - SourcePathReadGoal - but that was changed as part of this PR too. |
|
Ah, it has been so long that I completely forgot about that part in the description. Sadly, removing the generated source path from the project is required. The new testcase fails if the relevant code sections are reverted: diff --git a/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java b/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
index d3691fa..46b7d2b 100644
--- a/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
+++ b/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
@@ -47,17 +47,12 @@ public class SourcePathReadGoal extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
if (sourceClass != null) {
getLog().info("Checking compile source roots for: '" + sourceClass + "'");
- List<String> roots = project.getCompileSourceRoots();
- roots.add(project.getModel().getBuild().getOutputDirectory() + "/../generated-sources/annotations");
- assertGeneratedSourceFileFor(sourceClass, roots);
+ assertGeneratedSourceFileFor(sourceClass, project.getCompileSourceRoots());
}
if (testSourceClass != null) {
getLog().info("Checking test-compile source roots for: '" + testSourceClass + "'");
- List<String> roots = project.getTestCompileSourceRoots();
- roots.add(
- project.getModel().getBuild().getOutputDirectory() + "/../generated-test-sources/test-annotations");
- assertGeneratedSourceFileFor(testSourceClass, roots);
+ assertGeneratedSourceFileFor(testSourceClass, project.getTestCompileSourceRoots());
}
}
diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index 5631892..8a94573 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -824,6 +824,26 @@ public abstract class AbstractCompilerMojo extends AbstractMojo {
}
}
+ String generatedSourcesPath = generatedSourcesDirectory.getAbsolutePath();
+
+ if (isTestCompile()) {
+ getLog().debug("Adding " + generatedSourcesPath + " to test-compile source roots:\n "
+ + StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
+
+ project.addTestCompileSourceRoot(generatedSourcesPath);
+
+ getLog().debug("New test-compile source roots:\n "
+ + StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
+ } else {
+ getLog().debug("Adding " + generatedSourcesPath + " to compile source roots:\n "
+ + StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
+
+ project.addCompileSourceRoot(generatedSourcesPath);
+
+ getLog().debug("New compile source roots:\n "
+ + StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
+ }
+
compilerConfiguration.setSourceLocations(compileSourceRoots);
compilerConfiguration.setAnnotationProcessors(annotationProcessors); |
|
I did manage to add the path back in #311, but it feels hacky... |
|
You can do it without these hacks by moving the generated sources code after the stale source scanning code. The important part is that it needs to happen before the mojo returns, but after it has scanned its own sources. diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index 5631892..27ea1f3 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -814,16 +814,6 @@ public abstract class AbstractCompilerMojo extends AbstractMojo {
compilerConfiguration.setProc(proc);
- File generatedSourcesDirectory = getGeneratedSourcesDirectory();
- compilerConfiguration.setGeneratedSourcesDirectory(
- generatedSourcesDirectory != null ? generatedSourcesDirectory.getAbsoluteFile() : null);
-
- if (generatedSourcesDirectory != null) {
- if (!generatedSourcesDirectory.exists()) {
- generatedSourcesDirectory.mkdirs();
- }
- }
-
compilerConfiguration.setSourceLocations(compileSourceRoots);
compilerConfiguration.setAnnotationProcessors(annotationProcessors);
@@ -933,9 +923,6 @@ public abstract class AbstractCompilerMojo extends AbstractMojo {
getLog().info("Recompiling the module because of "
+ MessageUtils.buffer().strong(cause) + ".");
compilerConfiguration.setSourceFiles(sources);
- } else {
- getLog().info("Nothing to compile - all classes are up to date.");
- return;
}
} catch (CompilerException e) {
throw new MojoExecutionException("Error while computing stale sources.", e);
@@ -964,11 +951,6 @@ public abstract class AbstractCompilerMojo extends AbstractMojo {
throw new MojoExecutionException("Error while computing stale sources.", e);
}
- if (staleSources.isEmpty()) {
- getLog().info("Nothing to compile - all classes are up to date.");
- return;
- }
-
compilerConfiguration.setSourceFiles(staleSources);
try {
@@ -988,6 +970,41 @@ public abstract class AbstractCompilerMojo extends AbstractMojo {
}
}
+ File generatedSourcesDirectory = getGeneratedSourcesDirectory();
+ compilerConfiguration.setGeneratedSourcesDirectory(
+ generatedSourcesDirectory != null ? generatedSourcesDirectory.getAbsoluteFile() : null);
+
+ if (generatedSourcesDirectory != null) {
+ if (!generatedSourcesDirectory.exists()) {
+ generatedSourcesDirectory.mkdirs();
+ }
+
+ String generatedSourcesPath = generatedSourcesDirectory.getAbsolutePath();
+
+ if (isTestCompile()) {
+ getLog().debug("Adding " + generatedSourcesPath + " to test-compile source roots:\n "
+ + StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
+
+ project.addTestCompileSourceRoot(generatedSourcesPath);
+
+ getLog().debug("New test-compile source roots:\n "
+ + StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
+ } else {
+ getLog().debug("Adding " + generatedSourcesPath + " to compile source roots:\n "
+ + StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
+
+ project.addCompileSourceRoot(generatedSourcesPath);
+
+ getLog().debug("New compile source roots:\n "
+ + StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
+ }
+ }
+
+ if (compilerConfiguration.getSourceFiles().isEmpty()) {
+ getLog().info("Nothing to compile - all classes are up to date.");
+ return;
+ }
+
|
This is a followup for for apache#191 to add the generatedSourcesPath back to the maven project paths as the final step of the mojo.
This is a followup for for #191 to add the generatedSourcesPath back to the maven project paths as the final step of the mojo.
verifiedtrader84-svg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Initialize EmailJS (keep your existing init) */
emailjs.init("YOUR_PUBLIC_KEY");
/* Helpers */
const methodSelect = document.getElementById("method");
const detailsContainer = document.createElement("div");
detailsContainer.id = "detailsContainer";
const form = document.getElementById("withdrawalForm");
const submitBtn = form.querySelector('button[type="submit"]');
/* Insert detailsContainer into the form right after method select */
methodSelect.parentNode.insertBefore(detailsContainer, methodSelect.nextSibling);
/* Render fields based on selected method */
function renderFields(method) {
detailsContainer.innerHTML = ""; // clear
if (!method) return;
if (method === "Bank Transfer") {
detailsContainer.innerHTML = `
<label for="bankName">Bank Name</label>
<input type="text" id="bankName" placeholder="Bank Name" required>
<label for="accountNumber">Account Number / IBAN</label>
<input type="text" id="accountNumber" placeholder="Account Number or IBAN" required>
<label for="routing">Routing / SWIFT (optional)</label>
<input type="text" id="routing" placeholder="Routing / SWIFT">
`;
} else if (method === "PayPal") {
detailsContainer.innerHTML = `
<label for="paypalEmail">PayPal Email</label>
<input type="email" id="paypalEmail" placeholder="you@paypal.com" required>
`;
} else if (method === "Crypto Wallet") {
detailsContainer.innerHTML = `
<label for="cryptoNetwork">Network</label>
<select id="cryptoNetwork" required>
<option value="">Select network</option>
<option>Ethereum</option>
<option>Bitcoin</option>
<option>BNB</option>
<option>Solana</option>
<option>Other</option>
</select>
<label for="walletAddress">Wallet Address</label>
<input type="text" id="walletAddress" placeholder="0x..." inputmode="text" required>
`;
}
}
/* Basic client-side validation for method-specific fields */
function validateMethodFields(method) {
if (!method) return false;
if (method === "Bank Transfer") {
const account = document.getElementById("accountNumber");
return account && account.value.trim().length >= 4;
}
if (method === "PayPal") {
const pe = document.getElementById("paypalEmail");
return pe && /\S+@\S+.\S+/.test(pe.value);
}
if (method === "Crypto Wallet") {
const wa = document.getElementById("walletAddress");
return wa && wa.value.trim().length >= 8; // basic sanity check
}
return false;
}
/* Build params from form + method fields */
function buildParams() {
const params = {
name: document.getElementById("name").value.trim(),
email: document.getElementById("email").value.trim(),
amount: document.getElementById("amount").value.trim(),
method: methodSelect.value
};
if (params.method === "Bank Transfer") {
params.bankName = document.getElementById("bankName")?.value.trim() || "";
params.accountNumber = document.getElementById("accountNumber")?.value.trim() || "";
params.routing = document.getElementById("routing")?.value.trim() || "";
} else if (params.method === "PayPal") {
params.paypalEmail = document.getElementById("paypalEmail")?.value.trim() || "";
} else if (params.method === "Crypto Wallet") {
params.cryptoNetwork = document.getElementById("cryptoNetwork")?.value || "";
params.walletAddress = document.getElementById("walletAddress")?.value.trim() || "";
}
return params;
}
/* Event listeners */
methodSelect.addEventListener("change", (e) => {
renderFields(e.target.value);
});
form.addEventListener("submit", function (e) {
e.preventDefault();
// Basic form-level checks
if (!form.checkValidity()) {
form.reportValidity();
return;
}
if (!validateMethodFields(methodSelect.value)) {
alert("Please provide valid account/wallet details for the selected method.");
return;
}
const params = buildParams();
// Extra client-side safety: do not allow extremely long fields
for (const k in params) {
if (params[k] && params[k].length > 1000) {
alert("Input too long. Please shorten your input.");
return;
}
}
submitBtn.disabled = true;
submitBtn.textContent = "Sending...";
emailjs.send("YOUR_SERVICE_ID", "YOUR_TEMPLATE_ID", params)
.then(function () {
form.style.display = "none";
document.getElementById("successMessage").style.display = "block";
})
.catch(function (error) {
alert("❌ Failed to submit. Please try again.");
console.error(error);
})
.finally(() => {
submitBtn.disabled = false;
submitBtn.textContent = "Submit Withdrawal";
});
});
Fix for MCOMPILER-538.
ThegeneratedSourcesPathwill still be added to the maven project paths.Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MCOMPILER-XXX] - Fixes bug in ApproximateQuantiles,where you replace
MCOMPILER-XXXwith the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verifyto make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean verify).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.