diff --git a/tycho-cleancode-plugin/pom.xml b/tycho-cleancode-plugin/pom.xml index 74848cd3c8..0ae5e2c50b 100644 --- a/tycho-cleancode-plugin/pom.xml +++ b/tycho-cleancode-plugin/pom.xml @@ -36,12 +36,57 @@ org.eclipse.jdt org.eclipse.jdt.ui 3.33.200 + + + * + * + + org.eclipse.jdt org.eclipse.jdt.core.manipulation 1.21.300 + + + * + * + + + + org.eclipse.platform + org.eclipse.ltk.core.refactoring + 3.14.600 + + + * + * + + + + + org.eclipse.platform + org.eclipse.ui.workbench + + + * + * + + + + + org.eclipse.platform + org.eclipse.ui.ide + 3.22.400 + + + * + * + + + + diff --git a/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUp.java b/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUp.java index 6c85f26204..5d87ac6e91 100644 --- a/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUp.java +++ b/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUp.java @@ -20,6 +20,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; @@ -41,10 +42,12 @@ public class CleanUp extends AbstractEclipseBuild { private Map customProfile; + private boolean applyCleanupsIndividually; - CleanUp(Path projectDir, boolean debug, Map customProfile) { + CleanUp(Path projectDir, boolean debug, Map customProfile, boolean applyCleanupsIndividually) { super(projectDir, debug); this.customProfile = customProfile; + this.applyCleanupsIndividually = applyCleanupsIndividually; } @Override @@ -54,27 +57,38 @@ protected CleanupResult createResult(IProject project) throws Exception { ICleanUp[] cleanups = getCleanups(result, options); if (cleanups.length > 0) { List units = getCompilationUnits(project); - final CleanUpRefactoring refactoring = new CleanUpRefactoring(project.getName()); - for (ICompilationUnit cu : units) { - refactoring.addCompilationUnit(cu); - } - refactoring.setUseOptionsFromProfile(false); - for (ICleanUp cleanUp : cleanups) { - refactoring.addCleanUp(cleanUp); - } - final RefactoringStatus status = refactoring.checkAllConditions(this); - if (status.isOK()) { - Change change = refactoring.createChange(this); - change.initializeValidationData(this); - PerformChangeOperation performChangeOperation = new PerformChangeOperation(change); - performChangeOperation.run(this); - } else if (status.hasError()) { - throw new RuntimeException("Refactoring failed: " + status); + if (applyCleanupsIndividually) { + for (ICleanUp cleanUp : cleanups) { + applyCleanups(project, new ICleanUp[] { cleanUp }, units); + } + } else { + applyCleanups(project, cleanups, units); } } return result; } + private void applyCleanups(IProject project, ICleanUp[] cleanups, List units) + throws CoreException { + final CleanUpRefactoring refactoring = new CleanUpRefactoring(project.getName()); + for (ICompilationUnit cu : units) { + refactoring.addCompilationUnit(cu); + } + refactoring.setUseOptionsFromProfile(false); + for (ICleanUp cleanUp : cleanups) { + refactoring.addCleanUp(cleanUp); + } + final RefactoringStatus status = refactoring.checkAllConditions(this); + if (status.isOK()) { + Change change = refactoring.createChange(this); + change.initializeValidationData(this); + PerformChangeOperation performChangeOperation = new PerformChangeOperation(change); + performChangeOperation.run(this); + } else if (status.hasError()) { + throw new RuntimeException("Refactoring failed: " + status); + } + } + private List getCompilationUnits(IProject project) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); List units = new ArrayList(); diff --git a/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUpMojo.java b/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUpMojo.java index 21e390e323..94123c62ea 100644 --- a/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUpMojo.java +++ b/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/CleanUpMojo.java @@ -40,6 +40,9 @@ public class CleanUpMojo extends AbstractEclipseBuildMojo { @Parameter private Map cleanUpProfile; + @Parameter + private boolean applyCleanupsIndividually; + @Override protected String[] getRequireBundles() { return new String[] { "org.eclipse.jdt.ui" }; @@ -52,7 +55,7 @@ protected String getName() { @Override protected CleanUp createExecutable() { - return new CleanUp(project.getBasedir().toPath(), debug, cleanUpProfile); + return new CleanUp(project.getBasedir().toPath(), debug, cleanUpProfile, applyCleanupsIndividually); } @Override @@ -65,6 +68,7 @@ protected void handleResult(CleanupResult result) builder.h3("The following cleanups where applied:"); result.cleanups().forEach(cleanup -> { builder.addListItem(cleanup); + getLog().info("CleanUp: " + cleanup); }); builder.newLine(); builder.newLine(); diff --git a/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/QuickFixMojo.java b/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/QuickFixMojo.java index bdb96a57b9..911b59f317 100644 --- a/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/QuickFixMojo.java +++ b/tycho-cleancode-plugin/src/main/java/org/eclipse/tycho/cleancode/QuickFixMojo.java @@ -53,14 +53,13 @@ protected void handleResult(QuickFixResult result) throws MojoFailureException { MarkdownBuilder builder = new MarkdownBuilder(reportFileName); List fixes = result.fixes().toList(); builder.h3("The following " + (fixes.size() > 0 ? "warnings" : "warning") + " has been resolved:"); - builder.newLine(); - fixes.forEach(fix -> builder.addListItem(fix)); + fixes.forEach(fix -> { + builder.addListItem(fix); + getLog().info("QuickFix: " + fix); + }); builder.newLine(); builder.newLine(); builder.write(); - for (String fix : fixes) { - getLog().info("Fixed: " + fix); - } } @Override