1 package org.apache.maven.resolver.internal.ant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.PrintStream;
24
25 import org.apache.maven.resolver.internal.ant.ProjectWorkspaceReader;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.BuildFileTest;
28 import org.apache.tools.ant.DefaultLogger;
29 import org.apache.tools.ant.Project;
30 import org.eclipse.aether.internal.test.util.TestFileUtils;
31
32 public abstract class AntBuildsTest
33 extends BuildFileTest
34 {
35
36 private static final File BASE_DIR;
37
38 protected static final File BUILD_DIR;
39
40 static
41 {
42 BASE_DIR = new File( "" ).getAbsoluteFile();
43 BUILD_DIR = new File( BASE_DIR, "target/ant" );
44 }
45
46 protected File projectDir;
47
48 protected File localRepoDir;
49
50 protected File distRepoDir;
51
52 protected String getProjectDirName()
53 {
54 String name = getClass().getSimpleName();
55 if ( name.endsWith( "Test" ) )
56 {
57 name = name.substring( 0, name.length() - 4 );
58 }
59 return name;
60 }
61
62 protected void setUpProperties()
63 throws Exception
64 {
65
66 }
67
68 @Override
69 protected void setUp()
70 throws Exception
71 {
72 super.setUp();
73
74 TestFileUtils.deleteFile( BUILD_DIR );
75
76 projectDir = new File( new File( BASE_DIR, "src/test/resources/ant" ), getProjectDirName() );
77 localRepoDir = new File( BUILD_DIR, "local-repo" );
78 distRepoDir = new File( BUILD_DIR, "dist-repo" );
79
80 System.setProperty( "project.dir", projectDir.getAbsolutePath() );
81 System.setProperty( "build.dir", BUILD_DIR.getAbsolutePath() );
82 System.setProperty( "maven.repo.local", localRepoDir.getAbsolutePath() );
83 System.setProperty( "project.distrepo.url", distRepoDir.toURI().toString() );
84 if ( "1.7".equals( System.getProperty( "java.specification.version", "1.7" ) ) )
85 {
86 System.setProperty( "https.protocols", "TLSv1.2" );
87 }
88 setUpProperties();
89
90 configureProject( new File( projectDir, "ant.xml" ).getAbsolutePath(), Project.MSG_VERBOSE );
91 }
92
93 @Override
94 protected void tearDown()
95 throws Exception
96 {
97 try
98 {
99 ProjectWorkspaceReader.dropInstance();
100 TestFileUtils.deleteFile( BUILD_DIR );
101 }
102 finally
103 {
104 super.tearDown();
105 }
106 }
107
108 @Override
109 public void configureProject( String filename, int logLevel )
110 throws BuildException
111 {
112 super.configureProject( filename, logLevel );
113 DefaultLogger logger = new DefaultLogger()
114 {
115 @Override
116 protected void printMessage( String message, PrintStream stream, int priority )
117 {
118 message = System.currentTimeMillis() + " " + message;
119 super.printMessage( message, stream, priority );
120 }
121 };
122 logger.setMessageOutputLevel( logLevel );
123 logger.setOutputPrintStream( System.out );
124 logger.setErrorPrintStream( System.err );
125 getProject().addBuildListener( logger );
126 }
127
128 }