Ejemplo n.º 1
0
  protected List<CommitInfo> doHistory(
      Git git, String branch, String objectId, String path, int limit) {
    Repository r = git.getRepository();

    CommitFinder finder = new CommitFinder(r);
    CommitListFilter block = new CommitListFilter();
    if (Strings.isNotBlank(path)) {
      finder.setFilter(PathFilterUtils.and(path));
    }
    finder.setFilter(block);

    if (limit > 0) {
      finder.setFilter(new CommitLimitFilter(100).setStop(true));
    }
    if (Strings.isNotBlank(objectId)) {
      finder.findFrom(objectId);
    } else {
      if (Strings.isNotBlank(branch)) {
        RevCommit base = CommitUtils.getBase(r, branch);
        finder.findFrom(base);
      } else {
        finder.find();
      }
    }
    List<RevCommit> commits = block.getCommits();
    List<CommitInfo> results = new ArrayList<CommitInfo>();
    for (RevCommit entry : commits) {
      CommitInfo commitInfo = createCommitInfo(entry);
      results.add(commitInfo);
    }
    return results;
  }
Ejemplo n.º 2
0
 protected String doReadJsonChildContent(
     Git git, File rootDir, String branch, String path, String fileNameWildcard, String search)
     throws GitAPIException, IOException {
   checkoutBranch(git, branch);
   File file = getFile(rootDir, path);
   FileFilter filter = FileFilters.createFileFilter(fileNameWildcard);
   boolean first = true;
   StringBuilder buffer = new StringBuilder("{\n");
   List<FileInfo> children = new ArrayList<FileInfo>();
   if (file.isDirectory()) {
     if (file.exists()) {
       File[] files = file.listFiles();
       for (File child : files) {
         if (!isIgnoreFile(child) && child.isFile()) {
           String text = IOHelper.readFully(child);
           if (!Strings.isNotBlank(search) || text.contains(search)) {
             if (first) {
               first = false;
             } else {
               buffer.append(",\n");
             }
             buffer.append("\"");
             buffer.append(child.getName());
             buffer.append("\": ");
             buffer.append(text);
             children.add(FileInfo.createFileInfo(rootDir, child));
           }
         }
       }
     }
   }
   buffer.append("\n}");
   return buffer.toString();
 }
Ejemplo n.º 3
0
 @Override
 public String getConfigDir() {
   if (Strings.isBlank(configDir)) {
     // lets default to the users home directory
     String home = System.getProperty("user.home", "~");
     configDir = home + System.getProperty("hawtio.dirname", "/.hawtio");
   }
   return configDir;
 }
Ejemplo n.º 4
0
 public CommitInfo createCommitInfo(RevCommit entry) {
   final Date date = GitFacade.getCommitDate(entry);
   String author = entry.getAuthorIdent().getName();
   boolean merge = entry.getParentCount() > 1;
   String shortMessage = entry.getShortMessage();
   String trimmedMessage = Strings.trimString(shortMessage, 78);
   String name = entry.getName();
   String commitHashText = getShortCommitHash(name);
   return new CommitInfo(commitHashText, name, author, date, merge, trimmedMessage, shortMessage);
 }
Ejemplo n.º 5
0
 protected FileInfo doExists(Git git, File rootDir, String branch, String pathOrEmpty)
     throws GitAPIException {
   checkoutBranch(git, branch);
   final String path = Strings.isBlank(pathOrEmpty) ? "/" : pathOrEmpty;
   File file = getFile(rootDir, path);
   if (file.exists()) {
     return FileInfo.createFileInfo(rootDir, file);
   }
   return null;
 }
Ejemplo n.º 6
0
 protected Class<?> tryFindClass(String className, String filter) {
   Class<?> aClass = null;
   if (Strings.isNotBlank(className) && classNameMatches(className, filter)) {
     try {
       aClass = findClass(className);
     } catch (Throwable e) {
       LOG.debug("Could not load class " + className + ". " + e, e);
     }
   }
   return aClass;
 }
