Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FIXED JENKINS-5044] catch FileNotFoundException if mojos are execute…
…d from a classes directory instead from a jar
- Loading branch information
Showing
4 changed files
with
77 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
62 changes: 62 additions & 0 deletions
62
maven-plugin/src/test/java/hudson/maven/ExecutedMojoTest.java
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); | ||
} | ||
} |