This is the in-repo successor of {@code org.apache.maven.shared.verifier.Verifier} + * (maven-verifier), which is deprecated (see + * apache/maven-verifier#186). + * It keeps the API surface the 3.x core ITs actually use, but drives Maven through + * {@code org.apache.maven.executor:maven-executor} instead of the bespoke launchers + * maven-verifier used, the same way {@code apache/maven}'s {@code core-it-support/maven-it-helper} + * does on master.
+ * + *Unlike the master copy, this class does not rely on a plugin execution to resolve local-repository + * or artifact/metadata paths: it computes them locally (default repository layout only), the way + * maven-verifier did it, so running the ITs does not require downloading a third-party plugin + * (see apache/maven-executor#44).
+ * + * @author Jason van Zyl + * @author Brett Porter + */ +public class Verifier { + private static final String LOG_FILENAME = "log.txt"; + + private static final Listnull.
+ * @return true if the line appears to be a Velocity error, false otherwise.
+ */
+ private static boolean isVelocityError(String line) {
+ return line.contains("VM_global_library.vm") || line.contains("VM #") && line.contains("macro");
+ }
+
+ /**
+ * Throws an exception if the text is not present in the log.
+ *
+ * @param text the text to assert present
+ * @throws VerificationException if text is not found in log
+ */
+ public void verifyTextInLog(String text) throws VerificationException {
+ Listnull.
+ * @param encoding The character encoding of the file, may be null or empty to use the platform default
+ * encoding.
+ * @return The list of (non-empty) lines from the text file, can be empty but never null.
+ * @throws IOException If the file could not be loaded.
+ * @since 1.2
+ */
+ public Listnull.
+ * @param aid The artifact id, must not be null.
+ * @param version The artifact version, may be null.
+ * @return The (absolute) path to the local artifact metadata, never null.
+ */
+ public String getArtifactMetadataPath(String gid, String aid, String version) {
+ return getArtifactMetadataPath(gid, aid, version, "maven-metadata-local.xml");
+ }
+
+ /**
+ * Gets the path to a file in the local artifact directory. Note that the method does not check whether the returned
+ * path actually points to an existing file.
+ *
+ * @param gid The group id, must not be null.
+ * @param aid The artifact id, may be null.
+ * @param version The artifact version, may be null.
+ * @param filename The filename to use, must not be null.
+ * @return The (absolute) path to the local artifact metadata, never null.
+ */
+ public String getArtifactMetadataPath(String gid, String aid, String version, String filename) {
+ StringBuilder buffer = new StringBuilder(256);
+
+ buffer.append(getLocalRepository());
+ buffer.append('/');
+
+ buffer.append(gid.replace('.', '/'));
+ buffer.append('/');
+
+ if (aid != null) {
+ buffer.append(aid);
+ buffer.append('/');
+
+ if (version != null) {
+ buffer.append(version);
+ buffer.append('/');
+ }
+ }
+
+ buffer.append(filename);
+
+ return buffer.toString();
+ }
+
+ /**
+ * Gets the path to the local artifact metadata. Note that the method does not check whether the returned path
+ * actually points to existing metadata.
+ *
+ * @param gid The group id, must not be null.
+ * @param aid The artifact id, must not be null.
+ * @return The (absolute) path to the local artifact metadata, never null.
+ */
+ public String getArtifactMetadataPath(String gid, String aid) {
+ return getArtifactMetadataPath(gid, aid, null);
+ }
+
+ public void deleteArtifact(String org, String name, String version, String ext) throws IOException {
+ Listnull.
+ * @throws IOException If the artifacts could not be deleted.
+ * @since 1.2
+ */
+ public void deleteArtifacts(String gid) throws IOException {
+ String path = gid.replace('.', '/');
+ FileUtils.deleteDirectory(new File(getLocalRepository(), path));
+ }
+
+ /**
+ * Deletes all artifacts in the specified g:a:v from the local repository.
+ *
+ * @param gid The group id whose artifacts should be deleted, must not be null.
+ * @param aid The artifact id whose artifacts should be deleted, must not be null.
+ * @param version The (base) version whose artifacts should be deleted, must not be null.
+ * @throws IOException If the artifacts could not be deleted.
+ * @since 1.3
+ */
+ public void deleteArtifacts(String gid, String aid, String version) throws IOException {
+ String path = gid.replace('.', '/') + '/' + aid + '/' + version;
+ FileUtils.deleteDirectory(new File(getLocalRepository(), path));
+ }
+
+ /**
+ * Deletes the specified directory.
+ *
+ * @param path The path to the directory to delete, relative to the base directory, must not be null.
+ * @throws IOException If the directory could not be deleted.
+ * @since 1.2
+ */
+ public void deleteDirectory(String path) throws IOException {
+ FileUtils.deleteDirectory(new File(getBasedir(), path));
+ }
+
+ /**
+ * Filters a text file by replacing some user-defined tokens.
+ * This method is equivalent to:
+ *
+ * + * filterFile( srcPath, dstPath, fileEncoding, verifier.newDefaultFilterMap() ) + *+ * + * @param srcPath The path to the input file, relative to the base directory, must not be + *
null.
+ * @param dstPath The path to the output file, relative to the base directory and possibly equal to the
+ * input file, must not be null.
+ * @param fileEncoding The file encoding to use, may be null or empty to use the platform's default
+ * encoding.
+ * @return The path to the filtered output file, never null.
+ * @throws IOException If the file could not be filtered.
+ * @since 2.0
+ */
+ public File filterFile(String srcPath, String dstPath, String fileEncoding) throws IOException {
+ return filterFile(srcPath, dstPath, fileEncoding, newDefaultFilterMap());
+ }
+
+ /**
+ * Filters a text file by replacing some user-defined tokens.
+ *
+ * @param srcPath The path to the input file, relative to the base directory, must not be
+ * null.
+ * @param dstPath The path to the output file, relative to the base directory and possibly equal to the
+ * input file, must not be null.
+ * @param fileEncoding The file encoding to use, may be null or empty to use the platform's default
+ * encoding.
+ * @param filterMap The mapping from tokens to replacement values, must not be null.
+ * @return The path to the filtered output file, never null.
+ * @throws IOException If the file could not be filtered.
+ * @since 1.2
+ */
+ /**
+ * @deprecated use {@link #filterFile(String, String, String, Map)}
+ */
+ @Deprecated
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public File filterFile(String srcPath, String dstPath, String fileEncoding, Properties filterProperties)
+ throws IOException {
+ return filterFile(srcPath, dstPath, fileEncoding, (Map) filterProperties);
+ }
+
+ public File filterFile(String srcPath, String dstPath, String fileEncoding, Mapfile: URL, respectively.
+ *
+ * @return The (modifiable) map with the default filter map, never null.
+ * @since 2.0
+ */
+ public Map