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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* *******************************************************************
  2. * Copyright (c) 2006 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.systemtest.incremental.tools;
  13. import java.io.File;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. import org.aspectj.ajde.OutputLocationManager;
  19. /**
  20. * Test the OutputLocationManager support used to enable multiple output folders.
  21. * These aren't true "multi-project incremental" tests, but that superclass has some
  22. * 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(this.outputLocationManager);
  32. }
  33. public void testDefaultOutputLocationUsedWhenNoOutputLocationManager() {
  34. configureOutputLocationManager(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 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(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("-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
  61. * sent to a different output location. There should be an
  62. * aop.xml file in each of the two output directories.
  63. */
  64. public void testOutXmlForAspectsWithDifferentOutputDirs() {
  65. configureNonStandardCompileOptions("-outxml");
  66. build(PROJECT_NAME);
  67. assertFileExists(PROJECT_NAME,"target/main/classes/META-INF/aop-ajc.xml");
  68. assertFileExists(PROJECT_NAME,"target/test/classes/META-INF/aop-ajc.xml");
  69. // aop.xml file should exist even if there aren't any aspects (mirrors
  70. // what happens when there's one output dir)
  71. checkXMLAspectCount(PROJECT_NAME,"",0,getFile(PROJECT_NAME,"target/anotherTest/classes"));
  72. // add aspects to the srcRootThree src dir and they should appear in the
  73. // corresponding aop.xml file
  74. alter(PROJECT_NAME,"inc1");
  75. build(PROJECT_NAME);
  76. checkXMLAspectCount(PROJECT_NAME,"c.C$AnAspect",1,getFile(PROJECT_NAME,"target/anotherTest/classes"));
  77. }
  78. protected void assertFileExists(String project, String relativePath) {
  79. assertTrue("file " + relativePath + " should have been created as a result of building " + project,
  80. new File(getFile(project, relativePath)).exists());
  81. }
  82. private static class MyOutputLocationManager implements OutputLocationManager {
  83. private File projectHome;
  84. private List allOutputDirs;
  85. public MyOutputLocationManager(File projectHome) {
  86. this.projectHome = projectHome;
  87. }
  88. public File getOutputLocationForClass(File compilationUnit) {
  89. String relativePath = "";
  90. String compilationUnitName = compilationUnit.getAbsolutePath();
  91. if (compilationUnitName.indexOf("srcRootOne") != -1) {
  92. relativePath = "target/main/classes";
  93. } else if (compilationUnitName.indexOf("srcRootTwo") != -1) {
  94. relativePath = "target/test/classes";
  95. } else if (compilationUnitName.indexOf("srcRootThree") != -1) {
  96. relativePath = "target/anotherTest/classes";
  97. }
  98. File ret = new File(projectHome,relativePath);
  99. if (!ret.exists()) {
  100. ret.mkdirs();
  101. }
  102. return ret;
  103. }
  104. public File getOutputLocationForResource(File resource) {
  105. return getOutputLocationForClass(resource);
  106. }
  107. public List getAllOutputLocations() {
  108. if (allOutputDirs == null) {
  109. allOutputDirs = new ArrayList();
  110. allOutputDirs.add(new File(projectHome,"target/main/classes"));
  111. allOutputDirs.add(new File(projectHome,"target/test/classes"));
  112. allOutputDirs.add(new File(projectHome,"target/anotherTest/classes"));
  113. }
  114. return allOutputDirs;
  115. }
  116. public File getDefaultOutputLocation() {
  117. return new File(projectHome,"target/main/classes");
  118. }
  119. }
  120. }