testsourcesextractor.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 130 行
SVN-BASE
130 行
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.javatest;import java.io.File;import java.net.MalformedURLException;import java.net.URI;import java.net.URL;import java.util.ArrayList;import java.util.List;import com.sun.javatest.TestDescription;public class TestSourcesExtractor { private TestDescription td; public TestSourcesExtractor(TestDescription td) { this.td = td; } /** * Returns an array of sources referenced in the given test description's * entry. * <p> * All URLs represent valid, existing and readable files. * Never returns null, but may return an empty array, if no * sources found. * * @param entry * The entry with sources. * @return An array of sources, never <code>null</code>. */ public URL[] getSourcesFromEntry(String entry) { List results = new ArrayList(); String srcString = td.getParameter(entry); if (srcString != null) { String[] sources = srcString.split("\\s+"); URI baseDir = td.getDir().toURI(); assert baseDir.isAbsolute() : "Base dir is not absolute: " + baseDir; for (int i = 0; i < sources.length; i++) { String src = sources[i]; if (src.trim().length() == 0) { continue; } URI srcURI = baseDir.resolve(src); try { String srcPath = srcURI.getPath(); if (srcPath == null) { continue; } File file = new File(srcPath); if (file.canRead()) { URL srcURL = srcURI.toURL(); results.add(srcURL); } } catch (MalformedURLException e) { assert false : e.toString(); } } } return (URL[]) results.toArray(new URL[results.size()]); } /** * Merges two URL arrays into one, removing duplicates. Both arrays may be * <code>null</code>. Never returns <code>null</code>, but may return * an empty array. * * @param first * The first array. * @param second * The second array. * @return The merged array of URLs. */ public static URL[] mergeSourceArrays(URL[] first, URL[] second) { List results = new ArrayList(); if (first == null) { first = new URL[] {}; } if (second == null) { second = new URL[] {}; } addToListWithoutDuplicates(results, first); addToListWithoutDuplicates(results, second); return (URL[]) results.toArray(new URL[results.size()]); } private static void addToListWithoutDuplicates(List list, URL[] urls) { for (int i = 0; i < urls.length; i++) { URL url = urls[i]; if (!list.contains(url)) { list.add(url); } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?