Skip to main content

svn commit: r1020 - trunk/code: src/share/classes/com/sun/tck/cldc/javatest/util unitTests/classes/com/sun/tck/cldc/javatest unitTests/classes/com/...

1 reply [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Alexander Alexeev

Hi Dmitri,

please delete AllTests.java from unit tests. Our current practice not to
add such classes. For more information see ISSUE #58:
https://cqme.dev.java.net/issues/show_bug.cgi?id=58

Thanks,
Alexander

dtrounine@dev.java.net wrote:
> Author: dtrounine
> Date: 2007-05-24 23:57:28+0000
> New Revision: 1020
>
> Added:
> trunk/code/unitTests/classes/com/sun/tck/cldc/javatest/
> - copied from r1017, /branches/users/dtrounine/testExport/issue90a/unitTests/classes/com/sun/tck/cldc/javatest/
> trunk/code/unitTests/classes/com/sun/tck/cldc/javatest/util/
> - copied from r1017, /branches/users/dtrounine/testExport/issue90a/unitTests/classes/com/sun/tck/cldc/javatest/util/
> trunk/code/unitTests/classes/com/sun/tck/cldc/javatest/util/AllTests.java
> - copied unchanged from r1017, /branches/users/dtrounine/testExport/issue90a/unitTests/classes/com/sun/tck/cldc/javatest/util/AllTests.java
> trunk/code/unitTests/classes/com/sun/tck/cldc/javatest/util/JarBuilderTests.java
> - copied, changed from r1017, /branches/users/dtrounine/testExport/issue90a/unitTests/classes/com/sun/tck/cldc/javatest/util/JarBuilderTests.java
> Modified:
> trunk/code/src/share/classes/com/sun/tck/cldc/javatest/util/JarBuilder.java
>
> Log:
> Fixed issue #90: JarBuilder.createJar adds conntent to current JAR via private methods
>
> Contributor: Dmitri Trounine
> Reviewers: Stan Avzan
>
> Build: OK
> Unit tests: OK
> Test run: OK
> Copyrights check: OK
>
>
>
> Modified: trunk/code/src/share/classes/com/sun/tck/cldc/javatest/util/JarBuilder.java
> Url: https://cqme.dev.java.net/source/browse/cqme/trunk/code/src/share/classe...
> ==============================================================================
> --- trunk/code/src/share/classes/com/sun/tck/cldc/javatest/util/JarBuilder.java (original)
> +++ trunk/code/src/share/classes/com/sun/tck/cldc/javatest/util/JarBuilder.java 2007-05-24 23:57:28+0000
> @@ -38,6 +38,8 @@
> import java.util.Hashtable;
> import java.util.Vector;
> import java.util.Enumeration;
> +import java.util.Map;
> +import java.util.WeakHashMap;
> import java.util.jar.JarOutputStream;
> import java.util.jar.JarInputStream;
> import java.util.jar.JarEntry;
> @@ -54,10 +56,40 @@
> current = new ByteArrayOutputStream(maxSize > 0 ? maxSize : 100000);
> }
>
> + /**
> + * Creates a new JAR file with the content from the JAR file specified in
> + * the baseJar.
> + *

> + * This is just a convenient way to call createJar(baseJar, null)
> + *
.
> + *
> + * @param baseJar Pathname of a JAR file.
> + * @return true if new JAR file was successfully created,
> + * false otherwise.
> + */
> public synchronized boolean createJar(String baseJar) {
> return createJar(baseJar, null);
> }
>
> + /**
> + * Creates a new JAR file with the content from the JAR file specified in
> + * the baseJar and with manifest entry specified by the
> + * manifest.
> + *

> + * If baseJar is null an empty JAR file
> + * is created.
> + *

> + * If manifest is not null, new JAR file is
> + * created with specified manifest. Otherwise, the manifest of
> + * baseJar is used. If baseJar has no manifest,
> + * new JAR file is created without manifest.
> + *
> + * @param baseJar Pathname of a JAR file. Can be null
> + * @param manifest manifest for new JAR file. Can be null.
> + *
> + * @return true if new JAR file was successfully created,
> + * false otherwise.
> + */
> public synchronized boolean createJar(String baseJar, Manifest manifest) {
> if (currentJar != null) {
> throw new IllegalStateException(
> @@ -66,24 +98,14 @@
>
> try {
> if (baseJar == null) {
> - oldbaseJar = null;
> createJar(manifest);
> return true;
> }
> - if (baseJar.equals(oldbaseJar)) {
> - createJar((manifest == null) ? cachedManifest : manifest);
> - return addOldJarFileContent();
> - } else {
> - oldbaseJar = baseJar;
> - JarFile baseJarFile = new JarFile(baseJar);
> - try {
> - cachedManifest = baseJarFile.getManifest();
> - } finally {
> - baseJarFile.close();
> - }
> - createJar((manifest == null) ? cachedManifest : manifest);
> - return addJarFileContent(baseJar);
> + if (manifest == null) {
> + manifest = getManifest(baseJar);
> }
> + createJar(manifest);
> + return addJarFileContent(baseJar);
> } catch (IOException e) {
> throw new RuntimeException(e.toString());
> }
> @@ -142,47 +164,29 @@
> currentJar = null;
> }
>
> + /**
> + * Adds the content of specified JAR file to the current JAR file.
> + *
> + * @param fname Pathname of a JAR file.
> + *
> + * @return true if fname is null or
> + * if the content of specified file was successfully added to the
> + * current JAR file. false otherwise.
> + */
> public synchronized boolean addJarFileContent(String fname) {
> - if (fname == null)
> + if (fname == null) {
> return true;
> + }
> +
> checkCurrent();
> mark();
> -
> - boolean saveJarData = false;
> - if (fname.equals(oldbaseJar)) {
> - oldEntries.clear();
> - saveJarData = true;
> - }
> - try {
> - JarFile f = new JarFile(fname);
> - Enumeration es = f.entries();
> - while (es.hasMoreElements()) {
> - JarEntry e = (JarEntry) es.nextElement();
> - if (e.getName().startsWith("META-INF")) {
> - continue;
> - }
> - byte[] data = new byte[(int) e.getSize()];
> - InputStream is = f.getInputStream(e);
> - int chunk = 0;
> - int readed = 0;
> - while ((readed < data.length) && (chunk >= 0)) {
> - chunk = is.read(data, readed, data.length - readed);
> - readed += chunk;
> - }
> - is.close();
> - if (saveJarData) {
> - oldEntries.put(e.getName(), data);
> - }
> - add(e.getName(), data);
> - if (overLimit()) {
> - reset();
> - f.close();
> - return false;
> - }
> + for (Map.Entry entry
> + : getJarFileContent(fname).entrySet()) {
> + add(entry.getKey(), entry.getValue());
> + if (overLimit()) {
> + reset();
> + return false;
> }
> - f.close();
> - } catch (IOException e) {
> - throw new RuntimeException(e.toString());
> }
> return true;
> }
> @@ -190,7 +194,6 @@
> /**
> * Gives access to Jar's manifest
> */
> -
> public Manifest getCurrentManifest() {
> return currentManifest;
> }
> @@ -206,7 +209,8 @@
> return true;
> }
>
> - public synchronized boolean addByteArrays(String[] names, byte[][] contents) {
> + public synchronized boolean addByteArrays(String[] names,
> + byte[][] contents) {
> checkCurrent();
> mark();
> for (int i=0; i < names.length; i++) {
> @@ -225,12 +229,140 @@
> public void undoLastAdded() {
> reset();
> }
> +
> + /**
> + * Returns the content of specified JAR file.
> + *

> + * This method invokes {@link #updateCache(String jarPathName)} and then
> + * gets the content of specified JAR file from cache.
> + *
> + * @param jarPathName Pathname of a JAR file.
> + *
> + * @return Content of the JAR file in a mapping: (name, bytes).
> + */
> + private synchronized Map
> + getJarFileContent(String jarPathName) {
> + updateCache(jarPathName);
> + return cachedJarContent.get(jarPathName);
> + }
> +
> + /**
> + * Returns the manifest of specified JAR file.
> + *

> + * This method invokes {@link #updateCache(String jarPathName)} and then
> + * gets the manifest of specified JAR file from cache.
> + *
> + * @param jarPathName Pathname of a JAR file.
> + *
> + * @return Manifest of the JAR file. null if specified JAR
> + * file has no manifest.
> + */
> + private synchronized Manifest getManifest(String jarPathName) {
> + updateCache(jarPathName);
> + return cachedManifest.get(jarPathName);
> + }
> +
>
> -// ------ private stuff ---------
> + /**
> + * Checks the content of cache against the specified JAR file using
> + * {@link #jarTimestamp}. If the data in cache is outdated, invokes
> + * {@link #readJarFile(String jarPathName)}.
> + *
> + * @param jarPathName Pathname of a JAR file.
> + */
> + private synchronized void updateCache(String jarPathName) {
> + Long lastModified =
> + Long.valueOf(new File(jarPathName).lastModified());
> + if (!cachedJarContent.containsKey(jarPathName)
> + || (lastModified.compareTo(
> + jarTimestamps.get(jarPathName)) > 0)) {
> + /* No data in cache or data in cache is outdated:
> + * Read from file and update.
> + */
> + readJarFile(jarPathName);
> + }
> + }
> +
> + /**
> + * Reads the content and the manifest of specified JAR file and stores them
> + * in cache. Updates the timestamp.
> + *

> + * This method updates {@link #cachedJarContent}, {@link @cachedManifest}
> + * and {@link #jarTimestamp}.
> + *
> + * @param jarPathName Pathname of a JAR file.
> + */
> + private synchronized void readJarFile(String jarPathName) {
> + Map data = new Hashtable();
> + JarFile f = null;
> +
> + try {
> + f = new JarFile(jarPathName);
> + Enumeration es = f.entries();
> + while (es.hasMoreElements()) {
> + JarEntry e = (JarEntry) es.nextElement();
> + if (e.getName().startsWith("META-INF")) {
> + continue;
> + }
> + byte[] buffer = new byte[(int) e.getSize()];
> + InputStream is = f.getInputStream(e);
> + int chunk = 0;
> + int readed = 0;
> + while ((readed < buffer.length) && (chunk >= 0)) {
> + chunk = is.read(buffer, readed, buffer.length - readed);
> + readed += chunk;
> + }
> + is.close();
> + data.put(e.getName(), buffer);
> + }
> + // Update the cache
> + cachedJarContent.put(jarPathName, data);
> + cachedManifest.put(jarPathName, f.getManifest());
> + jarTimestamps.put(jarPathName,
> + Long.valueOf(new File(jarPathName).lastModified()));
> + } catch (IOException e) {
> + throw new RuntimeException(e.toString());
> + } finally {
> + try {
> + f.close();
> + } catch (Exception e) {}
> + }
> + }
>
> - private String oldbaseJar = null;
> - private Hashtable oldEntries = new Hashtable(40);
>
> + /**
> + * Internal cache for storing content of JAR files. Contains mapping
> + * from pathnames of JAR files to their content.
> + *

> + * cachedJarContent is synchronized with cachedManifest
> + *
and jarTimestamp. Content of the cache can only be
> + * changed by {@link #readJarFile(String jarPathName)} method.
> + */
> + private Map> cachedJarContent
> + = new WeakHashMap>();
> +
> + /**
> + * Internal cache for storing manifests of JAR files. Contains mapping
> + * from pathnames of JAR files to their manifests.
> + *

> + * cachedManifest is synchronized with cachedJarContent
> + *
and jarTimestamp. Content of the cache can only be
> + * changed by {@link #readJarFile(String jarPathName)} method.
> + */
> + private Map cachedManifest
> + = new WeakHashMap();
> +
> + /**
> + * Stores mapping from pathnames of JAR files to their timestamps. Timestamp
> + * is the value returned by File.lastModified() last time the
> + * JAR file was read by this JarBuilder.
> + *

> + * jarTimestamp is synchronized with cachedJarContent
> + *
and cachedManifest. Content of the cache can only be
> + * changed by {@link #readJarFile(String jarPathName)} method.
> + */
> + private Map jarTimestamps = new WeakHashMap();
> +
> private boolean overLimit() {
> return maxSize > 0 && estimatedSize() > maxSize;
> }
> @@ -248,7 +380,6 @@
> private JarOutputStream currentJar = null;
> private Manifest currentManifest = null;
> private Manifest originalManifest = null;
> - private Manifest cachedManifest = null;
> private Vector currentContent = new Vector(60);
>
> private int currentContentLength = 0;
> @@ -288,24 +419,6 @@
> }
> }
>
> -
> - private synchronized boolean addOldJarFileContent() {
> - checkCurrent();
> - mark();
> -
> - Enumeration es = oldEntries.keys();
> - while (es.hasMoreElements()) {
> - String name = (String) es.nextElement();
> - add(name, (byte[]) oldEntries.get(name));
> - if (overLimit()) {
> - reset();
> - oldbaseJar = null;
> - return false;
> - }
> - }
> - return true;
> - }
> -
> private void checkCurrent() {
> if (currentJar == null) {
> throw new IllegalStateException("No file is currently processed");
>
> Copied: trunk/code/unitTests/classes/com/sun/tck/cldc/javatest/util/JarBuilderTests.java (from r1017, /branches/users/dtrounine/testExport/issue90a/unitTests/classes/com/sun/tck/cldc/javatest/util/JarBuilderTests.java)
> Url: https://cqme.dev.java.net/source/browse/cqme/trunk/code/unitTests/classe...
> ==============================================================================
> --- /branches/users/dtrounine/testExport/issue90a/unitTests/classes/com/sun/tck/cldc/javatest/util/JarBuilderTests.java (original)
> +++ trunk/code/unitTests/classes/com/sun/tck/cldc/javatest/util/JarBuilderTests.java 2007-05-24 23:57:28+0000
> @@ -338,7 +338,7 @@
> props.put(TestExportInfo.JAR_URL_PREFIX_KEY, "");
> props.put(TestExportInfo.EXPORT_DIR_KEY, destDir.getPath());
> props.put(TestExportInfo.TEST_EXPORT_MODE_KEY,
> - TestExportInfo.EXPORTING_MODE);
> + TestExportInfo.EXPORT_MODE);
> try {
> env = new TestEnvironment("Unit test env", props,
> "Export props");
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commits-unsubscribe@cqme.dev.java.net
> For additional commands, e-mail: commits-help@cqme.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: meframework-unsubscribe@cqme.dev.java.net
For additional commands, e-mail: meframework-help@cqme.dev.java.net