This is an automated email from the ASF dual-hosted git repository. rec pushed a commit to branch feature/UIMA-6474-Switch-to-getDataPathElements()-in-UimaContext in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit 3111f48a4ea50c65946028c5ba434309eb87be8c Author: Richard Eckart de Castilho <[email protected]> AuthorDate: Wed Jun 22 10:09:40 2022 +0200 [UIMA-6474] Switch to getDataPathElements() in UimaContext - Deprecate getDataPath in UimaContext - Added getDataPathElements in UimaContext - Updated UimaContext_impl tests to use getDataPathElements instead of getDataPath --- .../src/main/java/org/apache/uima/UimaContext.java | 58 +++++++++++++--------- .../org/apache/uima/impl/UimaContext_ImplBase.java | 9 ++-- .../org/apache/uima/impl/UimaContext_implTest.java | 19 ++++--- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/uimaj-core/src/main/java/org/apache/uima/UimaContext.java b/uimaj-core/src/main/java/org/apache/uima/UimaContext.java index 04fdfeea4..9067a1895 100644 --- a/uimaj-core/src/main/java/org/apache/uima/UimaContext.java +++ b/uimaj-core/src/main/java/org/apache/uima/UimaContext.java @@ -21,6 +21,7 @@ package org.apache.uima; import java.io.InputStream; import java.net.URI; import java.net.URL; +import java.util.List; import org.apache.uima.cas.AbstractCas; import org.apache.uima.cas.CAS; @@ -174,9 +175,9 @@ public interface UimaContext { * you may use {@link #getResourceURI(String)} or {@link #getResourceFilePath(String)}. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * * @param aKey * the key by which the resource is identified. This key should be declared in the @@ -198,9 +199,9 @@ public interface UimaContext { * path (decoding %20 sequences to spaces) whereas {@link URL#getPath()} does not. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * * @param aKey * the key by which the resource is identified. This key should be declared in the @@ -224,9 +225,9 @@ public interface UimaContext { * that contain spaces. * * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * * @param aKey * the key by which the resource is identified. This key should be declared in the @@ -246,9 +247,9 @@ public interface UimaContext { * <externalResourceDependencies> section of the descriptor. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * * @param aKey * the key by which the resource is identified. This key should be declared in the @@ -288,9 +289,9 @@ public interface UimaContext { * you may use {@link #getResourceURI(String)} or {@link #getResourceFilePath(String)}. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * <p> * This version of this method takes an array of parameters used to further identify the resource. * This can be used, for example, with resources that vary depending on the language of the @@ -323,9 +324,9 @@ public interface UimaContext { * path (decoding %20 sequences to spaces) whereas {@link URL#getPath()} does not. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * <p> * This version of this method takes an array of parameters used to further identify the resource. * This can be used, for example, with resources that vary depending on the language of the @@ -360,9 +361,9 @@ public interface UimaContext { * that contain spaces. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElements() data path} and the class path. However, this + * usage is deprecated and support may be dropped in future versions. ALL external resource + * dependencies should be declared in the descriptor. * <p> * This version of this method takes an array of parameters used to further identify the resource. * This can be used, for example, with resources that vary depending on the language of the @@ -391,9 +392,9 @@ public interface UimaContext { * <externalResourceDependencies> section of the descriptor. * <p> * For backwards compatibility, if the key is not declared as a resource dependency, it is looked - * up directly in the {@link #getDataPath() data path} and the class path. However, this usage is - * deprecated and support may be dropped in future versions. ALL external resource dependencies - * should be declared in the descriptor. + * up directly in the {@link #getDataPathElementsgetDataPath() data path} and the class path. + * However, this usage is deprecated and support may be dropped in future versions. ALL external + * resource dependencies should be declared in the descriptor. * <p> * This version of this method takes an array of parameters used to further identify the resource. * This can be used, for example, with resources that vary depending on the language of the @@ -451,9 +452,18 @@ public interface UimaContext { * the <code>getResoureXXX</code> methods instead. * * @return the data path + * @deprecated Use {@link #getDataPathElements()} instead. */ + @Deprecated String getDataPath(); + /** + * Gets the data path elements used to resolve relative paths. + * + * @return the data path elements + */ + List<String> getDataPathElements(); + /** * Returns the Session object, which can be used to store data that pertains to a particular * client session. All data that must persist across requests must be stored in the Session object diff --git a/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java b/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java index 750c216cf..96381685f 100644 --- a/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java +++ b/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java @@ -534,14 +534,17 @@ public abstract class UimaContext_ImplBase implements UimaContextAdmin { } } - /** - * @see org.apache.uima.analysis_engine.annotator.AnnotatorContext#getDataPath() - */ + @Deprecated @Override public String getDataPath() { return getResourceManager().getDataPath(); } + @Override + public List<String> getDataPathElements() { + return getResourceManager().getDataPathElements(); + } + protected String makeQualifiedName(String name) { return mQualifiedContextName + name; } diff --git a/uimaj-core/src/test/java/org/apache/uima/impl/UimaContext_implTest.java b/uimaj-core/src/test/java/org/apache/uima/impl/UimaContext_implTest.java index 4526a702c..5635dcf50 100644 --- a/uimaj-core/src/test/java/org/apache/uima/impl/UimaContext_implTest.java +++ b/uimaj-core/src/test/java/org/apache/uima/impl/UimaContext_implTest.java @@ -19,6 +19,7 @@ package org.apache.uima.impl; +import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -30,6 +31,7 @@ import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.uima.UIMAFramework; import org.apache.uima.UimaContext; @@ -54,8 +56,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class UimaContext_implTest { - protected final String TEST_DATAPATH = JUnitExtension.getFile("AnnotatorContextTest").getPath() - + System.getProperty("path.separator") + JUnitExtension.getFile("ResourceTest"); + protected final List<String> TEST_DATAPATH = asList( // + JUnitExtension.getFile("AnnotatorContextTest").getPath(), + JUnitExtension.getFile("ResourceTest").getPath()); protected final String TEST_EXTENSION_CLASSPATH = JUnitExtension .getFile("ResourceTest/spaces in dir name").getPath(); @@ -75,7 +78,7 @@ public class UimaContext_implTest { try { // configure ResourceManager to allow test components to locate their resources ResourceManager rm = UIMAFramework.newDefaultResourceManager(); - rm.setDataPath(TEST_DATAPATH); + rm.setDataPathElements(TEST_DATAPATH.toArray(new String[TEST_DATAPATH.size()])); rm.setExtensionClassPath(TEST_EXTENSION_CLASSPATH, true); // create a UimaContext with Config Params and Resources @@ -893,13 +896,9 @@ public class UimaContext_implTest { } @Test - public void testGetDataPath() throws Exception { - try { - Assert.assertEquals(TEST_DATAPATH, mContext.getDataPath()); - Assert.assertEquals(TEST_DATAPATH, mContext2.getDataPath()); - } catch (Exception e) { - JUnitExtension.handleException(e); - } + public void testGetDataPathElements() throws Exception { + assertThat(mContext.getDataPathElements()).containsExactlyElementsOf(TEST_DATAPATH); + assertThat(mContext2.getDataPathElements()).containsExactlyElementsOf(TEST_DATAPATH); } @Test
