Skip to content

Commit

Permalink
增强错误异常提示以及修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EastWoodYang committed May 1, 2019
1 parent b00f06b commit 8a0351b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class MisPlugin implements Plugin<Project> {

project.gradle.getStartParameter().taskNames.each {
if (!isClean && it == 'clean') {
misDir.deleteDir()
boolean result = misDir.deleteDir()
if (!result) {
throw new RuntimeException("unable to delete dir " + misDir.absolute)
}
isClean = true
} else if (it.startsWith('publishMis')) {
executePublish = true
Expand All @@ -127,11 +130,16 @@ class MisPlugin implements Plugin<Project> {
MisExtension misExtension = project.extensions.create('mis', MisExtension, project)

Dependencies.metaClass.misPublication { String value ->
handleMisPublication(value, true)
String[] gav = filterGAV(value)
handleMisPublication(gav[0], gav[1], gav[2])
}

project.dependencies.metaClass.misPublication { Object value ->
handleMisPublication(value, false)
if (executePublish) {
return []
}
String[] gav = filterGAV(value)
handleMisPublication(gav[0], gav[1], gav[2])
}

project.gradle.removeListener(buildListener)
Expand Down Expand Up @@ -187,11 +195,7 @@ class MisPlugin implements Plugin<Project> {
publicationManager.loadManifest(project.rootProject, executePublish)
}

Object handleMisPublication(Object value, boolean fromPublication) {
if (executePublish && !fromPublication) {
return []
}

String[] filterGAV(Object value) {
String groupId = null, artifactId = null, version = null
if (value instanceof String) {
String[] values = value.split(":")
Expand Down Expand Up @@ -220,6 +224,10 @@ class MisPlugin implements Plugin<Project> {
"\n - Maps, for example [groupId: 'org.gradle', artifactId: 'gradle-core', version: '1.0'].")
}

return [groupId, artifactId, version]
}

Object handleMisPublication(String groupId, artifactId, version) {
def result
def key = "mis-" + groupId + "-" + artifactId
Publication publication = misPublicationMap.get(key)
Expand All @@ -246,7 +254,9 @@ class MisPlugin implements Plugin<Project> {
}
} else {
if (existPublication.invalid) {
result = []
// result = []
publication.useLocal = true
result = ":mis-${groupId}-${artifactId}:"
} else if (existPublication.version == null) {
if (version == null) {
publication.useLocal = true
Expand All @@ -265,12 +275,11 @@ class MisPlugin implements Plugin<Project> {
if (publication.invalid) {
result = []
} else if (publication.useLocal) {
result = ':' + key + ':'
result = ":mis-$publication.groupId-$publication.artifactId:"
} else {
result = "$publication.groupId:$publication.artifactId:$publication.version"
}
}

return result
}

Expand Down Expand Up @@ -469,8 +478,7 @@ class MisPlugin implements Plugin<Project> {
if (it.name.startsWith(publishTaskNamePrefix)) {
it.dependsOn compileTask
it.doLast {
File groupDir = project.rootProject.file(".gradle/mis/" + publication.groupId)
new File(groupDir, publication.artifactId + ".jar").delete()
new File(misDir, "mis-${publication.groupId}-${publication.artifactId}.jar").delete()
}
}
}
Expand All @@ -495,6 +503,10 @@ class MisPlugin implements Plugin<Project> {
if (publication.dependencies.implementation != null) {
publication.dependencies.implementation.each {
def gav = it.split(":")
if (gav[1].startsWith('mis-')) {
Publication dependencyPublication = misPublicationMap.get(gav[1])
throw new RuntimeException("mis publication [$dependencyPublication.groupId:$dependencyPublication.artifactId] has not publish yet.")
}
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', gav[0])
dependencyNode.appendNode('artifactId', gav[1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class JarUtil {
}

def hasDependencies = false
def random = new Random()
def name = "mis_" + random.nextLong()
def name = "mis[${publication.groupId}:${publication.artifactId}]Classpath"
project.configurations.create(name)
if (publication.dependencies != null) {
if (publication.dependencies.implementation != null) {
Expand Down Expand Up @@ -146,7 +145,7 @@ class JarUtil {
}

JavaVersion javaVersion = JavaVersion.toVersion(target)
if(javaVersion != JavaVersion.VERSION_1_8 && javaVersion != JavaVersion.VERSION_1_6) {
if (javaVersion != JavaVersion.VERSION_1_8 && javaVersion != JavaVersion.VERSION_1_6) {
throw new GradleException("Failure to compile mis kotlin source to bytecode: unknown JVM target version: $target, supported versions: 1.6, 1.8\nTry:\n " +
" android {\n" +
" ...\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PublicationManager {
}

boolean hasModified(Publication publication) {
def key = publication.groupId + "" + publication.artifactId
def key = publication.groupId + "-" + publication.artifactId
Publication lastPublication = publicationMap.get(key)
if (lastPublication == null) {
return true
Expand Down

0 comments on commit 8a0351b

Please sign in to comment.