Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-5044] catch FileNotFoundException if mojos are execute…
…d from a classes directory instead from a jar Originally-Committed-As: 68f5a0d23ab4a5631df15b521b8eb71a2a74cc49
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package hudson.maven; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.descriptor.MojoDescriptor; | ||
import org.apache.maven.plugin.descriptor.PluginDescriptor; | ||
import org.codehaus.plexus.classworlds.realm.ClassRealm; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Bug; | ||
|
||
/** | ||
* Unit test for {@link ExecutedMojo}. | ||
* | ||
* @author kutzi | ||
*/ | ||
public class ExecutedMojoTest { | ||
|
||
private MojoDescriptor mojoDescriptor; | ||
|
||
@Before | ||
public void before() { | ||
PluginDescriptor pluginDescriptor = new PluginDescriptor(); | ||
pluginDescriptor.setGroupId("com.test"); | ||
pluginDescriptor.setArtifactId("testPlugin"); | ||
pluginDescriptor.setVersion("1.0"); | ||
|
||
ClassRealm classRealm = new ClassRealm(null, "test", getClass().getClassLoader()); | ||
pluginDescriptor.setClassRealm(classRealm); | ||
|
||
MojoDescriptor descriptor = new MojoDescriptor(); | ||
descriptor.setPluginDescriptor(pluginDescriptor); | ||
this.mojoDescriptor = descriptor; | ||
} | ||
|
||
@Test | ||
public void testMojoFromJarFile() throws IOException, InterruptedException { | ||
// Faking JUnit's Assert to be the plugin class | ||
this.mojoDescriptor.setImplementation(Assert.class.getName()); | ||
MojoExecution execution = new MojoExecution(this.mojoDescriptor); | ||
MojoInfo info = new MojoInfo(execution, null, null, null); | ||
|
||
ExecutedMojo executedMojo = new ExecutedMojo(info, 1L); | ||
|
||
Assert.assertNotNull(executedMojo.digest); | ||
} | ||
|
||
@Test | ||
@Bug(5044) | ||
public void testMojoFromClassesDirectory() throws IOException, InterruptedException { | ||
// Faking this class as the mojo impl: | ||
this.mojoDescriptor.setImplementation(getClass().getName()); | ||
MojoExecution execution = new MojoExecution(this.mojoDescriptor); | ||
MojoInfo info = new MojoInfo(execution, null, null, null); | ||
|
||
ExecutedMojo executedMojo = new ExecutedMojo(info, 1L); | ||
|
||
Assert.assertEquals("com.test", executedMojo.groupId); | ||
} | ||
} |