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

Code simplifications in AbstractMojo #47

Merged
merged 4 commits into from Aug 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 14 additions & 28 deletions src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
Expand Up @@ -196,16 +196,17 @@ protected File getJarFile( File basedir, String resultFinalName, String classifi
throw new IllegalArgumentException( "finalName is not allowed to be null" );
}

StringBuilder fileName = new StringBuilder( resultFinalName );

String fileName;
if ( hasClassifier() )
{
fileName.append( "-" ).append( classifier );
fileName = resultFinalName + "-" + classifier + ".jar";
}
else
{
fileName = resultFinalName + ".jar";
}

fileName.append( ".jar" );

return new File( basedir, fileName.toString() );
return new File( basedir, fileName );
}

/**
Expand Down Expand Up @@ -243,18 +244,11 @@ public File createArchive()
}
}

String archiverName = containsModuleDescriptor ? "mjar" : "jar";

MavenArchiver archiver = new MavenArchiver();
archiver.setCreatedBy( "Maven JAR Plugin", "org.apache.maven.plugins", "maven-jar-plugin" );

if ( containsModuleDescriptor )
{
archiver.setArchiver( (JarArchiver) archivers.get( "mjar" ) );
}
else
{
archiver.setArchiver( (JarArchiver) archivers.get( "jar" ) );
}

archiver.setArchiver( (JarArchiver) archivers.get( archiverName ) );
archiver.setOutputFile( jarFile );

// configure for Reproducible Builds based on outputTimestamp value
Expand Down Expand Up @@ -328,28 +322,20 @@ public void execute()

private boolean projectHasAlreadySetAnArtifact()
{
if ( getProject().getArtifact().getFile() != null )
{
return getProject().getArtifact().getFile().isFile();
}
else
if ( getProject().getArtifact().getFile() == null )
{
return false;
}

return getProject().getArtifact().getFile().isFile();
}

/**
* @return true in case where the classifier is not {@code null} and contains something else than white spaces.
*/
protected boolean hasClassifier()
{
boolean result = false;
if ( getClassifier() != null && getClassifier().trim().length() > 0 )
{
result = true;
}

return result;
return getClassifier() != null && getClassifier().trim().length() > 0;
}

private String[] getIncludes()
Expand Down