Created
March 5, 2012 10:37
-
-
Save anpieber/1977817 to your computer and use it in GitHub Desktop.
simple osgi bundle package analyser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import java.util.Set; | |
public class OsgiPackageAnalyserScript { | |
private static final String BASE_STRING = "/home/pieber/projects/wicket/"; | |
private static final String[] PROJECTS = { | |
"wicket-auth-roles", | |
"wicket-core", | |
"wicket-datetime", | |
"wicket-devutils", | |
"wicket-extensions", | |
"wicket-guice", | |
"wicket-ioc", | |
"wicket-jmx", | |
"wicket-objectssizeof-agent", | |
"wicket-request", | |
"wicket-spring", | |
"wicket-util", | |
"wicket-velocity", | |
}; | |
public static void main(String[] args) { | |
Map<String, List<Project>> projectBuckets = new HashMap<String, List<Project>>(); | |
for (String projectName : PROJECTS) { | |
Project project = new Project(projectName, new File(BASE_STRING + projectName)); | |
project.sortIntoMap(projectBuckets); | |
} | |
Set<Entry<String, List<Project>>> entrySet = projectBuckets.entrySet(); | |
for (Entry<String, List<Project>> entry : entrySet) { | |
if (entry.getValue().size() > 1) { | |
printConflict(entry); | |
} | |
} | |
} | |
private static void printConflict(Entry<String, List<Project>> entry) { | |
StringBuilder builder = new StringBuilder(); | |
builder.append("Package: ").append(entry.getKey()).append(" in "); | |
for (Project conflict : entry.getValue()) { | |
builder.append(conflict.getName()).append(", "); | |
} | |
System.out.println(builder.toString()); | |
} | |
private static class Project { | |
private List<String> packagesWithContent = new ArrayList<String>(); | |
private String absoluteBase; | |
private final String name; | |
public Project(String name, File baseDirectory) { | |
this.name = name; | |
absoluteBase = baseDirectory.toString() + "/src/main/java/"; | |
analyse(new File(baseDirectory + "/src/main/java/")); | |
} | |
public void sortIntoMap(Map<String, List<Project>> projectBuckets) { | |
for (String packageWithContent : packagesWithContent) { | |
if (!projectBuckets.containsKey(packageWithContent)) { | |
projectBuckets.put(packageWithContent, new ArrayList<OsgiPackageAnalyserScript.Project>()); | |
} | |
projectBuckets.get(packageWithContent).add(this); | |
} | |
} | |
private void analyse(File dir) { | |
File[] listFiles = dir.listFiles(); | |
boolean addedAlready = false; | |
for (File file : listFiles) { | |
if (!file.isDirectory()) { | |
// in that case it contains anything which might be to be exported | |
if (!addedAlready) { | |
packagesWithContent.add(dir.toString().replaceAll(absoluteBase, "").replaceAll("/", ".")); | |
addedAlready = true; | |
} | |
} else { | |
analyse(file); | |
} | |
} | |
} | |
public String getName() { | |
return name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment