/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 in the LICENSE file that
* accompanied this code).
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6887710
* @summary Verify the impact of sun.misc.JarIndex.metaInfFilenames on Service loaders
*/
/**
* Verifies the impact of sun.misc.JarIndex.metaInfFilenames on service loaders
* (sun.misc.Service & java.util.ServiceLoader), as well as finding resources
* through Class.getResouce.
*
* 1) Compile the test sources:
* jarA:
* jarB:
* jarC:
*
* 2) Build three jar files a.jar, b.jar, c.jar
*
* 3) Create an index in a.jar (jar -i a.jar b.jar c.jar)
* with sun.misc.JarIndex.metaInfFilenames=true
*
* 4) Start a HTTP server serving out the three jars.
*
* URLClassLoader. Each request to the HTTP server is recorded to ensure
* only the correct amount of requests are being made.
*
*/
public class Basic {
// Set global url cache to false so that we can track every jar request.
buildTest();
try {
httpServer.start();
} catch (IOException ioe) {
} finally {
}
}
static void buildTest() {
/* compile the source that will be used to generate the jars */
"-sourcepath", testSrcDir,
/* build the 3 jar files */
/* Create an index in a.jar for b.jar and c.jar */
}
/* run jar <args> */
}
}
/* run javac <args> */
}
}
static {
if (index != -1)
}
}
/* create the index */
// ProcessBuilder is used so that the current directory can be set
// to the directory that directly contains the jars.
debug("Running jar to create the index");
//pd.inheritIO();
try {
if(p.waitFor() != 0)
throw new RuntimeException("jar indexing failed");
}
} catch(IOException e) { throw new RuntimeException(e); }
}
static final boolean debug = true;
/* service define in c.jar */
/* a service that is not defined in any of the jars */
int failed = 0;
// Tests using sun.misc.Service
failed++;
}
failed++;
}
// Tests using java.util.SerivceLoader
failed++;
}
failed++;
}
// Tests using java.lang.Class (similar to the FontManager in javafx)
failed++;
}
failed++;
}
if (failed > 0)
}
boolean expectToFind,
boolean expectbDotJar,
boolean expectcDotJar) throws IOException {
debug("----------------------------------");
httpServer.reset();
try {
} catch (ClassNotFoundException cnfe) {
}
return false;
}
}
debug("Unexpeced request sent to the httpserver for b.jar");
return false;
}
debug("Unexpeced request sent to the httpserver for c.jar");
return false;
}
return true;
}
boolean expectToFind,
boolean expectbDotJar,
boolean expectcDotJar) throws IOException {
debug("----------------------------------");
httpServer.reset();
try {
} catch (ClassNotFoundException cnfe) {
}
return false;
}
}
debug("Unexpeced request sent to the httpserver for b.jar");
return false;
}
debug("Unexpeced request sent to the httpserver for c.jar");
return false;
}
return true;
}
/* Tries to find a resource in a similar way to the font manager in javafx
* com.sun.javafx.scene.text.FontManager */
boolean expectToFind,
boolean expectbDotJar,
boolean expectcDotJar) throws IOException {
debug("----------------------------------");
httpServer.reset();
try {
} catch (ClassNotFoundException cnfe) {
}
if (expectToFind && u == null) {
return false;
}
debug("Unexpeced request sent to the httpserver for b.jar");
return false;
}
debug("Unexpeced request sent to the httpserver for c.jar");
return false;
}
return true;
}
return new URLClassLoader( new URL[]{
}
/**
* HTTP Server to server the jar files.
*/
}
httpServer.start();
}
}
return httpServer.getAddress();
}
void reset() {
}
}
aDotJar++;
bDotJar++;
cDotJar++;
else
try {
int len;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}