Skip to content
Browse files

Merge pull request #116 from koentsje/feature/FORGE-483

Implemented FORGE-483
  • Loading branch information...
2 parents a5c912a + 04c61bc commit 63491effa8e95e2761738f2b515b0fc8670f267b @lincolnthree lincolnthree committed Feb 27, 2012
Showing with 118 additions and 88 deletions.
  1. +118 −88 shell/src/main/java/org/jboss/forge/shell/plugins/builtin/ForgePlugin.java
View
206 shell/src/main/java/org/jboss/forge/shell/plugins/builtin/ForgePlugin.java
@@ -40,6 +40,7 @@
import org.jboss.forge.env.Configuration;
import org.jboss.forge.env.ConfigurationScope;
import org.jboss.forge.git.GitUtils;
+import org.jboss.forge.parser.ParserException;
import org.jboss.forge.parser.java.util.Strings;
import org.jboss.forge.parser.xml.Node;
import org.jboss.forge.parser.xml.XMLParser;
@@ -153,7 +154,8 @@ public void listInstalled(
private void displayModules(final DirectoryResource pluginDir)
{
List<PluginEntry> plugins = InstalledPluginRegistry.list();
- for (PluginEntry plugin : plugins) {
+ for (PluginEntry plugin : plugins)
+ {
writer.println(plugin.toString());
}
}
@@ -300,23 +302,11 @@ public void installFromMvnRepos(@Option(description = "plugin-identifier", requi
{
throw new IllegalStateException("Not implemented");
/*
- if (repoURL != null)
- {
- installFromMvnRepos(dep, out,
- new DependencyRepositoryImpl("custom", repoURL));
- }
- else if (repo == null)
- {
- List<DependencyRepository> repos = new ArrayList<DependencyRepository>();
- for (KnownRepository r : KnownRepository.values())
- {
- repos.add(new DependencyRepositoryImpl(r));
- }
- installFromMvnRepos(dep, out, repos);
- }
- else
- installFromMvnRepos(dep, out, new DependencyRepositoryImpl(repo));
- */
+ * if (repoURL != null) { installFromMvnRepos(dep, out, new DependencyRepositoryImpl("custom", repoURL)); } else
+ * if (repo == null) { List<DependencyRepository> repos = new ArrayList<DependencyRepository>(); for
+ * (KnownRepository r : KnownRepository.values()) { repos.add(new DependencyRepositoryImpl(r)); }
+ * installFromMvnRepos(dep, out, repos); } else installFromMvnRepos(dep, out, new DependencyRepositoryImpl(repo));
+ */
}
// @Command(value = "jar-plugin",
@@ -329,30 +319,20 @@ public void installFromLocalJar(
throw new IllegalStateException("Not implemented");
/*
- FileResource<?> source = resource.reify(FileResource.class);
- if ((source == null) || !source.exists())
- {
- throw new IllegalArgumentException("JAR file must be specified.");
- }
-
- if (environment.getPluginDirectory().equals(source.getParent()))
- {
- throw new IllegalArgumentException("Plugin is already installed.");
- }
-
- ShellMessages.info(out, "WARNING!");
- if (prompt.promptBoolean(
- "Installing plugins from remote sources is dangerous, and can leave untracked plugins. Continue?", true))
- {
- FileResource<?> target = createIncrementedPluginJarFile(dep);
- target.setContents(source.getResourceInputStream());
-
- ShellMessages.success(out, "Installed from [" + resource + "] successfully.");
- restart();
- }
- else
- throw new RuntimeException("Aborted.");
- */
+ * FileResource<?> source = resource.reify(FileResource.class); if ((source == null) || !source.exists()) { throw
+ * new IllegalArgumentException("JAR file must be specified."); }
+ *
+ * if (environment.getPluginDirectory().equals(source.getParent())) { throw new
+ * IllegalArgumentException("Plugin is already installed."); }
+ *
+ * ShellMessages.info(out, "WARNING!"); if (prompt.promptBoolean(
+ * "Installing plugins from remote sources is dangerous, and can leave untracked plugins. Continue?", true)) {
+ * FileResource<?> target = createIncrementedPluginJarFile(dep);
+ * target.setContents(source.getResourceInputStream());
+ *
+ * ShellMessages.success(out, "Installed from [" + resource + "] successfully."); restart(); } else throw new
+ * RuntimeException("Aborted.");
+ */
}
// @Command(value = "url-plugin",
@@ -365,18 +345,12 @@ public void installFromRemoteURL(
throw new IllegalStateException("Not implemented");
/*
- ShellMessages.info(out, "WARNING!");
- if (prompt.promptBoolean(
- "Installing plugins from remote sources is dangerous, and can leave untracked plugins. Continue?", true))
- {
- FileResource<?> jar = createIncrementedPluginJarFile(dep);
- PluginUtil.downloadFromURL(out, url, jar);
- ShellMessages.success(out, "Installed from [" + url.toExternalForm() + "] successfully.");
- restart();
- }
- else
- throw new RuntimeException("Aborted.");
- */
+ * ShellMessages.info(out, "WARNING!"); if (prompt.promptBoolean(
+ * "Installing plugins from remote sources is dangerous, and can leave untracked plugins. Continue?", true)) {
+ * FileResource<?> jar = createIncrementedPluginJarFile(dep); PluginUtil.downloadFromURL(out, url, jar);
+ * ShellMessages.success(out, "Installed from [" + url.toExternalForm() + "] successfully."); restart(); } else
+ * throw new RuntimeException("Aborted.");
+ */
}
@Command(value = "source-plugin",
@@ -450,7 +424,8 @@ public void installFromGit(
if (ref == null)
{
List<Ref> refs = GitUtils.getRemoteBranches(repo);
- for (Ref branchRef : refs) {
+ for (Ref branchRef : refs)
+ {
if (branchRef.getName().endsWith(targetRef))
{
ref = repo.branchCreate().setName(targetRef).setUpstreamMode(SetupUpstreamMode.TRACK)
@@ -566,7 +541,8 @@ private void buildFromCurrentProject(final PipeOut out, final DirectoryResource
// TODO Weld bug requires us to correct /add module for Seam Render dependency
List<String> groupIds = Arrays.asList("org.jboss.seam.render", "org.jboss.forge");
List<Dependency> dependencies = deps.getDependencies();
- for (Dependency dependency : dependencies) {
+ for (Dependency dependency : dependencies)
+ {
if (groupIds.contains(dependency.getGroupId())
&& !(ScopeType.PROVIDED.equals(dependency.getScopeTypeEnum())
|| ScopeType.TEST.equals(dependency.getScopeTypeEnum())))
@@ -604,9 +580,31 @@ private void buildFromCurrentProject(final PipeOut out, final DirectoryResource
}
}
+ private boolean needDependenciesAsResourceRoot(final Project project)
+ {
+ FileResource<?> forgeXml = (FileResource<?>) project.getProjectRoot().getChild(
+ "src/main/resources/META-INF/forge.xml");
+ if (forgeXml.exists())
+ {
+ try
+ {
+ Node node = XMLParser.parse(forgeXml.getResourceInputStream());
+ return node.getSingle("dependencies-as-resource-root") != null;
+ }
+ catch (ParserException e)
+ {
+ return false;
+ }
+ }
+ return false;
+ }
+
private DirectoryResource createModule(final Project project, final Dependency dep, final Resource<?> artifact,
final String apiVersion)
{
+
+ boolean dependenciesAsResourceRoot = needDependenciesAsResourceRoot(project);
+
DirectoryResource moduleDir = getOrCreatePluginModuleDirectory(dep);
String pluginName = dep.getGroupId() + "." + dep.getArtifactId();
String pluginSlot = dep.getVersion();
@@ -631,14 +629,25 @@ private DirectoryResource createModule(final Project project, final Dependency d
resources.createChild("resource-root").attribute("path", dep.getArtifactId() + ".jar");
+ if (dependenciesAsResourceRoot)
+ {
+ writeResourceRoots(project, module, moduleDir, resources);
+ }
+
// Copy the compiled JAR into the module directory
FileResource<?> jar = moduleDir.getChild(dep.getArtifactId() + ".jar").reify(FileResource.class);
jar.createNewFile();
jar.setContents(artifact.getResourceInputStream());
// <module name="org.jboss.forge:main" />
Node dependencies = module.getSingle("dependencies");
- dependencies.createChild("module").attribute("name", pluginName + ".dependencies").attribute("slot", pluginSlot);
+
+ if (!dependenciesAsResourceRoot)
+ {
+ dependencies.createChild("module").attribute("name", pluginName + ".dependencies")
+ .attribute("slot", pluginSlot);
+ }
+
dependencies.createChild("module").attribute("name", "org.jboss.forge.javaee.api")
.attribute("services", "import");
dependencies.createChild("module").attribute("name", "org.jboss.forge.maven.api").attribute("services", "import");
@@ -650,41 +659,25 @@ private DirectoryResource createModule(final Project project, final Dependency d
moduleXml.setContents(XMLParser.toXMLString(module));
- createDependenciesModule(project, dep);
+ if (!dependenciesAsResourceRoot)
+ {
+ createDependenciesModule(project, dep);
+ }
// Add to list modules.
registerPlugin(pluginName, pluginSlot, apiVersion);
return moduleDir;
}
- private void createDependenciesModule(final Project project, final Dependency dep)
+ private List<DependencyResource> getPluginDependencies(final Project project, Node module)
{
- DirectoryResource dependencyDir = getOrCreatePluginDependenciesModuleDirectory(dep);
- String pluginName = dep.getGroupId() + "." + dep.getArtifactId();
- String pluginSlot = dep.getVersion();
-
DependencyFacet deps = project.getFacet(DependencyFacet.class);
-
- FileResource<?> moduleXml = (FileResource<?>) dependencyDir.getChild("module.xml");
- moduleXml.delete();
- moduleXml.createNewFile();
-
- // <resource-root path="maven-dependency.jar" />
- Node module = XMLParser.parse(getClass().getResourceAsStream(MODULE_TEMPLATE_XML));
- module.attribute("name", pluginName + ".dependencies");
- module.attribute("slot", pluginSlot);
- Node resources = module.getSingle("resources");
-
- // <module name="org.jboss.forge:main" />
- Node dependencies = module.getSingle("dependencies");
- dependencies.createChild("module").attribute("name", "javax.api");
- dependencies.createChild("module").attribute("name", "org.jboss.forge.shell.api");
-
List<DependencyResource> pluginDependencies = new ArrayList<DependencyResource>();
List<Dependency> effectiveDependenciesInScopes = deps.getEffectiveDependenciesInScopes(ScopeType.COMPILE,
ScopeType.RUNTIME);
- for (Dependency d : effectiveDependenciesInScopes) {
+ for (Dependency d : effectiveDependenciesInScopes)
+ {
if (d.getPackagingTypeEnum().equals(PackagingType.JAR)
&& !d.getGroupId().equals("org.jboss.forge"))
{
@@ -711,16 +704,48 @@ private void createDependenciesModule(final Project project, final Dependency de
.attribute("services", "import");
}
}
+ return pluginDependencies;
+ }
- // Copy dependencies into module
- for (DependencyResource d : pluginDependencies) {
+ private void writeResourceRoots(
+ final Project project,
+ final Node module,
+ final DirectoryResource directory,
+ final Node resources) {
+ List<DependencyResource> pluginDependencies = getPluginDependencies(project, module);
+ for (DependencyResource d : pluginDependencies)
+ {
String name = d.getName();
- Resource<?> child = dependencyDir.getChild(name);
+ Resource<?> child = directory.getChild(name);
child.delete();
FileResource<?> depJar = child.reify(FileResource.class);
depJar.setContents(d.getResourceInputStream());
resources.createChild("resource-root").attribute("path", name);
}
+ }
+
+ private void createDependenciesModule(final Project project, final Dependency dep)
+ {
+ DirectoryResource dependencyDir = getOrCreatePluginDependenciesModuleDirectory(dep);
+ String pluginName = dep.getGroupId() + "." + dep.getArtifactId();
+ String pluginSlot = dep.getVersion();
+
+ FileResource<?> moduleXml = (FileResource<?>) dependencyDir.getChild("module.xml");
+ moduleXml.delete();
+ moduleXml.createNewFile();
+
+ // <resource-root path="maven-dependency.jar" />
+ Node module = XMLParser.parse(getClass().getResourceAsStream(MODULE_TEMPLATE_XML));
+ module.attribute("name", pluginName + ".dependencies");
+ module.attribute("slot", pluginSlot);
+ Node resources = module.getSingle("resources");
+
+ // <module name="org.jboss.forge:main" />
+ Node dependencies = module.getSingle("dependencies");
+ dependencies.createChild("module").attribute("name", "javax.api");
+ dependencies.createChild("module").attribute("name", "org.jboss.forge.shell.api");
+
+ writeResourceRoots(project, module, dependencyDir, resources);
// Write out the module XML file.
moduleXml.setContents(XMLParser.toXMLString(module));
@@ -733,7 +758,8 @@ private void createDependenciesModule(final Project project, final Dependency de
List<DependencyResource> artifacts = new ArrayList<DependencyResource>();
DependencyFacet deps = project.getFacet(DependencyFacet.class);
- for (Dependency d2 : deps.getDependencies()) {
+ for (Dependency d2 : deps.getDependencies())
+ {
if (DependencyBuilder.areEquivalent(d, d2) && (d2.getVersion() != null))
{
d = d2;
@@ -765,11 +791,13 @@ public DirectoryResource getOrCreatePluginModuleDirectory(final Dependency dep)
List<String> groupId = Arrays.asList(dep.getGroupId().split("\\."));
List<String> artifactId = Arrays.asList(dep.getArtifactId().split("\\."));
DirectoryResource dir = pluginDir;
- for (String segment : groupId) {
+ for (String segment : groupId)
+ {
dir = dir.getOrCreateChildDirectory(segment);
}
- for (String segment : artifactId) {
+ for (String segment : artifactId)
+ {
dir = dir.getOrCreateChildDirectory(segment);
}
@@ -784,11 +812,13 @@ public DirectoryResource getOrCreatePluginDependenciesModuleDirectory(final Depe
List<String> groupId = Arrays.asList(dep.getGroupId().split("\\."));
List<String> artifactId = Arrays.asList(dep.getArtifactId().split("\\."));
DirectoryResource dir = pluginDir;
- for (String segment : groupId) {
+ for (String segment : groupId)
+ {
dir = dir.getOrCreateChildDirectory(segment);
}
- for (String segment : artifactId) {
+ for (String segment : artifactId)
+ {
dir = dir.getOrCreateChildDirectory(segment);
}

0 comments on commit 63491ef

Please sign in to comment.
Something went wrong with that request. Please try again.