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.

TestOutputLocationManager.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /********************************************************************
  2. * Copyright (c) 2007 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version
  10. *******************************************************************/
  11. package org.aspectj.ajde.core;
  12. import java.io.File;
  13. import java.util.ArrayList;
  14. import java.util.Collections;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * Test implementation of IOutputLocationManager. By default returns the same location for both resources and classes, however,
  19. * setter methods enable the user to specify different location for these. Note that the user is unable to specify different output
  20. * location for different class files.
  21. */
  22. public class TestOutputLocationManager implements IOutputLocationManager {
  23. private String testProjectOutputPath;
  24. private File classOutputLoc;
  25. private File resourceOutputLoc;
  26. private List<File> allOutputLocations;
  27. private Map<File,String> inpathMap = Collections.emptyMap();
  28. public TestOutputLocationManager(String testProjectPath) {
  29. this.testProjectOutputPath = testProjectPath + File.separator + "bin";
  30. }
  31. public TestOutputLocationManager(String string, Map<File,String> inpathMap) {
  32. this(string);
  33. this.inpathMap = inpathMap;
  34. }
  35. @Override
  36. public File getOutputLocationForClass(File compilationUnit) {
  37. initLocations();
  38. return classOutputLoc;
  39. }
  40. @Override
  41. public File getOutputLocationForResource(File resource) {
  42. initLocations();
  43. return resourceOutputLoc;
  44. }
  45. @Override
  46. public Map<File,String> getInpathMap() {
  47. return inpathMap;
  48. }
  49. // -------------- setter methods useful for testing -------------
  50. public void setOutputLocForClass(File f) {
  51. classOutputLoc = f;
  52. }
  53. public void setOutputLocForResource(File f) {
  54. resourceOutputLoc = f;
  55. }
  56. @Override
  57. public List<File> getAllOutputLocations() {
  58. if (allOutputLocations == null) {
  59. allOutputLocations = new ArrayList<>();
  60. initLocations();
  61. allOutputLocations.add(classOutputLoc);
  62. if (!classOutputLoc.equals(resourceOutputLoc)) {
  63. allOutputLocations.add(resourceOutputLoc);
  64. }
  65. }
  66. return allOutputLocations;
  67. }
  68. @Override
  69. public File getDefaultOutputLocation() {
  70. initLocations();
  71. return classOutputLoc;
  72. }
  73. private void initLocations() {
  74. if (classOutputLoc == null) {
  75. classOutputLoc = new File(testProjectOutputPath);
  76. }
  77. if (resourceOutputLoc == null) {
  78. resourceOutputLoc = new File(testProjectOutputPath);
  79. }
  80. }
  81. @Override
  82. public String getSourceFolderForFile(File sourceFile) {
  83. return null;
  84. }
  85. @Override
  86. public void reportFileWrite(String outputfile, int filetype) {
  87. }
  88. @Override
  89. public void reportFileRemove(String outputfile, int filetype) {
  90. }
  91. @Override
  92. public int discoverChangesSince(File dir, long buildtime) {
  93. // TODO Auto-generated method stub
  94. return 0;
  95. }
  96. }