This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit a7c6477db41904a71f2ed4eb198830344de1fb32 Author: Shad Storhaug <[email protected]> AuthorDate: Tue Jul 16 08:21:37 2019 +0700 BUG: Lucene.Net.TestFramework: Removed dependency on local file path location of europarl.lines.txt.gz and embedded the file. Removed Lucene.Net.TestFramework.Paths class whose only purpose was to resolve such dependencies (and didn't exist in Java). --- .../Lucene.Net.TestFramework.csproj | 5 + src/Lucene.Net.TestFramework/Util/LineFileDocs.cs | 13 +- .../Util/LuceneTestCase.cs | 4 - src/Lucene.Net.TestFramework/Util/Paths.cs | 206 --------------------- .../Util}/europarl.lines.txt.gz | Bin 5 files changed, 16 insertions(+), 212 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj index dc54660..db84739 100644 --- a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj +++ b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj @@ -43,6 +43,11 @@ </ItemGroup> <ItemGroup> + <None Remove="Util\europarl.lines.txt.gz" /> + <EmbeddedResource Include="Util\europarl.lines.txt.gz" /> + </ItemGroup> + + <ItemGroup> <ProjectReference Include="..\Lucene.Net.Analysis.Common\Lucene.Net.Analysis.Common.csproj" /> <ProjectReference Include="..\Lucene.Net.Codecs\Lucene.Net.Codecs.csproj" /> </ItemGroup> diff --git a/src/Lucene.Net.TestFramework/Util/LineFileDocs.cs b/src/Lucene.Net.TestFramework/Util/LineFileDocs.cs index 4177e10..1a361ba 100644 --- a/src/Lucene.Net.TestFramework/Util/LineFileDocs.cs +++ b/src/Lucene.Net.TestFramework/Util/LineFileDocs.cs @@ -54,7 +54,7 @@ namespace Lucene.Net.Util /// </summary> public LineFileDocs(Random random, string path, bool useDocValues) { - this.Path = Paths.ResolveTestArtifactPath(path); + this.Path = path; this.UseDocValues = useDocValues; Open(random); } @@ -100,7 +100,16 @@ namespace Lucene.Net.Util try { - @is = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read); + // LUCENENET: We have embedded the default file, so if that filename is passed, + // open the local resource instead of an external file. + if (Path == LuceneTestCase.DEFAULT_LINE_DOCS_FILE) + { + @is = this.GetType().getResourceAsStream(Path); + } + else + { + @is = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read); + } } catch (Exception) { diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 81af013..54d08ec 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -200,13 +200,9 @@ namespace Lucene.Net.Util [TestFixture] public abstract partial class LuceneTestCase : Assert // Wait long for leaked threads to complete before failure. zk needs this. - See LUCENE-3995 for rationale. { - public static System.IO.FileInfo TEMP_DIR; - public LuceneTestCase() { ClassEnvRule = new TestRuleSetupAndRestoreClassEnv(); - String directory = Paths.TempDirectory; - TEMP_DIR = new System.IO.FileInfo(directory); } // -------------------------------------------------------------------- diff --git a/src/Lucene.Net.TestFramework/Util/Paths.cs b/src/Lucene.Net.TestFramework/Util/Paths.cs deleted file mode 100644 index c9104b6..0000000 --- a/src/Lucene.Net.TestFramework/Util/Paths.cs +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Lucene.Net.Support; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace Lucene.Net.Util -{ - /// <summary> - /// The static accessor class for file paths used in testing. - /// </summary> - public static class Paths - { - private static string s_tempDirectory = null; - private static string s_testDocDirectory = null; - private static string s_assemblyDirectory = null; - private static string s_projectRootDirectory = null; - - /// <summary> - /// Gets the temp directory. - /// </summary> - /// <value> - /// The temp directory. - /// </value> - /// <remarks> - /// <para> - /// The temp directory first looks at the app settings for the &qt;tempDir&qt; - /// key. If the path does not exists or the setting is empty, the temp directory - /// fall back to using the environment's temp directory path and - /// append &qt;lucene-net&qt; to it. - /// </para> - /// </remarks> - public static string TempDirectory - { - get - { - if (s_tempDirectory == null) - { - string tempDirectory = SystemProperties.GetProperty("lucene.temp.dir"); - - if (string.IsNullOrEmpty(tempDirectory)) - { - tempDirectory = CombinePath(Path.GetTempPath(), "lucene-net"); - } - - if (!Directory.Exists(tempDirectory)) - Directory.CreateDirectory(tempDirectory); - - s_tempDirectory = tempDirectory; - } - - return s_tempDirectory; - } - } - - /// <summary> - /// Gets the test document directory. - /// </summary> - /// <value> - /// The test document directory. - /// </value> - public static string TestDocDirectory - { - get - { - if (s_testDocDirectory == null) - { - s_testDocDirectory = CombinePath(TempDirectory, "TestDoc"); - } - return s_testDocDirectory; - } - } - - /// <summary> - /// Gets the directory where the compiled assembly Lucene.Net.Tests is found. - /// We use Assembly.CodeBase in case NUnit or the current test runner - /// has shadow copy enabled. - /// </summary> - public static string AssemblyDirectory - { - get - { - if (s_assemblyDirectory == null) - { - // CodeBase uses unc path, get rid of the file prefix if it exists. - // File prefix could be file:// or file:/// - var assemblyDirectoryUri = new Uri(typeof(Paths).GetTypeInfo().Assembly.Location); - s_assemblyDirectory = Path.GetDirectoryName(assemblyDirectoryUri.LocalPath); - } - return s_assemblyDirectory; - } - } - - private const string TestArtifactsFolder = "test-files"; - - public static string ResolveTestArtifactPath(string fileName) - { - var rootPath = ProjectRootDirectory; - while (true) - { - var possiblePath = Path.Combine(rootPath, TestArtifactsFolder); - if (Directory.Exists(possiblePath)) return Path.Combine(possiblePath, fileName); - - var parent = Directory.GetParent(rootPath); - if (parent == parent.Root) break; - rootPath = parent.FullName; - } - throw new FileNotFoundException("Could not find the test-files folder"); - } - - /// <summary> - /// Gets the root directory for the project. e.g. if you were working on trunk - /// it would be the trunk directory. - /// </summary> - public static string ProjectRootDirectory - { - get - { - if (s_projectRootDirectory == null) - { - // we currently assume that the assembly's directory is root/bin/[Section]/[Build] - // where [Section] is either core, demo, or contrib, and [Build] is either Debug or Release. - var assemblyLocation = AssemblyDirectory; - - var index = assemblyLocation.IndexOf(Path.DirectorySeparatorChar + "build" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase); - if (index == -1) - { - index = assemblyLocation.IndexOf(Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase); - } - - if (index < 0) - { - throw new ArgumentOutOfRangeException("Could not locate project root directory in " + assemblyLocation); - } - - var difference = assemblyLocation.Substring(index).Count(o => o == Path.DirectorySeparatorChar); - - var list = new List<string>(); - - for (int i = 0; i < difference; i++) - { - list.Add(".."); - } - - var parameters = list.ToArray(); - - s_projectRootDirectory = Path.GetFullPath(CombinePath(assemblyLocation, parameters)); - } - return s_projectRootDirectory; - } - } - - /// <summary> - /// Combines the path. - /// </summary> - /// <returns> - /// The path. - /// </returns> - /// <param name='startSegment'> - /// Start segment of the path. - /// </param> - /// <param name='segments'> - /// Path segments e.g. directory or file names. - /// </param> - /// <exception cref='ArgumentNullException'> - /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> . - /// </exception> - /// <exception cref='InvalidOperationException'> - /// Is thrown when an operation cannot be performed. - /// </exception> - internal static string CombinePath(string startSegment, params string[] segments) - { - if (startSegment == null) - throw new ArgumentNullException(startSegment); - - if (segments == null || segments.Length == 0) - throw new InvalidOperationException("Paths can not be combined" + - " unless the startSegment and one additional segment is present."); - - string path = startSegment; - - foreach (string segment in segments) - path = System.IO.Path.Combine(path, segment); - - return path; - } - } -} \ No newline at end of file diff --git a/test-files/europarl.lines.txt.gz b/src/Lucene.Net.TestFramework/Util/europarl.lines.txt.gz similarity index 100% rename from test-files/europarl.lines.txt.gz rename to src/Lucene.Net.TestFramework/Util/europarl.lines.txt.gz
