Skip to content
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

Log parsed files to Maven debug log #616

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: bump-rewrite-properties-to-releases
run: |
./mvnw versions:update-properties -DincludeProperties=rewrite.version,rewrite.python.version -DallowDowngrade=true
./mvnw versions:update-properties -DincludeProperties=rewrite.version,rewrite.all.version,rewrite.python.version -DallowDowngrade=true
git diff-index --quiet HEAD pom.xml || git commit -m "Bump rewrite.version properties" pom.xml && rm -f pom.xml.versionsBackup

- name: publish-release
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<properties>
<!-- Pinned versions, as RELEASE would make it into the published pom.xml -->
<rewrite.version>8.2.0-SNAPSHOT</rewrite.version>
<rewrite.all.version>1.1.0-SNAPSHOT</rewrite.all.version>
<rewrite.python.version>1.1.0-SNAPSHOT</rewrite.python.version>

<!-- using 'ssh' url scheme by default, which assumes a human is performing git operations leveraging an ssh key -->
Expand Down Expand Up @@ -159,6 +160,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-all</artifactId>
<version>${rewrite.all.version}</version>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
import org.openrewrite.ipc.http.HttpUrlConnectionSender;
import org.openrewrite.java.tree.JavaSourceFile;
import org.openrewrite.marker.*;
import org.openrewrite.maven.ux.MavenLogProgressBar;
import org.openrewrite.maven.ux.ProgressBarParsingEventListener;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.tree.ParsingExecutionContextView;
import org.openrewrite.xml.tree.Xml;

import java.io.File;
Expand Down Expand Up @@ -141,7 +144,10 @@ protected Environment environment(@Nullable ClassLoader recipeClassLoader) throw
}

protected ExecutionContext executionContext() {
return new InMemoryExecutionContext(t -> getLog().debug(t));
InMemoryExecutionContext ctx = new InMemoryExecutionContext(t -> getLog().debug(t));
ParsingExecutionContextView view = ParsingExecutionContextView.view(ctx);
view.setParsingListener(new ProgressBarParsingEventListener(new MavenLogProgressBar(getLog())));
return view;
}

protected Path getBuildRoot() {
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/org/openrewrite/maven/ux/MavenLogProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.maven.ux;

import org.apache.maven.plugin.logging.Log;
import org.openrewrite.NoopProgressBar;
import org.openrewrite.ProgressBar;
import org.openrewrite.internal.lang.Nullable;

public class MavenLogProgressBar extends NoopProgressBar {

private final Log log;

public MavenLogProgressBar(Log log) {
this.log = log;
}

@Override
public ProgressBar setExtraMessage(String extraMessage) {
log.info(extraMessage);
return this;
}

@Override
public void intermediateResult(@Nullable String message) {
log.debug(message);
}

@Override
public void finish(String message) {
log.info(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.maven.ux;

import org.openrewrite.Parser;
import org.openrewrite.ProgressBar;
import org.openrewrite.SourceFile;
import org.openrewrite.tree.ParsingEventListener;

public class ProgressBarParsingEventListener implements ParsingEventListener {

private final ProgressBar progressBar;

public ProgressBarParsingEventListener(ProgressBar progressBar) {
this.progressBar = progressBar;
}

@Override
public void parsed(Parser.Input input, SourceFile sourceFile) {
progressBar.intermediateResult("Parsed " + input.getPath());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would we want to add any details here based on the produced SourceFile or ParseError?

Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect anyway, as it is called after the file is parsed.

}
}