geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r486868 - /geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/VerifyLegalFilesMojo.java
Date Wed, 13 Dec 2006 22:25:38 GMT
Author: jdillon
Date: Wed Dec 13 14:25:38 2006
New Revision: 486868

URL: http://svn.apache.org/viewvc?view=rev&rev=486868
Log:
Improved the legal file checking, forcing a set of files to exist to pass
Checks in META-INF/ and artifactId-version/ (for assemblies)

Modified:
    geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/VerifyLegalFilesMojo.java

Modified: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/VerifyLegalFilesMojo.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/VerifyLegalFilesMojo.java?view=diff&rev=486868&r1=486867&r2=486868
==============================================================================
--- geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/VerifyLegalFilesMojo.java
(original)
+++ geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/VerifyLegalFilesMojo.java
Wed Dec 13 14:25:38 2006
@@ -46,15 +46,11 @@
     extends MojoSupport
 {
     /**
-     * The list of legal files under META-INF we look for.
+     * The default required legal files.
      */
-    private static final String[] LEGAL_FILES = {
+    private static final String[] DEFAULT_REQUIRED_FILES = {
         "LICENSE.txt",
-        "LICENSE",
-        "NOTICE.txt",
-        "NOTICE",
-        "DISCLAIMER.txt",
-        "DISCLAIMER"
+        "NOTICE.txt"
     };
 
     /**
@@ -64,6 +60,14 @@
      */
     private boolean strict;
 
+
+    /**
+     * The list of required legal files.
+     *
+     * @parameter
+     */
+    private String[] requiredFiles = DEFAULT_REQUIRED_FILES;
+
     /**
      * The maven project.
      *
@@ -89,16 +93,18 @@
                 continue;
             }
 
-            log.info("Verifying legal files: " + file.getName());
-            
             try {
                 ZipFile zfile = new ZipFile(file);
+
+                log.info("Checking legal files in: " + file.getName());
+
                 if (!containsLegalFiles(zfile)) {
+                    String msg = "Artifact does not contain any legal files: " + file.getName();
                     if (strict) {
-                        throw new MojoExecutionException("Artifact does not contain any legal
files: " + file);
+                        throw new MojoExecutionException(msg);
                     }
                     else {
-                        log.warn("Artifact does not contain any legal files: " + file);
+                        log.warn(msg);
                     }
                 }
             }
@@ -111,24 +117,24 @@
     private boolean containsLegalFiles(final ZipFile file) throws IOException {
         assert file != null;
 
-        // First check in META-INF
-        for (int i=0; i < LEGAL_FILES.length; i++) {
-            ZipEntry entry = file.getEntry("META-INF/" + LEGAL_FILES[i]);
-            if (entry != null) {
-                // found one, thats all we need
-                return true;
-            }
-        }
+        return containsLegalFiles(file, "META-INF") ||
+               containsLegalFiles(file, project.getArtifactId() + "-" + project.getVersion());
+    }
 
-        // Then root (needed for assemblies)
-        for (int i=0; i < LEGAL_FILES.length; i++) {
-            ZipEntry entry = file.getEntry(LEGAL_FILES[i]);
-            if (entry != null) {
-                // found one, thats all we need
-                return true;
+    private boolean containsLegalFiles(final ZipFile file, final String basedir) {
+        assert file != null;
+        assert basedir != null;
+
+        for (int i=0; i < requiredFiles.length; i++) {
+            String filename = basedir + "/" + requiredFiles[i];
+            log.debug("Checking for: " + filename);
+            
+            ZipEntry entry = file.getEntry(filename);
+            if (entry == null) {
+                return false;
             }
         }
 
-        return false;
+        return true;
     }
 }



Mime
View raw message