Example #1
0
 private void addModule(Project parent, Project module) {
   ProjectDefinition parentDefinition = projectTree.getProjectDefinition(parent);
   java.io.File parentBaseDir = parentDefinition.getBaseDir();
   ProjectDefinition moduleDefinition = projectTree.getProjectDefinition(module);
   java.io.File moduleBaseDir = moduleDefinition.getBaseDir();
   module.setPath(new PathResolver().relativePath(parentBaseDir, moduleBaseDir));
   addResource(module);
   for (Project submodule : module.getModules()) {
     addModule(module, submodule);
   }
 }
Example #2
0
 @Override
 public String getSource(Resource reference) {
   Resource resource = getResource(reference);
   if (resource instanceof File) {
     File file = (File) resource;
     Project module = currentProject;
     ProjectDefinition def = projectTree.getProjectDefinition(module);
     try {
       return FileUtils.readFileToString(new java.io.File(def.getBaseDir(), file.getPath()));
     } catch (IOException e) {
       throw new IllegalStateException("Unable to read file content " + reference, e);
     }
   }
   return null;
 }
Example #3
0
 private Bucket getBucket(@Nullable Resource reference) {
   if (reference == null) {
     return null;
   }
   if (StringUtils.isNotBlank(reference.getKey())) {
     return buckets.get(reference);
   }
   String relativePathFromSourceDir = null;
   boolean isTest = false;
   boolean isDir = false;
   if (reference instanceof File) {
     File referenceFile = (File) reference;
     isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier());
     relativePathFromSourceDir = referenceFile.relativePathFromSourceDir();
   } else if (reference instanceof Directory) {
     isDir = true;
     Directory referenceDir = (Directory) reference;
     relativePathFromSourceDir = referenceDir.relativePathFromSourceDir();
     if (Directory.ROOT.equals(relativePathFromSourceDir)) {
       relativePathFromSourceDir = "";
     }
   }
   if (relativePathFromSourceDir != null) {
     // Resolve using deprecated key
     List<String> dirs;
     ProjectDefinition projectDef = projectTree.getProjectDefinition(getProject());
     if (isTest) {
       dirs = projectDef.getTestDirs();
     } else {
       dirs = projectDef.getSourceDirs();
     }
     for (String src : dirs) {
       java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src);
       java.io.File abs = new java.io.File(dirOrFile, relativePathFromSourceDir);
       Bucket b =
           getBucket(
               isDir
                   ? Directory.fromIOFile(abs, getProject())
                   : File.fromIOFile(abs, getProject()));
       if (b != null) {
         return b;
       }
     }
   }
   return null;
 }