Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new plugin publishing mechanism that eliminates the huge amount of ti…
…me it takes to publish a plugin and also fixes the problem where the plugin list could get corrupted
- Loading branch information
1 parent
f2287c9
commit 2b2ee34
Showing
6 changed files
with
468 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
grails/src/java/org/codehaus/groovy/grails/plugins/publishing/DefaultPluginPublisher.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright 2008 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 org.codehaus.groovy.grails.plugins.publishing | ||
|
||
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils | ||
import groovy.util.slurpersupport.GPathResult | ||
import groovy.xml.MarkupBuilder | ||
import org.springframework.core.io.Resource | ||
import grails.util.BuildSettingsHolder | ||
|
||
/** | ||
* Utility methods for manipulating the plugin-list.xml file used | ||
* when publishing plugins to a Grails plugin repository | ||
* | ||
* @author Graeme Rocher | ||
* @since 1.2 | ||
*/ | ||
|
||
public class DefaultPluginPublisher { | ||
|
||
String revision = "0" | ||
DefaultPluginPublisher(String revNumber) { | ||
if(revNumber) | ||
this.revision = revNumber | ||
} | ||
|
||
void writePluginList(GPathResult pluginList, Writer targetWriter) { | ||
def stringWriter = new StringWriter() | ||
stringWriter << new groovy.xml.StreamingMarkupBuilder().bind { | ||
mkp.yield pluginList | ||
} | ||
new XmlNodePrinter(new PrintWriter(targetWriter)).print(new XmlParser().parseText(stringWriter.toString())) | ||
} | ||
|
||
/** | ||
* Publishes a plugin release to the given plugin list | ||
* | ||
* @param pluginName the name of the plugin | ||
* @param pluginsListFile The plugin list file | ||
* @param makeLatest Whether to make the release the latest release | ||
* | ||
* @return the updated plugin list | ||
*/ | ||
GPathResult publishRelease(String pluginName, Resource pluginsList, boolean makeLatest) { | ||
def xml = parsePluginList(pluginsList) | ||
|
||
xml.@revision = revision | ||
|
||
def releaseMetadata = getPluginMetadata(pluginName) | ||
def pluginVersion = releaseMetadata.@version.toString().trim() | ||
def releaseTag = "RELEASE_${pluginVersion.replaceAll('\\.','_')}" | ||
|
||
def props = ['title', 'author', 'authorEmail', 'description', 'documentation'] | ||
def releaseInfo = { | ||
release([tag:releaseTag,version:pluginVersion, type:'svn']) { | ||
for(p in props) { | ||
"$p"(releaseMetadata."$p".text()) | ||
} | ||
} | ||
} | ||
|
||
// build argument, if makeLatest is true make the plugin the latest release | ||
def pluginArgs = [name:pluginName] | ||
if(makeLatest) { | ||
pluginArgs.'latest-release' = pluginVersion | ||
} | ||
|
||
def pluginInfo = { | ||
plugin(pluginArgs, releaseInfo) | ||
} | ||
|
||
|
||
// find plugin | ||
def allPlugins = xml.plugin | ||
if(allPlugins.size()==0) { | ||
// create new plugin list | ||
xml << pluginInfo | ||
} | ||
else { | ||
def existingEntry = xml.plugin.find { it.@name == pluginName } | ||
|
||
if(existingEntry.size()==0) { | ||
// plugin doesn't exist, create new entry | ||
def lastPlugin = allPlugins[allPlugins.size()-1] | ||
lastPlugin + pluginInfo | ||
} | ||
else { | ||
// plugin exists, add release info and make latest is appropriate | ||
if(makeLatest) { | ||
existingEntry.'@latest-release' = pluginVersion | ||
} | ||
def existingRelease = existingEntry.release.find { it.@version == pluginVersion } | ||
if(existingRelease.size()==0) { | ||
existingEntry << releaseInfo | ||
} | ||
} | ||
} | ||
|
||
return xml | ||
|
||
} | ||
|
||
protected GPathResult parsePluginList(Resource pluginsListFile) { | ||
if(pluginsListFile.exists()) { | ||
InputStream stream = pluginsListFile.getInputStream() | ||
try { | ||
return new XmlSlurper().parse(stream) | ||
} | ||
finally { | ||
stream?.close() | ||
} | ||
} | ||
else { | ||
return new XmlSlurper().parseText('<?xml version="1.0" encoding="UTF-8"?><plugins revision="0" />') | ||
} | ||
} | ||
|
||
GPathResult publishRelease(String pluginName, Resource pluginsList) { | ||
publishRelease(pluginName, pluginsList, true) | ||
} | ||
|
||
protected GPathResult getPluginMetadata(String pluginName) { | ||
def basedir = BuildSettingsHolder.settings?.baseDir ?: new File(".") | ||
return new XmlSlurper().parse(new File("${basedir.absolutePath}/plugin.xml")) | ||
} | ||
} |
Oops, something went wrong.