1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.util.Properties;
24
25 import org.apache.maven.plugin.eclipse.writers.workspace.EclipseWorkspaceWriter;
26 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
27 import org.codehaus.plexus.PlexusTestCase;
28
29
30
31
32 public class AddMavenRepoMojoTest
33 extends AbstractMojoTestCase
34 {
35 public void testMinConfiguration()
36 throws Exception
37 {
38 }
39
40 private AddMavenRepoMojo executeMojo( String pomXml )
41 throws Exception
42 {
43 AddMavenRepoMojo mojo = getConfiguredMojo( pomXml );
44
45 mojo.execute();
46
47 File workDir = new File( mojo.getWorkspace(), EclipseWorkspaceWriter.ECLIPSE_CORE_RUNTIME_SETTINGS_DIR );
48
49 File eclipseJDTCorePrefsFile = new File( workDir, EclipseWorkspaceWriter.ECLIPSE_JDT_CORE_PREFS_FILE );
50
51 assertTrue( "Test if workspace properties exists", eclipseJDTCorePrefsFile.exists() );
52
53 Properties props = new Properties();
54 props.load( new FileInputStream( eclipseJDTCorePrefsFile ) );
55
56 String M2_REPO = props.getProperty( EclipseWorkspaceWriter.CLASSPATH_VARIABLE_M2_REPO );
57
58 assertNotNull( "Test M2_REPO has a value", M2_REPO );
59
60 String localRepo = PlexusTestCase.getBasedir() + "/target/local-repo";
61
62 assertEquals( "Test M2_REPO value", localRepo.replace( '\\', '/' ), M2_REPO.replace( '\\', '/' ) );
63
64 return mojo;
65 }
66
67 private AddMavenRepoMojo getConfiguredMojo( String pomXml )
68 throws Exception
69 {
70 File pomXmlFile =
71 new File( PlexusTestCase.getBasedir(), "target/test-classes/test-harness/add-maven-repo/" + pomXml );
72
73 AddMavenRepoMojo mojo = (AddMavenRepoMojo) lookupMojo( "add-maven-repo", pomXmlFile );
74
75 return mojo;
76 }
77 }