From e341ec0afe5677c96326d2d6852549085e636f0b Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 25 Apr 2018 01:05:13 +0200 Subject: [PATCH] Fix non-externalized String warnings - suppress warning for non-translatable texts - externalize error messages Change-Id: Ieba42219b2c0b51a288f5a60438a6cc4f9dfe641 Signed-off-by: Matthias Sohn --- .../eclipse/jgit/internal/JGitText.properties | 2 + .../org/eclipse/jgit/internal/JGitText.java | 2 + .../eclipse/jgit/transport/RefAdvertiser.java | 11 +++-- .../jgit/transport/TransferConfig.java | 40 ++++++++------- .../eclipse/jgit/transport/UploadPack.java | 49 ++++++++++--------- 5 files changed, 58 insertions(+), 46 deletions(-) diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 28c414dcb2..01946e064a 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -708,6 +708,7 @@ unexpectedEndOfInput=Unexpected end of input unexpectedEofInPack=Unexpected EOF in partially created pack unexpectedHunkTrailer=Unexpected hunk trailer unexpectedOddResult=odd: {0} + {1} - {2} +unexpectedPacketLine=unexpected {0} unexpectedRefReport={0}: unexpected ref report: {1} unexpectedReportLine=unexpected report line: {0} unexpectedReportLine2={0} unexpected report line: {1} @@ -722,6 +723,7 @@ unknownObjectType=Unknown object type {0}. unknownObjectType2=unknown unknownRepositoryFormat=Unknown repository format unknownRepositoryFormat2=Unknown repository format "{0}"; expected "0". +unknownTransportCommand=unknown command {0} unknownZlibError=Unknown zlib error. unmergedPath=Unmerged path: {0} unmergedPaths=Repository contains unmerged paths diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 3c02302d22..6799576c78 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -769,6 +769,7 @@ public class JGitText extends TranslationBundle { /***/ public String unexpectedEofInPack; /***/ public String unexpectedHunkTrailer; /***/ public String unexpectedOddResult; + /***/ public String unexpectedPacketLine; /***/ public String unexpectedRefReport; /***/ public String unexpectedReportLine; /***/ public String unexpectedReportLine2; @@ -783,6 +784,7 @@ public class JGitText extends TranslationBundle { /***/ public String unknownObjectType2; /***/ public String unknownRepositoryFormat; /***/ public String unknownRepositoryFormat2; + /***/ public String unknownTransportCommand; /***/ public String unknownZlibError; /***/ public String unmergedPath; /***/ public String unmergedPaths; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java index 60401355a6..07d0bfdc0a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java @@ -297,19 +297,20 @@ public abstract class RefAdvertiser { if (useProtocolV2) { String symrefPart = symrefs.containsKey(ref.getName()) - ? (" symref-target:" + symrefs.get(ref.getName())) - : ""; - String peelPart = ""; + ? (" symref-target:" + symrefs.get(ref.getName())) //$NON-NLS-1$ + : ""; //$NON-NLS-1$ + String peelPart = ""; //$NON-NLS-1$ if (derefTags) { if (!ref.isPeeled() && repository != null) { ref = repository.peel(ref); } ObjectId peeledObjectId = ref.getPeeledObjectId(); if (peeledObjectId != null) { - peelPart = " peeled:" + peeledObjectId.getName(); + peelPart = " peeled:" + peeledObjectId.getName(); //$NON-NLS-1$ } } - writeOne(objectId.getName() + " " + ref.getName() + symrefPart + peelPart + "\n"); + writeOne(objectId.getName() + " " + ref.getName() + symrefPart //$NON-NLS-1$ + + peelPart + "\n"); //$NON-NLS-1$ continue; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java index 7a7efd6b88..21c0a92964 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java @@ -97,8 +97,8 @@ public class TransferConfig { * Used in protocol.version. */ enum ProtocolVersion { - V0("0"), - V2("2"); + V0("0"), //$NON-NLS-1$ + V2("2"); //$NON-NLS-1$ final String name; @@ -136,26 +136,28 @@ public class TransferConfig { this(db.getConfig()); } + @SuppressWarnings("nls") TransferConfig(final Config rc) { - boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); //$NON-NLS-1$ //$NON-NLS-2$ - fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); //$NON-NLS-1$ //$NON-NLS-2$ - receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); //$NON-NLS-1$ //$NON-NLS-2$ - fsckSkipList = rc.getString(FSCK, null, "skipList"); //$NON-NLS-1$ - allowInvalidPersonIdent = rc.getBoolean(FSCK, "allowInvalidPersonIdent", false); //$NON-NLS-1$ - safeForWindows = rc.getBoolean(FSCK, "safeForWindows", //$NON-NLS-1$ + boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); + fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); + receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); + fsckSkipList = rc.getString(FSCK, null, "skipList"); + allowInvalidPersonIdent = rc.getBoolean(FSCK, "allowInvalidPersonIdent", + false); + safeForWindows = rc.getBoolean(FSCK, "safeForWindows", SystemReader.getInstance().isWindows()); - safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", //$NON-NLS-1$ + safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", SystemReader.getInstance().isMacOS()); ignore = EnumSet.noneOf(ObjectChecker.ErrorType.class); EnumSet set = EnumSet .noneOf(ObjectChecker.ErrorType.class); for (String key : rc.getNames(FSCK)) { - if (equalsIgnoreCase(key, "skipList") //$NON-NLS-1$ - || equalsIgnoreCase(key, "allowLeadingZeroFileMode") //$NON-NLS-1$ - || equalsIgnoreCase(key, "allowInvalidPersonIdent") //$NON-NLS-1$ - || equalsIgnoreCase(key, "safeForWindows") //$NON-NLS-1$ - || equalsIgnoreCase(key, "safeForMacOS")) { //$NON-NLS-1$ + if (equalsIgnoreCase(key, "skipList") + || equalsIgnoreCase(key, "allowLeadingZeroFileMode") + || equalsIgnoreCase(key, "allowInvalidPersonIdent") + || equalsIgnoreCase(key, "safeForWindows") + || equalsIgnoreCase(key, "safeForMacOS")) { continue; } @@ -174,18 +176,18 @@ public class TransferConfig { } } if (!set.contains(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE) - && rc.getBoolean(FSCK, "allowLeadingZeroFileMode", false)) { //$NON-NLS-1$ + && rc.getBoolean(FSCK, "allowLeadingZeroFileMode", false)) { ignore.add(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE); } allowTipSha1InWant = rc.getBoolean( - "uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$ + "uploadpack", "allowtipsha1inwant", false); allowReachableSha1InWant = rc.getBoolean( - "uploadpack", "allowreachablesha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$ + "uploadpack", "allowreachablesha1inwant", false); allowFilter = rc.getBoolean( - "uploadpack", "allowfilter", false); //$NON-NLS-1$ //$NON-NLS-2$ + "uploadpack", "allowfilter", false); protocolVersion = ProtocolVersion.parse(rc.getString("protocol", null, "version")); - hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); //$NON-NLS-1$ //$NON-NLS-2$ + hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); } /** 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 5c02ae9658..79c35e37e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -44,8 +44,8 @@ package org.eclipse.jgit.transport; import static org.eclipse.jgit.lib.RefDatabase.ALL; -import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_LS_REFS; import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_FETCH; +import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_LS_REFS; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_AGENT; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_ALLOW_REACHABLE_SHA1_IN_WANT; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_ALLOW_TIP_SHA1_IN_WANT; @@ -75,6 +75,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; + import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; @@ -119,7 +120,7 @@ public class UploadPack { // UploadPack sends these lines as the first response to a client that // supports protocol version 2. private static final String[] v2CapabilityAdvertisement = { - "version 2", + "version 2", //$NON-NLS-1$ COMMAND_LS_REFS, COMMAND_FETCH }; @@ -688,7 +689,7 @@ public class UploadPack { * @since 5.0 */ public void setExtraParameters(Collection params) { - this.clientRequestedV2 = params.contains("version=2"); // $NON-NLS-1$ + this.clientRequestedV2 = params.contains("version=2"); //$NON-NLS-1$ } private boolean useProtocolV2() { @@ -883,18 +884,20 @@ public class UploadPack { // line is DELIM if there are arguments or END if not. if (line == PacketLineIn.DELIM) { while ((line = pckIn.readString()) != PacketLineIn.END) { - if (line.equals("peel")) { + if (line.equals("peel")) { //$NON-NLS-1$ adv.setDerefTags(true); - } else if (line.equals("symrefs")) { + } else if (line.equals("symrefs")) { //$NON-NLS-1$ needToFindSymrefs = true; - } else if (line.startsWith("ref-prefix ")) { - refPrefixes.add(line.substring("ref-prefix ".length())); + } else if (line.startsWith("ref-prefix ")) { //$NON-NLS-1$ + refPrefixes.add(line.substring("ref-prefix ".length())); //$NON-NLS-1$ } else { - throw new PackProtocolException("unexpected " + line); + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); } } } else if (line != PacketLineIn.END) { - throw new PackProtocolException("unexpected " + line); + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); } rawOut.stopBuffering(); @@ -944,15 +947,16 @@ public class UploadPack { // Currently, we do not support any capabilities, so the next // line is DELIM. if ((line = pckIn.readString()) != PacketLineIn.DELIM) { - throw new PackProtocolException("unexpected " + line); + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); } while ((line = pckIn.readString()) != PacketLineIn.END) { - if (line.startsWith("want ")) { + if (line.startsWith("want ")) { //$NON-NLS-1$ wantIds.add(ObjectId.fromString(line.substring(5))); - } else if (line.startsWith("have ")) { + } else if (line.startsWith("have ")) { //$NON-NLS-1$ peerHas.add(ObjectId.fromString(line.substring(5))); - } else if (line.equals("done")) { + } else if (line.equals("done")) { //$NON-NLS-1$ doneReceived = true; } else if (line.equals(OPTION_THIN_PACK)) { options.add(OPTION_THIN_PACK); @@ -967,24 +971,24 @@ public class UploadPack { if (doneReceived) { processHaveLines(peerHas, ObjectId.zeroId(), new PacketLineOut(NullOutputStream.INSTANCE)); } else { - pckOut.writeString("acknowledgments\n"); + pckOut.writeString("acknowledgments\n"); //$NON-NLS-1$ for (ObjectId id : peerHas) { if (walk.getObjectReader().has(id)) { - pckOut.writeString("ACK " + id.getName() + "\n"); + pckOut.writeString("ACK " + id.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } } processHaveLines(peerHas, ObjectId.zeroId(), new PacketLineOut(NullOutputStream.INSTANCE)); if (okToGiveUp()) { - pckOut.writeString("ready\n"); + pckOut.writeString("ready\n"); //$NON-NLS-1$ } else if (commonBase.isEmpty()) { - pckOut.writeString("NAK\n"); + pckOut.writeString("NAK\n"); //$NON-NLS-1$ } sectionSent = true; } if (doneReceived || okToGiveUp()) { if (sectionSent) pckOut.writeDelim(); - pckOut.writeString("packfile\n"); + pckOut.writeString("packfile\n"); //$NON-NLS-1$ sendPack(new PackStatistics.Accumulator()); } pckOut.end(); @@ -1008,15 +1012,16 @@ public class UploadPack { // case. return true; } - if (command.equals("command=" + COMMAND_LS_REFS)) { + if (command.equals("command=" + COMMAND_LS_REFS)) { //$NON-NLS-1$ lsRefsV2(); return false; } - if (command.equals("command=" + COMMAND_FETCH)) { + if (command.equals("command=" + COMMAND_FETCH)) { //$NON-NLS-1$ fetchV2(); return false; } - throw new PackProtocolException("unknown command " + command); + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unknownTransportCommand, command)); } private void serviceV2() throws IOException { @@ -1026,7 +1031,7 @@ public class UploadPack { // not, the client is expected to call // sendAdvertisedRefs() on its own.) for (String s : v2CapabilityAdvertisement) { - pckOut.writeString(s + "\n"); + pckOut.writeString(s + "\n"); //$NON-NLS-1$ } pckOut.end(); -- 2.39.5