Skip to content

Commit

Permalink
make jdk 1.8 minimum and switch to some sugar syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed May 3, 2023
1 parent f472a4d commit da85d3a
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 272 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@

<properties>
<mavenVersion>3.5.4</mavenVersion>
<mojo.java.target>7</mojo.java.target>
<minimalJavaBuildVersion>1.7</minimalJavaBuildVersion>
<mojo.java.target>8</mojo.java.target>
<minimalJavaBuildVersion>1.8</minimalJavaBuildVersion>

<processorVersion>1.3</processorVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ public LicenseMap createLicenseMap( SortedMap<String, MavenProject> dependencies

LicenseMap licenseMap = new LicenseMap();

for ( MavenProject project : dependencies.values() )
{
thirdPartyTool.addLicense( licenseMap, project, project.getLicenses() );
}
dependencies.
values().
forEach(project -> thirdPartyTool.addLicense( licenseMap, project, project.getLicenses() ));

return licenseMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -252,11 +253,7 @@ public SortedProperties loadThirdPartyDescriptorsForUnsafeMapping( Set<Artifact>
loadGlobalLicenses( topLevelDependencies, remoteRepositories, unsafeDependencies,
licenseMap, unsafeProjects, result );
}
catch ( ArtifactNotFoundException e )
{
throw new ThirdPartyToolException( "Failed to load global licenses", e );
}
catch ( ArtifactResolutionException e )
catch ( ArtifactNotFoundException | ArtifactResolutionException e )
{
throw new ThirdPartyToolException( "Failed to load global licenses", e );
}
Expand Down Expand Up @@ -356,7 +353,7 @@ public void addLicense( LicenseMap licenseMap, MavenProject project, License lic
/**
* {@inheritDoc}
*/
public void addLicense( LicenseMap licenseMap, MavenProject project, List<?> licenses )
public void addLicense( LicenseMap licenseMap, MavenProject project, List<License> licenses )
{

if ( Artifact.SCOPE_SYSTEM.equals( project.getArtifact().getScope() ) )
Expand All @@ -374,15 +371,14 @@ public void addLicense( LicenseMap licenseMap, MavenProject project, List<?> lic
return;
}

for ( Object o : licenses )
for ( License license : licenses )
{
String id = MojoHelper.getArtifactId( project.getArtifact() );
if ( o == null )
if ( license == null )
{
LOG.warn( "could not acquire the license for {}", id );
continue;
}
License license = (License) o;
String licenseKey = license.getName();

// tchemit 2010-08-29 Ano #816 Check if the License object is well formed
Expand Down Expand Up @@ -505,9 +501,8 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap,
// since GAV is good enough to qualify a license of any artifact of it...
Map<String, String> migrateKeys = migrateMissingFileKeys( unsafeMappings.keySet() );

for ( Object o : migrateKeys.keySet() )
for ( String id : migrateKeys.keySet() )
{
String id = (String) o;
String migratedId = migrateKeys.get( id );

MavenProject project = artifactCache.get( migratedId );
Expand Down Expand Up @@ -708,10 +703,10 @@ private void loadOneGlobalSet( SortedSet<MavenProject> unsafeDependencies, Licen
File propFile = resolveArtifact( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getType(),
dep.getClassifier(), remoteRepositories );
LOG.info(
"Loading global license map from {}: {}", dep.toString(), propFile.getAbsolutePath() );
"Loading global license map from {}: {}", dep, propFile.getAbsolutePath() );
SortedProperties props = new SortedProperties( "utf-8" );

try ( InputStream propStream = new FileInputStream( propFile ) )
try (InputStream propStream = Files.newInputStream( propFile.toPath() ) )
{
props.load( propStream );
}
Expand All @@ -736,8 +731,7 @@ private void loadOneGlobalSet( SortedSet<MavenProject> unsafeDependencies, Licen

/**
* @param project not null
* @param localRepository not null
* @param repositories not null
* \@param remoteRepositories not null
* @return the resolved site descriptor
* @throws IOException if any
* @throws ArtifactResolutionException if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public class FreeMarkerHelper
public static FreeMarkerHelper newDefaultHelper()
{
ClassTemplateLoader templateLoader = new ClassTemplateLoader( FreeMarkerHelper.class, "/" );
FreeMarkerHelper result = new FreeMarkerHelper( templateLoader );
return result;
return new FreeMarkerHelper( templateLoader );
}

/**
Expand All @@ -79,8 +78,7 @@ public static FreeMarkerHelper newHelperFromContent( String stringTemplate )
StringTemplateLoader templateLoader = new StringTemplateLoader();
templateLoader.putTemplate( TEMPLATE, stringTemplate );

FreeMarkerHelper result = new FreeMarkerHelper( templateLoader );
return result;
return new FreeMarkerHelper( templateLoader );
}

protected FreeMarkerHelper( TemplateLoader templateLoader )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ File resolveMissingLicensesDescriptor( String groupId, String artifactId, String
* From the given {@code licenseMap}, obtain all the projects with no license.
*
* @param licenseMap the license map to query
* @param doLog a flag to add debug logs
* @return the set of projects with no license
*/
SortedSet<MavenProject> getProjectsWithNoLicense( LicenseMap licenseMap );
Expand Down Expand Up @@ -184,7 +183,7 @@ void overrideLicenses( LicenseMap licenseMap, SortedMap<String, MavenProject> ar
* @param project the project
* @param licenses the licenses to add
*/
void addLicense( LicenseMap licenseMap, MavenProject project, List<?> licenses );
void addLicense( LicenseMap licenseMap, MavenProject project, List<License> licenses );

/**
* For a given {@code licenseMap}, merge all {@code licenses}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected HttpHost determineProxy( HttpHost target, HttpRequest request, HttpCon
* can be adjusted based on the mime type of the HTTP response.
*
* @param licenseUrlString the URL
* @param outputFile a hint where to store the license file
* @param fileNameEntry a hint where to store the license file
* @return the path to the file where the downloaded license file was stored
* @throws IOException
* @throws URISyntaxException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.maven.plugin.MojoExecutionException;

Expand Down Expand Up @@ -67,10 +68,7 @@ public static LicenseMatchers load( File licenseMatchersFile )
final List<ProjectLicenseInfo> replacements =
LicenseSummaryReader.parseLicenseSummary( licenseMatchersFile );

for ( ProjectLicenseInfo dependency : replacements )
{
matchers.add( DependencyMatcher.of( dependency ) );
}
replacements.forEach( dependency -> matchers.add( DependencyMatcher.of( dependency ) ) );
}
}
catch ( Exception e )
Expand Down Expand Up @@ -204,10 +202,7 @@ public List<ProjectLicense> cloneLicenses()
final ArrayList<ProjectLicense> result = new ArrayList<>( licenses != null ? licenses.size() : 0 );
if ( licenses != null )
{
for ( ProjectLicense license : licenses )
{
result.add( license.clone() );
}
result.addAll( licenses.stream().map( license -> license.clone() ).collect( Collectors.toList() ) );
}
return result;
}
Expand Down Expand Up @@ -287,12 +282,9 @@ public static LicenseListMatcher of( ProjectLicenseInfo dependency )
}
else
{
licenseMatchers = new ArrayList<>();
for ( ProjectLicense lic : rawMatchers )
{
licenseMatchers.add( new LicenseMatcher( lic.getName(), lic.getUrl(), lic.getDistribution(),
lic.getComments() ) );
}
licenseMatchers = rawMatchers.stream()
.map( lic -> new LicenseMatcher( lic.getName(), lic.getUrl(), lic.getDistribution(), lic.getComments() ))
.collect( Collectors.toList() );
}
return new LicenseListMatcher( licenseMatchers );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,33 @@ private static ProjectLicenseInfo parseDependencyNode( Node dependencyNode )
{
Node node = depElements.item( i );

if ( node.getNodeName().equals( "groupId" ) )
{
dependency.setGroupId( node.getTextContent() );
}
else if ( node.getNodeName().equals( "artifactId" ) )
{
dependency.setArtifactId( node.getTextContent() );
}
else if ( node.getNodeName().equals( "version" ) )
{
dependency.setVersion( node.getTextContent() );
}
else if ( node.getNodeName().equals( "licenses" ) )
{
Map.Entry<Boolean, List<ProjectLicense>> entry = parseLicenses( node );
dependency.setLicenses( entry.getValue() );
dependency.setApproved( entry.getKey() );
}
else if ( node.getNodeName().equals( "matchLicenses" ) )
{
dependency.setHasMatchLicenses( true );
dependency.setMatchLicenses( parseLicenses( node ).getValue() );
switch (node.getNodeName()) {
case "groupId":
dependency.setGroupId(node.getTextContent());
break;
case "artifactId":
dependency.setArtifactId(node.getTextContent());
break;
case "version":
dependency.setVersion(node.getTextContent());
break;
case "licenses":
Map.Entry<Boolean, List<ProjectLicense>> entry = parseLicenses(node);
dependency.setLicenses(entry.getValue());
dependency.setApproved(entry.getKey());
break;
case "matchLicenses":
dependency.setHasMatchLicenses(true);
dependency.setMatchLicenses(parseLicenses(node).getValue());
break;
}
}
return dependency;
}

private static Map.Entry<Boolean, List<ProjectLicense>> parseLicenses( Node node )
{
final List<ProjectLicense> result = new ArrayList<ProjectLicense>();
final List<ProjectLicense> result = new ArrayList<>();
final NodeList licensesChildNodes = node.getChildNodes();
final Node approvedNode = node.getAttributes().getNamedItem( "approved" );
boolean approved = Boolean.parseBoolean( approvedNode != null ? approvedNode.getNodeValue() : "false" );
Expand All @@ -157,7 +154,7 @@ private static Map.Entry<Boolean, List<ProjectLicense>> parseLicenses( Node node
result.add( parseLicense( licensesChildNode ) );
}
}
return new AbstractMap.SimpleImmutableEntry<Boolean, List<ProjectLicense>>( approved, result );
return new AbstractMap.SimpleImmutableEntry<>( approved, result );
}

private static ProjectLicense parseLicense( Node licenseNode )
Expand All @@ -167,25 +164,22 @@ private static ProjectLicense parseLicense( Node licenseNode )
for ( int i = 0; i < licenseElements.getLength(); ++i )
{
Node node = licenseElements.item( i );
if ( node.getNodeName().equals( "name" ) )
{
license.setName( node.getTextContent() );
}
else if ( node.getNodeName().equals( "url" ) )
{
license.setUrl( node.getTextContent() );
}
else if ( node.getNodeName().equals( "distribution" ) )
{
license.setDistribution( node.getTextContent() );
}
else if ( node.getNodeName().equals( "comments" ) )
{
license.setComments( node.getTextContent() );
}
else if ( node.getNodeName().equals( "file" ) )
{
license.setFile( node.getTextContent() );
switch (node.getNodeName()) {
case "name":
license.setName(node.getTextContent());
break;
case "url":
license.setUrl(node.getTextContent());
break;
case "distribution":
license.setDistribution(node.getTextContent());
break;
case "comments":
license.setComments(node.getTextContent());
break;
case "file":
license.setFile(node.getTextContent());
break;
}
}
return license;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public static void writeLicenseSummary( List<ProjectLicenseInfo> dependencies, F
Node dependenciesNode = doc.createElement( "dependencies" );
root.appendChild( dependenciesNode );

for ( ProjectLicenseInfo dep : dependencies )
{
dependenciesNode.appendChild( createDependencyNode( doc, dep, writeVersions ) );
}
dependencies.forEach( dep -> dependenciesNode.appendChild( createDependencyNode( doc, dep, writeVersions ) ) );

// Prepare the output file File
try ( StringWriter sw = new StringWriter() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,9 @@ else if ( !licenses.equals( other.licenses ) )
return false;
if ( version == null )
{
if ( other.version != null )
return false;
return other.version == null;
}
else if ( !version.equals( other.version ) )
return false;
return true;
else return version.equals(other.version);
// CHECKSTYLE_ON: NeedBraces
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ public class LicensedArtifactResolver
* For a given {@code project}, obtain the universe of its dependencies after applying transitivity and filtering
* rules given in the {@code configuration} object. Result is given in a map where keys are unique artifact id
*
* @param dependencies the project dependencies
* @param artifacts the project dependencies
* @param configuration the configuration
* @param localRepository local repository used to resolv dependencies
* @param remoteRepositories remote repositories used to resolv dependencies
* @param cache a optional cache where to keep resolved dependencies
* @return the map of resolved dependencies indexed by their unique id.
* @param result the map of resolved dependencies indexed by their unique id.
* @see MavenProjectDependenciesConfigurator
*/
public void loadProjectDependencies( ResolvedProjectDependencies artifacts,
Expand Down
Loading

0 comments on commit da85d3a

Please sign in to comment.