Test for various import errors.
diff --git a/data/input/importErrors/plugins/file.txt b/data/input/importErrors/plugins/file.txt new file mode 100644 index 0000000..d6459e0 --- /dev/null +++ b/data/input/importErrors/plugins/file.txt
@@ -0,0 +1 @@ +xxx
diff --git a/data/input/importErrors/plugins/nomanifest.jar b/data/input/importErrors/plugins/nomanifest.jar new file mode 100644 index 0000000..e6ab833 --- /dev/null +++ b/data/input/importErrors/plugins/nomanifest.jar Binary files differ
diff --git a/data/input/importErrors/plugins/notajar.jar b/data/input/importErrors/plugins/notajar.jar new file mode 100644 index 0000000..d6459e0 --- /dev/null +++ b/data/input/importErrors/plugins/notajar.jar
@@ -0,0 +1 @@ +xxx
diff --git a/data/input/importErrors/plugins/org.eclipse.birt.report.data.oda.jdbc.dbprofile-3.7.0.v20110603.jar b/data/input/importErrors/plugins/org.eclipse.birt.report.data.oda.jdbc.dbprofile-3.7.0.v20110603.jar new file mode 100644 index 0000000..28f96e6 --- /dev/null +++ b/data/input/importErrors/plugins/org.eclipse.birt.report.data.oda.jdbc.dbprofile-3.7.0.v20110603.jar Binary files differ
diff --git a/src/main/groovy/m4e/AbstractCommand.groovy b/src/main/groovy/m4e/AbstractCommand.groovy index 21c53a4..e7b6e36 100644 --- a/src/main/groovy/m4e/AbstractCommand.groovy +++ b/src/main/groovy/m4e/AbstractCommand.groovy
@@ -62,28 +62,42 @@ warningCount ++ log.warn( msg + '\nFor details, see ' + warning.url() ) - if( errorLog && xml ) { - Map map = new LinkedHashMap() - - map['code'] = warning.code() - map.putAll( xml ) - - errorLog.write().invokeMethod( 'warning', [ map, msg ] ) + appendToErrorLog( 'warning', warning.code(), msg, xml ) + } + + void appendToErrorLog( String nodeName, String code, String msg, Map xml ) { + if( ! errorLog ) { + return } + + Map map = new LinkedHashMap() + + map['code'] = code + if( xml ) { + map.putAll( xml ) + } + + errorLog.write().invokeMethod( nodeName, [ map, msg ] ) } void error( Error error, String msg, Map xml = null ) { errorCount ++ log.error( msg + '\nFor details, see ' + error.url() ) - if( errorLog && xml ) { - Map map = new LinkedHashMap() - - map['code'] = error.code() - map.putAll( xml ) - - errorLog.write().invokeMethod( 'error', [ map, msg ] ) + appendToErrorLog( 'error', error.code(), msg, xml ) + } + + void error( Error error, String msg, Exception e, Map xml = null ) { + errorCount ++ + log.error( msg + '\nFor details, see ' + error.url(), e ) + + if( ! xml ) { + xml = [:] } + + xml[ 'exception' ] = e.message + + appendToErrorLog( 'error', error.code(), msg, xml ) } void mergeCounters( AbstractCommand other ) {
diff --git a/src/main/groovy/m4e/Error.java b/src/main/groovy/m4e/Error.java index 60865f0..05f4085 100644 --- a/src/main/groovy/m4e/Error.java +++ b/src/main/groovy/m4e/Error.java
@@ -14,7 +14,8 @@ public enum Error { TWO_VERSIONS( 1 ), MAVEN_FAILED( 2 ), - MISSING_MANIFEST( 3 ); + MISSING_MANIFEST( 3 ), + IMPORT_ERROR( 4 ); private final int id;
diff --git a/src/main/groovy/m4e/InstallCmd.groovy b/src/main/groovy/m4e/InstallCmd.groovy index 5c0f07c..de5731f 100644 --- a/src/main/groovy/m4e/InstallCmd.groovy +++ b/src/main/groovy/m4e/InstallCmd.groovy
@@ -231,7 +231,7 @@ tool.close() } catch( Exception e ) { - throw new RuntimeException( "Error processing ${it.absolutePath}: ${e}", e ) + installCmd.error( Error.IMPORT_ERROR, "Error processing ${it.absolutePath}: ${e}", e, [ file: it.absolutePath ] ) } } }
diff --git a/src/test/groovy/m4e/InstallCmdTest.groovy b/src/test/groovy/m4e/InstallCmdTest.groovy index 35788ef..cfdda2e 100644 --- a/src/test/groovy/m4e/InstallCmdTest.groovy +++ b/src/test/groovy/m4e/InstallCmdTest.groovy
@@ -21,7 +21,7 @@ import de.pdark.decentxml.XMLParser; import de.pdark.decentxml.XMLStringSource; -class InstallCmdTest { +class InstallCmdTest implements CommonConstants { static { MopSetup.setup() @@ -208,6 +208,53 @@ , actual) } + + @Test + public void testImportErrors() throws Exception { + def workDir = CommonTestCode.newFile( 'testImportErrors' ) + assert workDir.deleteDir(), "Failed to delete ${workDir.absolutePath}" + workDir.makedirs() + + File data = new File( 'data/input/importErrors' ) + File inputDir = new File( workDir, 'downloads/junit' ) + data.copy( inputDir ) + + InstallCmd cmd = new InstallCmd( workDir: workDir ) + + cmd.run([ 'install', inputDir.path ]) + + File repo = cmd.m2repos[ 0 ] + + File installLog = new File( repo, MT4E_FOLDER + '/logs/install.xml' ) + assert installLog.exists() + + def lines = installLog.getText( UTF_8 ) + .replace( repo.absolutePath, '${m2repo}' ) + .replace( inputDir.absolutePath, '${input}' ) + .replace( '\\', '/' ) + lines = lines.split( '\n' ) as List + + lines = [lines[0]] + lines[1..-2].sort() + [lines[-1]] + String actual = lines.join( '\n' ) + +// lines = ['0','1','2','3','4','5'] +// println lines[1..lines.size()-1] +// println lines[1..-1] +// println lines[1..<lines.size()-1] +// println lines[1..<-1] +// println lines[1..<-2] +// println lines[1..-2] + + + assertEquals( '''\ +<mt4e-log command='install'> +<error code='E0003' jar='${input}/plugins/nomanifest.jar'>Can't find manifest in ${input}/plugins/nomanifest.jar</error> +<error code='E0003' jar='${input}/plugins/unpackedPlugin/META-INF/MANIFEST.MF'>Can't find manifest ${input}/plugins/unpackedPlugin/META-INF/MANIFEST.MF</error> +<error code='E0004' file='${input}/plugins/file.txt' exception='error in opening zip file'>Error processing ${input}/plugins/file.txt: java.util.zip.ZipException: error in opening zip file</error> +<error code='E0004' file='${input}/plugins/notajar.jar' exception='error in opening zip file'>Error processing ${input}/plugins/notajar.jar: java.util.zip.ZipException: error in opening zip file</error> +<warning code='W0004' jar='${m2repo}/org/eclipse/birt/org.eclipse.birt.report.data.oda.jdbc.dbprofile/3.7.0.v20110603/org.eclipse.birt.report.data.oda.jdbc.dbprofile-3.7.0.v20110603.jar' nestedJarPath='.,src'>Multiple nested JARs are not supported; just copying the original bundle</warning> +</mt4e-log>''', actual ) + } void downloadDeltaPack() { if( archive.exists() ) {