Skip to content

Commit 449a110

Browse files
committed
FORGE-412 FORGE-414 FORGE-413
1 parent fc51d6a commit 449a110

File tree

16 files changed

+529
-97
lines changed

16 files changed

+529
-97
lines changed

dev-plugins/src/test/java/org/jboss/forge/dev/PluginsPluginTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.jboss.forge.project.Project;
2727
import org.jboss.forge.project.facets.MetadataFacet;
2828
import org.jboss.forge.shell.InstalledPluginRegistry;
29+
import org.jboss.forge.shell.InstalledPluginRegistry.PluginEntry;
2930
import org.jboss.forge.test.AbstractShellTest;
3031
import org.junit.Assert;
3132
import org.junit.Test;
@@ -69,18 +70,18 @@ public void testInstallPlugin() throws Exception
6970
getShell().execute("cd ~~");
7071
getShell().execute("forge source-plugin .");
7172

72-
String installed = null;
73-
List<String> installedPlugins = InstalledPluginRegistry.getInstalledPlugins();
74-
for (String plugin : installedPlugins) {
75-
if (plugin.contains(javaProject.getFacet(MetadataFacet.class).getProjectName()))
73+
PluginEntry installed = null;
74+
List<PluginEntry> installedPlugins = InstalledPluginRegistry.list();
75+
for (PluginEntry plugin : installedPlugins) {
76+
if (plugin.getName().contains(javaProject.getFacet(MetadataFacet.class).getProjectName()))
7677
{
7778
installed = plugin;
7879
getShell().execute("forge remove-plugin " + plugin);
7980
}
8081
}
8182

8283
Assert.assertNotNull(installed);
83-
Assert.assertFalse(InstalledPluginRegistry.hasPlugin(installed));
84+
Assert.assertFalse(InstalledPluginRegistry.has(installed));
8485

8586
}
8687

dist/src/main/resources/modules/org/jboss/forge/shell/api/main/module.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
<module name="javax.annotation.api" export="true" />
1111
<module name="javax.enterprise.api" export="true" />
1212

13+
<module name="org.apache.commons.config" export="true" services="export">
14+
<imports>
15+
<include path="**" />
16+
<include path="META-INF" />
17+
</imports>
18+
</module>
19+
1320
<module name="org.javassist" export="true" />
1421
<module name="org.jboss.interceptor" export="true" />
1522
<module name="org.jboss.weld.core" export="true" />

git-tools-tests/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<artifactId>forge-parent</artifactId>
7+
<groupId>org.jboss.forge</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<relativePath>../</relativePath>
10+
</parent>
11+
12+
<artifactId>forge-git-tools-tests</artifactId>
13+
14+
<name>Forge - Git Integration Tests</name>
15+
<description>Tests for Forge git Integration</description>
16+
17+
<dependencies>
18+
<!-- Test Dependencies -->
19+
<dependency>
20+
<groupId>org.jboss.forge</groupId>
21+
<artifactId>forge-test-harness</artifactId>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.jboss.forge</groupId>
26+
<artifactId>forge-shell</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.jboss.forge.git;
23+
24+
import java.util.Map;
25+
26+
import org.eclipse.jgit.api.Git;
27+
import org.eclipse.jgit.lib.Ref;
28+
import org.jboss.forge.project.Project;
29+
import org.jboss.forge.test.AbstractShellTest;
30+
import org.junit.Assert;
31+
import org.junit.Test;
32+
33+
/**
34+
* @author <a href="mailto:[email protected]">Lincoln Baxter, III</a>
35+
*
36+
*/
37+
public class GitUtilsTest extends AbstractShellTest
38+
{
39+
@Test
40+
public void testCreateRepo() throws Exception
41+
{
42+
Project project = initializeJavaProject();
43+
44+
Git repo = GitUtils.init(project.getProjectRoot());
45+
Assert.assertTrue(repo.getRepository().getDirectory().exists());
46+
}
47+
48+
@Test
49+
public void testGetTags() throws Exception
50+
{
51+
52+
Project project = initializeJavaProject();
53+
54+
Git repo = GitUtils.init(project.getProjectRoot());
55+
Map<String, Ref> tags = repo.getRepository().getTags();
56+
Assert.assertTrue(tags.isEmpty());
57+
}
58+
}

git-tools/pom.xml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<scope>provided</scope>
2727
</dependency>
2828
</dependencies>
29+
2930
<repositories>
3031
<repository>
3132
<id>jgit-repository</id>
@@ -40,15 +41,5 @@
4041
</releases>
4142
</repository>
4243
</repositories>
43-
<build>
44-
<plugins>
45-
<plugin>
46-
<artifactId>maven-compiler-plugin</artifactId>
47-
<configuration>
48-
<source>1.6</source>
49-
<target>1.6</target>
50-
</configuration>
51-
</plugin>
52-
</plugins>
53-
</build>
44+
5445
</project>

