Skip to content

Commit

Permalink
Merge pull request #144 from prokod/bugfix/prokod/#141
Browse files Browse the repository at this point in the history
Initial commit for issue #141
  • Loading branch information
prokod committed Mar 31, 2024
2 parents 24b304a + 6d3251a commit d60e2b5
Show file tree
Hide file tree
Showing 20 changed files with 441 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uses: gradle/wrapper-validation-action@v1
- name: code_coverage
run: ./gradlew clean codeCoverageTest jacocoCodeCoverageTestReport
- name: codecove_integration
- name: codecov_integration
uses: codecov/codecov-action@v2
with:
verbose: true
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: 'signing'
apply plugin: 'codenarc'

group = 'com.github.prokod'
version = '0.16.0'
version = '0.17.0-SNAPSHOT'

repositories {
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion config/spock/SpockConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ runner {
enabled true
defaultSpecificationExecutionMode ExecutionMode.CONCURRENT
defaultExecutionMode ExecutionMode.SAME_THREAD
// fixed(3)
fixed(2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.github.prokod.gradle.crossbuild.tasks.CrossBuildPomTask
import com.github.prokod.gradle.crossbuild.tasks.CrossBuildsReportTask
import com.github.prokod.gradle.crossbuild.tasks.CrossBuildsClasspathResolvedConfigurationReportTask
import com.github.prokod.gradle.crossbuild.utils.CrossBuildPluginUtils
import com.github.prokod.gradle.crossbuild.utils.DependencyInsights
import com.github.prokod.gradle.crossbuild.utils.DependencyOps
import com.github.prokod.gradle.crossbuild.utils.UniDependencyInsights
import com.github.prokod.gradle.crossbuild.utils.LoggerUtils
import com.github.prokod.gradle.crossbuild.utils.SourceSetInsights
Expand Down Expand Up @@ -113,7 +113,7 @@ class CrossBuildPlugin implements Plugin<Project> {
// 1. Adds scala-lib dependency to all sub projects (User convenience)
// 2. Helps with the creation of the correct dependencies for pom creation
// see ResolutionStrategyConfigurer::assemble3rdPartyDependencies
def moduleName = ScalaModuleType.LIBRARY.getName(scalaVersionInsights.majorVersion)
def moduleName = DependencyModuleType.SCALA_LIBRARY.getName(scalaVersionInsights.majorVersion)
def module = "org.scala-lang:${moduleName}:${scalaVersionInsights.compilerVersion}"
extension.project.dependencies.add(sourceSetInsight.getImplementationName(), module)
}
Expand Down Expand Up @@ -278,7 +278,7 @@ class CrossBuildPlugin implements Plugin<Project> {
.fromExt(extension)
.withMainSourceSet(main)
.build()
def di = new DependencyInsights(sourceSetInsights)
def di = new DependencyOps(sourceSetInsights)

//todo add other needed configuration types (except COMPILE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
package com.github.prokod.gradle.crossbuild

/**
* Abstraction for Scala lang module types
* With the introduction of Scala 3 which introduced modified naming convention, became the need to cater for
* both scala lang module naming convention
*/
@SuppressWarnings(['ThisReferenceEscapesConstructor', 'PrivateFieldCouldBeFinal', 'LineLength', 'DuplicateListLiteral'])
enum ScalaModuleType {
LIBRARY(['2':'scala-library', '3':'scala3-library_3']),
COMPILER(['2':'scala-compiler', '3':'scala3-compiler_3']),
REFLECT(['2':'scala-reflect'])
enum DependencyModuleType {
NON_SCALA_3RD_PARTY_LIB([:]),
SCALA_3RD_PARTY_LIB([:]),
SCALA_LIBRARY(['2':'scala-library', '3':'scala3-library_3']),
SCALA_COMPILER(['2':'scala-compiler', '3':'scala3-compiler_3']),
SCALA_REFLECT(['2':'scala-reflect']),
UNKNOWN([:])

private final Map<String, String> namingConventionMap

private ScalaModuleType(Map<String, String> namingConventionMap) {
private DependencyModuleType(Map<String, String> namingConventionMap) {
this.namingConventionMap = namingConventionMap
}

Expand All @@ -37,16 +43,20 @@ enum ScalaModuleType {
this.namingConventionMap.values().toSet()
}

/**
* All ViewType filtered by given tags
*
* @return
*/
static String convert(String name, String targetScalaVersion) {
def moduleType = values().find { moduleType ->
static DependencyModuleType findByName(String name) {
def found = values().find { moduleType ->
moduleType.names.contains(name)
}
found ?: UNKNOWN
}

moduleType.getName(targetScalaVersion)
/**
* Converts module type based current compiled scala major version
*
* @return dependencyModuleType after conversion
*/
static String convert(String name, String targetScalaMajorVersion) {
def moduleType = findByName(name)
moduleType.getName(targetScalaMajorVersion)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020-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
*
* http://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 com.github.prokod.gradle.crossbuild

import static com.github.prokod.gradle.crossbuild.ResolutionStrategyHandler.*

/**
* Abstraction similar to SBT for3use2_13/fore2_13use3
* With the introduction of Scala 3 which introduced transitive dependency between scala 2.13 and 3, became the need
* to detect that across different parts of the plugin
*/
@SuppressWarnings(['ThisReferenceEscapesConstructor', 'PrivateFieldCouldBeFinal', 'LineLength', 'DuplicateListLiteral'])
enum ForUseType {
FOR3USE2_13,
FOR2_13USE3,
NONE

/**
* This detects a scenario where a ussr default scala lang dependency in build.gradle is 2.13 and cross compiling
* currently compiles for scala 3
*
* @param requestedCoordinates
* @param compiled
* @return
*/
static boolean isRequested2_13Compiled3(ScalaVersionInsights requested, ScalaVersionInsights compiled) {
if (compiled.majorVersion == '3' && requested.baseVersion == '2.13') {
return true
}
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.github.prokod.gradle.crossbuild
import static com.github.prokod.gradle.crossbuild.ResolutionStrategyHandler.*

import com.github.prokod.gradle.crossbuild.model.DependencyLimitedInsight
import com.github.prokod.gradle.crossbuild.utils.DependencyInsights
import com.github.prokod.gradle.crossbuild.utils.DependencyOps
import com.github.prokod.gradle.crossbuild.utils.SourceSetInsights
import com.github.prokod.gradle.crossbuild.utils.LoggerUtils
import com.github.prokod.gradle.crossbuild.utils.ViewType
Expand Down Expand Up @@ -72,7 +72,7 @@ class ResolutionStrategyConfigurer {

def allDependencies = dependencySets.flatMapped()

//avoid big string creation
//avoid unnecessary string creation
if (project.logger.infoEnabled) {
project.logger.info(LoggerUtils.logTemplate(project,
lifecycle:'afterEvaluate',
Expand All @@ -83,7 +83,7 @@ class ResolutionStrategyConfigurer {
"${allDependencies.collect { "${it.group}:${it.name}" }.join(', ')}]"
))
}
def di = new DependencyInsights(sourceSetInsights)
def di = new DependencyOps(sourceSetInsights)

def projectDependencies =
di.findAllCrossBuildProjectTypeDependenciesDependenciesFor([configs.main.name] as Set, view)
Expand Down Expand Up @@ -146,11 +146,14 @@ class ResolutionStrategyConfigurer {
// Not a cross build dependency, specifically from org.scala-lang group
else {
if (requested.group == 'org.scala-lang') {
def targetModule =
ResolutionStrategyHandler.handleScalaModuleCase(Coordinates.from(requested),
scalaVersionInsights)
details.useTarget(targetModule.toString())
details.because('Cross compilation')
def requestedScalaVersionInsights = new ScalaVersionInsights(requested.version, scalaVersions)
if (!ForUseType.isRequested2_13Compiled3(requestedScalaVersionInsights, scalaVersionInsights)) {
def targetModule =
ResolutionStrategyHandler.handleScalaModuleCase(Coordinates.from(requested),
scalaVersionInsights)
details.useTarget(targetModule.toString())
details.because('Cross compilation')
}
}
}
}
Expand Down Expand Up @@ -186,15 +189,15 @@ class ResolutionStrategyConfigurer {
SourceSetInsightsView insightsView) {
def dependencySet = [configuration.allDependencies]

def di = new DependencyInsights(sourceSetInsights)
def di = new DependencyOps(sourceSetInsights)

def configurationNames = [configuration.name] as Set
def crossBuildProjectDependencySet =
di.findAllCrossBuildProjectTypeDependenciesDependenciesFor(configurationNames, insightsView.viewType)

def allDependencySet = (crossBuildProjectDependencySet + dependencySet.collectMany { it.toSet() })

def scalaDeps = DependencyInsights.findScalaDependencies(allDependencySet, scalaVersions)
def scalaDeps = DependencyOps.findScalaDependencies(allDependencySet, scalaVersions)

def versions = scalaDeps*.supposedScalaVersion.toSet()
if (versions.size() == 1) {
Expand Down Expand Up @@ -233,15 +236,15 @@ class ResolutionStrategyConfigurer {
SourceSetInsightsView insightsView) {
def dependencySet = insightsView.getDependencySets(DependencySetType.ALL).flatMapped().toSet()

def di = new DependencyInsights(sourceSetInsights)
def di = new DependencyOps(sourceSetInsights)

def configurationNames = insightsView.configurations.flatMapped()*.name.toSet()
def crossBuildProjectDependencySet =
di.findAllCrossBuildProjectTypeDependenciesDependenciesFor(configurationNames, insightsView.viewType)

def allDependencySet = (crossBuildProjectDependencySet + dependencySet)

def libGrid = DependencyInsights.findAllNonMatchingScalaVersionDependenciesWithCounterparts(
def libGrid = DependencyOps.findAllNonMatchingScalaVersionDependenciesWithCounterparts(
allDependencySet, targetScalaVersion, scalaVersions)

// dependencyMap key is name of dependency and value contains suggested correct dependency/ies
Expand Down Expand Up @@ -296,7 +299,7 @@ class ResolutionStrategyConfigurer {
SourceSetInsightsView insightsView) {
def dependencySet = [configuration.allDependencies]

def di = new DependencyInsights(sourceSetInsights)
def di = new DependencyOps(sourceSetInsights)

def configurationNames = [configuration.name] as Set
def crossBuildProjectDependencySet =
Expand All @@ -306,7 +309,7 @@ class ResolutionStrategyConfigurer {

def probableScalaVersionRaw = scalaVersions.catalog*.key.collect { String scalaVersion ->
def scalaVersionInsights = new ScalaVersionInsights(scalaVersion, scalaVersions)
def deps = DependencyInsights.findAllNonMatchingScalaVersionDependenciesQMarksExcluded(
def deps = DependencyOps.findAllNonMatchingScalaVersionDependenciesQMarksExcluded(
allDependencySet, scalaVersionInsights.artifactInlinedVersion, scalaVersions)
new Tuple2(scalaVersionInsights.artifactInlinedVersion, deps.size())
}.findAll { tuple ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.github.prokod.gradle.crossbuild
import org.gradle.api.artifacts.ModuleVersionSelector

/**
* Dependency resolution strategy handler. Holds dependency coordinated abstraction that supports both
* Dependency resolution strategy handler. Holds dependency coordinates abstraction that supports both
* <hl>
* <li>{@link ModuleVersionSelector}
* <li> Pom XMl Node
Expand All @@ -27,8 +27,8 @@ import org.gradle.api.artifacts.ModuleVersionSelector
class ResolutionStrategyHandler {

static Coordinates handleScalaModuleCase(Coordinates requested, ScalaVersionInsights scalaVersionInsights) {
if (requested.group.id == 'org.scala-lang') {
def targetModuleName = ScalaModuleType.convert(requested.name.id, scalaVersionInsights.majorVersion)
if (requested.group.id == 'org.scala-lang' ) {
def targetModuleName = DependencyModuleType.convert(requested.name.id, scalaVersionInsights.majorVersion)
return new Coordinates(requested.group.id, targetModuleName, scalaVersionInsights.compilerVersion)
}
requested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package com.github.prokod.gradle.crossbuild
*/
class ScalaVersions {
private static final Map<String, String> DEFAULT_CATALOG =
['2.9':'2.9.3', '2.10':'2.10.7', '2.11':'2.11.12', '2.12':'2.12.17', '2.13':'2.13.10', '3':'3.2.2']
['2.9':'2.9.3', '2.10':'2.10.7', '2.11':'2.11.12', '2.12':'2.12.18', '2.13':'2.13.13', '3':'3.3.3']

static final ScalaVersions DEFAULT_SCALA_VERSIONS = new ScalaVersions(DEFAULT_CATALOG)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.github.prokod.gradle.crossbuild.model

import com.github.prokod.gradle.crossbuild.DependencyModuleType
import com.github.prokod.gradle.crossbuild.ScalaVersions
import groovy.transform.EqualsAndHashCode
import org.gradle.api.artifacts.Dependency

/**
* Represents a dependency result object returned from some of the API methods in
* {@link com.github.prokod.gradle.crossbuild.utils.DependencyInsights}
* {@link com.github.prokod.gradle.crossbuild.utils.DependencyOps}
*
*/
@EqualsAndHashCode(excludes = ['dependency'], callSuper = true)
class DependencyInsight extends DependencyLimitedInsight {
String group
String version
DependencyModuleType moduleType
Dependency dependency

/**
Expand All @@ -23,15 +25,42 @@ class DependencyInsight extends DependencyLimitedInsight {
*/
static DependencyInsight parse(Dependency dependency, ScalaVersions scalaVersions) {
def limitedInsight = parseByDependencyName(dependency.name, scalaVersions)

new DependencyInsight(baseName:limitedInsight.baseName,
supposedScalaVersion:limitedInsight.supposedScalaVersion,
appendix:limitedInsight.appendix,
group:dependency.group,
version:dependency.version,
moduleType:inferModuleType(dependency, limitedInsight),
dependency:dependency)
}

String getGroupAndBaseName() {
"$group:$baseName".toString()
}

/**
* To tag {@link DependencyInsight} with a correct DependencyModuleType the following logic is followed:
* Check if it is {@link DependencyModuleType#SCALA_LIBRARY} or {@link DependencyModuleType#SCALA_COMPILER}
* If it so return, otherwise
* Check if this is {@link DependencyModuleType#SCALA_3RD_PARTY_LIB} otherwise
* {@link DependencyModuleType#NON_SCALA_3RD_PARTY_LIB}
* @param dependency
* @param limitedInsight
* @return DependencyModuleType
*/
private static DependencyModuleType inferModuleType(Dependency dependency,
DependencyLimitedInsight limitedInsight) {
def moduleType = dependency.group == 'org.scala-lang' ?
DependencyModuleType.findByName(dependency.name) : DependencyModuleType.UNKNOWN
if (DependencyModuleType.UNKNOWN == moduleType) {
if (limitedInsight.supposedScalaVersion) {
moduleType = DependencyModuleType.SCALA_3RD_PARTY_LIB
}
else {
moduleType = DependencyModuleType.NON_SCALA_3RD_PARTY_LIB
}
}
moduleType
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.github.prokod.gradle.crossbuild.ResolutionStrategyHandler
import com.github.prokod.gradle.crossbuild.ScalaVersions
import com.github.prokod.gradle.crossbuild.model.DependencyLimitedInsight
import com.github.prokod.gradle.crossbuild.model.ResolvedBuildAfterEvalLifeCycle
import com.github.prokod.gradle.crossbuild.utils.DependencyInsights
import com.github.prokod.gradle.crossbuild.utils.DependencyOps
import com.github.prokod.gradle.crossbuild.utils.SourceSetInsights
import com.github.prokod.gradle.crossbuild.utils.ViewType
import org.gradle.api.DefaultTask
Expand Down Expand Up @@ -81,7 +81,7 @@ abstract class AbstractCrossBuildPomTask extends DefaultTask {
def sourceSetInsights = new SourceSetInsights.Builder(resolvedBuild.name)
.fromPrj(project)
.build()
def di = new DependencyInsights(sourceSetInsights)
def di = new DependencyOps(sourceSetInsights)

def prjToJarNameMap = di.extractCrossBuildProjectTypeDependencies(ViewType.COMPILE_CLASSPATH).collectEntries {
setPublicationAlias(it.dependencyProject)
Expand Down

0 comments on commit d60e2b5

Please sign in to comment.