Skip to content

Use optimised plexus-utils CachingWriter #186

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

Merged
merged 2 commits into from
Jun 9, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

import java.io.File;
import java.io.FilterWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.Path;
Expand All @@ -41,6 +43,7 @@
import org.codehaus.modello.model.Version;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.util.io.CachingWriter;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
Expand Down Expand Up @@ -291,15 +294,31 @@ protected BuildContext getBuildContext()
return buildContext;
}

protected Writer newWriter( Path path )
protected Writer newWriter( Path path ) throws IOException
{
Charset charset = getEncoding() != null ? Charset.forName( getEncoding() ) : Charset.defaultCharset();
return newWriter( path, charset );
}

protected Writer newWriter( Path path, Charset charset )
protected Writer newWriter( Path path, Charset charset ) throws IOException
{
return new CachingWriter( getBuildContext(), path, charset );
CachingWriter cachingWriter = new CachingWriter( path, charset );
return new FilterWriter( cachingWriter )
{
@Override
public void close() throws IOException
{
super.close();
if ( cachingWriter.isModified() )
{
getBuildContext().refresh( path.toFile() );
}
else
{
getLogger().debug( "The contents of the file " + path + " matches, skipping writing file." );
}
}
};
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.codehaus.modello.model.ModelInterface;
import org.codehaus.modello.model.ModelType;
import org.codehaus.modello.plugin.AbstractModelloGenerator;
import org.codehaus.modello.plugin.CachingWriter;
import org.codehaus.modello.plugin.java.javasource.JClass;
import org.codehaus.modello.plugin.java.javasource.JComment;
import org.codehaus.modello.plugin.java.javasource.JInterface;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand Down