git-tools/src/main/java/org/jboss/forge/git/GitUtils.java

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,36 @@
2222
package org.jboss.forge.git;
2323

2424
import java.io.IOException;
25+
import java.util.List;
2526

2627
import org.eclipse.jgit.api.CheckoutCommand;
2728
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
2829
import org.eclipse.jgit.api.FetchCommand;
2930
import org.eclipse.jgit.api.Git;
31+
import org.eclipse.jgit.api.ListBranchCommand;
3032
import org.eclipse.jgit.api.PullCommand;
3133
import org.eclipse.jgit.api.PullResult;
34+
import org.eclipse.jgit.api.TagCommand;
3235
import org.eclipse.jgit.api.errors.CanceledException;
36+
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
3337
import org.eclipse.jgit.api.errors.DetachedHeadException;
3438
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
3539
import org.eclipse.jgit.api.errors.InvalidRefNameException;
3640
import org.eclipse.jgit.api.errors.InvalidRemoteException;
41+
import org.eclipse.jgit.api.errors.InvalidTagNameException;
3742
import org.eclipse.jgit.api.errors.JGitInternalException;
43+
import org.eclipse.jgit.api.errors.NoHeadException;
3844
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
3945
import org.eclipse.jgit.api.errors.RefNotFoundException;
4046
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
4147
import org.eclipse.jgit.lib.Ref;
4248
import org.eclipse.jgit.lib.RepositoryBuilder;
4349
import org.eclipse.jgit.lib.TextProgressMonitor;
50+
import org.eclipse.jgit.revwalk.RevTag;
4451
import org.eclipse.jgit.transport.FetchResult;
4552
import org.eclipse.jgit.transport.RefSpec;
4653
import org.jboss.forge.resources.DirectoryResource;
54+
import org.jboss.forge.resources.FileResource;
4755

