Skip to content

Commit

Permalink
JENKINS-10325: fixing issue
Browse files Browse the repository at this point in the history
- made more strings localizable, 
- added german localization
- now requires Jenkins 1.420+

Signed-off-by: cklein <carsten.klein@axn-software.de>
  • Loading branch information
cklein committed Jul 16, 2011
1 parent 1f4ddbb commit 86b7826
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/localizer"/> <classpathentry kind="src" path="target/generated-sources/localizer"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/> <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
Expand Down
5 changes: 1 addition & 4 deletions .settings/org.eclipse.jdt.core.prefs
@@ -1,6 +1,3 @@
#Wed Jul 13 21:15:01 CEST 2011 #Sat Jul 16 15:57:31 CEST 2011
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
16 changes: 9 additions & 7 deletions pom.xml
@@ -1,9 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.jvnet.hudson.plugins</groupId> <groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId> <artifactId>plugin</artifactId>
<version>1.324</version> <version>1.420</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>svn-tag</artifactId> <artifactId>svn-tag</artifactId>
Expand All @@ -24,11 +24,6 @@
</developer> </developer>
</developers> </developers>
<dependencies> <dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>subversion</artifactId>
<version>[1.1,)</version>
</dependency>
<dependency> <dependency>
<groupId>dom4j</groupId> <groupId>dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
Expand All @@ -41,5 +36,12 @@
<classifier>jdk15</classifier> <classifier>jdk15</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>subversion</artifactId>
<version>[1.28,)</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
99 changes: 50 additions & 49 deletions src/main/java/hudson/plugins/svn_tag/SvnTagPlugin.java
Expand Up @@ -2,6 +2,7 @@


