diff options
author | Sasa Zivkov <sasa.zivkov@sap.com> | 2010-05-19 16:59:28 +0200 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-05-19 14:37:16 -0700 |
commit | f3d8a8ecad614906a2c4ec0077cdb24129da6c6d (patch) | |
tree | 34d041692beff0f392c27869f49b76c0fc2053e6 /org.eclipse.jgit/src/org/eclipse/jgit/transport | |
parent | 2e961989e42b1fe7e8bd9eaa7a3d2e88a0d1d001 (diff) | |
download | jgit-f3d8a8ecad614906a2c4ec0077cdb24129da6c6d.tar.gz jgit-f3d8a8ecad614906a2c4ec0077cdb24129da6c6d.zip |
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: Sasa Zivkov <sasa.zivkov@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport')
33 files changed, 276 insertions, 244 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index c5d6db7e3e..0430b5fdca 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -60,6 +60,7 @@ import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; +import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; @@ -78,6 +79,7 @@ import java.util.TreeMap; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor; @@ -158,7 +160,7 @@ public class AmazonS3 { try { return MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("JRE lacks MD5 implementation", e); + throw new RuntimeException(JGitText.get().JRELacksMD5Implementation, e); } } @@ -211,11 +213,11 @@ public class AmazonS3 { public AmazonS3(final Properties props) { publicKey = props.getProperty("accesskey"); if (publicKey == null) - throw new IllegalArgumentException("Missing accesskey."); + throw new IllegalArgumentException(JGitText.get().missingAccesskey); final String secret = props.getProperty("secretkey"); if (secret == null) - throw new IllegalArgumentException("Missing secretkey."); + throw new IllegalArgumentException(JGitText.get().missingSecretkey); privateKey = new SecretKeySpec(Constants.encodeASCII(secret), HMAC); final String pacl = props.getProperty("acl", "PRIVATE"); @@ -241,9 +243,9 @@ public class AmazonS3 { encryption = WalkEncryption.NONE; } } catch (InvalidKeySpecException e) { - throw new IllegalArgumentException("Invalid encryption", e); + throw new IllegalArgumentException(JGitText.get().invalidEncryption, e); } catch (NoSuchAlgorithmException e) { - throw new IllegalArgumentException("Invalid encryption", e); + throw new IllegalArgumentException(JGitText.get().invalidEncryption, e); } maxAttempts = Integer.parseInt(props.getProperty( @@ -471,7 +473,7 @@ public class AmazonS3 { if (monitor == null) monitor = NullProgressMonitor.INSTANCE; if (monitorTask == null) - monitorTask = "Uploading " + key; + monitorTask = MessageFormat.format(JGitText.get().progressMonUploading, key); final String md5str = Base64.encodeBytes(csum); final long len = buf.length(); @@ -508,9 +510,8 @@ public class AmazonS3 { private IOException error(final String action, final String key, final HttpURLConnection c) throws IOException { - final IOException err = new IOException(action + " of '" + key - + "' failed: " + HttpSupport.response(c) + " " - + c.getResponseMessage()); + final IOException err = new IOException(MessageFormat.format(JGitText.get().amazonS3ActionFailed + , action, key, HttpSupport.response(c), c.getResponseMessage())); final ByteArrayOutputStream b = new ByteArrayOutputStream(); byte[] buf = new byte[2048]; for (;;) { @@ -527,8 +528,8 @@ public class AmazonS3 { } private IOException maxAttempts(final String action, final String key) { - return new IOException(action + " of '" + key + "' failed:" - + " Giving up after " + maxAttempts + " attempts."); + return new IOException(MessageFormat.format(JGitText.get().amazonS3ActionFailedGivingUp + , action, key, maxAttempts)); } private HttpURLConnection open(final String method, final String bucket, @@ -614,9 +615,9 @@ public class AmazonS3 { m.init(privateKey); sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes("UTF-8"))); } catch (NoSuchAlgorithmException e) { - throw new IOException("No " + HMAC + " support:" + e.getMessage()); + throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage())); } catch (InvalidKeyException e) { - throw new IOException("Invalid key: " + e.getMessage()); + throw new IOException(MessageFormat.format(JGitText.get().invalidKey, e.getMessage())); } c.setRequestProperty("Authorization", "AWS " + publicKey + ":" + sec); } @@ -668,7 +669,7 @@ public class AmazonS3 { try { xr = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { - throw new IOException("No XML parser available."); + throw new IOException(JGitText.get().noXMLParserAvailable); } xr.setContentHandler(this); final InputStream in = c.getInputStream(); @@ -676,7 +677,7 @@ public class AmazonS3 { xr.parse(new InputSource(in)); } catch (SAXException parsingError) { final IOException p; - p = new IOException("Error listing " + prefix); + p = new IOException(MessageFormat.format(JGitText.get().errorListing, prefix)); p.initCause(parsingError); throw p; } finally { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java index 1339b86913..30d3bb13e7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java @@ -52,6 +52,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Ref; @@ -111,7 +112,7 @@ public abstract class BaseConnection implements Connection { protected void markStartedOperation() throws TransportException { if (startedOperation) throw new TransportException( - "Only one operation call per connection is supported."); + JGitText.get().onlyOneOperationCallPerConnectionIsSupported); startedOperation = true; } @@ -136,7 +137,7 @@ public abstract class BaseConnection implements Connection { */ protected void setMessageWriter(Writer writer) { if (messageWriter != null) - throw new IllegalStateException("Writer already initialized"); + throw new IllegalStateException(JGitText.get().writerAlreadyInitialized); messageWriter = writer; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java index 7b6d3e121a..2927cada9c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java @@ -50,10 +50,12 @@ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.MessageFormat; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.RemoteRepositoryException; @@ -230,8 +232,8 @@ abstract class BasePackConnection extends BaseConnection { name = name.substring(0, name.length() - 3); final Ref prior = avail.get(name); if (prior == null) - throw new PackProtocolException(uri, "advertisement of " - + name + "^{} came before " + name); + throw new PackProtocolException(uri, MessageFormat.format( + JGitText.get().advertisementCameBefore, name, name)); if (prior.getPeeledObjectId() != null) throw duplicateAdvertisement(name + "^{}"); @@ -258,7 +260,7 @@ abstract class BasePackConnection extends BaseConnection { * possibly why. */ protected TransportException noRepository() { - return new NoRemoteRepositoryException(uri, "not found."); + return new NoRemoteRepositoryException(uri, JGitText.get().notFound); } protected boolean isCapableOf(final String option) { @@ -274,8 +276,7 @@ abstract class BasePackConnection extends BaseConnection { } private PackProtocolException duplicateAdvertisement(final String name) { - return new PackProtocolException(uri, "duplicate advertisements of " - + name); + return new PackProtocolException(uri, MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, name)); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java index 7b90ec199f..2819ae26de 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java @@ -47,11 +47,13 @@ package org.eclipse.jgit.transport; import java.io.IOException; import java.io.InputStream; +import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.AnyObjectId; @@ -391,8 +393,7 @@ abstract class BasePackFetchConnection extends BasePackConnection implements // ACK status to tell us common objects for reuse in future // requests. If its not enabled, we can't talk to the peer. // - throw new PackProtocolException(uri, "stateless RPC requires " - + OPTION_MULTI_ACK_DETAILED + " to be enabled"); + throw new PackProtocolException(uri, MessageFormat.format(JGitText.get().statelessRPCRequiresOptionToBeEnabled, OPTION_MULTI_ACK_DETAILED)); } return line.toString(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java index e10cefd3ab..44ccd2d6ad 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java @@ -45,10 +45,12 @@ package org.eclipse.jgit.transport; import java.io.IOException; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.PackProtocolException; @@ -137,7 +139,7 @@ class BasePackPushConnection extends BasePackConnection implements } catch (TransportException e) { // Fall through. } - return new TransportException(uri, "push not permitted"); + return new TransportException(uri, JGitText.get().pushNotPermitted); } protected void doPush(final ProgressMonitor monitor, @@ -158,8 +160,7 @@ class BasePackPushConnection extends BasePackConnection implements // int b = in.read(); if (0 <= b) - throw new TransportException(uri, "expected EOF;" - + " received '" + (char) b + "' instead"); + throw new TransportException(uri, MessageFormat.format(JGitText.get().expectedEOFReceived, (char) b)); } } } catch (TransportException e) { @@ -201,7 +202,7 @@ class BasePackPushConnection extends BasePackConnection implements } if (monitor.isCancelled()) - throw new TransportException(uri, "push cancelled"); + throw new TransportException(uri, JGitText.get().pushCancelled); pckOut.end(); outNeedsEnd = false; } @@ -252,13 +253,11 @@ class BasePackPushConnection extends BasePackConnection implements throws IOException { final String unpackLine = readStringLongTimeout(); if (!unpackLine.startsWith("unpack ")) - throw new PackProtocolException(uri, "unexpected report line: " - + unpackLine); + throw new PackProtocolException(uri, MessageFormat.format(JGitText.get().unexpectedReportLine, unpackLine)); final String unpackStatus = unpackLine.substring("unpack ".length()); if (!unpackStatus.equals("ok")) - throw new TransportException(uri, - "error occurred during unpacking on the remote end: " - + unpackStatus); + throw new TransportException(uri, MessageFormat.format( + JGitText.get().errorOccurredDuringUnpackingOnTheRemoteEnd, unpackStatus)); String refLine; while ((refLine = pckIn.readString()) != PacketLineIn.END) { @@ -272,16 +271,15 @@ class BasePackPushConnection extends BasePackConnection implements refNameEnd = refLine.indexOf(" ", 3); } if (refNameEnd == -1) - throw new PackProtocolException(uri - + ": unexpected report line: " + refLine); + throw new PackProtocolException(MessageFormat.format(JGitText.get().unexpectedReportLine2 + , uri, refLine)); final String refName = refLine.substring(3, refNameEnd); final String message = (ok ? null : refLine .substring(refNameEnd + 1)); final RemoteRefUpdate rru = refUpdates.get(refName); if (rru == null) - throw new PackProtocolException(uri - + ": unexpected ref report: " + refName); + throw new PackProtocolException(MessageFormat.format(JGitText.get().unexpectedRefReport, uri, refName)); if (ok) { rru.setStatus(Status.OK); } else { @@ -291,9 +289,8 @@ class BasePackPushConnection extends BasePackConnection implements } for (final RemoteRefUpdate rru : refUpdates.values()) { if (rru.getStatus() == Status.AWAITING_REPORT) - throw new PackProtocolException(uri - + ": expected report for ref " + rru.getRemoteName() - + " not received"); + throw new PackProtocolException(MessageFormat.format( + JGitText.get().expectedReportForRefNotReceived , uri, rru.getRemoteName())); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java index c788244f74..3b97dfc0d6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java @@ -50,6 +50,7 @@ package org.eclipse.jgit.transport; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -59,6 +60,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.MissingBundlePrerequisiteException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.PackProtocolException; @@ -101,7 +103,7 @@ class BundleFetchConnection extends BaseFetchConnection { readBundleV2(); break; default: - throw new TransportException(transport.uri, "not a bundle"); + throw new TransportException(transport.uri, JGitText.get().notABundle); } } catch (TransportException err) { close(); @@ -119,7 +121,7 @@ class BundleFetchConnection extends BaseFetchConnection { final String rev = readLine(new byte[1024]); if (TransportBundle.V2_BUNDLE_SIGNATURE.equals(rev)) return 2; - throw new TransportException(transport.uri, "not a bundle"); + throw new TransportException(transport.uri, JGitText.get().notABundle); } private void readBundleV2() throws IOException { @@ -151,7 +153,7 @@ class BundleFetchConnection extends BaseFetchConnection { private PackProtocolException duplicateAdvertisement(final String name) { return new PackProtocolException(transport.uri, - "duplicate advertisements of " + name); + MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, name)); } private String readLine(final byte[] hdrbuf) throws IOException { @@ -227,8 +229,8 @@ class BundleFetchConnection extends BaseFetchConnection { } catch (MissingObjectException notFound) { missing.put(p, e.getValue()); } catch (IOException err) { - throw new TransportException(transport.uri, "Cannot read commit " - + p.name(), err); + throw new TransportException(transport.uri + , MessageFormat.format(JGitText.get().cannotReadCommit, p.name()), err); } } if (!missing.isEmpty()) @@ -253,7 +255,7 @@ class BundleFetchConnection extends BaseFetchConnection { } } } catch (IOException err) { - throw new TransportException(transport.uri, "Cannot read object", err); + throw new TransportException(transport.uri, JGitText.get().cannotReadObject, err); } if (remaining > 0) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java index 7b0a5eec45..7e91557b09 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java @@ -47,11 +47,13 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.text.MessageFormat; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.TreeMap; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -112,9 +114,9 @@ public class BundleWriter { */ public void include(final String name, final AnyObjectId id) { if (!Repository.isValidRefName(name)) - throw new IllegalArgumentException("Invalid ref name: " + name); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidRefName, name)); if (include.containsKey(name)) - throw new IllegalStateException("Duplicate ref: " + name); + throw new IllegalStateException(JGitText.get().duplicateRef + name); include.put(name, id.toObjectId()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java index cafcd7b4bd..39c7ae8f01 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java @@ -57,6 +57,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; @@ -250,7 +251,7 @@ public class Daemon { */ public synchronized void start() throws IOException { if (acceptThread != null) - throw new IllegalStateException("Daemon already running"); + throw new IllegalStateException(JGitText.get().daemonAlreadyRunning); final ServerSocket listenSock = new ServerSocket( myAddress != null ? myAddress.getPort() : 0, BACKLOG, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index b86f86d2f9..fc203f69c8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -48,6 +48,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -57,6 +58,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; @@ -122,8 +124,8 @@ class FetchProcess { final Set<Ref> matched = new HashSet<Ref>(); for (final RefSpec spec : toFetch) { if (spec.getSource() == null) - throw new TransportException( - "Source ref not specified for refspec: " + spec); + throw new TransportException(MessageFormat.format( + JGitText.get().sourceRefNotSpecifiedForRefspec, spec)); if (spec.isWildcard()) expandWildcard(spec, matched); @@ -181,8 +183,8 @@ class FetchProcess { u.update(walk); result.add(u); } catch (IOException err) { - throw new TransportException("Failure updating tracking ref " - + u.getLocalName() + ": " + err.getMessage(), err); + throw new TransportException(MessageFormat.format( + JGitText.get().failureUpdatingTrackingRef, u.getLocalName(), err.getMessage()), err); } } @@ -190,8 +192,8 @@ class FetchProcess { try { updateFETCH_HEAD(result); } catch (IOException err) { - throw new TransportException("Failure updating FETCH_HEAD: " - + err.getMessage(), err); + throw new TransportException(MessageFormat.format( + JGitText.get().failureUpdatingFETCH_HEAD, err.getMessage()), err); } } } @@ -207,7 +209,7 @@ class FetchProcess { if (transport.isCheckFetchedObjects() && !conn.didFetchTestConnectivity() && !askForIsComplete()) throw new TransportException(transport.getURI(), - "peer did not supply a complete object graph"); + JGitText.get().peerDidNotSupplyACompleteObjectGraph); } private void closeConnection(final FetchResult result) { @@ -301,7 +303,7 @@ class FetchProcess { } catch (MissingObjectException e) { return false; } catch (IOException e) { - throw new TransportException("Unable to check connectivity.", e); + throw new TransportException(JGitText.get().unableToCheckConnectivity, e); } } @@ -317,8 +319,7 @@ class FetchProcess { throws TransportException { final Ref src = conn.getRef(spec.getSource()); if (src == null) { - throw new TransportException("Remote does not have " - + spec.getSource() + " available for fetch."); + throw new TransportException(MessageFormat.format(JGitText.get().remoteDoesNotHaveSpec, spec.getSource())); } if (matched.add(src)) want(src, spec); @@ -376,9 +377,8 @@ class FetchProcess { } catch (IOException err) { // Bad symbolic ref? That is the most likely cause. // - throw new TransportException("Cannot resolve" - + " local tracking ref " + spec.getDestination() - + " for updating.", err); + throw new TransportException( MessageFormat.format( + JGitText.get().cannotResolveLocalTrackingRefForUpdating, spec.getDestination()), err); } } @@ -432,13 +432,12 @@ class FetchProcess { case FORCED: break; default: - throw new TransportException(transport.getURI(), - "Cannot delete stale tracking ref " + name + ": " - + u.getResult().name()); + throw new TransportException(transport.getURI(), MessageFormat.format( + JGitText.get().cannotDeleteStaleTrackingRef2, name, u.getResult().name())); } } catch (IOException e) { - throw new TransportException(transport.getURI(), - "Cannot delete stale tracking ref " + name, e); + throw new TransportException(transport.getURI(), MessageFormat.format( + JGitText.get().cannotDeleteStaleTrackingRef, name), e); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java index 6eeccea841..2a5b4344f5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java @@ -52,6 +52,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; import java.security.MessageDigest; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -60,6 +61,7 @@ import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.lib.AnyObjectId; @@ -82,10 +84,10 @@ import org.eclipse.jgit.util.NB; /** Indexes Git pack files for local use. */ public class IndexPack { /** Progress message when reading raw data from the pack. */ - public static final String PROGRESS_DOWNLOAD = "Receiving objects"; + public static final String PROGRESS_DOWNLOAD = JGitText.get().receivingObjects; /** Progress message when computing names of delta compressed objects. */ - public static final String PROGRESS_RESOLVE_DELTA = "Resolving deltas"; + public static final String PROGRESS_RESOLVE_DELTA = JGitText.get().resolvingDeltas; /** * Size of the internal stream buffer. @@ -392,20 +394,19 @@ public class IndexPack { indexOneObject(); progress.update(1); if (progress.isCancelled()) - throw new IOException("Download cancelled"); + throw new IOException(JGitText.get().downloadCancelled); } readPackFooter(); endInput(); progress.endTask(); if (deltaCount > 0) { if (packOut == null) - throw new IOException("need packOut"); + throw new IOException(JGitText.get().needPackOut); resolveDeltas(progress); if (entryCount < objectCount) { if (!fixThin) { - throw new IOException("pack has " - + (objectCount - entryCount) - + " unresolved deltas"); + throw new IOException(MessageFormat.format( + JGitText.get().packHasUnresolvedDeltas, (objectCount - entryCount))); } fixThinPack(progress); } @@ -458,7 +459,7 @@ public class IndexPack { resolveDeltas(entries[i]); progress.update(entryCount - before); if (progress.isCancelled()) - throw new IOException("Download cancelled during indexing"); + throw new IOException(JGitText.get().downloadCancelledDuringIndexing); } progress.endTask(); } @@ -505,12 +506,12 @@ public class IndexPack { break; } default: - throw new IOException("Unknown object type " + typeCode + "."); + throw new IOException(MessageFormat.format(JGitText.get().unknownObjectType, typeCode)); } final int crc32 = (int) crc.getValue(); if (oldCRC != crc32) - throw new IOException("Corruption detected re-reading at " + pos); + throw new IOException(MessageFormat.format(JGitText.get().corruptionDetectedReReadingAt, pos)); if (oe == null) { objectDigest.update(Constants.encodedTypeString(type)); objectDigest.update((byte) ' '); @@ -602,7 +603,7 @@ public class IndexPack { resolveChildDeltas(oe.getOffset(), typeCode, data, oe); if (progress.isCancelled()) - throw new IOException("Download cancelled during indexing"); + throw new IOException(JGitText.get().downloadCancelledDuringIndexing); } def.end(); @@ -691,7 +692,7 @@ public class IndexPack { if (!Arrays.equals(origDigest.digest(), origcsum) || !Arrays.equals(tailDigest.digest(), tailcsum)) - throw new IOException("Pack corrupted while writing to filesystem"); + throw new IOException(JGitText.get().packCorruptedWhileWritingToFilesystem); packcsum = packDigest.digest(); packOut.write(packcsum); @@ -730,11 +731,11 @@ public class IndexPack { final int p = fillFromInput(hdrln); for (int k = 0; k < Constants.PACK_SIGNATURE.length; k++) if (buf[p + k] != Constants.PACK_SIGNATURE[k]) - throw new IOException("Not a PACK file."); + throw new IOException(JGitText.get().notAPACKFile); final long vers = NB.decodeUInt32(buf, p + 4); if (vers != 2 && vers != 3) - throw new IOException("Unsupported pack version " + vers + "."); + throw new IOException(MessageFormat.format(JGitText.get().unsupportedPackVersion, vers)); objectCount = NB.decodeUInt32(buf, p + 8); use(hdrln); } @@ -750,7 +751,7 @@ public class IndexPack { packOut.write(packcsum); if (!Arrays.equals(cmpcsum, packcsum)) - throw new CorruptObjectException("Packfile checksum incorrect."); + throw new CorruptObjectException(JGitText.get().corruptObjectPackfileChecksumIncorrect); } // Cleanup all resources associated with our input parsing. @@ -814,7 +815,7 @@ public class IndexPack { break; } default: - throw new IOException("Unknown object type " + typeCode + "."); + throw new IOException(MessageFormat.format(JGitText.get().unknownObjectType, typeCode)); } } @@ -839,9 +840,8 @@ public class IndexPack { try { objCheck.check(type, data); } catch (CorruptObjectException e) { - throw new IOException("Invalid " - + Constants.typeString(type) + " " + id.name() - + ":" + e.getMessage()); + throw new IOException(MessageFormat.format(JGitText.get().invalidObject + , Constants.typeString(type) , id.name() , e.getMessage())); } } @@ -849,7 +849,7 @@ public class IndexPack { if (ldr != null) { final byte[] existingData = ldr.getCachedBytes(); if (ldr.getType() != type || !Arrays.equals(data, existingData)) { - throw new IOException("Collision on " + id.name()); + throw new IOException(MessageFormat.format(JGitText.get().collisionOn, id.name())); } } } @@ -904,7 +904,7 @@ public class IndexPack { } next = in.read(buf, next, free); if (next <= 0) - throw new EOFException("Packfile is truncated."); + throw new EOFException(JGitText.get().packfileIsTruncated); bAvail += next; } return bOffset; @@ -924,7 +924,7 @@ public class IndexPack { } next = packOut.read(buf, next, free); if (next <= 0) - throw new EOFException("Packfile is truncated."); + throw new EOFException(JGitText.get().packfileIsTruncated); bAvail += next; } return bOffset; @@ -966,7 +966,7 @@ public class IndexPack { n += inf.inflate(dst, n, free); } if (n != sz) - throw new DataFormatException("wrong decompressed length"); + throw new DataFormatException(JGitText.get().wrongDecompressedLength); n = bAvail - inf.getRemaining(); if (n > 0) { crc.update(buf, p, n); @@ -998,7 +998,7 @@ public class IndexPack { n += inf.inflate(dst, n, dst.length - n); } if (n != sz) - throw new DataFormatException("wrong decompressed length"); + throw new DataFormatException(JGitText.get().wrongDecompressedLength); n = bAvail - inf.getRemaining(); if (n > 0) { crc.update(buf, p, n); @@ -1043,8 +1043,8 @@ public class IndexPack { } private static CorruptObjectException corrupt(final DataFormatException dfe) { - return new CorruptObjectException("Packfile corruption detected: " - + dfe.getMessage()); + return new CorruptObjectException(MessageFormat.format( + JGitText.get().packfileCorruptionDetected, dfe.getMessage())); } private static class DeltaChain extends ObjectId { @@ -1138,7 +1138,7 @@ public class IndexPack { // to create it. There is no way to move this pack in. // cleanupTemporaryFiles(); - throw new IOException("Cannot create " + packDir.getAbsolutePath()); + throw new IOException(MessageFormat.format(JGitText.get().cannotCreateDirectory, packDir.getAbsolutePath())); } if (finalPack.exists()) { @@ -1154,7 +1154,7 @@ public class IndexPack { // try { if (!keep.lock(lockMessage)) - throw new IOException("Cannot lock pack in " + finalPack); + throw new IOException(MessageFormat.format(JGitText.get().cannotLockPackIn, finalPack)); } catch (IOException e) { cleanupTemporaryFiles(); throw e; @@ -1164,7 +1164,7 @@ public class IndexPack { if (!dstPack.renameTo(finalPack)) { cleanupTemporaryFiles(); keep.unlock(); - throw new IOException("Cannot move pack to " + finalPack); + throw new IOException(MessageFormat.format(JGitText.get().cannotMovePackTo, finalPack)); } if (!dstIdx.renameTo(finalIdx)) { @@ -1172,7 +1172,7 @@ public class IndexPack { keep.unlock(); if (!finalPack.delete()) finalPack.deleteOnExit(); - throw new IOException("Cannot move index to " + finalIdx); + throw new IOException(MessageFormat.format(JGitText.get().cannotMoveIndexTo, finalIdx)); } try { @@ -1199,4 +1199,4 @@ public class IndexPack { if (needNewObjectIds()) newObjectIds.add(oe); } -}
\ No newline at end of file +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index 170e4ddbe0..3821d696ed 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -47,7 +47,9 @@ package org.eclipse.jgit.transport; import java.io.IOException; import java.io.InputStream; +import java.text.MessageFormat; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.MutableObjectId; @@ -82,7 +84,7 @@ class PacketLineIn { AckNackResult readACK(final MutableObjectId returnedId) throws IOException { final String line = readString(); if (line.length() == 0) - throw new PackProtocolException("Expected ACK/NAK, found EOF"); + throw new PackProtocolException(JGitText.get().expectedACKNAKFoundEOF); if ("NAK".equals(line)) return AckNackResult.NAK; if (line.startsWith("ACK ")) { @@ -98,7 +100,7 @@ class PacketLineIn { else if (arg.equals(" ready")) return AckNackResult.ACK_READY; } - throw new PackProtocolException("Expected ACK/NAK, got: " + line); + throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedACKNAKGot, line)); } String readString() throws IOException { @@ -142,9 +144,9 @@ class PacketLineIn { throw new ArrayIndexOutOfBoundsException(); return len; } catch (ArrayIndexOutOfBoundsException err) { - throw new IOException("Invalid packet line header: " - + (char) lineBuffer[0] + (char) lineBuffer[1] - + (char) lineBuffer[2] + (char) lineBuffer[3]); + throw new IOException(MessageFormat.format(JGitText.get().invalidPacketLineHeader, + "" + (char) lineBuffer[0] + (char) lineBuffer[1] + + (char) lineBuffer[2] + (char) lineBuffer[3])); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java index 03b783427a..02497cb06f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java @@ -44,10 +44,12 @@ package org.eclipse.jgit.transport; import java.io.IOException; +import java.text.MessageFormat; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; @@ -66,7 +68,7 @@ import org.eclipse.jgit.transport.RemoteRefUpdate.Status; */ class PushProcess { /** Task name for {@link ProgressMonitor} used during opening connection. */ - static final String PROGRESS_OPENING_CONNECTION = "Opening connection"; + static final String PROGRESS_OPENING_CONNECTION = JGitText.get().openingConnection; /** Transport used to perform this operation. */ private final Transport transport; @@ -97,9 +99,8 @@ class PushProcess { this.toPush = new HashMap<String, RemoteRefUpdate>(); for (final RemoteRefUpdate rru : toPush) { if (this.toPush.put(rru.getRemoteName(), rru) != null) - throw new TransportException( - "Duplicate remote ref update is illegal. Affected remote name: " - + rru.getRemoteName()); + throw new TransportException(MessageFormat.format( + JGitText.get().duplicateRemoteRefUpdateIsIllegal, rru.getRemoteName())); } } @@ -200,9 +201,8 @@ class PushProcess { } catch (MissingObjectException x) { fastForward = false; } catch (Exception x) { - throw new TransportException(transport.getURI(), - "reading objects from local repository failed: " - + x.getMessage(), x); + throw new TransportException(transport.getURI(), MessageFormat.format( + JGitText.get().readingObjectsFromLocalRepositoryFailed, x.getMessage()), x); } rru.setFastForward(fastForward); if (!fastForward && !rru.isForceUpdate()) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java index 4e62d7427f..e42b7fe0c9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java @@ -57,6 +57,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -64,6 +65,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.lib.Config; @@ -724,7 +726,7 @@ public class ReceivePack { } if (line.length() < 83) { - final String m = "error: invalid protocol: wanted 'old new ref'"; + final String m = JGitText.get().errorInvalidProtocolWantedOldNewRef; sendError(m); throw new PackProtocolException(m); } @@ -898,7 +900,7 @@ public class ReceivePack { // other requested old id is invalid. // cmd.setResult(Result.REJECTED_OTHER_REASON, - "invalid old id sent"); + JGitText.get().invalidOldIdSent); continue; } @@ -906,7 +908,7 @@ public class ReceivePack { if (ref == null) { // The ref must have been advertised in order to be updated. // - cmd.setResult(Result.REJECTED_OTHER_REASON, "no such ref"); + cmd.setResult(Result.REJECTED_OTHER_REASON, JGitText.get().noSuchRef); continue; } @@ -915,7 +917,7 @@ public class ReceivePack { // object id we advertised. // cmd.setResult(Result.REJECTED_OTHER_REASON, - "invalid old id sent"); + JGitText.get().invalidOldIdSent); continue; } @@ -958,7 +960,7 @@ public class ReceivePack { if (!cmd.getRefName().startsWith(Constants.R_REFS) || !Repository.isValidRefName(cmd.getRefName())) { - cmd.setResult(Result.REJECTED_OTHER_REASON, "funny refname"); + cmd.setResult(Result.REJECTED_OTHER_REASON, JGitText.get().funnyRefname); } } } @@ -997,8 +999,8 @@ public class ReceivePack { break; } } catch (IOException err) { - cmd.setResult(Result.REJECTED_OTHER_REASON, "lock error: " - + err.getMessage()); + cmd.setResult(Result.REJECTED_OTHER_REASON, MessageFormat.format( + JGitText.get().lockError, err.getMessage())); } } @@ -1047,7 +1049,7 @@ public class ReceivePack { private void sendStatusReport(final boolean forClient, final Reporter out) throws IOException { if (unpackError != null) { - out.sendString("unpack error " + unpackError.getMessage()); + out.sendString(MessageFormat.format(JGitText.get().unpackError, unpackError.getMessage())); if (forClient) { for (final ReceiveCommand cmd : commands) { out.sendString("ng " + cmd.getRefName() diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java index 154ae3fedc..ca6f01500b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java @@ -43,6 +43,9 @@ package org.eclipse.jgit.transport; +import java.text.MessageFormat; + +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; @@ -125,7 +128,7 @@ public class RefSpec { if (c == 0) { s = s.substring(1); if (isWildcard(s)) - throw new IllegalArgumentException("Invalid wildcards " + spec); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidWildcards, spec)); dstName = s; } else if (c > 0) { srcName = s.substring(0, c); @@ -133,10 +136,10 @@ public class RefSpec { if (isWildcard(srcName) && isWildcard(dstName)) wildcard = true; else if (isWildcard(srcName) || isWildcard(dstName)) - throw new IllegalArgumentException("Invalid wildcards " + spec); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidWildcards, spec)); } else { if (isWildcard(s)) - throw new IllegalArgumentException("Invalid wildcards " + spec); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidWildcards, spec)); srcName = s; } } @@ -211,9 +214,9 @@ public class RefSpec { final RefSpec r = new RefSpec(this); r.srcName = source; if (isWildcard(r.srcName) && r.dstName == null) - throw new IllegalStateException("Destination is not a wildcard."); + throw new IllegalStateException(JGitText.get().destinationIsNotAWildcard); if (isWildcard(r.srcName) != isWildcard(r.dstName)) - throw new IllegalStateException("Source/Destination must match."); + throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch); return r; } @@ -250,9 +253,9 @@ public class RefSpec { final RefSpec r = new RefSpec(this); r.dstName = destination; if (isWildcard(r.dstName) && r.srcName == null) - throw new IllegalStateException("Source is not a wildcard."); + throw new IllegalStateException(JGitText.get().sourceIsNotAWildcard); if (isWildcard(r.srcName) != isWildcard(r.dstName)) - throw new IllegalStateException("Source/Destination must match."); + throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch); return r; } @@ -271,7 +274,7 @@ public class RefSpec { public RefSpec setSourceDestination(final String source, final String destination) { if (isWildcard(source) != isWildcard(destination)) - throw new IllegalArgumentException("Source/Destination must match."); + throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch); final RefSpec r = new RefSpec(this); r.wildcard = isWildcard(source); r.srcName = source; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java index b2aa6335d8..1b17c9f0f4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java @@ -44,7 +44,9 @@ package org.eclipse.jgit.transport; import java.io.IOException; +import java.text.MessageFormat; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevWalk; @@ -184,13 +186,13 @@ public class RemoteRefUpdate { final String localName, final ObjectId expectedOldObjectId) throws IOException { if (remoteName == null) - throw new IllegalArgumentException("Remote name can't be null."); + throw new IllegalArgumentException(JGitText.get().remoteNameCantBeNull); this.srcRef = srcRef; this.newObjectId = (srcRef == null ? ObjectId.zeroId() : localDb .resolve(srcRef)); if (newObjectId == null) - throw new IOException("Source ref " + srcRef - + " doesn't resolve to any object."); + throw new IOException(MessageFormat.format( + JGitText.get().sourceRefDoesntResolveToAnyObject, srcRef)); this.remoteName = remoteName; this.forceUpdate = forceUpdate; if (localName != null && localDb != null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java index 796cb745a1..1f9883e504 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java @@ -49,9 +49,11 @@ import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE; import java.io.IOException; import java.io.InputStream; import java.io.Writer; +import java.text.MessageFormat; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; @@ -75,7 +77,7 @@ import org.eclipse.jgit.util.RawParseUtils; * @see SideBandOutputStream */ class SideBandInputStream extends InputStream { - private static final String PFX_REMOTE = "remote: "; + private static final String PFX_REMOTE = JGitText.get().prefixRemote; static final int CH_DATA = 1; @@ -170,7 +172,7 @@ class SideBandInputStream extends InputStream { eof = true; throw new TransportException(PFX_REMOTE + readString(available)); default: - throw new PackProtocolException("Invalid channel " + channel); + throw new PackProtocolException(MessageFormat.format(JGitText.get().invalidChannel, channel)); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java index 6e0a52627e..31acdcde5b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.transport; import java.io.IOException; import java.io.OutputStream; +import java.text.MessageFormat; + +import org.eclipse.jgit.JGitText; /** * Multiplexes data and progress messages. @@ -94,14 +97,11 @@ class SideBandOutputStream extends OutputStream { */ SideBandOutputStream(final int chan, final int sz, final OutputStream os) { if (chan <= 0 || chan > 255) - throw new IllegalArgumentException("channel " + chan - + " must be in range [0, 255]"); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().channelMustBeInRange0_255, chan)); if (sz <= HDR_SIZE) - throw new IllegalArgumentException("packet size " + sz - + " must be >= " + HDR_SIZE); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().packetSizeMustBeAtLeast, sz, HDR_SIZE)); else if (MAX_BUF < sz) - throw new IllegalArgumentException("packet size " + sz - + " must be <= " + MAX_BUF); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().packetSizeMustBeAtMost, sz, MAX_BUF)); out = os; buffer = new byte[sz]; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java index 5c6b498cad..d25a7b6180 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java @@ -50,6 +50,7 @@ package org.eclipse.jgit.transport; import java.net.ConnectException; import java.net.UnknownHostException; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; @@ -96,10 +97,10 @@ public abstract class SshTransport extends TcpTransport { */ public void setSshSessionFactory(SshSessionFactory factory) { if (factory == null) - throw new NullPointerException("The factory must not be null"); + throw new NullPointerException(JGitText.get().theFactoryMustNotBeNull); if (sock != null) throw new IllegalStateException( - "An SSH session has been already created"); + JGitText.get().anSSHSessionHasBeenAlreadyCreated); sch = factory; } @@ -133,7 +134,7 @@ public abstract class SshTransport extends TcpTransport { } catch (JSchException je) { final Throwable c = je.getCause(); if (c instanceof UnknownHostException) - throw new TransportException(uri, "unknown host"); + throw new TransportException(uri, JGitText.get().unknownHost); if (c instanceof ConnectException) throw new TransportException(uri, c.getMessage()); throw new TransportException(uri, je.getMessage(), je); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java index 66f36a0d27..82a5f23b6a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java @@ -44,6 +44,10 @@ package org.eclipse.jgit.transport; +import java.text.MessageFormat; + +import org.eclipse.jgit.JGitText; + /** Specification of annotated tag behavior during fetch. */ public enum TagOpt { /** @@ -105,6 +109,6 @@ public enum TagOpt { if (tagopt.option().equals(o)) return tagopt; } - throw new IllegalArgumentException("Invalid tag option: " + o); + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidTagOption, o)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index d6400963ac..c0b2eedc00 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -48,6 +48,7 @@ package org.eclipse.jgit.transport; import java.io.IOException; import java.net.URISyntaxException; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -56,6 +57,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; @@ -240,9 +242,8 @@ public abstract class Transport { throws NotSupportedException { final List<URIish> uris = getURIs(cfg, op); if (uris.isEmpty()) - throw new IllegalArgumentException( - "Remote config \"" - + cfg.getName() + "\" has no URIs associated"); + throw new IllegalArgumentException(MessageFormat.format( + JGitText.get().remoteConfigHasNoURIAssociated, cfg.getName())); final Transport tn = open(local, uris.get(0)); tn.applyConfig(cfg); return tn; @@ -351,7 +352,7 @@ public abstract class Transport { else if (TransportLocal.canHandle(remote)) return new TransportLocal(local, remote); - throw new NotSupportedException("URI not supported: " + remote); + throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, remote)); } /** @@ -787,7 +788,7 @@ public abstract class Transport { // If the caller did not ask for anything use the defaults. // if (fetch.isEmpty()) - throw new TransportException("Nothing to fetch."); + throw new TransportException(JGitText.get().nothingToFetch); toFetch = fetch; } else if (!fetch.isEmpty()) { // If the caller asked for something specific without giving @@ -862,12 +863,11 @@ public abstract class Transport { try { toPush = findRemoteRefUpdatesFor(push); } catch (final IOException e) { - throw new TransportException( - "Problem with resolving push ref specs locally: " - + e.getMessage(), e); + throw new TransportException(MessageFormat.format( + JGitText.get().problemWithResolvingPushRefSpecsLocally, e.getMessage()), e); } if (toPush.isEmpty()) - throw new TransportException("Nothing to push."); + throw new TransportException(JGitText.get().nothingToPush); } final PushProcess pushProcess = new PushProcess(this, toPush); return pushProcess.execute(monitor); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index a3fd1ceae5..bcf6e873fe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -50,6 +50,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URLConnection; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -57,6 +58,7 @@ import java.util.Map; import java.util.Properties; import java.util.TreeMap; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; @@ -133,7 +135,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { try { props = AmazonS3.properties(propsFile); } catch (IOException e) { - throw new NotSupportedException("cannot read " + propsFile, e); + throw new NotSupportedException(MessageFormat.format(JGitText.get().cannotReadFile, propsFile), e); } } else { props = new Properties(); @@ -277,7 +279,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { + "refs"))) readRef(avail, "refs/" + n); } catch (IOException e) { - throw new TransportException(getURI(), "cannot list refs", e); + throw new TransportException(getURI(), JGitText.get().cannotListRefs, e); } } @@ -295,11 +297,12 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { } catch (FileNotFoundException noRef) { return null; } catch (IOException err) { - throw new TransportException(getURI(), "read " + ref, err); + throw new TransportException(getURI(), MessageFormat.format( + JGitText.get().transportExceptionReadRef, ref), err); } if (s == null) - throw new TransportException(getURI(), "Empty ref: " + rn); + throw new TransportException(getURI(), MessageFormat.format(JGitText.get().transportExceptionEmptyRef, rn)); if (s.startsWith("ref: ")) { final String target = s.substring("ref: ".length()); @@ -320,7 +323,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { return r; } - throw new TransportException(getURI(), "Bad ref: " + rn + ": " + s); + throw new TransportException(getURI(), MessageFormat.format(JGitText.get().transportExceptionBadRef, rn, s)); } private Storage loose(final Ref r) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java index 17e3bdd229..0245818fe3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java @@ -51,6 +51,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; @@ -84,7 +85,7 @@ class TransportBundleFile extends Transport implements TransportBundle { try { src = new FileInputStream(bundle); } catch (FileNotFoundException err) { - throw new TransportException(uri, "not found"); + throw new TransportException(uri, JGitText.get().notFound); } return new BundleFetchConnection(this, src); } @@ -92,7 +93,7 @@ class TransportBundleFile extends Transport implements TransportBundle { @Override public PushConnection openPush() throws NotSupportedException { throw new NotSupportedException( - "Push is not supported for bundle transport"); + JGitText.get().pushIsNotSupportedForBundleTransport); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleStream.java index e5188bb236..defc8c2bb6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleStream.java @@ -49,6 +49,7 @@ package org.eclipse.jgit.transport; import java.io.IOException; import java.io.InputStream; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; @@ -92,7 +93,7 @@ public class TransportBundleStream extends Transport implements TransportBundle @Override public FetchConnection openFetch() throws TransportException { if (src == null) - throw new TransportException(uri, "Only one fetch supported"); + throw new TransportException(uri, JGitText.get().onlyOneFetchSupported); try { return new BundleFetchConnection(this, src); } finally { @@ -103,7 +104,7 @@ public class TransportBundleStream extends Transport implements TransportBundle @Override public PushConnection openPush() throws NotSupportedException { throw new NotSupportedException( - "Push is not supported for bundle transport"); + JGitText.get().pushIsNotSupportedForBundleTransport); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java index 8a0b4357cd..5ad57768fe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java @@ -56,6 +56,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; @@ -107,7 +108,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport { // ignore a failure during close, we're already failing } if (c instanceof UnknownHostException) - throw new TransportException(uri, "unknown host"); + throw new TransportException(uri, JGitText.get().unknownHost); if (c instanceof ConnectException) throw new TransportException(uri, c.getMessage()); throw new TransportException(uri, c.getMessage(), c); @@ -151,7 +152,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport { } catch (IOException err) { close(); throw new TransportException(uri, - "remote hung up unexpectedly", err); + JGitText.get().remoteHungUpUnexpectedly, err); } readAdvertisedRefs(); } @@ -190,7 +191,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport { } catch (IOException err) { close(); throw new TransportException(uri, - "remote hung up unexpectedly", err); + JGitText.get().remoteHungUpUnexpectedly, err); } readAdvertisedRefs(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java index 8df3ea5b2b..34b13b2d1d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java @@ -51,7 +51,9 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; +import java.text.MessageFormat; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; @@ -172,8 +174,8 @@ public class TransportGitSsh extends SshTransport implements PackTransport { IOException cause = null; if (why != null && why.length() > 0) cause = new IOException(why); - throw new TransportException(uri, "cannot execute: " - + commandFor(exe), cause); + throw new TransportException(uri, MessageFormat.format( + JGitText.get().cannotExecute, commandFor(exe)), cause); } } @@ -257,7 +259,7 @@ public class TransportGitSsh extends SshTransport implements PackTransport { } catch (IOException err) { close(); throw new TransportException(uri, - "remote hung up unexpectedly", err); + JGitText.get().remoteHungUpUnexpectedly, err); } try { @@ -325,7 +327,7 @@ public class TransportGitSsh extends SshTransport implements PackTransport { } catch (IOException err) { close(); throw new TransportException(uri, - "remote hung up unexpectedly", err); + JGitText.get().remoteHungUpUnexpectedly, err); } try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index f49828bf2d..71e7bf285e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -65,6 +65,7 @@ import java.net.MalformedURLException; import java.net.Proxy; import java.net.ProxySelector; import java.net.URL; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Map; @@ -73,6 +74,7 @@ import java.util.TreeMap; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.PackProtocolException; @@ -170,7 +172,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, baseUrl = new URL(uriString); objectsUrl = new URL(baseUrl, "objects/"); } catch (MalformedURLException e) { - throw new NotSupportedException("Invalid URL " + uri, e); + throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e); } http = local.getConfig().get(HTTP_KEY); proxySelector = ProxySelector.getDefault(); @@ -216,7 +218,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } catch (TransportException err) { throw err; } catch (IOException err) { - throw new TransportException(uri, "error reading info/refs", err); + throw new TransportException(uri, JGitText.get().errorReadingInfoRefs, err); } } @@ -265,8 +267,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport, break; default: - throw new TransportException(uri, "cannot read HEAD: " + status - + " " + conn.getResponseMessage()); + throw new TransportException(uri, MessageFormat.format( + JGitText.get().cannotReadHEAD, status, conn.getResponseMessage())); } } @@ -292,11 +294,11 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return new SmartHttpPushConnection(in); } else if (!useSmartHttp) { - final String msg = "smart HTTP push disabled"; + final String msg = JGitText.get().smartHTTPPushDisabled; throw new NotSupportedException(msg); } else { - final String msg = "remote does not support smart HTTP push"; + final String msg = JGitText.get().remoteDoesNotSupportSmartHTTPPush; throw new NotSupportedException(msg); } } finally { @@ -307,7 +309,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } catch (TransportException err) { throw err; } catch (IOException err) { - throw new TransportException(uri, "error reading info/refs", err); + throw new TransportException(uri, JGitText.get().errorReadingInfoRefs, err); } } @@ -335,7 +337,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, u = new URL(b.toString()); } catch (MalformedURLException e) { - throw new NotSupportedException("Invalid URL " + uri, e); + throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e); } try { @@ -352,10 +354,10 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return conn; case HttpURLConnection.HTTP_NOT_FOUND: - throw new NoRemoteRepositoryException(uri, u + " not found"); + throw new NoRemoteRepositoryException(uri, MessageFormat.format(JGitText.get().URLNotFound, u)); case HttpURLConnection.HTTP_FORBIDDEN: - throw new TransportException(uri, service + " not permitted"); + throw new TransportException(uri, MessageFormat.format(JGitText.get().serviceNotPermitted, service)); default: String err = status + " " + conn.getResponseMessage(); @@ -366,7 +368,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } catch (TransportException e) { throw e; } catch (IOException e) { - throw new TransportException(uri, "cannot open " + service, e); + throw new TransportException(uri, MessageFormat.format(JGitText.get().cannotOpenService, service), e); } } @@ -389,8 +391,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } IOException wrongContentType(String expType, String actType) { - final String why = "expected Content-Type " + expType - + "; received Content-Type " + actType; + final String why = MessageFormat.format(JGitText.get().expectedReceivedContentType, expType, actType); return new TransportException(uri, why); } @@ -410,9 +411,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport, final byte[] magic = new byte[5]; IO.readFully(in, magic, 0, magic.length); if (magic[4] != '#') { - throw new TransportException(uri, "expected pkt-line with" - + " '# service=', got '" + RawParseUtils.decode(magic) - + "'"); + throw new TransportException(uri, MessageFormat.format( + JGitText.get().expectedPktLineWithService, RawParseUtils.decode(magic))); } final PacketLineIn pckIn = new PacketLineIn(new UnionInputStream( @@ -420,8 +420,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport, final String exp = "# service=" + service; final String act = pckIn.readString(); if (!exp.equals(act)) { - throw new TransportException(uri, "expected '" + exp + "', got '" - + act + "'"); + throw new TransportException(uri, MessageFormat.format( + JGitText.get().expectedGot, exp, act)); } while (pckIn.readString() != PacketLineIn.END) { @@ -546,16 +546,15 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } private PackProtocolException outOfOrderAdvertisement(final String n) { - return new PackProtocolException("advertisement of " + n - + "^{} came before " + n); + return new PackProtocolException(MessageFormat.format(JGitText.get().advertisementOfCameBefore, n, n)); } private PackProtocolException invalidAdvertisement(final String n) { - return new PackProtocolException("invalid advertisement of " + n); + return new PackProtocolException(MessageFormat.format(JGitText.get().invalidAdvertisementOf, n)); } private PackProtocolException duplicateAdvertisement(final String n) { - return new PackProtocolException("duplicate advertisements of " + n); + return new PackProtocolException(MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, n)); } @Override @@ -667,9 +666,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport, // our request buffer. Send with a Content-Length header. // if (out.length() == 0) { - throw new TransportException(uri, "Starting read stage" - + " without written request data pending" - + " is not supported"); + throw new TransportException(uri, + JGitText.get().startingReadStageWithoutWrittenRequestDataPendingIsNotSupported); } // Try to compress the content, but only if that is smaller. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java index 22c436de3a..cf4dbd5392 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java @@ -56,6 +56,7 @@ import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; @@ -175,7 +176,7 @@ class TransportLocal extends Transport implements PackTransport { try { dst = new Repository(remoteGitDir); } catch (IOException err) { - throw new TransportException(uri, "not a git directory"); + throw new TransportException(uri, JGitText.get().notAGitDirectory); } final PipedInputStream in_r; @@ -199,7 +200,7 @@ class TransportLocal extends Transport implements PackTransport { out_w = new PipedOutputStream(out_r); } catch (IOException err) { dst.close(); - throw new TransportException(uri, "cannot connect pipes", err); + throw new TransportException(uri, JGitText.get().cannotConnectPipes, err); } worker = new Thread("JGit-Upload-Pack") { @@ -315,7 +316,7 @@ class TransportLocal extends Transport implements PackTransport { try { dst = new Repository(remoteGitDir); } catch (IOException err) { - throw new TransportException(uri, "not a git directory"); + throw new TransportException(uri, JGitText.get().notAGitDirectory); } final PipedInputStream in_r; @@ -331,7 +332,7 @@ class TransportLocal extends Transport implements PackTransport { out_w = new PipedOutputStream(out_r); } catch (IOException err) { dst.close(); - throw new TransportException(uri, "cannot connect pipes", err); + throw new TransportException(uri, JGitText.get().cannotConnectPipes, err); } worker = new Thread("JGit-Receive-Pack") { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index 80b94b2324..5939bc2f28 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -50,6 +50,7 @@ import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.Constants; /** @@ -107,7 +108,7 @@ public class URIish { host = matcher.group(2); path = matcher.group(3); } else - throw new URISyntaxException(s, "Cannot parse Git URI-ish"); + throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 3d5abd34bd..3381c0724a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -47,6 +47,7 @@ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -54,6 +55,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; @@ -371,7 +373,7 @@ public class UploadPack { if (line == PacketLineIn.END) break; if (!line.startsWith("want ") || line.length() < 45) - throw new PackProtocolException("expected want; got " + line); + throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedGot, "want", line)); if (isFirst && line.length() > 45) { String opt = line.substring(45); @@ -387,10 +389,10 @@ public class UploadPack { try { o = walk.parseAny(id); } catch (IOException e) { - throw new PackProtocolException(id.name() + " not valid", e); + throw new PackProtocolException(MessageFormat.format(JGitText.get().notValid, id.name()), e); } if (!o.has(ADVERTISED)) - throw new PackProtocolException(id.name() + " not valid"); + throw new PackProtocolException(MessageFormat.format(JGitText.get().notValid, id.name())); want(o); } } @@ -473,7 +475,7 @@ public class UploadPack { return true; } else { - throw new PackProtocolException("expected have; got " + line); + throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedGot, "have", line)); } } } @@ -521,7 +523,7 @@ public class UploadPack { i.remove(); } } catch (IOException e) { - throw new PackProtocolException("internal revision error", e); + throw new PackProtocolException(JGitText.get().internalRevisionError, e); } return wantCommits.isEmpty(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java index d368fb2cd7..b55de9265a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java @@ -51,6 +51,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; +import java.text.MessageFormat; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; @@ -61,6 +62,8 @@ import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; +import org.eclipse.jgit.JGitText; + abstract class WalkEncryption { static final WalkEncryption NONE = new NoEncryption(); @@ -84,18 +87,18 @@ abstract class WalkEncryption { if (v == null) v = ""; if (!version.equals(v)) - throw new IOException("Unsupported encryption version: " + v); + throw new IOException(MessageFormat.format(JGitText.get().unsupportedEncryptionVersion, v)); v = u.getHeaderField(p + JETS3T_CRYPTO_ALG); if (v == null) v = ""; if (!name.equals(v)) - throw new IOException("Unsupported encryption algorithm: " + v); + throw new IOException(JGitText.get().unsupportedEncryptionAlgorithm + v); } IOException error(final Throwable why) { final IOException e; - e = new IOException("Encryption error: " + why.getMessage()); + e = new IOException(MessageFormat.format(JGitText.get().encryptionError, why.getMessage())); e.initCause(why); return e; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java index ba4486144d..6254745476 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java @@ -49,6 +49,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.security.MessageDigest; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -58,6 +59,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.CompoundException; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.MissingObjectException; @@ -261,7 +263,7 @@ class WalkFetchConnection extends BaseFetchConnection { if (inWorkQueue.add(id)) workQueue.add(id); } catch (IOException e) { - throw new TransportException("Cannot read " + id.name(), e); + throw new TransportException(MessageFormat.format(JGitText.get().cannotRead, id.name()), e); } } } @@ -280,7 +282,7 @@ class WalkFetchConnection extends BaseFetchConnection { return; } } catch (IOException e) { - throw new TransportException("Cannot read " + id.name(), e); + throw new TransportException(MessageFormat.format(JGitText.get().cannotRead, id.name()), e); } switch (obj.getType()) { @@ -297,7 +299,7 @@ class WalkFetchConnection extends BaseFetchConnection { processTag(obj); break; default: - throw new TransportException("Unknown object type " + id.name()); + throw new TransportException(MessageFormat.format(JGitText.get().unknownObjectType, id.name())); } // If we had any prior errors fetching this object they are @@ -308,7 +310,7 @@ class WalkFetchConnection extends BaseFetchConnection { private void processBlob(final RevObject obj) throws TransportException { if (!local.hasObject(obj)) - throw new TransportException("Cannot read blob " + obj.name(), + throw new TransportException(MessageFormat.format(JGitText.get().cannotReadBlob, obj.name()), new MissingObjectException(obj, Constants.TYPE_BLOB)); obj.add(COMPLETE); } @@ -331,14 +333,12 @@ class WalkFetchConnection extends BaseFetchConnection { if (FileMode.GITLINK.equals(mode)) continue; treeWalk.getObjectId(idBuffer, 0); - throw new CorruptObjectException("Invalid mode " + mode - + " for " + idBuffer.name() + " " - + treeWalk.getPathString() + " in " - + obj.getId().name() + "."); + throw new CorruptObjectException(MessageFormat.format(JGitText.get().invalidModeFor + , mode, idBuffer.name(), treeWalk.getPathString(), obj.getId().name())); } } } catch (IOException ioe) { - throw new TransportException("Cannot read tree " + obj.name(), ioe); + throw new TransportException(MessageFormat.format(JGitText.get().cannotReadTree, obj.name()), ioe); } obj.add(COMPLETE); } @@ -445,7 +445,7 @@ class WalkFetchConnection extends BaseFetchConnection { List<Throwable> failures = fetchErrors.get(id.copy()); final TransportException te; - te = new TransportException("Cannot get " + id.name() + "."); + te = new TransportException(MessageFormat.format(JGitText.get().cannotGet, id.name())); if (failures != null && !failures.isEmpty()) { if (failures.size() == 1) te.initCause(failures.get(0)); @@ -521,8 +521,8 @@ class WalkFetchConnection extends BaseFetchConnection { // the object, but after indexing we didn't // actually find it in the pack. // - recordError(id, new FileNotFoundException("Object " + id.name() - + " not found in " + pack.packName + ".")); + recordError(id, new FileNotFoundException(MessageFormat.format( + JGitText.get().objectNotFoundIn, id.name(), pack.packName))); continue; } @@ -565,7 +565,7 @@ class WalkFetchConnection extends BaseFetchConnection { recordError(id, e); return false; } catch (IOException e) { - throw new TransportException("Cannot download " + id.name(), e); + throw new TransportException(MessageFormat.format(JGitText.get().cannotDownload, id.name()), e); } } @@ -601,18 +601,15 @@ class WalkFetchConnection extends BaseFetchConnection { idBuffer.fromRaw(objectDigest.digest(), 0); if (!AnyObjectId.equals(id, idBuffer)) { - throw new TransportException("Incorrect hash for " + id.name() - + "; computed " + idBuffer.name() + " as a " - + Constants.typeString(uol.getType()) + " from " - + compressed.length + " bytes."); + throw new TransportException(MessageFormat.format(JGitText.get().incorrectHashFor + , id.name(), idBuffer.name(), Constants.typeString(uol.getType()), compressed.length)); } if (objCheck != null) { try { objCheck.check(uol.getType(), uol.getCachedBytes()); } catch (CorruptObjectException e) { - throw new TransportException("Invalid " - + Constants.typeString(uol.getType()) + " " - + id.name() + ":" + e.getMessage()); + throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionInvalid + , Constants.typeString(uol.getType()), id.name(), e.getMessage())); } } } @@ -650,7 +647,7 @@ class WalkFetchConnection extends BaseFetchConnection { tmp.delete(); if (local.hasObject(id)) return; - throw new ObjectWritingException("Unable to store " + id.name() + "."); + throw new ObjectWritingException(MessageFormat.format(JGitText.get().unableToStore, id.name())); } private Collection<WalkRemoteObjectDatabase> expandOneAlternate( @@ -658,7 +655,7 @@ class WalkFetchConnection extends BaseFetchConnection { while (!noAlternatesYet.isEmpty()) { final WalkRemoteObjectDatabase wrr = noAlternatesYet.removeFirst(); try { - pm.beginTask("Listing alternates", ProgressMonitor.UNKNOWN); + pm.beginTask(JGitText.get().listingAlternates, ProgressMonitor.UNKNOWN); Collection<WalkRemoteObjectDatabase> altList = wrr .getAlternates(); if (altList != null && !altList.isEmpty()) @@ -679,15 +676,14 @@ class WalkFetchConnection extends BaseFetchConnection { try { markLocalObjComplete(revWalk.parseAny(r.getObjectId())); } catch (IOException readError) { - throw new TransportException("Local ref " + r.getName() - + " is missing object(s).", readError); + throw new TransportException(MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError); } } for (final ObjectId id : have) { try { markLocalObjComplete(revWalk.parseAny(id)); } catch (IOException readError) { - throw new TransportException("Missing assumed "+id.name(), readError); + throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionMissingAssumed, id.name()), readError); } } } @@ -726,7 +722,7 @@ class WalkFetchConnection extends BaseFetchConnection { pushLocalCommit(p); } } catch (IOException err) { - throw new TransportException("Local objects incomplete.", err); + throw new TransportException(JGitText.get().localObjectsIncomplete, err); } } @@ -769,9 +765,8 @@ class WalkFetchConnection extends BaseFetchConnection { if (FileMode.GITLINK.equals(mode)) continue; treeWalk.getObjectId(idBuffer, 0); - throw new CorruptObjectException("Invalid mode " + mode - + " for " + idBuffer.name() + " " - + treeWalk.getPathString() + " in " + tree.name() + "."); + throw new CorruptObjectException(MessageFormat.format(JGitText.get().corruptObjectInvalidMode3 + , mode, idBuffer.name(), treeWalk.getPathString(), tree.name())); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java index f977915bb3..0edf9678e4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java @@ -55,6 +55,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; @@ -145,7 +146,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { final String n = u.getRemoteName(); if (!n.startsWith("refs/") || !Repository.isValidRefName(n)) { u.setStatus(Status.REJECTED_OTHER_REASON); - u.setMessage("funny refname"); + u.setMessage(JGitText.get().funnyRefname); continue; } @@ -187,14 +188,14 @@ class WalkPushConnection extends BaseConnection implements PushConnection { u.setStatus(Status.REJECTED_OTHER_REASON); u.setMessage(err.getMessage()); } - throw new TransportException(uri, "failed updating refs", err); + throw new TransportException(uri, JGitText.get().failedUpdatingRefs, err); } } try { refWriter.writeInfoRefs(); } catch (IOException err) { - throw new TransportException(uri, "failed updating refs", err); + throw new TransportException(uri, JGitText.get().failedUpdatingRefs, err); } } @@ -279,7 +280,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { safeDelete(pathIdx); safeDelete(pathPack); - throw new TransportException(uri, "cannot store objects", err); + throw new TransportException(uri, JGitText.get().cannotStoreObjects, err); } } @@ -349,7 +350,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { final byte[] bytes = Constants.encode(ref); dest.writeFile(ROOT_DIR + Constants.HEAD, bytes); } catch (IOException e) { - throw new TransportException(uri, "cannot create HEAD", e); + throw new TransportException(uri, JGitText.get().cannotCreateHEAD, e); } try { @@ -358,7 +359,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { final byte[] bytes = Constants.encode(config); dest.writeFile(ROOT_DIR + "config", bytes); } catch (IOException e) { - throw new TransportException(uri, "cannot create config", e); + throw new TransportException(uri, JGitText.get().cannotCreateConfig, e); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java index 2aa644ce8b..f1743b378d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java @@ -50,10 +50,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -198,7 +200,7 @@ abstract class WalkRemoteObjectDatabase { * deletion is not supported, or deletion failed. */ void deleteFile(final String path) throws IOException { - throw new IOException("Deleting '" + path + "' not supported."); + throw new IOException(MessageFormat.format(JGitText.get().deletingNotSupported, path)); } /** @@ -230,7 +232,7 @@ abstract class WalkRemoteObjectDatabase { */ OutputStream writeFile(final String path, final ProgressMonitor monitor, final String monitorTask) throws IOException { - throw new IOException("Writing of '" + path + "' not supported."); + throw new IOException(MessageFormat.format(JGitText.get().writingNotSupported, path)); } /** @@ -428,7 +430,7 @@ abstract class WalkRemoteObjectDatabase { } catch (FileNotFoundException notPacked) { // Perhaps it wasn't worthwhile, or is just an older repository. } catch (IOException e) { - throw new TransportException(getURI(), "error in packed-refs", e); + throw new TransportException(getURI(), JGitText.get().errorInPackedRefs, e); } } @@ -449,7 +451,7 @@ abstract class WalkRemoteObjectDatabase { } if (line.charAt(0) == '^') { if (last == null) - throw new TransportException("Peeled line before ref."); + throw new TransportException(JGitText.get().peeledLineBeforeRef); final ObjectId id = ObjectId.fromString(line.substring(1)); last = new ObjectIdRef.PeeledTag(Ref.Storage.PACKED, last .getName(), last.getObjectId(), id); @@ -459,7 +461,7 @@ abstract class WalkRemoteObjectDatabase { final int sp = line.indexOf(' '); if (sp < 0) - throw new TransportException("Unrecognized ref: " + line); + throw new TransportException(MessageFormat.format(JGitText.get().unrecognizedRef, line)); final ObjectId id = ObjectId.fromString(line.substring(0, sp)); final String name = line.substring(sp + 1); if (peeled) |