Skip to content
Snippets Groups Projects
Commit f3d8a8ec authored by Saša Živkov's avatar Saša Živkov Committed by Shawn Pearce
Browse files

Externalize strings from JGit


The strings are externalized into the root resource bundles.
The resource bundles are stored under the new "resources" source
folder to get proper maven build.

Strings from tests are, in general, not externalized. Only in
cases where it was necessary to make the test pass the strings
were externalized. This was typically necessary in cases where
e.getMessage() was used in assert and the exception message was
slightly changed due to reuse of the externalized strings.

Change-Id: Ic0f29c80b9a54fcec8320d8539a3e112852a1f7b
Signed-off-by: default avatarSasa Zivkov <sasa.zivkov@sap.com>
parent 2e961989
No related branches found
No related tags found
No related merge requests found
Showing
with 221 additions and 26 deletions
......@@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -7,6 +7,7 @@ Bundle-Version: 0.8.0.qualifier
Bundle-Vendor: %provider_name
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.eclipse.jgit.console;version="0.8.0"
Import-Package: org.eclipse.jgit.transport;version="[0.8.0,0.9.0)",
Import-Package: org.eclipse.jgit.nls;version="[0.8.0,0.9.0)",
org.eclipse.jgit.transport;version="[0.8.0,0.9.0)",
org.eclipse.jgit.util;version="[0.8.0,0.9.0)"
Require-Bundle: com.jcraft.jsch;bundle-version="[0.1.37,0.2.0)"
......@@ -84,6 +84,9 @@
<include>plugin.properties</include>
</includes>
</resource>
<resource>
<directory>resources/</directory>
</resource>
</resources>
<plugins>
......
answerNo=n
answerYes=y
noSystemConsoleAvailable=No System.console available
password=Password:
usernameFor=Username for {0}:
......@@ -47,6 +47,7 @@
import java.io.Console;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.text.MessageFormat;
import org.eclipse.jgit.util.CachedAuthenticator;
......@@ -56,7 +57,7 @@ public class ConsoleAuthenticator extends CachedAuthenticator {
public static void install() {
final ConsoleAuthenticator c = new ConsoleAuthenticator();
if (c.cons == null)
throw new NoClassDefFoundError("No System.console available");
throw new NoClassDefFoundError(ConsoleText.get().noSystemConsoleAvailable);
Authenticator.setDefault(c);
}
......@@ -65,11 +66,11 @@ public static void install() {
@Override
protected PasswordAuthentication promptPasswordAuthentication() {
final String realm = formatRealm();
String username = cons.readLine("Username for %s: ", realm);
String username = cons.readLine(MessageFormat.format(ConsoleText.get().usernameFor + " ", realm));
if (username == null || username.isEmpty()) {
return null;
}
char[] password = cons.readPassword("Password: ");
char[] password = cons.readPassword(ConsoleText.get().password + " ");
if (password == null) {
password = new char[0];
}
......
......@@ -70,7 +70,7 @@ public class ConsoleSshSessionFactory extends SshConfigSessionFactory {
public static void install() {
final ConsoleSshSessionFactory c = new ConsoleSshSessionFactory();
if (c.cons == null)
throw new NoClassDefFoundError("No System.console available");
throw new NoClassDefFoundError(ConsoleText.get().noSystemConsoleAvailable);
SshSessionFactory.setInstance(c);
}
......@@ -93,8 +93,8 @@ public void showMessage(final String msg) {
}
public boolean promptYesNo(final String msg) {
String r = cons.readLine("%s [y/n]? ", msg);
return "y".equalsIgnoreCase(r);
String r = cons.readLine("%s [%s/%s]? ", msg, ConsoleText.get().answerYes, ConsoleText.get().answerNo);
return ConsoleText.get().answerYes.equalsIgnoreCase(r);
}
public boolean promptPassword(final String msg) {
......
/*
* Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.console;
import org.eclipse.jgit.nls.NLS;
import org.eclipse.jgit.nls.TranslationBundle;
/**
* Translation bundle for JGit console
*/
public class ConsoleText extends TranslationBundle {
/**
* @return an instance of this translation bundle
*/
public static ConsoleText get() {
return NLS.getBundleFor(ConsoleText.class);
}
/***/ public String answerNo;
/***/ public String answerYes;
/***/ public String noSystemConsoleAvailable;
/***/ public String password;
/***/ public String usernameFor;
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<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.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
......
......@@ -15,6 +15,7 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
javax.servlet.http;version="[2.5.0,3.0.0)",
org.eclipse.jgit.errors;version="[0.8.0,0.9.0)",
org.eclipse.jgit.lib;version="[0.8.0,0.9.0)",
org.eclipse.jgit.nls;version="[0.8.0,0.9.0)",
org.eclipse.jgit.revwalk;version="[0.8.0,0.9.0)",
org.eclipse.jgit.transport;version="[0.8.0,0.9.0)",
org.eclipse.jgit.util;version="[0.8.0,0.9.0)",
......
......@@ -90,6 +90,9 @@
<include>plugin.properties</include>
</includes>
</resource>
<resource>
<directory>resources/</directory>
</resource>
</resources>
<plugins>
......
alreadyInitializedByContainer=Already initialized by container
cannotGetLengthOf=Cannot get length of {0}
encodingNotSupportedByThisLibrary={0} "{1}": not supported by this library.
expectedRepositoryAttribute=Expected Repository attribute
filterMustNotBeNull=filter must not be null
internalErrorDuringReceivePack=Internal error during receive-pack
internalErrorDuringUploadPack=Internal error during upload-pack
internalServerErrorRequestAttributeWasAlreadySet=Internal server error, request attribute {0} was already set when {1} was invoked.
invalidBoolean=Invalid boolean {0} = {1}
invalidIndex=Invalid index: {0}
invalidRegexGroup=Invalid regex group {0}
noResolverAvailable=No resolver available
parameterNotSet=Parameter {0} not set
pathForParamNotFound={0} (for {1}) not found
pathNotSupported={0} not supported
serviceNotEnabled=Service not enabled
serviceNotPermitted=Service not permitted
servletAlreadyInitialized=Servlet already initialized
servletMustNotBeNull=servlet must not be null
servletWasAlreadyBound=servlet was already bound
unexpectedeOFOn=Unexpected EOF on {0}
......@@ -57,6 +57,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.text.MessageFormat;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
......@@ -100,7 +101,7 @@ final class FileSender {
}
final FileNotFoundException r;
r = new FileNotFoundException("Cannot get length of " + path);
r = new FileNotFoundException(MessageFormat.format(HttpServerText.get().cannotGetLengthOf, path));
r.initCause(e);
throw r;
}
......@@ -143,7 +144,7 @@ void serve(final HttpServletRequest req, final HttpServletResponse rsp,
final int r = (int) Math.min(buf.length, end - pos);
final int n = source.read(buf, 0, r);
if (n < 0) {
throw new EOFException("Unexpected EOF on " + path);
throw new EOFException(MessageFormat.format(HttpServerText.get().unexpectedeOFOn, path));
}
out.write(buf, 0, n);
pos += n;
......
......@@ -44,6 +44,7 @@
package org.eclipse.jgit.http.server;
import java.io.File;
import java.text.MessageFormat;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
......@@ -169,7 +170,7 @@ public void setReceivePackFactory(ReceivePackFactory f) {
private void assertNotInitialized() {
if (initialized)
throw new IllegalStateException("Already initialized by container");
throw new IllegalStateException(HttpServerText.get().alreadyInitializedByContainer);
}
@Override
......@@ -259,11 +260,11 @@ public void init(final ServletConfig config) throws ServletException {
private File getFile(final String param) throws ServletException {
String n = getInitParameter(param);
if (n == null || "".equals(n))
throw new ServletException("Parameter " + param + " not set");
throw new ServletException(MessageFormat.format(HttpServerText.get().parameterNotSet, param));
File path = new File(n);
if (!path.exists())
throw new ServletException(path + " (for " + param + ") not found");
throw new ServletException(MessageFormat.format(HttpServerText.get().pathForParamNotFound, path, param));
return path;
}
......@@ -274,14 +275,14 @@ private boolean getBoolean(String param) throws ServletException {
try {
return StringUtils.toBoolean(n);
} catch (IllegalArgumentException err) {
throw new ServletException("Invalid boolean " + param + " = " + n);
throw new ServletException(MessageFormat.format(HttpServerText.get().invalidBoolean, param, n));
}
}
@Override
protected ServletBinder register(ServletBinder binder) {
if (resolver == null)
throw new IllegalStateException("No resolver available");
throw new IllegalStateException(HttpServerText.get().noResolverAvailable);
binder = binder.through(new NoCacheFilter());
binder = binder.through(new RepositoryFilter(resolver));
return binder;
......
/*
* Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.http.server;
import org.eclipse.jgit.nls.NLS;
import org.eclipse.jgit.nls.TranslationBundle;
/**
* Translation bundle for JGit http server
*/
public class HttpServerText extends TranslationBundle {
/**
* @return an instance of this translation bundle
*/
public static HttpServerText get() {
return NLS.getBundleFor(HttpServerText.class);
}
/***/ public String alreadyInitializedByContainer;
/***/ public String cannotGetLengthOf;
/***/ public String encodingNotSupportedByThisLibrary;
/***/ public String expectedRepositoryAttribute;
/***/ public String filterMustNotBeNull;
/***/ public String internalErrorDuringReceivePack;
/***/ public String internalErrorDuringUploadPack;
/***/ public String internalServerErrorRequestAttributeWasAlreadySet;
/***/ public String invalidBoolean;
/***/ public String invalidIndex;
/***/ public String invalidRegexGroup;
/***/ public String noResolverAvailable;
/***/ public String parameterNotSet;
/***/ public String pathForParamNotFound;
/***/ public String pathNotSupported;
/***/ public String serviceNotEnabled;
/***/ public String serviceNotPermitted;
/***/ public String servletAlreadyInitialized;
/***/ public String servletMustNotBeNull;
/***/ public String servletWasAlreadyBound;
/***/ public String unexpectedeOFOn;
}
......@@ -120,7 +120,7 @@ public void doPost(final HttpServletRequest req,
return;
} catch (IOException e) {
getServletContext().log("Internal error during receive-pack", e);
getServletContext().log(HttpServerText.get().internalErrorDuringReceivePack, e);
rsp.sendError(SC_INTERNAL_SERVER_ERROR);
return;
}
......
......@@ -50,6 +50,7 @@
import static org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_REPOSITORY;
import java.io.IOException;
import java.text.MessageFormat;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
......@@ -109,9 +110,9 @@ public void doFilter(final ServletRequest request,
final ServletResponse rsp, final FilterChain chain)
throws IOException, ServletException {
if (request.getAttribute(ATTRIBUTE_REPOSITORY) != null) {
context.log("Internal server error, request attribute "
+ ATTRIBUTE_REPOSITORY + " was already set when "
+ getClass().getName() + " was invoked.");
context.log(MessageFormat.format(HttpServerText.get().internalServerErrorRequestAttributeWasAlreadySet
, ATTRIBUTE_REPOSITORY
, getClass().getName()));
((HttpServletResponse) rsp).sendError(SC_INTERNAL_SERVER_ERROR);
return;
}
......
......@@ -54,6 +54,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.text.MessageFormat;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
......@@ -85,7 +86,7 @@ public final class ServletUtils {
public static Repository getRepository(final ServletRequest req) {
Repository db = (Repository) req.getAttribute(ATTRIBUTE_REPOSITORY);
if (db == null)
throw new IllegalStateException("Expected Repository attribute");
throw new IllegalStateException(HttpServerText.get().expectedRepositoryAttribute);
return db;
}
......@@ -109,8 +110,8 @@ public static InputStream getInputStream(final HttpServletRequest req)
if (ENCODING_GZIP.equals(enc) || "x-gzip".equals(enc)) //$NON-NLS-1$
in = new GZIPInputStream(in);
else if (enc != null)
throw new IOException(HDR_CONTENT_ENCODING + " \"" + enc + "\""
+ ": not supported by this library.");
throw new IOException(MessageFormat.format(HttpServerText.get().encodingNotSupportedByThisLibrary
, HDR_CONTENT_ENCODING, enc));
return in;
}
......
......@@ -122,7 +122,7 @@ public void doPost(final HttpServletRequest req,
return;
} catch (IOException e) {
getServletContext().log("Internal error during upload-pack", e);
getServletContext().log(HttpServerText.get().internalErrorDuringUploadPack, e);
rsp.reset();
rsp.sendError(SC_INTERNAL_SERVER_ERROR);
return;
......
......@@ -46,6 +46,7 @@
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.IdentityHashMap;
......@@ -59,6 +60,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.http.server.HttpServerText;
/**
* Generic container servlet to manage routing to different pipelines.
* <p>
......@@ -95,7 +98,7 @@ public MetaServlet() {
public ServletBinder serve(String path) {
if (path.startsWith("*"))
return register(new SuffixPipeline.Binder(path.substring(1)));
throw new IllegalArgumentException("\"" + path + "\" not supported");
throw new IllegalArgumentException(MessageFormat.format(HttpServerText.get().pathNotSupported, path));
}
/**
......@@ -164,7 +167,7 @@ private UrlPipeline find(final HttpServletRequest req)
private ServletBinder register(ServletBinderImpl b) {
synchronized (bindings) {
if (pipelines != null)
throw new IllegalStateException("Servlet already initialized");
throw new IllegalStateException(HttpServerText.get().servletAlreadyInitialized);
bindings.add(b);
}
return register((ServletBinder) b);
......
......@@ -44,6 +44,7 @@
package org.eclipse.jgit.http.server.glue;
import java.io.IOException;
import java.text.MessageFormat;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
......@@ -52,6 +53,8 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.eclipse.jgit.http.server.HttpServerText;
/**
* Switch servlet path and path info to use another regex match group.
* <p>
......@@ -69,7 +72,7 @@ public class RegexGroupFilter implements Filter {
*/
public RegexGroupFilter(final int groupIdx) {
if (groupIdx < 1)
throw new IllegalArgumentException("Invalid index: " + groupIdx);
throw new IllegalArgumentException(MessageFormat.format(HttpServerText.get().invalidIndex, groupIdx));
this.groupIdx = groupIdx - 1;
}
......@@ -88,7 +91,7 @@ public void doFilter(final ServletRequest request,
if (groupIdx < g.length)
chain.doFilter(g[groupIdx], rsp);
else
throw new ServletException("Invalid regex group " + (groupIdx + 1));
throw new ServletException(MessageFormat.format(HttpServerText.get().invalidRegexGroup, (groupIdx + 1)));
}
private static WrappedRequest[] groupsFor(final ServletRequest r) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment