Skip to content

Commit 986347d

Browse files
committed
FORGE-1730: Moved git addon to core
1 parent 24fa980 commit 986347d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3687
-0
lines changed

README.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ This plugin starts the Forge 2 Container and your installed addons, so you can u
123123
|link:facets/README.asciidoc[Facets]
124124
|yes
125125

126+
|link:git/README.asciidoc[Git]
127+
|yes
128+
126129
|link:javaee/README.asciidoc[Java EE]
127130
|yes
128131

bom/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,17 @@
442442
<version>${version.furnace}</version>
443443
<classifier>forge-addon</classifier>
444444
</dependency>
445+
<dependency>
446+
<groupId>org.jboss.forge.addon</groupId>
447+
<artifactId>git</artifactId>
448+
<version>${version.furnace}</version>
449+
<classifier>forge-addon</classifier>
450+
</dependency>
451+
<dependency>
452+
<groupId>org.jboss.forge.addon</groupId>
453+
<artifactId>git-api</artifactId>
454+
<version>${version.furnace}</version>
455+
</dependency>
445456
</dependencies>
446457
</dependencyManagement>
447458

core/addon/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@
107107
<artifactId>database-tools</artifactId>
108108
<classifier>forge-addon</classifier>
109109
</dependency>
110+
<dependency>
111+
<groupId>org.jboss.forge.addon</groupId>
112+
<artifactId>git</artifactId>
113+
<classifier>forge-addon</classifier>
114+
</dependency>
110115
</dependencies>
111116

112117
<build>

git/README.asciidoc

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
== git-tools
2+
:idprefix: id_
3+
4+
This addon provides both *standalone* functionality to be used in other addons as well as commands.
5+
6+
The git-tools addon enables creating and cloning GIT repositories, working with branches, commits and other Git objects.
7+
8+
It has some useful commands for setting up .gitIgnore files.
9+
10+
=== Depends on
11+
12+
[options="header"]
13+
|===
14+
|Addon |Exported |Optional
15+
16+
|ui
17+
|no
18+
|no
19+
20+
|configuration
21+
|no
22+
|no
23+
24+
|resource
25+
|no
26+
|no
27+
28+
|projects
29+
|no
30+
|no
31+
32+
|facets
33+
|no
34+
|no
35+
36+
|org.jboss.forge.furnace.container:cdi
37+
|no
38+
|no
39+
40+
|===
41+
42+
== Setup
43+
44+
This Addon requires the following installation steps.
45+
46+
=== Add git-tools to pom.xml
47+
To use this addon, you must add it as a dependency in the *pom.xml* of your `forge-addon` classified artifact:
48+
49+
[source,xml]
50+
----
51+
<dependency>
52+
<groupId>org.jboss.forge.addon</groupId>
53+
<artifactId>git-tools</artifactId>
54+
<classifier>forge-addon</classifier>
55+
<version>${version}</version>
56+
</dependency>
57+
----
58+
59+
== Features
60+
61+
Obtaining GIT utilities::
62+
Allows for programatically manipulating GIT repositories. Works as a wrapper over the JGit library.
63+
+
64+
[source,java]
65+
----
66+
@Inject
67+
private GitUtils gitUtils;
68+
----
69+
+
70+
71+
[TIP]
72+
====
73+
If your addon uses a container that does not support "@Inject" annotations, services such as the `GitUtils` may also be
74+
accessed via the `AddonRegistry`:
75+
+
76+
[source,java]
77+
----
78+
Imported<GitUtils> imported = addonRegistry.getServices(GitUtils.class);
79+
GitUtils gitUtils = imported.get();
80+
----
81+
+
82+
====
83+
84+
Cloning a GIT repository::
85+
Once you have access to the `GitUtils` object, you can use it to clone an existing GIT repository. Most of the other git utilities work with the Git object returned from this operation, so it is a good idea to cache it.
86+
+
87+
[source,java]
88+
----
89+
import org.eclipse.jgit.api.Git;
90+
91+
// ...
92+
93+
private Git gitHandle;
94+
95+
private void cloneRepository(String remoteUri, DirectoryResource localDirectory)
96+
{
97+
this.gitHandle = gitUtils.clone(localDirectory, remoteUri);
98+
}
99+
----
100+
+
101+
102+
You can obtain the gitHandle object of an existing local repository by simply calling the `git` method of gitUtils:
103+
+
104+
[source,java]
105+
----
106+
private Git getGitRepository(DirectoryResource localDirectory)
107+
{
108+
return gitUtils.git(localDirectory);
109+
}
110+
----
111+
+
112+
113+
Working with branches::
114+
The GIT utilities provide handy methods for listing, checking out and creating branches. For all of them you will need the gitHandle object, obtained when cloning or getting a GIT repository.
115+
+
116+
[source,java]
117+
----
118+
// List all the local branches
119+
List<Ref> localBranches = gitUtils.getLocalBranches(gitHandle);
120+
121+
// Create a branch
122+
gitUtils.createBranch(gitHandle, "FORGE-123");
123+
124+
// Get current branch name
125+
String currentBranch = gitUtils.getCurrentBranchName(gitHandle);
126+
127+
// Checkout 'master' branch
128+
gitUtils.checkout(gitHandle, "master", false, null, false);
129+
----
130+
+
131+
132+
Staging files to index::
133+
You can use the GIT utilities to perform adding new, modified and deleted files from the GIT working tree to the staging area.
134+
+
135+
[source,java]
136+
----
137+
// Stage files with a certain pattern
138+
gitUtils.add(gitHandle, "src\");
139+
140+
// Stage all the files in the working tree
141+
gitUtils.addAll(gitHandle);
142+
----
143+
+
144+
145+
Working with commits::
146+
GIT utilities allow for creating, stashing and cherry picking commits. There is also functionality for reseting the HEAD to a previous state. At the moment there is only hard reset, i.e. reset the HEAD, the index and the working tree.
147+
+
148+
[source,java]
149+
----
150+
// Commit the staged files along with a message
151+
gitUtils.commit(gitHandle, "This is a test commit message");
152+
153+
// Stage all the files in the working tree and then commit them along with a message
154+
gitUtils.commitAll(gitHandle, "This is a test commit message");
155+
156+
// Stash the content of the working tree and the index into separate commits
157+
gitUtils.stashCreate(gitHandle);
158+
159+
// Reset to the previous commit
160+
gitUtils.resetHard(gitHandle, "f414f31");
161+
----
162+
+
163+
164+
== UI commands
165+
166+
The git-tools addon provides a few handy UI commands for working with GIT repositories as well as
167+
for setting up and manipulating the .gitignore file
168+
169+
Working with GIT repositories::
170+
You can init a GIT repository in an existing project by running the +git-setup+ command.
171+
You may use the +git-clone+ command to clone a remote repository to a local directory.
172+
The +git-checkout+ command may be used for creating or checking out existing branches.
173+
174+
Working with .gitignore::
175+
There are some UI commands for working with .gitignore. You can set everything up by running
176+
gitignore-setup inside an existing project. It will download from a remote repository a list
177+
of .gitignore template files for almost all the programs that create artefacts that should be
178+
ignored by GIT. The +git-create+ command will create the .gitignore file in the root of the
179+
current project and will add there all the patterns from a list of templates, provided by the
180+
user. There are commands for adding, deleting and listing the patterns in the .gitignore file.
181+

git/addon/pom.xml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
<parent>
5+
<groupId>org.jboss.forge.addon</groupId>
6+
<artifactId>git-parent</artifactId>
7+
<version>2.3.1-SNAPSHOT</version>
8+
</parent>
9+
10+
<name>Forge - Git Addon</name>
11+
<artifactId>git</artifactId>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.jboss.forge.addon</groupId>
16+
<artifactId>git-api</artifactId>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.jboss.forge.addon</groupId>
20+
<artifactId>git-impl</artifactId>
21+
<scope>runtime</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.jboss.forge.addon</groupId>
25+
<artifactId>projects</artifactId>
26+
<classifier>forge-addon</classifier>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.jboss.forge.addon</groupId>
31+
<artifactId>configuration</artifactId>
32+
<classifier>forge-addon</classifier>
33+
<scope>provided</scope>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.jboss.forge.addon</groupId>
38+
<artifactId>ui</artifactId>
39+
<classifier>forge-addon</classifier>
40+
<scope>provided</scope>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.jboss.forge.furnace.container</groupId>
45+
<artifactId>cdi</artifactId>
46+
<classifier>forge-addon</classifier>
47+
<scope>provided</scope>
48+
</dependency>
49+
</dependencies>
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.jboss.forge.furnace</groupId>
54+
<artifactId>furnace-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>generate-dot</id>
58+
<phase>prepare-package</phase>
59+
<goals>
60+
<goal>generate-dot</goal>
61+
</goals>
62+
<configuration>
63+
<attach>true</attach>
64+
</configuration>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
<plugin>
69+
<artifactId>maven-jar-plugin</artifactId>
70+
<executions>
71+
<execution>
72+
<id>create-forge-addon</id>
73+
<phase>package</phase>
74+
<goals>
75+
<goal>jar</goal>
76+
</goals>
77+
<configuration>
78+
<classifier>forge-addon</classifier>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"/>

git/api/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+
<parent>
5+
<groupId>org.jboss.forge.addon</groupId>
6+
<artifactId>git-parent</artifactId>
7+
<version>2.3.1-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>git-api</artifactId>
10+
<name>Forge - Git API</name>
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.jboss.forge.addon</groupId>
14+
<artifactId>projects</artifactId>
15+
<classifier>forge-addon</classifier>
16+
</dependency>
17+
18+
<dependency>
19+
<groupId>org.jboss.forge.furnace.container</groupId>
20+
<artifactId>cdi</artifactId>
21+
<classifier>forge-addon</classifier>
22+
<scope>provided</scope>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.eclipse.jgit</groupId>
27+
<artifactId>org.eclipse.jgit</artifactId>
28+
</dependency>
29+
30+
</dependencies>
31+
</project>

0 commit comments

Comments
 (0)