Skip to content

Commit

Permalink
Clean up code as suggested by IntelliJ linters
Browse files Browse the repository at this point in the history
  • Loading branch information
goneall committed Jan 22, 2025
1 parent 3e5cb04 commit b5be6be
Show file tree
Hide file tree
Showing 31 changed files with 417 additions and 509 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/spdx/maven/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* Simple class to hold an SPDX Annotation.
*
* @author Gary O'Neall
* @see org.spdx.library.model.Annotation
* @see AnnotationType
*/
@SuppressWarnings("unused")
public class Annotation
{
private static final Logger LOG = LoggerFactory.getLogger( Annotation.class );
Expand Down Expand Up @@ -122,7 +121,6 @@ public void setAnnotationComment( String annotationComment )

public void logInfo()
{
LOG.debug(
"Annotator: " + this.annotator + ", Date: " + this.annotationDate + ", Type: " + this.annotationType );
LOG.debug( "Annotator: {}, Date: {}, Type: {}", this.annotator, this.annotationDate, this.annotationType );
}
}
1 change: 1 addition & 0 deletions src/main/java/org/spdx/maven/Checksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public String getAlgorithm()
/**
* @param algorithm the algorithm to set
*/
@SuppressWarnings("unused")
public void setAlgorithm( String algorithm )
{
this.algorithm = algorithm;
Expand Down
57 changes: 22 additions & 35 deletions src/main/java/org/spdx/maven/CreateSpdxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;

/**
* NOTE: Currently this is a prototype plugin for supporting SPDX in a Maven build.
Expand Down Expand Up @@ -91,6 +86,7 @@
* </ul><p>
* Additional SPDX fields are supplied as configuration parameters to this plugin.
*/
@SuppressWarnings({"unused", "DefaultAnnotationParam"})
@Mojo( name = "createSPDX",
defaultPhase = LifecyclePhase.VERIFY,
requiresOnline = true,
Expand Down Expand Up @@ -567,7 +563,7 @@ public void execute() throws MojoExecutionException

// check errors
List<String> spdxErrors = builder.verify();
if ( spdxErrors != null && spdxErrors.size() > 0 )
if ( spdxErrors != null && !spdxErrors.isEmpty() )
{
getLog().warn( "The following errors were found in the SPDX file:\n " + String.join( "\n ", spdxErrors ) );
}
Expand Down Expand Up @@ -597,6 +593,7 @@ private OutputFormat prepareOutput()
throw new MojoExecutionException(
"Invalid path for SPDX output file. " + "Specify a configuration parameter spdxFile with a valid directory path to resolve." );
}
//noinspection ResultOfMethodCallIgnored
outputDir.mkdirs();
return outputFormatEnum;
}
Expand All @@ -622,12 +619,12 @@ private AbstractDocumentBuilder initSpdxDocumentBuilder( OutputFormat outputForm
URI namespaceUri = new URI( spdxDocumentNamespace );
if ( SpdxMajorVersion.VERSION_3.equals( outputFormatEnum.getSpecVersion() ) ) {
builder = new SpdxV3DocumentBuilder( mavenProject, generatePurls, spdxFile, namespaceUri,
this.matchLicensesOnCrossReferenceUrls, outputFormatEnum );
outputFormatEnum );
}
else
{
builder = new SpdxV2DocumentBuilder( mavenProject, generatePurls, spdxFile, namespaceUri,
this.matchLicensesOnCrossReferenceUrls, outputFormatEnum );
outputFormatEnum );
}

}
Expand Down Expand Up @@ -662,8 +659,8 @@ private AbstractDocumentBuilder initSpdxDocumentBuilder( OutputFormat outputForm
* Collect dependency information from Maven dependencies and adds it to the builder SPDX document
*
* @param builder SPDX document builder
* @throws LicenseMapperException
* @throws InvalidSPDXAnalysisException
* @throws LicenseMapperException on errors related to mapping Maven licenses to SPDX licenses
* @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void buildSpdxDependencyInformation( AbstractDocumentBuilder builder, OutputFormat outputFormatEnum )
throws LicenseMapperException, InvalidSPDXAnalysisException, DependencyGraphBuilderException
Expand Down Expand Up @@ -708,19 +705,16 @@ private void logFileSpecificInfo( HashMap<String, SpdxDefaultFileInformation> fi
/**
* Get the patch specific information
*
* @param projectDefault
* @param spdxDoc SPDX document containing any extracted license infos
* @return
* @throws MojoExecutionException
* @param projectDefault default file information if no path specific overrides are present
* @return map path to project specific SPDX parameters
*/
private HashMap<String, SpdxDefaultFileInformation> getPathSpecificInfoFromParameters( SpdxDefaultFileInformation projectDefault ) throws MojoExecutionException
{
private HashMap<String, SpdxDefaultFileInformation> getPathSpecificInfoFromParameters( SpdxDefaultFileInformation projectDefault ) {
HashMap<String, SpdxDefaultFileInformation> retval = new HashMap<>();
if ( this.pathsWithSpecificSpdxInfo != null )
{
for ( PathSpecificSpdxInfo spdxInfo : this.pathsWithSpecificSpdxInfo )
{
SpdxDefaultFileInformation value = null;
SpdxDefaultFileInformation value;
value = spdxInfo.getDefaultFileInformation( projectDefault );
if ( retval.containsKey( spdxInfo.getPath() ) )
{
Expand All @@ -735,7 +729,7 @@ private HashMap<String, SpdxDefaultFileInformation> getPathSpecificInfoFromParam
/**
* Primarily for debugging purposes - logs nonStandardLicenses as info
*
* @param nonStandardLicenses
* @param nonStandardLicenses non standard licenses to log
*/
private void logNonStandardLicenses( NonStandardLicense[] nonStandardLicenses )
{
Expand Down Expand Up @@ -763,7 +757,7 @@ private void logNonStandardLicenses( NonStandardLicense[] nonStandardLicenses )
/**
* Primarily for debugging purposes - logs includedDirectories as info
*
* @param includedDirectories
* @param includedDirectories included directory fileSet to log
*/
private void logIncludedDirectories( List<FileSet> includedDirectories )
{
Expand Down Expand Up @@ -792,12 +786,9 @@ private void logIncludedDirectories( List<FileSet> includedDirectories )
}

/**
* @param spdxDoc SPDX Document containing any extracted license infos
* @return default file information from the plugin parameters
* @throws MojoExecutionException
*/
private SpdxDefaultFileInformation getDefaultFileInfoFromParameters() throws MojoExecutionException
{
private SpdxDefaultFileInformation getDefaultFileInfoFromParameters() {
SpdxDefaultFileInformation retval;
retval = new SpdxDefaultFileInformation();
retval.setComment( defaultFileComment );
Expand All @@ -823,17 +814,16 @@ private SpdxDefaultFileInformation getDefaultFileInfoFromParameters() throws Moj
* " is prepended
*
* @param builder SPDX document builder
* @return
* @throws MojoExecutionException
* @return SPDX project level information
*/
private SpdxProjectInformation getSpdxProjectInfoFromParameters( AbstractDocumentBuilder builder ) throws MojoExecutionException, InvalidSPDXAnalysisException
private SpdxProjectInformation getSpdxProjectInfoFromParameters( AbstractDocumentBuilder builder ) throws InvalidSPDXAnalysisException
{
SpdxProjectInformation retval = new SpdxProjectInformation();
if ( this.documentComment != null )
{
retval.setDocumentComment( this.documentComment );
}
String declaredLicense = null;
String declaredLicense;
if ( this.licenseDeclared == null )
{
List<License> mavenLicenses = mavenProject.getLicenses();
Expand All @@ -851,7 +841,7 @@ private SpdxProjectInformation getSpdxProjectInfoFromParameters( AbstractDocumen
{
declaredLicense = this.licenseDeclared.trim();
}
String concludedLicense = null;
String concludedLicense;
if ( this.licenseConcluded == null )
{
concludedLicense = declaredLicense;
Expand All @@ -866,7 +856,7 @@ private SpdxProjectInformation getSpdxProjectInfoFromParameters( AbstractDocumen
{
this.creators = new String[0];
}
String[] allCreators = (String[]) Arrays.copyOf( creators, creators.length + 1 );
String[] allCreators = Arrays.copyOf( creators, creators.length + 1 );
allCreators[allCreators.length - 1] = CREATOR_TOOL_MAVEN_PLUGIN;
retval.setCreators( allCreators );
retval.setCopyrightText( this.copyrightText );
Expand Down Expand Up @@ -955,7 +945,7 @@ private SpdxProjectInformation getSpdxProjectInfoFromParameters( AbstractDocumen
/**
* Get the default project name if no project name is specified in the POM
*
* @return
* @return the default project name if no project name is specified in the POM
*/
private String getDefaultProjectName()
{
Expand Down Expand Up @@ -1010,10 +1000,7 @@ private Set<String> getChecksumAlgorithms()
algorithms.add( "SHA1" );
if ( checksumAlgorithms != null )
{
for ( String checksumAlgorithm : checksumAlgorithms )
{
algorithms.add( checksumAlgorithm );
}
Collections.addAll( algorithms, checksumAlgorithms );
}
return algorithms;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/spdx/maven/ExternalReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
* enumerations, asset identifiers, or downloadable content believed to be relevant to the Package.
*
* @author Gary O'Neall
* @see ExternalRef
* @see ReferenceType
* @see ReferenceCategory
*
*/
@SuppressWarnings("unused")
public class ExternalReference
{
private String category;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/spdx/maven/NonStandardLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package org.spdx.maven;

import java.net.URL;
import java.util.Objects;

/**
* Non-standard license (e.g. license which is not in the SPDX standard license list http://spdx.org/licenses)
* Non-standard license (e.g. license which is not in the <a href="http://spdx.org/licenses">SPDX standard license list</a>)
*
* @author Gary O'Neall
*/
Expand Down Expand Up @@ -94,11 +95,7 @@ public String getName()
*/
public String getComment()
{
if ( comment == null )
{
return "";
}
return comment;
return Objects.requireNonNullElse( comment, "" );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/maven/OutputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public enum OutputFormat
private final String fileType;
private final SpdxMajorVersion specVersion;

private OutputFormat(final String value, final String artifactType, final String fileType,
final SpdxMajorVersion specVersion)
OutputFormat( final String value, final String artifactType, final String fileType,
final SpdxMajorVersion specVersion )
{
this.value = value;
this.artifactType = artifactType;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/maven/Packaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum Packaging
private final Purpose v2Purpose;
private final SoftwarePurpose softwarePurpose;

private Packaging(final String name, final Purpose v2purpose, final SoftwarePurpose v3softwarePurpose)
Packaging( final String name, final Purpose v2purpose, final SoftwarePurpose v3softwarePurpose )
{
this.name = name;
this.v2Purpose = v2purpose;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/spdx/maven/PathSpecificSpdxInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* @author Gary O'Neall
*/
@SuppressWarnings("unused")
public class PathSpecificSpdxInfo
{
/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public class PathSpecificSpdxInfo
* or (d) NOASSERTION, if the SPDX file creator has not examined the contents of the actual file or the SPDX file
* creator has intentionally provided no information (no meaning should be implied by doing so). For a license set,
* when there is a choice between licenses (“disjunctive license”), they should be separated with “or” and enclosed
* in brackets. Similarly when multiple licenses need to be applied (“conjunctive license”), they should be
* in brackets. Similarly, when multiple licenses need to be applied (“conjunctive license”), they should be
* separated with “and” and enclosed in parentheses.
*/
private String licenseInformationInFile;
Expand All @@ -101,10 +102,8 @@ public PathSpecificSpdxInfo()
* Get the default file information to be used with this file path
*
* @param defaults Default file information to use if the parameter was not specified for this file path
* @param spdxDoc SPDX document containing any extracted license infos that may be needed for concluded or declared
* licenses
* @return default file information to be used with this file path
* @throws InvalidSPDXAnalysisException
*/
public SpdxDefaultFileInformation getDefaultFileInformation( SpdxDefaultFileInformation defaults )
{
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/spdx/maven/SnippetInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,26 @@ public void logInfo()
LOG.debug( "Snippet information follows:" );
if ( this.name != null )
{
LOG.debug( "Name: " + this.name );
LOG.debug( "Name: {}", this.name );
}
LOG.debug( "Byte range: " + this.byteRange );
LOG.debug( "Byte range: {}", this.byteRange );
if ( this.comment != null )
{
LOG.debug( "Comment: " + this.comment );
LOG.debug( "Comment: {}", this.comment );
}
LOG.debug( "Concluded license: " + this.concludedLicense );
LOG.debug( "Concluded license: {}", this.concludedLicense );
if ( this.copyrightText != null )
{
LOG.debug( "Copyright: " + this.copyrightText );
LOG.debug( "Copyright: {}", this.copyrightText );
}
if ( this.licenseComment != null )
{
LOG.debug( "License comment: " + this.licenseComment );
LOG.debug( "License comment: {}", this.licenseComment );
}
LOG.debug( "License info in Snippet: " + this.licenseInfoInSnippet );
LOG.debug( "License info in Snippet: {}", this.licenseInfoInSnippet );
if ( this.lineRange != null )
{
LOG.debug( "Line range: " + this.lineRange );
LOG.debug( "Line range: {}", this.lineRange );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

/**
* Contains information about package dependencies collected from the Maven dependencies.
*
* <p>
* Subclasses implement dependency information specific to SPDX spec major versions
*
* @author Gary O'Neall
Expand Down Expand Up @@ -107,7 +107,7 @@ abstract void addMavenDependency( CoreModelObject parentPackage, DependencyNode
if ( versionFilter == null || versionFilter.equals( of.getSpecVersion() ))
{
File retval = getFileWithDifferentType( file, of.getFileType() );
if ( retval != null && retval.exists() ) {
if ( retval.exists() ) {
return retval;
}
}
Expand All @@ -131,8 +131,7 @@ private File getFileWithDifferentType( File file, String type )
filePath = filePath.substring( 0, indexOfDot + 1 );
}
filePath = filePath + type;
File retval = new File( filePath );
return retval;
return new File( filePath );
}

private void logDependencies( List<DependencyNode> dependencies )
Expand All @@ -157,15 +156,14 @@ private void logDependencies( List<DependencyNode> dependencies )
Artifact dependency = node.getArtifact();
String filePath = dependency.getFile() != null ? dependency.getFile().getAbsolutePath() : "[NONE]";
String scope = dependency.getScope() != null ? dependency.getScope() : "[NONE]";
LOG.debug(
"ArtifactId: " + dependency.getArtifactId() + ", file path: " + filePath + ", Scope: " + scope );
LOG.debug("ArtifactId: {}, file path: {}, Scope: {}", dependency.getArtifactId(), filePath, scope);
}
}

/**
* Make an external document reference ID valid by replacing any invalid characters with dashes
*
* @param externalRefId
* @param externalRefId ID for external reference
* @return valid external ref ID
*/
protected String fixExternalRefId( String externalRefId )
Expand Down
Loading

0 comments on commit b5be6be

Please sign in to comment.