import groovy.lang.Binding; import groovy.lang.Binding;
import groovy.lang.GroovyShell; import groovy.lang.GroovyShell;
import hudson.EnvVars;
import hudson.Launcher; import hudson.Launcher;
import hudson.model.*; import hudson.model.*;
import hudson.scm.SubversionSCM; import hudson.scm.SubversionSCM;
Expand Down Expand Up @@ -54,14 +55,16 @@ private SvnTagPlugin() {
* @param tagBaseURLStr tag base URL string * @param tagBaseURLStr tag base URL string
* @param tagComment tag comment * @param tagComment tag comment
* @return true if the operation was successful * @return true if the operation was successful
* @throws InterruptedException
* @throws IOException
*/ */
@SuppressWarnings({"FeatureEnvy", "UnusedDeclaration", "TypeMayBeWeakened", @SuppressWarnings({"FeatureEnvy", "UnusedDeclaration", "TypeMayBeWeakened",
"LocalVariableOfConcreteClass"}) "LocalVariableOfConcreteClass"})
public static boolean perform(AbstractBuild<?,?> abstractBuild, public static boolean perform(AbstractBuild<?,?> abstractBuild,
Launcher launcher, Launcher launcher,
BuildListener buildListener, BuildListener buildListener,
String tagBaseURLStr, String tagComment, String tagBaseURLStr, String tagComment,
String tagDeleteComment) { String tagDeleteComment) throws IOException, InterruptedException {
PrintStream logger = buildListener.getLogger(); PrintStream logger = buildListener.getLogger();


if (!Result.SUCCESS.equals(abstractBuild.getResult())) { if (!Result.SUCCESS.equals(abstractBuild.getResult())) {
Expand All @@ -72,47 +75,37 @@ public static boolean perform(AbstractBuild<?,?> abstractBuild,
AbstractProject<?, ?> rootProject = AbstractProject<?, ?> rootProject =
abstractBuild.getProject().getRootProject(); abstractBuild.getProject().getRootProject();


Map<String, String> env;

if (!(rootProject.getScm() instanceof SubversionSCM)) { if (!(rootProject.getScm() instanceof SubversionSCM)) {
logger.println(Messages.NotSubversion(rootProject.getScm().toString())); logger.println(Messages.NotSubversion(rootProject.getScm().toString()));
return true; return true;
} }


SubversionSCM scm = SubversionSCM.class.cast(rootProject.getScm()); SubversionSCM scm = SubversionSCM.class.cast(rootProject.getScm());
try { EnvVars envVars = abstractBuild.getEnvironment(buildListener);
env = abstractBuild.getEnvironment(buildListener);
} catch (Exception e) {
logger.println(
"Failed to get environment. " + e.getLocalizedMessage());
return false;
}


// Let SubversionSCM fill revision number. // Let SubversionSCM fill revision number.
// It is guaranteed for getBuilds() return the latest build (i.e. // It is guaranteed for getBuilds() return the latest build (i.e.
// current build) at first // current build) at first
// The passed in abstractBuild may be the sub maven module and not // The passed in abstractBuild may be the sub maven module and not
// have revision.txt holding Svn revision information, so need to use // have revision.txt holding Svn revision information, so need to use
// the build associated with the root level project. // the build associated with the root level project.
scm.buildEnvVars(rootProject.getBuilds().get(0), env); scm.buildEnvVars(rootProject.getBuilds().get(0), envVars);


SubversionSCM.ModuleLocation[] moduleLocations = scm.getLocations();

// environment variable "SVN_REVISION" doesn't contain revision number when multiple modules are // environment variable "SVN_REVISION" doesn't contain revision number when multiple modules are
// specified. Instead, parse revision.txt and obtain the corresponding revision numbers. // specified. Instead, parse revision.txt and obtain the corresponding revision numbers.
Map<String, Long> revisions; Map<String, Long> revisions;
try { try {
revisions = parseRevisionFile(abstractBuild); revisions = parseRevisionFile(abstractBuild);
} catch (IOException e) { } catch (IOException e) {
logger.println( logger.println(
"Failed to parse revision.txt. " + e.getLocalizedMessage()); Messages.FailedParsingRevisionFile(e.getLocalizedMessage()));
return false; return false;
} }


ISVNAuthenticationProvider sap = ISVNAuthenticationProvider sap =
scm.getDescriptor().createAuthenticationProvider(); scm.getDescriptor().createAuthenticationProvider(rootProject);
if (sap == null) { if (sap == null) {
logger.println("Subversion authentication info is not set."); logger.println(Messages.NoSVNAuthProvider());
return false; return false;
} }


Expand All @@ -122,41 +115,40 @@ public static boolean perform(AbstractBuild<?,?> abstractBuild,


SVNCommitClient commitClient = new SVNCommitClient(sam, null); SVNCommitClient commitClient = new SVNCommitClient(sam, null);



for (SubversionSCM.ModuleLocation ml : scm.getLocations(envVars, abstractBuild)) {
for (SubversionSCM.ModuleLocation ml : moduleLocations) { String mlUrl = null;
logger.println("moduleLocation: Remote ->" + ml.remote); URI repoURI = null;

try {
List locationPathElements = mlUrl = ml.getSVNURL().toString();
Arrays.asList(StringUtils.split(ml.remote, "/")); repoURI = new URI(mlUrl);

} catch (SVNException e) {
String evaledTagBaseURLStr = logger.println(
evalGroovyExpression(env, tagBaseURLStr, Messages.FailedParsingRepositoryURL(ml.remote, e.getLocalizedMessage()));
locationPathElements); return false;

} catch (URISyntaxException e) {
URI repoURI; logger.println(
try { Messages.FailedParsingRepositoryURL(ml.remote, e.getLocalizedMessage()));
repoURI = new URI(StringUtils.replace(ml.remote, " ", "%20")); return false;
} catch (URISyntaxException e) { }
logger.println("Failed to parse SVN repo URL. " + logger.println(Messages.RemoteModuleLocation(mlUrl));
e.getLocalizedMessage());
return false; List<String> locationPathElements = Arrays.asList(StringUtils.split(mlUrl, "/"));
} String evaledTagBaseURLStr = evalGroovyExpression(
envVars, tagBaseURLStr, locationPathElements);


SVNURL parsedTagBaseURL = null; SVNURL parsedTagBaseURL = null;
try { try {
parsedTagBaseURL = SVNURL.parseURIEncoded( parsedTagBaseURL = SVNURL.parseURIDecoded(
repoURI.resolve(evaledTagBaseURLStr).toString()); repoURI.resolve(evaledTagBaseURLStr).toString());
logger.println( logger.println(Messages.TagBaseURL(parsedTagBaseURL.toString()));
"Tag Base URL: '" + parsedTagBaseURL.toString() + "'.");
} catch (SVNException e) { } catch (SVNException e) {
logger.println( logger.println(Messages.FailedParsingTagBaseURL(
"Failed to parse tag base URL '" + evaledTagBaseURLStr + evaledTagBaseURLStr, e.getLocalizedMessage()));
"'. " + e.getLocalizedMessage());
} }


try { try {
String evalDeleteComment = evalGroovyExpression( String evalDeleteComment = evalGroovyExpression(
env, tagDeleteComment, locationPathElements); envVars, tagDeleteComment, locationPathElements);
SVNCommitInfo deleteInfo = SVNCommitInfo deleteInfo =
commitClient.doDelete(new SVNURL[]{parsedTagBaseURL}, commitClient.doDelete(new SVNURL[]{parsedTagBaseURL},
evalDeleteComment); evalDeleteComment);
Expand All @@ -176,18 +168,25 @@ public static boolean perform(AbstractBuild<?,?> abstractBuild,


try { try {
String evalComment = evalGroovyExpression( String evalComment = evalGroovyExpression(
env, tagComment, locationPathElements); envVars, tagComment, locationPathElements);
SVNRevision rev = SVNRevision.create(Long.valueOf(revisions.get(ml.remote)));
Long revision = revisions.get(mlUrl);
if (revision == null)
{
logger.println(Messages.RevisionNotAvailable(mlUrl));
}
SVNRevision rev = SVNRevision.create(revision);


SVNCommitInfo commitInfo = SVNCommitInfo commitInfo =
copyClient.doCopy(new SVNCopySource[] { copyClient.doCopy(new SVNCopySource[] {
new SVNCopySource(rev, rev, SVNURL.parseURIEncoded(ml.remote)) }, new SVNCopySource(rev, rev,
SVNURL.parseURIEncoded(mlUrl)) },
parsedTagBaseURL, false, parsedTagBaseURL, false,
true, false, evalComment, new SVNProperties()); true, false, evalComment, new SVNProperties());
SVNErrorMessage errorMsg = commitInfo.getErrorMessage(); SVNErrorMessage errorMsg = commitInfo.getErrorMessage();


if (null != errorMsg) { if (null != errorMsg) {
logger.println(errorMsg.getFullMessage()); logger.println(Messages.FailedToTag(errorMsg.getFullMessage()));
return false; return false;
} else { } else {
logger.println(Messages.Tagged(commitInfo.getNewRevision())); logger.println(Messages.Tagged(commitInfo.getNewRevision()));
Expand Down Expand Up @@ -254,10 +253,12 @@ static Map<String, Long> parseRevisionFile(AbstractBuild build)
continue; // invalid line? continue; // invalid line?
} }
try { try {
revisions.put(line.substring(0, index), revisions.put(SVNURL.parseURIEncoded(line.substring(0, index)).toString(),
Long.parseLong(line.substring(index + 1))); Long.parseLong(line.substring(index + 1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// perhaps a corrupted line. ignore // perhaps a corrupted line. ignore
} catch(SVNException e) {
// perhaps a corrupted line. ignore
} }
} }
} finally { } finally {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/hudson/plugins/svn_tag/Messages.properties
Expand Up @@ -10,3 +10,11 @@ DeleteOldTag=Delete old tag {0}.
NoOldTag=There was no old tag at {0}. NoOldTag=There was no old tag at {0}.
Tagged=Tagged as Revision {0} Tagged=Tagged as Revision {0}
CopyFailed=Subversion copy failed. {0} CopyFailed=Subversion copy failed. {0}
RevisionNotAvailable=Revision not available for {0}.
FailedParsingRepositoryURL=Failed to parse SVN repository URL {0}. {1}
FailedParsingTagBaseURL=Failed to parse SVN Tag Base URL {0}. {1}
TagBaseURL=Tag Base URL: {0}.
RemoteModuleLocation=Remote Module Location: {0}.
NoSVNAuthProvider=No subversion authentication provider available.
FailedParsingRevisionFile=Failed to parse revision.txt. {0}
FailedToTag=Creating the tag failed with the following error: {0}
20 changes: 20 additions & 0 deletions src/main/resources/hudson/plugins/svn_tag/Messages_de.properties
@@ -0,0 +1,20 @@
DisplayName=Erstellt Subversion Tags für erfolgreiche Builds.
DefaultTagBaseURL='http://subversion_host/project/tags/last-successful/${env[''JOB_NAME'']}'
DefaultTagComment='Tag erzeugt durch SvnTag Plugin. Build:${env[''BUILD_TAG'']}.'
DefaultTagDeleteComment=Tag gelöscht durch SvnTag Plugin.
MissingURL=Bitte geben Sie eine gültige URL ein.
BadGroovy=Überprüfen Sie Ihr Skript. {0}
UnsuccessfulBuild=Nicht erfolgreiche Builds werden nicht getagged.
NotSubversion=SvnTag Plugin kann keine Tags für das SCM {0} erstellen.
DeleteOldTag=Lösche bestehendes Tag {0}.
NoOldTag=Es existiert kein vorheriges Tag {0}.
Tagged=Tagged in der Revision {0}
CopyFailed=Das Erstellen des Tags ist fehlgeschlagen. {0}
RevisionNotAvailable=Es existiert keine Revision für {0}.
FailedParsingRepositoryURL=Die SVN repository URL {0} ist ungültig. {1}
FailedParsingTagBaseURL=Die SVN Tag Base URL {0} ist ungültig. {1}
TagBaseURL=Tag Base URL: {0}.
RemoteModuleLocation=Entfernter Modulpfad: {0}.
NoSVNAuthProvider=Authentifizierung an Subversion nicht möglich.
FailedParsingRevisionFile=Die Datei revision.txt konnte nicht gelesen werden. {0}
FailedToTag=Die Erzeugung des Tags schlug mit folgender Fehlermeldung fehl: {0}

0 comments on commit 86b7826

Please sign in to comment.