### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java,v retrieving revision 1.73 diff -u -r1.73 TestAll.java --- src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java 16 Oct 2007 10:24:51 -0000 1.73 +++ src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java 4 Mar 2009 16:09:53 -0000 @@ -59,6 +59,7 @@ standardTests.add(RuntimeTests.class); standardTests.add(DebugAttributeTest.class); standardTests.add(NullReferenceTest.class); + standardTests.add(ManifestAnalyzerTest.class); if (UnconditionalFlowInfo.coverageTestFlag) { standardTests.add(NullReferenceImplTests.class); } Index: src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java =================================================================== RCS file: src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java diff -N src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Fabrice Matrat - initial contribution + * IBM Corporation - code review and integration + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; +import java.io.IOException; +import java.io.StringReader; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.batch.ClasspathJar.ManifestAnalyzer; + +public class ManifestAnalyzerTest extends AbstractRegressionTest { + + private static final String FIRST_JAR = "firstJar.jar"; + private static final String SECOND_JAR = "secondJar.jar"; + private static final String WHITESPACE = " "; + + ManifestAnalyzer manifestAnalyzer = new ManifestAnalyzer(); + + public ManifestAnalyzerTest(String name) { + super(name); + } + public void testWithOneJar() throws IOException { + String testWithOneJar = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithOneJar); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithOneJarWithWiteSpace() throws IOException { + String testWithOneJarWithWiteSpace = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithOneJarWithWiteSpace); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithSecondJarOnNextLine() throws IOException { + String testWithSecondJarOnNextLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n"+ WHITESPACE + WHITESPACE +"secondJar.jar\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithSecondJarOnNextLine); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLine() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLine); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLine2() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + WHITESPACE + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLine); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 3, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals("second", jars.get(1)); + assertEquals("Jar.jar", jars.get(2)); + } + + public void testWithSecondJarOnTwoLine3() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + "Jar.jar\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLine); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals("second", jars.get(1)); + } + + public void testWithSecondJarOnTwoLine4() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n" + "second\n" + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLine); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithSecondJarOnNextLine5() throws IOException { + String testWithSecondJarOnNextLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n"+ WHITESPACE + "secondJar.jar\nBuild-Reference: Version toto"; + StringReader reader = new StringReader(testWithSecondJarOnNextLine); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR + SECOND_JAR, jars.get(0)); + } + + public void testWithSecondJarOnTwoLineEndedWithEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithEOF); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithSecondJarOnTwoLineEndedWithEOF2() throws IOException { + String testWithSecondJarOnTwoLineEndedWithEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar\n"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithEOF); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar "; + StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar \n"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLineEndedWithNewLineEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithNewLineEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar\n"; + StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithNewLineEOF); + this.manifestAnalyzer.analyzeManifestContents(reader); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } +} #P org.eclipse.jdt.core Index: batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java,v retrieving revision 1.45.2.1 diff -u -r1.45.2.1 ClasspathJar.java --- batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java 10 Nov 2008 17:46:09 -0000 1.45.2.1 +++ batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java 4 Mar 2009 16:09:54 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Fabrice Matrat - fix for 265103 *******************************************************************************/ package org.eclipse.jdt.internal.compiler.batch; @@ -54,18 +55,20 @@ READING_JAR = 4, CONTINUING = 5, SKIP_LINE = 6; - private static final char[] CLASSPATH_HEADER_TOKEN = + private static final char[] CLASSPATH_HEADER_TOKEN = "Class-Path:".toCharArray(); //$NON-NLS-1$ - private int ClasspathSectionsCount; + private int classpathSectionsCount; private ArrayList calledFilesNames; public boolean analyzeManifestContents(Reader reader) throws IOException { int state = START, substate = 0; StringBuffer currentJarToken = new StringBuffer(); int currentChar; - this.ClasspathSectionsCount = 0; + this.classpathSectionsCount = 0; this.calledFilesNames = null; for (;;) { currentChar = reader.read(); + if (currentChar == '\r') // skip \r, will consider \n later (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=251079 ) + currentChar = reader.read(); switch (state) { case START: if (currentChar == -1) { @@ -91,50 +94,71 @@ case PAST_CLASSPATH_HEADER: if (currentChar == ' ') { state = SKIPPING_WHITESPACE; - this.ClasspathSectionsCount++; + this.classpathSectionsCount++; } else { return false; } break; case SKIPPING_WHITESPACE: if (currentChar == -1) { + // >>>>>>>>>>>>>>>>>> Add the latest jar read + addCurrentTokenJarWhenNecessary(currentJarToken); return true; } else if (currentChar == '\n') { state = CONTINUING; } else if (currentChar != ' ') { currentJarToken.append((char) currentChar); state = READING_JAR; + } else { + // >>>>>>>>>>>>>>>>>> Add the latest jar read + addCurrentTokenJarWhenNecessary(currentJarToken); } break; case CONTINUING: if (currentChar == -1) { + // >>>>>>>>>>>>>>>>>> Add the latest jar read + addCurrentTokenJarWhenNecessary(currentJarToken); return true; } else if (currentChar == '\n') { + addCurrentTokenJarWhenNecessary(currentJarToken); state = START; } else if (currentChar == ' ') { state = SKIPPING_WHITESPACE; } else if (currentChar == CLASSPATH_HEADER_TOKEN[0]) { + addCurrentTokenJarWhenNecessary(currentJarToken); state = IN_CLASSPATH_HEADER; substate = 1; } else if (this.calledFilesNames == null) { - return false; + // >>>>>>>>>>>>>>>>>> Add the latest jar read + addCurrentTokenJarWhenNecessary(currentJarToken); + state = START; } else { + // >>>>>>>>>>>>>>>>>> Add the latest jar read + addCurrentTokenJarWhenNecessary(currentJarToken); state = SKIP_LINE; } break; case SKIP_LINE: if (currentChar == -1) { + if (this.classpathSectionsCount != 0) { + if (this.calledFilesNames == null) { + return false; + } + } return true; } else if (currentChar == '\n') { state = START; } break; - case READING_JAR: + case READING_JAR: if (currentChar == -1) { + // >>>>>>>>>>>>>>>>>> Add the latest jar read return false; } else if (currentChar == '\n') { // appends token below state = CONTINUING; + // >>>>>>>>>>> Add a break to not add the jar yet as it can continue on the next line + break; } else if (currentChar == ' ') { // appends token below state = SKIPPING_WHITESPACE; @@ -142,17 +166,29 @@ currentJarToken.append((char) currentChar); break; } - if (this.calledFilesNames == null) { - this.calledFilesNames = new ArrayList(); - } - this.calledFilesNames.add(currentJarToken.toString()); - currentJarToken.setLength(0); + addCurrentTokenJarWhenNecessary(currentJarToken); break; } - } + } + } + + // >>>>>>>>>>>>>>>> Method Extracted from analyzeManifestContents in the READING_JAR Block + private boolean addCurrentTokenJarWhenNecessary(StringBuffer currentJarToken) { + if (currentJarToken != null && currentJarToken.length() > 0) { + if (this.calledFilesNames == null) { + this.calledFilesNames = new ArrayList(); + } + this.calledFilesNames.add(currentJarToken.toString()); + currentJarToken.setLength(0); + return true; + } + return false; } + // <<<<<<<<<<<<<<<<<<<<<< + + public int getClasspathSectionsCount() { - return this.ClasspathSectionsCount; + return this.classpathSectionsCount; } public List getCalledFileNames() { return this.calledFilesNames;