Ejemplo n.º 7
0
 /**
  * Returns the configuration directory; lazily attempting to create it if it does not yet exist
  */
 public File getConfigDirectory() {
   String dirName = getConfigDir();
   File answer = null;
   if (Strings.isNotBlank(dirName)) {
     answer = new File(dirName);
   } else {
     answer = new File(".hawtio");
   }
   answer.mkdirs();
   return answer;
 }
Ejemplo n.º 8
0
 protected void processDirectoryClassNames(
     File directory, String packageName, Set<String> classes) {
   String[] fileNames = directory.list();
   if (fileNames != null) {
     for (String fileName : fileNames) {
       String packagePrefix = Strings.isNotBlank(packageName) ? packageName + '.' : packageName;
       if (fileName.endsWith(".class")) {
         String className = packagePrefix + fileName.substring(0, fileName.length() - 6);
         classes.add(className);
       }
       File subdir = new File(directory, fileName);
       if (subdir.isDirectory()) {
         processDirectoryClassNames(subdir, packagePrefix + fileName, classes);
       }
     }
   }
 }
Ejemplo n.º 9
0
 protected List<String> doCompletePath(
     Git git, File rootDir, String branch, String completionText, boolean directoriesOnly)
     throws GitAPIException {
   checkoutBranch(git, branch);
   boolean empty = Strings.isBlank(completionText);
   String pattern = completionText;
   File file = getFile(rootDir, completionText);
   String prefix = completionText;
   if (file.exists()) {
     pattern = "";
   } else {
     String startPath = ".";
     if (!empty) {
       int idx = completionText.lastIndexOf('/');
       if (idx >= 0) {
         startPath = completionText.substring(0, idx);
         if (startPath.length() == 0) {
           startPath = "/";
         }
         pattern = completionText.substring(idx + 1);
       }
     }
     file = getFile(rootDir, startPath);
     prefix = startPath;
   }
   if (prefix.length() > 0 && !prefix.endsWith("/")) {
     prefix += "/";
   }
   if (prefix.equals("./")) {
     prefix = "";
   }
   File[] list = file.listFiles();
   List<String> answer = new ArrayList<String>();
   for (File aFile : list) {
     String name = aFile.getName();
     if (pattern.length() == 0 || name.contains(pattern)) {
       if (!isIgnoreFile(aFile) && (!directoriesOnly || aFile.isDirectory())) {
         answer.add(prefix + name);
       }
     }
   }
   return answer;
 }
Ejemplo n.º 10
0
 /** Reads the file contents from the currently checked out branch */
 protected FileContents doRead(Git git, File rootDir, String branch, String pathOrEmpty)
     throws IOException, GitAPIException {
   checkoutBranch(git, branch);
   String path = Strings.isBlank(pathOrEmpty) ? "/" : pathOrEmpty;
   File file = getFile(rootDir, path);
   if (file.isFile()) {
     String contents = IOHelper.readFully(file);
     return new FileContents(false, contents, null);
   } else {
     List<FileInfo> children = new ArrayList<FileInfo>();
     if (file.exists()) {
       File[] files = file.listFiles();
       for (File child : files) {
         if (!isIgnoreFile(child)) {
           children.add(FileInfo.createFileInfo(rootDir, child));
         }
       }
     }
     return new FileContents(file.isDirectory(), null, children);
   }
 }
Ejemplo n.º 11
0
 protected void processDirectory(
     File directory, String packageName, Set<Class<?>> classes, String filter, Integer limit) {
   String[] fileNames = directory.list();
   if (fileNames != null) {
     for (String fileName : fileNames) {
       if (!withinLimit(limit, classes)) {
         return;
       }
       String className = null;
       String packagePrefix = Strings.isNotBlank(packageName) ? packageName + '.' : packageName;
       if (fileName.endsWith(".class")) {
         className = packagePrefix + fileName.substring(0, fileName.length() - 6);
       }
       Class<?> aClass = tryFindClass(className, filter);
       if (aClass != null) {
         classes.add(aClass);
       }
       File subdir = new File(directory, fileName);
       if (subdir.isDirectory()) {
         processDirectory(subdir, packagePrefix + fileName, classes, filter, limit);
       }
     }
   }
 }