4856
/**
4957
* Convenience tools for interacting with the Git version control system.
@@ -52,19 +60,20 @@
5260
*/
5361
public abstract class GitUtils
5462
{
55-
public static Git clone(DirectoryResource dir, String repoUri) throws IOException
63+
public static Git clone(final DirectoryResource dir, final String repoUri) throws IOException
5664
{
5765
new Clone().run(dir.getUnderlyingResourceObject(), repoUri);
5866
return git(dir);
5967
}
6068

61-
public static Git git(DirectoryResource dir) throws IOException
69+
public static Git git(final DirectoryResource dir) throws IOException
6270
{
6371
RepositoryBuilder db = new RepositoryBuilder().findGitDir(dir.getUnderlyingResourceObject());
6472
return new Git(db.build());
6573
}
6674

67-
public static Ref checkout(Git git, String remote, boolean createBranch, SetupUpstreamMode mode, boolean force)
75+
public static Ref checkout(final Git git, final String remote, final boolean createBranch,
76+
final SetupUpstreamMode mode, final boolean force)
6877
throws JGitInternalException,
6978
RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException
7079
{
@@ -76,9 +85,22 @@ public static Ref checkout(Git git, String remote, boolean createBranch, SetupUp
7685
return checkout.call();
7786
}
7887

79-
public static FetchResult fetch(Git git, String remote, String refSpec, int timeout, boolean fsck, boolean dryRun,
80-
boolean thin,
81-
boolean prune) throws JGitInternalException, InvalidRemoteException
88+
public static Ref checkout(final Git git, final Ref remote, final boolean createBranch,
89+
final SetupUpstreamMode mode, final boolean force)
90+
throws JGitInternalException,
91+
RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException
92+
{
93+
CheckoutCommand checkout = git.checkout();
94+
checkout.setName(remote.getName());
95+
checkout.setForce(force);
96+
checkout.setUpstreamMode(mode);
97+
return checkout.call();
98+
}
99+
100+
public static FetchResult fetch(final Git git, final String remote, final String refSpec, final int timeout,
101+
final boolean fsck, final boolean dryRun,
102+
final boolean thin,
103+
final boolean prune) throws JGitInternalException, InvalidRemoteException
82104
{
83105
FetchCommand fetch = git.fetch();
84106
fetch.setCheckFetchedObjects(fsck);
@@ -96,7 +118,23 @@ public static FetchResult fetch(Git git, String remote, String refSpec, int time
96118
return result;
97119
}
98120

99-
public static PullResult pull(Git git, int timeout) throws WrongRepositoryStateException,
121+
/**
122+
* Initialize a new git repository.
123+
*
124+
* @param dir The directory in which to create a new .git/ folder and repository.
125+
*/
126+
public static Git init(final DirectoryResource dir) throws IllegalArgumentException, IOException
127+
{
128+
FileResource<?> gitDir = dir.getChildDirectory(".git").reify(FileResource.class);
129+
gitDir.mkdirs();
130+
131+
RepositoryBuilder db = new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup();
132+
Git git = new Git(db.build());
133+
git.getRepository().create();
134+
return git;
135+
}
136+
137+
public static PullResult pull(final Git git, final int timeout) throws WrongRepositoryStateException,
100138
InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException
101139
{
102140
PullCommand pull = git.pull();
@@ -107,4 +145,23 @@ public static PullResult pull(Git git, int timeout) throws WrongRepositoryStateE
107145
PullResult result = pull.call();
108146
return result;
109147
}
148+
149+
public static List<Ref> getBranches(final Git repo) throws JGitInternalException, ConcurrentRefUpdateException,
150+
InvalidTagNameException, NoHeadException
151+
{
152+
ListBranchCommand branchListCommand = repo.branchList();
153+
List<Ref> branchList = branchListCommand.call();
154+
155+
return branchList;
156+
}
157+
158+
public static List<Ref> getTags(final Git repo) throws JGitInternalException, ConcurrentRefUpdateException,
159+
InvalidTagNameException, NoHeadException
160+
{
161+
TagCommand tagCommand = repo.tag();
162+
RevTag revTag = tagCommand.call();
163+
String tagName = revTag.getTagName();
164+
165+
return null;
166+
}
110167
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<module>maven-api</module>
8484
<module>shell-api</module>
8585
<module>git-tools</module>
86+
<module>git-tools-tests</module>
8687
<module>parser-java</module>
8788
<module>project-model-maven</module>
8889
<module>project-model-maven-tests</module>

shell-api/src/main/java/org/jboss/forge/ForgeEnvironment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
*/
3333
public interface ForgeEnvironment
3434
{
35+
/**
36+
* Return the current Forge version as a String. E.g.: "1.0.0.Final"
37+
*/
38+
String getRuntimeVersion();
3539

3640
/**
3741
* Return the directory Forge is using to store and load third-party plugins.

shell/src/main/java/org/jboss/forge/shell/Bootstrap.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.jboss.forge.shell;
2424

2525
import java.io.File;
26+
import java.util.ArrayList;
2627
import java.util.List;
2728
import java.util.logging.Handler;
2829
import java.util.logging.Level;
@@ -32,6 +33,7 @@
3233
import javax.enterprise.inject.spi.BeanManager;
3334
import javax.inject.Inject;
3435

36+
import org.jboss.forge.shell.InstalledPluginRegistry.PluginEntry;
3537
import org.jboss.forge.shell.events.AcceptUserInput;
3638
import org.jboss.forge.shell.events.PostStartup;
3739
import org.jboss.forge.shell.events.PreStartup;
@@ -156,13 +158,38 @@ synchronized private static void loadPlugins()
156158
CompositeClassLoader composite = new CompositeClassLoader();
157159
composite.add(Module.forClassLoader(Bootstrap.class.getClassLoader(), true).getClassLoader());
158160

159-
List<String> installed = InstalledPluginRegistry.getInstalledPlugins();
161+
List<PluginEntry> toLoad = new ArrayList<InstalledPluginRegistry.PluginEntry>();
160162

161-
for (String plugin : installed)
163+
List<PluginEntry> installed = InstalledPluginRegistry.listByVersion(Bootstrap.class.getPackage()
164+
.getImplementationVersion());
165+
166+
toLoad.addAll(installed);
167+
168+
// Add in the SNAPSHOT versions, we can't ignore them.
169+
List<PluginEntry> incompatible = InstalledPluginRegistry.list();
170+
incompatible.removeAll(installed);
171+
if (!incompatible.isEmpty())
172+
{
173+
for (PluginEntry pluginEntry : incompatible) {
174+
if (pluginEntry.getApiVersion().contains("SNAPSHOT"))
175+
{
176+
toLoad.add(pluginEntry);
177+
incompatible.remove(pluginEntry);
178+
}
179+
}
180+
}
181+
182+
for (PluginEntry pluginEntry : incompatible) {
183+
System.out.println("Not loading plugin [" + pluginEntry.getName()
184+
+ "] due to incompatible Forge API version [" + pluginEntry.getApiVersion()
185+
+ "]. To remove this plugin, type 'forge remove-plugin " + pluginEntry + "' inside Forge.");
186+
}
187+
188+
for (PluginEntry plugin : toLoad)
162189
{
163190
try
164191
{
165-
Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(plugin));
192+
Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(plugin.toModuleId()));
166193
composite.add(module.getClassLoader());
167194
}
168195
catch (Exception e)

0 commit comments

Comments
 (0)