1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/********************************************************************
* Copyright (c) 2006 Contributors. All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://eclipse.org/legal/epl-v10.html
*
* Contributors:
* Adrian Colyer initial implementation
* Helen Hawkins Converted to new interface (bug 148190)
*******************************************************************/
package org.aspectj.systemtest.incremental.tools;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.aspectj.ajde.core.IOutputLocationManager;
/**
* Test the OutputLocationManager support used to enable multiple output folders. These aren't true "multi-project incremental"
* tests, but that superclass has some handy methods over and above AjdeInteractionTestCase that I want to use.
*/
public class OutputLocationManagerTests extends AbstractMultiProjectIncrementalAjdeInteractionTestbed {
private static final String PROJECT_NAME = "MultipleOutputFolders";
private MyOutputLocationManager outputLocationManager;
protected void setUp() throws Exception {
super.setUp();
initialiseProject(PROJECT_NAME);
this.outputLocationManager = new MyOutputLocationManager(new File(getFile(PROJECT_NAME, "")));
configureOutputLocationManager(PROJECT_NAME, this.outputLocationManager);
}
public void testDefaultOutputLocationUsedWhenNoOutputLocationManager() {
configureOutputLocationManager(PROJECT_NAME, null);
build(PROJECT_NAME);
assertFileExists(PROJECT_NAME, "bin/a/A.class");
assertFileExists(PROJECT_NAME, "bin/b/B.class");
}
public void testTwoSourceRootsWithSeparateOutputLocations() {
build(PROJECT_NAME);
assertFileExists(PROJECT_NAME, "target/main/classes/a/A.class");
assertFileExists(PROJECT_NAME, "target/test/classes/b/B.class");
}
public void testResourceCopying() {
Map<String,File> resourceMap = new HashMap<>();
resourceMap.put("resourceOne.txt", new File(getFile(PROJECT_NAME, "srcRootOne/resourceOne.txt")));
resourceMap.put("resourceTwo.txt", new File(getFile(PROJECT_NAME, "srcRootTwo/resourceTwo.txt")));
configureResourceMap(PROJECT_NAME, resourceMap);
build(PROJECT_NAME);
assertFileExists(PROJECT_NAME, "target/main/classes/resourceOne.txt");
assertFileExists(PROJECT_NAME, "target/test/classes/resourceTwo.txt");
}
public void testGeneratedClassesPlacedInAppropriateOutputFolder() {
configureNonStandardCompileOptions(PROJECT_NAME, "-XnoInline");
build(PROJECT_NAME);
assertFileExists(PROJECT_NAME, "target/main/classes/a/A.class");
assertFileExists(PROJECT_NAME, "target/main/classes/a/A$AjcClosure1.class");
}
/**
* Tests the case when we have two aspects, each of which are sent to a different output location. There should be an aop.xml
* file in each of the two output directories.
*/
public void testOutXmlForAspectsWithDifferentOutputDirs() {
configureNonStandardCompileOptions(PROJECT_NAME, "-outxml");
build(PROJECT_NAME);
assertFileExists(PROJECT_NAME, "target/main/classes/META-INF/aop-ajc.xml");
assertFileExists(PROJECT_NAME, "target/test/classes/META-INF/aop-ajc.xml");
// aop.xml file should exist even if there aren't any aspects (mirrors
// what happens when there's one output dir)
checkXMLAspectCount(PROJECT_NAME, "", 0, getFile(PROJECT_NAME, "target/anotherTest/classes"));
// add aspects to the srcRootThree src dir and they should appear in the
// corresponding aop.xml file
alter(PROJECT_NAME, "inc1");
build(PROJECT_NAME);
checkXMLAspectCount(PROJECT_NAME, "c.C$AnAspect", 1, getFile(PROJECT_NAME, "target/anotherTest/classes"));
}
protected void assertFileExists(String project, String relativePath) {
assertTrue("file " + relativePath + " should have been created as a result of building " + project, new File(getFile(
project, relativePath)).exists());
}
private static class MyOutputLocationManager implements IOutputLocationManager {
private File projectHome;
private List<File> allOutputDirs;
public MyOutputLocationManager(File projectHome) {
this.projectHome = projectHome;
}
public void reportFileWrite(String outputfile, int filetype) {
}
public void reportFileRemove(String outputfile, int filetype) {
}
public Map<File,String> getInpathMap() {
return Collections.emptyMap();
}
public File getOutputLocationForClass(File compilationUnit) {
String relativePath = "";
String compilationUnitName = compilationUnit.getAbsolutePath();
if (compilationUnitName.indexOf("srcRootOne") != -1) {
relativePath = "target/main/classes";
} else if (compilationUnitName.indexOf("srcRootTwo") != -1) {
relativePath = "target/test/classes";
} else if (compilationUnitName.indexOf("srcRootThree") != -1) {
relativePath = "target/anotherTest/classes";
}
File ret = new File(projectHome, relativePath);
if (!ret.exists()) {
ret.mkdirs();
}
return ret;
}
public File getOutputLocationForResource(File resource) {
return getOutputLocationForClass(resource);
}
public List<File> getAllOutputLocations() {
if (allOutputDirs == null) {
allOutputDirs = new ArrayList<>();
allOutputDirs.add(new File(projectHome, "target/main/classes"));
allOutputDirs.add(new File(projectHome, "target/test/classes"));
allOutputDirs.add(new File(projectHome, "target/anotherTest/classes"));
}
return allOutputDirs;
}
public File getDefaultOutputLocation() {
return new File(projectHome, "target/main/classes");
}
public String getSourceFolderForFile(File sourceFile) {
return null;
}
public int discoverChangesSince(File dir, long buildtime) {
// TODO Auto-generated method stub
return 0;
}
}
public void reportFileWrite(String outputfile, int filetype) {
}
public void reportFileRemove(String outputfile, int filetype) {
}
}
|