Skip to content

Commit 1528ca8

Browse files
committedSep 11, 2022
Initial commit of RascalGit code
0 parents  commit 1528ca8

File tree

6 files changed

+192
-0
lines changed

6 files changed

+192
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
.vscode

‎META-INF/RASCAL.MF

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Project-Name: RascalGit
2+
Source: src/main/rascal
3+
Require-Libraries:
4+

‎pom.xml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>edu.appstate.cs</groupId>
7+
<artifactId>RascalGit</artifactId>
8+
<version>0.1.0</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
14+
<repositories>
15+
<repository>
16+
<id>usethesource</id>
17+
<url>https://releases.usethesource.io/maven/</url>
18+
</repository>
19+
</repositories>
20+
21+
<pluginRepositories>
22+
<pluginRepository>
23+
<id>usethesource</id>
24+
<url>https://releases.usethesource.io/maven/</url>
25+
</pluginRepository>
26+
</pluginRepositories>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.rascalmpl</groupId>
31+
<artifactId>rascal</artifactId>
32+
<version>0.23.2</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.eclipse.jgit</groupId>
36+
<artifactId>org.eclipse.jgit</artifactId>
37+
<version>6.3.0.202209071007-r</version>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-compiler-plugin</artifactId>
46+
<version>3.8.0</version>
47+
<configuration>
48+
<compilerArgument>-parameters</compilerArgument>
49+
<release>11</release>
50+
</configuration>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.rascalmpl</groupId>
54+
<artifactId>rascal-maven-plugin</artifactId>
55+
<version>0.8.2</version>
56+
<configuration>
57+
<errorsAsWarnings>true</errorsAsWarnings>
58+
<bin>${project.build.outputDirectory}</bin>
59+
<srcs>
60+
<src>${project.basedir}/src/main/rascal</src>
61+
</srcs>
62+
</configuration>
63+
<executions>
64+
<execution>
65+
<id>rascal-compile</id>
66+
<phase>compile</phase>
67+
<goals>
68+
<goal>compile</goal>
69+
</goals>
70+
</execution>
71+
<execution>
72+
<id>rascal-package</id>
73+
<phase>pre-package</phase>
74+
<goals>
75+
<goal>package</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package edu.appstate.cs.rascalgit;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.ArrayList;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
9+
import org.eclipse.jgit.api.Git;
10+
import org.eclipse.jgit.api.errors.GitAPIException;
11+
import org.eclipse.jgit.api.errors.InvalidRemoteException;
12+
import org.eclipse.jgit.api.errors.TransportException;
13+
import org.eclipse.jgit.lib.Constants;
14+
import org.eclipse.jgit.lib.Ref;
15+
import org.eclipse.jgit.lib.Repository;
16+
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
17+
18+
import io.usethesource.vallang.IList;
19+
import io.usethesource.vallang.IListWriter;
20+
import io.usethesource.vallang.ISourceLocation;
21+
import io.usethesource.vallang.IString;
22+
import io.usethesource.vallang.IValueFactory;
23+
24+
public class RascalGit {
25+
private final IValueFactory values;
26+
private HashMap<ISourceLocation, Repository> repoMap = new HashMap<>();
27+
28+
public RascalGit(IValueFactory values) {
29+
super();
30+
this.values = values;
31+
}
32+
33+
public void cloneRemoteRepository(IString remotePath, ISourceLocation localPath) {
34+
if (!repoMap.containsKey(localPath)) {
35+
String origin = remotePath.getValue();
36+
File localDir = new File(localPath.getPath());
37+
38+
try {
39+
Git git = Git.cloneRepository()
40+
.setURI(origin)
41+
.setDirectory(localDir)
42+
.call();
43+
Repository repo = git.getRepository();
44+
repoMap.put(localPath, repo);
45+
} catch (InvalidRemoteException e) {
46+
throw RuntimeExceptionFactory.javaException(e, null, null);
47+
} catch (TransportException e) {
48+
throw RuntimeExceptionFactory.javaException(e, null, null);
49+
} catch (GitAPIException e) {
50+
throw RuntimeExceptionFactory.javaException(e, null, null);
51+
}
52+
}
53+
}
54+
55+
public IList getTags(ISourceLocation localPath) {
56+
if (repoMap.containsKey(localPath)) {
57+
Repository repo = repoMap.get(localPath);
58+
List<Ref> tagRefs;
59+
try {
60+
tagRefs = repo.getRefDatabase().getRefsByPrefix(Constants.R_TAGS);
61+
} catch (IOException e) {
62+
throw RuntimeExceptionFactory.javaException(e, null, null);
63+
}
64+
65+
IListWriter lw = values.listWriter();
66+
for (Ref r : tagRefs) {
67+
lw.append(values.string(r.getName().substring(Constants.R_TAGS.length())));
68+
}
69+
return lw.done();
70+
}
71+
return values.listWriter().done();
72+
}
73+
74+
public void openLocalRepository(ISourceLocation loc) {
75+
if (!repoMap.containsKey(loc)) {
76+
File repoDir = new File(loc.getPath());
77+
try {
78+
Git git = Git.open(repoDir);
79+
Repository repo = git.getRepository();
80+
repoMap.put(loc, repo);
81+
} catch (IOException ioe) {
82+
throw RuntimeExceptionFactory.javaException(ioe, null, null);
83+
}
84+
}
85+
}
86+
87+
}

‎src/main/rascal/Main.rsc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Main
2+
3+
import IO;
4+
5+
int main(int testArgument=0) {
6+
println("argument: <testArgument>");
7+
}

‎src/main/rascal/RascalGit.rsc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module RascalGit
2+
3+
@javaClass{edu.appstate.cs.rascalgit.RascalGit}
4+
public java void cloneRemoteRepository(str remotePath, loc localPath);
5+
6+
@javaClass{edu.appstate.cs.rascalgit.RascalGit}
7+
public java void openLocalRepository(loc localPath);
8+
9+
@javaClass{edu.appstate.cs.rascalgit.RascalGit}
10+
public java list[str] getTags(loc repoPath);

0 commit comments

Comments
 (0)
Please sign in to comment.