You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OutputLocationManagerTests.java 5.9KB

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