Ejemplo n.º 12
0
  public AetherResult resolve(
      String groupId, String artifactId, String version, String extension, String classifier)
      throws PlexusContainerException, ComponentLookupException, DependencyCollectionException,
          ArtifactResolutionException, DependencyResolutionException {
    if (Strings.isBlank(extension) || extension.equals("bundle")) {
      extension = DEFAULT_EXTENSION;
    }
    if (classifier == null) {
      classifier = DEFAULT_CLASSIFIER;
    }

    RepositorySystemSession session = newSession();
    Dependency dependency =
        new Dependency(
            new DefaultArtifact(groupId, artifactId, classifier, extension, version), "runtime");

    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(dependency);

    List<RemoteRepository> repos = getRemoteRepositories();
    RemoteRepository[] repoArray = new RemoteRepository[repos.size()];
    repos.toArray(repoArray);
    for (RemoteRepository repo : repoArray) {
      collectRequest.addRepository(repo);
    }
    RepositorySystem system = getRepositorySystem();
    DependencyNode rootNode = system.collectDependencies(session, collectRequest).getRoot();
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setRoot(rootNode);
    system.resolveDependencies(session, dependencyRequest);

    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    rootNode.accept(nlg);

    return new AetherResult(rootNode, nlg.getFiles(), nlg.getClassPath());
  }
Ejemplo n.º 13
0
  protected String doDiff(Git git, String objectId, String baseObjectId, String path) {
    Repository r = git.getRepository();
    /*
            RevCommit commit = JGitUtils.getCommit(r, objectId);

            ObjectId current;
            if (isNotBlank(objectId)) {
                current = BlobUtils.getId(r, objectId, blobPath);
            } else {
                current = CommitUtils.getHead(r).getId();
            }
            ObjectId previous;
            if (isNotBlank(baseObjectId)) {
                previous = BlobUtils.getId(r, baseObjectId, blobPath);
            } else {
                RevCommit revCommit = CommitUtils.getCommit(r, current);
                RevCommit[] parents = revCommit.getParents();
                if (parents.length == 0) {
                    throw new IllegalArgumentException("No parent commits!");
                } else {
                    previous = parents[0];
                }
            }
            Collection<Edit> changes = BlobUtils.diff(r, previous, current);

            // no idea how to format Collection<Edit> :)

    */

    RevCommit commit;
    if (Strings.isNotBlank(objectId)) {
      commit = CommitUtils.getCommit(r, objectId);
    } else {
      commit = CommitUtils.getHead(r);
    }
    RevCommit baseCommit = null;
    if (Strings.isNotBlank(baseObjectId)) {
      baseCommit = CommitUtils.getCommit(r, baseObjectId);
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    RawTextComparator cmp = RawTextComparator.DEFAULT;
    DiffFormatter formatter = new DiffFormatter(buffer);
    formatter.setRepository(r);
    formatter.setDiffComparator(cmp);
    formatter.setDetectRenames(true);

    RevTree commitTree = commit.getTree();
    RevTree baseTree;
    try {
      if (baseCommit == null) {
        if (commit.getParentCount() > 0) {
          final RevWalk rw = new RevWalk(r);
          RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
          rw.dispose();
          baseTree = parent.getTree();
        } else {
          // FIXME initial commit. no parent?!
          baseTree = commitTree;
        }
      } else {
        baseTree = baseCommit.getTree();
      }

      List<DiffEntry> diffEntries = formatter.scan(baseTree, commitTree);
      if (path != null && path.length() > 0) {
        for (DiffEntry diffEntry : diffEntries) {
          if (diffEntry.getNewPath().equalsIgnoreCase(path)) {
            formatter.format(diffEntry);
            break;
          }
        }
      } else {
        formatter.format(diffEntries);
      }
      formatter.flush();
      return buffer.toString();
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
  }