Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 212382 Details for
Bug 372119
Provide REST API for git command line
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
JGit patch v01
jgit_v01.patch (text/plain), 23.82 KB, created by
Tomasz Zarna
on 2012-03-09 09:09:27 EST
(
hide
)
Description:
JGit patch v01
Filename:
MIME Type:
Creator:
Tomasz Zarna
Created:
2012-03-09 09:09:27 EST
Size:
23.82 KB
patch
obsolete
>diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF >index e0bb07d..c4ca0e3 100644 >--- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF >+++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF >@@ -16,7 +16,6 @@ Import-Package: org.eclipse.jgit.api;version="[2.0.0,2.1.0)", > org.eclipse.jgit.iplog;version="[2.0.0,2.1.0)", > org.eclipse.jgit.lib;version="[2.0.0,2.1.0)", > org.eclipse.jgit.merge;version="2.0.0", >- org.eclipse.jgit.nls;version="[2.0.0,2.1.0)", > org.eclipse.jgit.notes;version="[2.0.0,2.1.0)", > org.eclipse.jgit.revplot;version="[2.0.0,2.1.0)", > org.eclipse.jgit.revwalk;version="[2.0.0,2.1.0)", >@@ -39,6 +38,7 @@ Export-Package: org.eclipse.jgit.pgm;version="2.0.0"; > javax.swing, > org.eclipse.jgit.pgm.opt, > org.eclipse.jgit.awtui, >- org.eclipse.jgit.transport" >+ org.eclipse.jgit.transport", >+ org.eclipse.jgit.pgm.opt;version="2.0.0" > Main-Class: org.eclipse.jgit.pgm.Main > Implementation-Title: JGit Command Line Interface >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java >index e1c26ad..106cb5a 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java >@@ -43,8 +43,8 @@ > > package org.eclipse.jgit.pgm; > >-import org.eclipse.jgit.nls.NLS; >-import org.eclipse.jgit.nls.TranslationBundle; >+import org.eclipse.jgit.pgm.nls.NLS; >+import org.eclipse.jgit.pgm.nls.TranslationBundle; > > /** > * Translation bundle for JGit command line interface >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java >index de43029..71ac9aa 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java >@@ -89,7 +89,7 @@ > private FileRepository dst; > > @Override >- protected final boolean requiresRepository() { >+ public final boolean requiresRepository() { > return false; > } > >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java >index 9b637cd..c213509 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java >@@ -94,7 +94,7 @@ > final List<File> directory = new ArrayList<File>(); > > @Override >- protected boolean requiresRepository() { >+ public boolean requiresRepository() { > return false; > } > >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java >index e1e38e5..ba91e85 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java >@@ -61,7 +61,7 @@ > private boolean bare; > > @Override >- protected final boolean requiresRepository() { >+ public final boolean requiresRepository() { > return false; > } > >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java >index 7a27617..b4e1093 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java >@@ -58,7 +58,7 @@ > File dstGitdir; > > @Override >- protected final boolean requiresRepository() { >+ public final boolean requiresRepository() { > return false; > } > >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java >index 2988dfc..c53b2e1 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java >@@ -80,7 +80,7 @@ > private boolean help; > > /** Stream to output to, typically this is standard output. */ >- protected PrintWriter out; >+ public PrintWriter out; > > /** Git repository the command was invoked within. */ > protected Repository db; >@@ -96,7 +96,7 @@ final void setCommandName(final String name) { > } > > /** @return true if {@link #db}/{@link #getRepository()} is required. */ >- protected boolean requiresRepository() { >+ public boolean requiresRepository() { > return true; > } > >@@ -109,7 +109,7 @@ protected boolean requiresRepository() { > * value of the {@code --git-dir} command line option, if > * {@code repository} is null. > */ >- protected void init(final Repository repository, final String gitDir) { >+ public void init(final Repository repository, final String gitDir) { > try { > final String outputEncoding = repository != null ? repository > .getConfig() >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java >index d4e2bce..f200cfc 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java >@@ -62,7 +62,7 @@ > File srcGitdir; > > @Override >- protected final boolean requiresRepository() { >+ public final boolean requiresRepository() { > return false; > } > >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java >index 9b51b87..4faeac6 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java >@@ -57,7 +57,7 @@ protected void run() throws Exception { > } > > @Override >- protected final boolean requiresRepository() { >+ public final boolean requiresRepository() { > return false; > } > } >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java >index f98cdfa..5fae7b3 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java >@@ -123,7 +123,7 @@ DiffAlgorithm create() { > private ThreadMXBean mxBean; > > @Override >- protected boolean requiresRepository() { >+ public boolean requiresRepository() { > return false; > } > >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java >index e7051a1..daef51b 100644 >--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java >@@ -258,7 +258,7 @@ public int fold(int hash, int bits) { > List<File> gitDirs = new ArrayList<File>(); > > @Override >- protected boolean requiresRepository() { >+ public boolean requiresRepository() { > return false; > } >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/GlobalBundleCache.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/GlobalBundleCache.java >new file mode 100644 >index 0000000..a3d89e1 >--- /dev/null >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/GlobalBundleCache.java >@@ -0,0 +1,105 @@ >+/* >+ * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com> >+ * and other copyright owners as documented in the project's IP log. >+ * >+ * This program and the accompanying materials are made available >+ * under the terms of the Eclipse Distribution License v1.0 which >+ * accompanies this distribution, is reproduced below, and is >+ * available at http://www.eclipse.org/org/documents/edl-v10.php >+ * >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or >+ * without modification, are permitted provided that the following >+ * conditions are met: >+ * >+ * - Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * >+ * - Redistributions in binary form must reproduce the above >+ * copyright notice, this list of conditions and the following >+ * disclaimer in the documentation and/or other materials provided >+ * with the distribution. >+ * >+ * - Neither the name of the Eclipse Foundation, Inc. nor the >+ * names of its contributors may be used to endorse or promote >+ * products derived from this software without specific prior >+ * written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND >+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, >+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER >+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, >+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+package org.eclipse.jgit.pgm.nls; >+ >+import java.util.HashMap; >+import java.util.Locale; >+import java.util.Map; >+ >+import org.eclipse.jgit.errors.TranslationBundleLoadingException; >+import org.eclipse.jgit.errors.TranslationStringMissingException; >+ >+/** >+ * Global cache of translation bundles. >+ * <p> >+ * Every translation bundle will be cached here when it gets loaded for the >+ * first time from a thread. Another lookup for the same translation bundle >+ * (same locale and type) from the same or a different thread will return the >+ * cached one. >+ * <p> >+ * Note that NLS instances maintain per-thread Map of loaded translation >+ * bundles. Once a thread accesses a translation bundle it will keep reference >+ * to it and will not call {@link #lookupBundle(Locale, Class)} again for the >+ * same translation bundle as long as its locale doesn't change. >+ */ >+class GlobalBundleCache { >+ private static final Map<Locale, Map<Class, TranslationBundle>> cachedBundles >+ = new HashMap<Locale, Map<Class, TranslationBundle>>(); >+ >+ /** >+ * Looks up for a translation bundle in the global cache. If found returns >+ * the cached bundle. If not found creates a new instance puts it into the >+ * cache and returns it. >+ * >+ * @param <T> >+ * required bundle type >+ * @param locale >+ * the preferred locale >+ * @param type >+ * required bundle type >+ * @return an instance of the required bundle type >+ * @exception TranslationBundleLoadingException see {@link TranslationBundle#load(Locale)} >+ * @exception TranslationStringMissingException see {@link TranslationBundle#load(Locale)} >+ */ >+ static synchronized <T extends TranslationBundle> T lookupBundle(Locale locale, Class<T> type) { >+ try { >+ Map<Class, TranslationBundle> bundles = cachedBundles.get(locale); >+ if (bundles == null) { >+ bundles = new HashMap<Class, TranslationBundle>(); >+ cachedBundles.put(locale, bundles); >+ } >+ TranslationBundle bundle = bundles.get(type); >+ if (bundle == null) { >+ bundle = type.newInstance(); >+ bundle.load(locale); >+ bundles.put(type, bundle); >+ } >+ return (T) bundle; >+ } catch (InstantiationException e) { >+ throw new Error(e); >+ } catch (IllegalAccessException e) { >+ throw new Error(e); >+ } >+ } >+} >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/NLS.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/NLS.java >new file mode 100644 >index 0000000..7732fa4 >--- /dev/null >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/NLS.java >@@ -0,0 +1,141 @@ >+/* >+ * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com> >+ * and other copyright owners as documented in the project's IP log. >+ * >+ * This program and the accompanying materials are made available >+ * under the terms of the Eclipse Distribution License v1.0 which >+ * accompanies this distribution, is reproduced below, and is >+ * available at http://www.eclipse.org/org/documents/edl-v10.php >+ * >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or >+ * without modification, are permitted provided that the following >+ * conditions are met: >+ * >+ * - Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * >+ * - Redistributions in binary form must reproduce the above >+ * copyright notice, this list of conditions and the following >+ * disclaimer in the documentation and/or other materials provided >+ * with the distribution. >+ * >+ * - Neither the name of the Eclipse Foundation, Inc. nor the >+ * names of its contributors may be used to endorse or promote >+ * products derived from this software without specific prior >+ * written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND >+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, >+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER >+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, >+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+package org.eclipse.jgit.pgm.nls; >+ >+import java.util.Locale; >+import java.util.concurrent.ConcurrentHashMap; >+ >+import org.eclipse.jgit.errors.TranslationBundleLoadingException; >+import org.eclipse.jgit.errors.TranslationStringMissingException; >+ >+/** >+ * The purpose of this class is to provide NLS (National Language Support) >+ * configurable per thread. >+ * >+ * <p> >+ * The {@link #setLocale(Locale)} method is used to configure locale for the >+ * calling thread. The locale setting is thread inheritable. This means that a >+ * child thread will have the same locale setting as its creator thread until it >+ * changes it explicitly. >+ * >+ * <p> >+ * Example of usage: >+ * >+ * <pre> >+ * NLS.setLocale(Locale.GERMAN); >+ * TransportText t = NLS.getBundleFor(TransportText.class); >+ * </pre> >+ */ >+public class NLS { >+ /** The root locale constant. It is defined here because the Locale.ROOT is not defined in Java 5 */ >+ public static final Locale ROOT_LOCALE = new Locale("", "", ""); >+ >+ private static final InheritableThreadLocal<NLS> local = new InheritableThreadLocal<NLS>() { >+ protected NLS initialValue() { >+ return new NLS(Locale.getDefault()); >+ } >+ }; >+ >+ /** >+ * Sets the locale for the calling thread. >+ * <p> >+ * The {@link #getBundleFor(Class)} method will honor this setting if if it >+ * is supported by the provided resource bundle property files. Otherwise, >+ * it will use a fall back locale as described in the >+ * {@link TranslationBundle} >+ * >+ * @param locale >+ * the preferred locale >+ */ >+ public static void setLocale(Locale locale) { >+ local.set(new NLS(locale)); >+ } >+ >+ /** >+ * Sets the JVM default locale as the locale for the calling thread. >+ * <p> >+ * Semantically this is equivalent to <code>NLS.setLocale(Locale.getDefault())</code>. >+ */ >+ public static void useJVMDefaultLocale() { >+ local.set(new NLS(Locale.getDefault())); >+ } >+ >+ /** >+ * Returns an instance of the translation bundle of the required type. All >+ * public String fields of the bundle instance will get their values >+ * injected as described in the {@link TranslationBundle}. >+ * >+ * @param <T> >+ * required bundle type >+ * @param type >+ * required bundle type >+ * @return an instance of the required bundle type >+ * @exception TranslationBundleLoadingException see {@link TranslationBundleLoadingException} >+ * @exception TranslationStringMissingException see {@link TranslationStringMissingException} >+ */ >+ public static <T extends TranslationBundle> T getBundleFor(Class<T> type) { >+ return local.get().get(type); >+ } >+ >+ final private Locale locale; >+ final private ConcurrentHashMap<Class, TranslationBundle> map = new ConcurrentHashMap<Class, TranslationBundle>(); >+ >+ private NLS(Locale locale) { >+ this.locale = locale; >+ } >+ >+ @SuppressWarnings("unchecked") >+ private <T extends TranslationBundle> T get(Class<T> type) { >+ TranslationBundle bundle = map.get(type); >+ if (bundle == null) { >+ bundle = GlobalBundleCache.lookupBundle(locale, type); >+ // There is a small opportunity for a race, which we may >+ // lose. Accept defeat and return the winner's instance. >+ TranslationBundle old = map.putIfAbsent(type, bundle); >+ if (old != null) >+ bundle = old; >+ } >+ return (T) bundle; >+ } >+} >diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/TranslationBundle.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/TranslationBundle.java >new file mode 100644 >index 0000000..c27b76f >--- /dev/null >+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/nls/TranslationBundle.java >@@ -0,0 +1,183 @@ >+/* >+ * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com> >+ * and other copyright owners as documented in the project's IP log. >+ * >+ * This program and the accompanying materials are made available >+ * under the terms of the Eclipse Distribution License v1.0 which >+ * accompanies this distribution, is reproduced below, and is >+ * available at http://www.eclipse.org/org/documents/edl-v10.php >+ * >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or >+ * without modification, are permitted provided that the following >+ * conditions are met: >+ * >+ * - Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * >+ * - Redistributions in binary form must reproduce the above >+ * copyright notice, this list of conditions and the following >+ * disclaimer in the documentation and/or other materials provided >+ * with the distribution. >+ * >+ * - Neither the name of the Eclipse Foundation, Inc. nor the >+ * names of its contributors may be used to endorse or promote >+ * products derived from this software without specific prior >+ * written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND >+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, >+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER >+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, >+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+package org.eclipse.jgit.pgm.nls; >+ >+import java.lang.reflect.Field; >+import java.util.Locale; >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+import org.eclipse.jgit.errors.TranslationBundleLoadingException; >+import org.eclipse.jgit.errors.TranslationStringMissingException; >+ >+/** >+ * Base class for all translation bundles that provides injection of translated >+ * texts into public String fields. >+ * >+ * <p> >+ * The usage pattern is shown with the following example. First define a new >+ * translation bundle: >+ * >+ * <pre> >+ * public class TransportText extends TranslationBundle { >+ * public static TransportText get() { >+ * return NLS.getBundleFor(TransportText.class); >+ * } >+ * >+ * public String repositoryNotFound; >+ * >+ * public String transportError; >+ * } >+ * </pre> >+ * >+ * Second, define one or more resource bundle property files. >+ * >+ * <pre> >+ * TransportText_en_US.properties: >+ * repositoryNotFound=repository {0} not found >+ * transportError=unknown error talking to {0} >+ * TransportText_de.properties: >+ * repositoryNotFound=repository {0} nicht gefunden >+ * transportError=unbekannter Fehler während der Kommunikation mit {0} >+ * ... >+ * </pre> >+ * >+ * Then make use of it: >+ * >+ * <pre> >+ * NLS.setLocale(Locale.GERMAN); // or skip this call to stick to the JVM default locale >+ * ... >+ * throw new TransportException(uri, TransportText.get().transportError); >+ * </pre> >+ * >+ * The translated text is automatically injected into the public String fields >+ * according to the locale set with {@link NLS#setLocale(Locale)}. However, the >+ * {@link NLS#setLocale(Locale)} method defines only prefered locale which will >+ * be honored only if it is supported by the provided resource bundle property >+ * files. Basically, this class will use >+ * {@link ResourceBundle#getBundle(String, Locale)} method to load a resource >+ * bundle. See the documentation of this method for a detailed explanation of >+ * resource bundle loading strategy. After a bundle is created the >+ * {@link #effectiveLocale()} method can be used to determine whether the >+ * bundle really corresponds to the requested locale or is a fallback. >+ * >+ * <p> >+ * To load a String from a resource bundle property file this class uses the >+ * {@link ResourceBundle#getString(String)}. This method can throw the >+ * {@link MissingResourceException} and this class is not making any effort to >+ * catch and/or translate this exception. >+ * >+ * <p> >+ * To define a concrete translation bundle one has to: >+ * <ul> >+ * <li>extend this class >+ * <li>define a public static get() method like in the example above >+ * <li>define public static String fields for each text message >+ * <li>make sure the translation bundle class provide public no arg constructor >+ * <li>provide one or more resource bundle property files in the same package >+ * where the translation bundle class resides >+ * </ul> >+ */ >+public abstract class TranslationBundle { >+ >+ private Locale effectiveLocale; >+ private ResourceBundle resourceBundle; >+ >+ /** >+ * @return the locale locale used for loading the resource bundle from which >+ * the field values were taken >+ */ >+ public Locale effectiveLocale() { >+ return effectiveLocale; >+ } >+ >+ /** >+ * @return the resource bundle on which this translation bundle is based >+ */ >+ public ResourceBundle resourceBundle() { >+ return resourceBundle; >+ } >+ >+ /** >+ * Injects locale specific text in all instance fields of this instance. >+ * Only public instance fields of type <code>String</code> are considered. >+ * <p> >+ * The name of this (sub)class plus the given <code>locale</code> parameter >+ * define the resource bundle to be loaded. In other words the >+ * <code>this.getClass().getName()</code> is used as the >+ * <code>baseName</code> parameter in the >+ * {@link ResourceBundle#getBundle(String, Locale)} parameter to load the >+ * resource bundle. >+ * <p> >+ * >+ * @param locale >+ * defines the locale to be used when loading the resource bundle >+ * @exception TranslationBundleLoadingException see {@link TranslationBundleLoadingException} >+ * @exception TranslationStringMissingException see {@link TranslationStringMissingException} >+ */ >+ void load(Locale locale) throws TranslationBundleLoadingException { >+ Class bundleClass = getClass(); >+ try { >+ resourceBundle = ResourceBundle.getBundle(bundleClass.getName(), locale); >+ } catch (MissingResourceException e) { >+ throw new TranslationBundleLoadingException(bundleClass, locale, e); >+ } >+ this.effectiveLocale = resourceBundle.getLocale(); >+ >+ for (Field field : bundleClass.getFields()) { >+ if (field.getType().equals(String.class)) { >+ try { >+ String translatedText = resourceBundle.getString(field.getName()); >+ field.set(this, translatedText); >+ } catch (MissingResourceException e) { >+ throw new TranslationStringMissingException(bundleClass, locale, field.getName(), e); >+ } catch (IllegalArgumentException e) { >+ throw new Error(e); >+ } catch (IllegalAccessException e) { >+ throw new Error(e); >+ } >+ } >+ } >+ } >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 372119
:
212379
|
212380
| 212382