/*
* 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 6920317
* @summary package-info.java file has to be specified on the javac cmdline, else it will not be avail
* @library ../lib
*/
/**
* The test exercises different ways of providing annotations for a package.
* Each way provides an annotation with a unique argument. For each test
* case, the test verifies that the annotation with the correct argument is
* found by the compiler.
*/
public class T6920317 {
}
// Used to describe properties of files to be put on command line, source path, class path
enum Kind {
/** File is not used. */
NONE,
/** File is used. */
OLD,
/** Only applies to files on classpath/sourcepath, when there is another file on the
* other path of type OLD, in which case, this file must be newer than the other one. */
NEW,
/** Only applies to files on classpath/sourcepath, when there is no file in any other
* location, in which case, this file will be generated by the annotation processor. */
}
// if no args given, all test cases are run
// if args given, they indicate the test cases to be run
}
setup();
// Run tests for all combinations of files on command line, source path and class path.
// Invalid combinations are skipped in the test method
try {
} catch (Exception e) {
e.printStackTrace();
error("Exception " + e);
// uncomment to stop on first failed test case
// throw e;
}
}
}
}
if (errors > 0)
}
/** One time setup for files and directories to be used in the various test cases. */
// Annotation used in test cases to annotate package. This file is
// given on the command line in test cases.
// Compile the annotation for use later in setup
// package-info file to use on the command line when requied
// source path containing package-info
// class path containing package-info
// source path containing package-info which is newer than the one in cp-old
// class path containing package-info which is newer than the one in sp-old
// directory containing package-info.java to be "generated" later by annotation processor
// directory containing package-info.class to be "generated" later by annotation processor
}
return;
++count;
// if test cases specified, skip this test case if not selected
return;
// test specific tmp directory
// build up list of options and files to be compiled
// expected value for annotation
//opts.add("-verbose");
/*
* Analyze each of cl, cp, sp, building up the options and files to
* be compiled, and determining the expected outcome fo the test case.
*/
// command line file: either omitted or given
// command line files always supercede files on paths
expect = "CL";
}
// source path:
switch (sp) {
case NONE:
break;
case OLD:
expect = "SP_OLD";
}
break;
case NEW:
expect = "SP_NEW";
}
break;
case GEN:
expect = "SP_GEN";
break;
}
// class path:
switch (cp) {
case NONE:
break;
case OLD:
expect = "CP_OLD";
}
break;
case NEW:
expect = "CP_NEW";
}
break;
case GEN:
expect = "CP_GEN";
break;
}
// pass expected value to annotation processor
// compile the files with the options that have been built up
}
/**
* Return true if this combination of parameters does not identify a useful test case.
*/
// skip if no package files required
return true;
// skip if both sp and sp are OLD, since results may be indeterminate
return true;
// skip if sp or cp is NEW but the other is not OLD
return true;
// only use GEN if no other package-info files present
return true;
}
// remaining combinations are valid
return false;
}
/** Write a file with a given body. */
if (f.getParentFile() != null)
f.getParentFile().mkdirs();
try {
} finally {
}
return f;
}
/** Write a file with a given body, ensuring that the file is newer than a reference file. */
for (int i = 0; i < 5; i++) {
return f;
}
}
/** Compile a file to a given directory, with options provided. */
}
/** Compile files with options provided. */
if (rc != 0)
}
/** Report an error. */
errors++;
}
/** Test case counter. */
int count;
/** Number of errors found. */
int errors;
/** Optional set of test cases to be run; empty implies all test cases. */
/* Files created by setup. */
/** Annotation processor used to verify the expected value for the
package annotations found by javac. */
round++;
System.err.println("Round " + round + " annots:" + annots + " rootElems:" + renv.getRootElements());
// if this is the first round and the gen option is given, use the filer to create
// a copy of the file specified by the gen option.
try {
else
} catch (IOException e) {
error("Cannot create package-info file: " + e);
}
}
// if annotation processing is complete, verify the package annotation
// found by the compiler.
if (renv.processingOver()) {
} else {
}
}
return true;
}
/** Get an option given to the annotation processor. */
}
/** Read a file. */
try {
} catch (IOException e) {
error("Error reading file: " + e);
} finally {
try {
} catch (IOException e) {
error("Error closing file: " + e);
}
}
}
return bytes;
}
/** Write a file. */
try {
} catch (IOException e) {
error("Error writing file: " + e);
} finally {
try {
} catch (IOException e) {
error("Error closing file: " + e);
}
}
}
}
/** Check two strings are equal, and report an error if they are not. */
}
}
/** Report an error to the annotation processing system. */
}
int round;
}
}