Skip to content

Commit eeea757

Browse files
committed
Add local cloning to tmp directory
1 parent 13bae72 commit eeea757

16 files changed

+130
-269
lines changed

pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@
6262
<artifactId>commons-io</artifactId>
6363
<version>1.3.2</version>
6464
</dependency>
65-
<dependency>
66-
<groupId>org.eclipse.mylyn.github</groupId>
67-
<artifactId>org.eclipse.egit.github.core</artifactId>
68-
<version>2.1.5</version>
69-
</dependency>
7065
<dependency>
7166
<groupId>org.yaml</groupId>
7267
<artifactId>snakeyaml</artifactId>

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
import org.apache.jena.rdf.model.StmtIterator;
3636
import org.apache.jena.riot.RiotException;
3737
import org.commonwl.view.docker.DockerService;
38-
import org.commonwl.view.github.GitDetails;
3938
import org.commonwl.view.github.GitService;
4039
import org.commonwl.view.graphviz.ModelDotWriter;
4140
import org.commonwl.view.graphviz.RDFDotWriter;
4241
import org.commonwl.view.workflow.Workflow;
43-
import org.commonwl.view.workflow.WorkflowOverview;
4442
import org.slf4j.Logger;
4543
import org.slf4j.LoggerFactory;
4644
import org.springframework.beans.factory.annotation.Autowired;
@@ -178,18 +176,15 @@ public Workflow parseWorkflowNative(File workflowFile) throws IOException {
178176

179177
/**
180178
* Create a workflow model from cwltool rdf output
181-
* @param githubInfo The Github repository information
182-
* @param latestCommit The latest commit ID
179+
* @param workflowFile The workflow file to run cwltool on
183180
* @param packedWorkflowID The workflow ID if the file has multiple objects
184181
* @return The constructed workflow object
185182
*/
186-
public Workflow parseWorkflowWithCwltool(GitDetails githubInfo,
187-
String latestCommit,
183+
public Workflow parseWorkflowWithCwltool(File workflowFile,
188184
String packedWorkflowID) throws CWLValidationException {
189185

190186
// Get RDF representation from cwltool
191-
String url = String.format("https://cdn.rawgit.com/%s/%s/%s/%s", githubInfo.getOwner(),
192-
githubInfo.getRepoName(), latestCommit, githubInfo.getPath());
187+
String url = workflowFile.toPath().toAbsolutePath().toString();
193188
if (packedWorkflowID != null) {
194189
if (packedWorkflowID.charAt(0) != '#') {
195190
url += "#";
@@ -209,7 +204,7 @@ public Workflow parseWorkflowWithCwltool(GitDetails githubInfo,
209204
}
210205

211206
// Base workflow details
212-
String label = FilenameUtils.getName(githubInfo.getPath());
207+
String label = FilenameUtils.getName(url);
213208
String doc = null;
214209
ResultSet labelAndDoc = rdfService.getLabelAndDoc(url);
215210
if (labelAndDoc.hasNext()) {
@@ -425,57 +420,6 @@ public Workflow parseWorkflowWithCwltool(GitDetails githubInfo,
425420

426421
}
427422

428-
/**
429-
* Get an overview of a workflow
430-
* @param githubInfo The details to access the workflow
431-
* @return A constructed WorkflowOverview of the workflow
432-
* @throws IOException Any API errors which may have occurred
433-
*/
434-
public WorkflowOverview getWorkflowOverview(GitDetails githubInfo) throws IOException {
435-
436-
// Get the content of this file from Github
437-
String fileContent = githubService.downloadFile(githubInfo);
438-
int fileSizeBytes = fileContent.getBytes("UTF-8").length;
439-
440-
// Check file size limit before parsing
441-
if (fileSizeBytes <= singleFileSizeLimit) {
442-
443-
// Parse file as yaml
444-
JsonNode cwlFile = yamlStringToJson(fileContent);
445-
446-
// If the CWL file is packed there can be multiple workflows in a file
447-
if (cwlFile.has(DOC_GRAPH)) {
448-
// Packed CWL, find the first subelement which is a workflow and take it
449-
for (JsonNode jsonNode : cwlFile.get(DOC_GRAPH)) {
450-
if (extractProcess(jsonNode) == CWLProcess.WORKFLOW) {
451-
cwlFile = jsonNode;
452-
}
453-
}
454-
}
455-
456-
// Can only make an overview if this is a workflow
457-
if (extractProcess(cwlFile) == CWLProcess.WORKFLOW) {
458-
// Use filename for label if there is no defined one
459-
String path = FilenameUtils.getName(githubInfo.getPath());
460-
String label = extractLabel(cwlFile);
461-
if (label == null) {
462-
label = path;
463-
}
464-
465-
// Return the constructed overview
466-
return new WorkflowOverview(path, label, extractDoc(cwlFile));
467-
468-
} else {
469-
return null;
470-
}
471-
} else {
472-
throw new IOException("File '" + githubInfo.getPath() + "' is over singleFileSizeLimit - " +
473-
FileUtils.byteCountToDisplaySize(fileSizeBytes) + "/" +
474-
FileUtils.byteCountToDisplaySize(singleFileSizeLimit));
475-
}
476-
477-
}
478-
479423
/**
480424
* Set the format for an input or output, handling ontologies
481425
* @param inputOutput The input or output CWL Element

src/main/java/org/commonwl/view/cwl/CWLToolRunner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.scheduling.annotation.EnableAsync;
3333
import org.springframework.stereotype.Component;
3434

35+
import java.io.File;
3536
import java.io.IOException;
3637
import java.util.Date;
3738

@@ -67,22 +68,21 @@ public CWLToolRunner(WorkflowRepository workflowRepository,
6768
}
6869

6970
@Async
70-
public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow)
71+
public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow, File workflowFile)
7172
throws IOException, InterruptedException {
7273

7374
Workflow tempWorkflow = queuedWorkflow.getTempRepresentation();
7475

7576
// Parse using cwltool and replace in database
7677
try {
77-
String commitSha = githubService.getCommitSha(tempWorkflow.getRetrievedFrom());
7878
Workflow newWorkflow = cwlService.parseWorkflowWithCwltool(
79-
tempWorkflow.getRetrievedFrom(), commitSha,
79+
workflowFile,
8080
tempWorkflow.getPackedWorkflowID());
8181

8282
// Success
8383
newWorkflow.setRetrievedFrom(tempWorkflow.getRetrievedFrom());
8484
newWorkflow.setRetrievedOn(new Date());
85-
newWorkflow.setLastCommit(commitSha);
85+
newWorkflow.setLastCommit(tempWorkflow.getLastCommit());
8686
newWorkflow.setCwltoolVersion(cwlToolVersion);
8787
workflowRepository.save(newWorkflow);
8888

src/main/java/org/commonwl/view/github/GitService.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,44 @@
2121

2222
import org.eclipse.jgit.api.Git;
2323
import org.eclipse.jgit.api.errors.GitAPIException;
24-
import org.eclipse.jgit.lib.Ref;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.beans.factory.annotation.Value;
2526
import org.springframework.stereotype.Service;
2627

27-
import java.io.File;
28-
import java.util.Map;
28+
import java.nio.file.Path;
2929

3030
import static java.util.Collections.singleton;
31+
import static org.apache.jena.ext.com.google.common.io.Files.createTempDir;
3132

3233
/**
3334
* Handles Git related functionality
3435
*/
3536
@Service
3637
public class GitService {
3738

38-
/**
39-
* Gets a map of commits and their references from a remote repository
40-
* @param gitDetails
41-
* @return
42-
* @throws GitAPIException
43-
*/
44-
public Map<String, Ref> getCommits(GitDetails gitDetails) throws GitAPIException {
45-
return Git.lsRemoteRepository()
46-
.setHeads(true)
47-
.setTags(true)
48-
.setRemote(gitDetails.getRepoUrl())
49-
.callAsMap();
39+
// Location to check out git repositories into
40+
private Path gitStorage;
41+
42+
// Whether submodules are also cloned
43+
private boolean cloneSubmodules;
44+
45+
@Autowired
46+
public GitService(@Value("${gitStorage}") Path gitStorage,
47+
@Value("${gitAPI.cloneSubmodules}") boolean cloneSubmodules) {
48+
this.gitStorage = gitStorage;
49+
this.cloneSubmodules = cloneSubmodules;
5050
}
5151

5252
/**
5353
* Clone a repository into a local directory
5454
* @param gitDetails The details of the Git repository
55-
* @param dest The destination folder for the clone
5655
*/
57-
public Git cloneRepository(GitDetails gitDetails, File dest)
56+
public Git cloneRepository(GitDetails gitDetails)
5857
throws GitAPIException {
5958
return Git.cloneRepository()
60-
.setCloneSubmodules(true)
59+
.setCloneSubmodules(cloneSubmodules)
6160
.setURI(gitDetails.getRepoUrl())
62-
.setDirectory(dest)
61+
.setDirectory(createTempDir())
6362
.setBranchesToClone(singleton("refs/heads/" + gitDetails.getBranch()))
6463
.setBranch("refs/heads/" + gitDetails.getBranch())
6564
.call();

src/main/java/org/commonwl/view/researchobject/ROBundleFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ROBundleFactory(ROBundleService roBundleService,
5757
}
5858

5959
/**
60-
* Creates a new Workflow Research Object Bundle from a Github URL
60+
* Creates a new Workflow Research Object Bundle from Git details
6161
* and saves it to a file
6262
* @param workflow The workflow to generate a RO bundle for
6363
* @throws IOException Any API errors which may have occurred
@@ -69,11 +69,11 @@ public void workflowROFromGithub(Workflow workflow)
6969

7070
// Get the whole containing folder, not just the workflow itself
7171
GitDetails githubInfo = workflow.getRetrievedFrom();
72-
GitDetails roDetails = new GitDetails(githubInfo.getOwner(), githubInfo.getRepoName(),
73-
githubInfo.getBranch(), FilenameUtils.getPath(githubInfo.getPath()));
72+
GitDetails roDetails = new GitDetails(githubInfo.getRepoUrl(), githubInfo.getBranch(),
73+
FilenameUtils.getPath(githubInfo.getPath()), githubInfo.getType());
7474

7575
// Create a new Research Object Bundle with Github contents
76-
Bundle bundle = roBundleService.newBundleFromGithub(workflow, roDetails);
76+
Bundle bundle = roBundleService.createBundle(workflow, roDetails);
7777

7878
// Save the bundle to the storage location in properties
7979
Path bundleLocation = roBundleService.saveToFile(bundle);

src/main/java/org/commonwl/view/researchobject/ROBundleService.java

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,30 @@
1919

2020
package org.commonwl.view.researchobject;
2121

22-
import org.apache.commons.io.FileUtils;
23-
import org.apache.commons.io.FilenameUtils;
2422
import org.apache.taverna.robundle.Bundle;
2523
import org.apache.taverna.robundle.Bundles;
26-
import org.apache.taverna.robundle.manifest.*;
24+
import org.apache.taverna.robundle.manifest.Agent;
25+
import org.apache.taverna.robundle.manifest.Manifest;
26+
import org.apache.taverna.robundle.manifest.PathAnnotation;
2727
import org.commonwl.view.cwl.CWLTool;
2828
import org.commonwl.view.github.GitDetails;
2929
import org.commonwl.view.github.GitService;
3030
import org.commonwl.view.graphviz.GraphVizService;
3131
import org.commonwl.view.workflow.Workflow;
32-
import org.eclipse.egit.github.core.CommitUser;
33-
import org.eclipse.egit.github.core.RepositoryCommit;
34-
import org.eclipse.egit.github.core.RepositoryContents;
35-
import org.eclipse.egit.github.core.User;
32+
import org.eclipse.jgit.api.Git;
3633
import org.slf4j.Logger;
3734
import org.slf4j.LoggerFactory;
3835
import org.springframework.beans.factory.annotation.Autowired;
3936
import org.springframework.beans.factory.annotation.Value;
4037
import org.springframework.stereotype.Service;
4138

42-
import java.io.File;
4339
import java.io.IOException;
4440
import java.net.URI;
4541
import java.net.URISyntaxException;
4642
import java.nio.file.Files;
4743
import java.nio.file.Path;
48-
import java.nio.file.Paths;
49-
import java.util.ArrayList;
50-
import java.util.HashSet;
5144
import java.util.List;
5245
import java.util.Set;
53-
import java.util.regex.Matcher;
5446
import java.util.regex.Pattern;
5547

5648
/**
@@ -102,16 +94,16 @@ public ROBundleService(@Value("${bundleStorage}") Path bundleStorage,
10294
}
10395

10496
/**
105-
* Creates a new research object bundle for a workflow from a Github repository
97+
* Creates a new research object bundle for a workflow from a Git repository
10698
* @param workflow The workflow to create the research object for
10799
* @return The constructed bundle
108100
*/
109-
public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) throws IOException {
101+
public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOException {
110102

111103
// Create a new RO bundle
112104
Bundle bundle = Bundles.createBundle();
113105
Manifest manifest = bundle.getManifest();
114-
106+
/*
115107
// Simplified attribution for RO bundle
116108
try {
117109
// Tool attribution in createdBy
@@ -121,17 +113,17 @@ public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) thro
121113
// TODO: Make this importedBy/On/From
122114
manifest.setRetrievedBy(appAgent);
123115
manifest.setRetrievedOn(manifest.getCreatedOn());
124-
manifest.setRetrievedFrom(new URI(githubInfo.getUrl()));
116+
manifest.setRetrievedFrom(new URI(gitInfo.getUrl()));
125117
126118
// Make a directory in the RO bundle to store the files
127119
Path bundleRoot = bundle.getRoot();
128120
Path bundleFiles = bundleRoot.resolve("workflow");
129121
Files.createDirectory(bundleFiles);
130122
131123
// Add the files from the Github repo to this workflow
132-
List<RepositoryContents> repoContents = githubService.getContents(githubInfo);
133124
Set<HashableAgent> authors = new HashSet<>();
134-
addFilesToBundle(bundle, githubInfo, repoContents, bundleFiles, authors);
125+
Git gitRepo = Git.open(new File(workflow.getGitRepoPath()));
126+
addFilesToBundle(bundle, gitInfo, gitRepo, bundleFiles, authors);
135127
136128
// Add combined authors
137129
manifest.setAuthoredBy(new ArrayList<>(authors));
@@ -161,13 +153,13 @@ public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) thro
161153
162154
// Git2prov history
163155
List<Path> history = new ArrayList<>();
164-
history.add(Paths.get("http://git2prov.org/git2prov?giturl=https://github.com/" + githubInfo.getOwner()
165-
+ "/" + githubInfo.getRepoName() + "&serialization=PROV-JSON"));
156+
history.add(Paths.get("http://git2prov.org/git2prov?giturl=" +
157+
gitInfo.getRepoUrl() + "&serialization=PROV-JSON"));
166158
bundle.getManifest().setHistory(history);
167159
168160
} catch (URISyntaxException ex) {
169161
logger.error("Error creating URI for RO Bundle", ex);
170-
}
162+
}*/
171163

172164
// Return the completed bundle
173165
return bundle;
@@ -177,39 +169,34 @@ public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) thro
177169
/**
178170
* Add files to this bundle from a list of Github repository contents
179171
* @param bundle The RO bundle to add files/directories to
180-
* @param githubInfo The information used to access the repository
181-
* @param repoContents The contents of the Github repository
172+
* @param gitInfo The information used to access the repository
173+
* @param gitRepo The Git repository
182174
* @param path The path in the Research Object to add the files
183175
*/
184-
private void addFilesToBundle(Bundle bundle, GitDetails githubInfo,
185-
List<RepositoryContents> repoContents, Path path,
176+
private void addFilesToBundle(Bundle bundle, GitDetails gitInfo,
177+
Git gitRepo, Path path,
186178
Set<HashableAgent> authors) throws IOException {
187-
188-
// Loop through repo contents and add them
189-
for (RepositoryContents repoContent : repoContents) {
190-
191-
// Parse subdirectories if they exist
192-
if (repoContent.getType().equals(GitService.TYPE_DIR)) {
179+
/*File[] files = gitRepo.getRepository().getDirectory().listFiles();
180+
for (File file : files) {
181+
if (file.isDirectory()) {
193182
194183
// Get the contents of the subdirectory
195-
GitDetails githubSubdir = new GitDetails(githubInfo.getOwner(),
196-
githubInfo.getRepoName(), githubInfo.getBranch(), repoContent.getPath());
184+
GitDetails githubSubdir = new GitDetails(gitInfo.getOwner(),
185+
gitInfo.getRepoName(), gitInfo.getBranch(), repoContent.getPath());
197186
List<RepositoryContents> subdirectory = githubService.getContents(githubSubdir);
198187
199188
// Create a new folder in the RO for it
200189
Path subdirPath = path.resolve(repoContent.getName());
201190
Files.createDirectory(subdirPath);
202191
203192
// Add the files in the subdirectory to this new folder
204-
addFilesToBundle(bundle, githubInfo, subdirectory, subdirPath, authors);
205-
206-
// Otherwise this is a file so add to the bundle
207-
} else if (repoContent.getType().equals(GitService.TYPE_FILE)) {
193+
addFilesToBundle(bundle, gitInfo, subdirectory, subdirPath, authors);
208194
195+
} else {
209196
try {
210197
// Raw URI of the bundle
211-
GitDetails githubFile = new GitDetails(githubInfo.getOwner(),
212-
githubInfo.getRepoName(), githubInfo.getBranch(), repoContent.getPath());
198+
GitDetails githubFile = new GitDetails(gitInfo.getOwner(),
199+
gitInfo.getRepoName(), gitInfo.getBranch(), repoContent.getPath());
213200
214201
// Where to store the new file in bundle
215202
Path bundleFilePath = path.resolve(repoContent.getName());
@@ -297,7 +284,7 @@ private void addFilesToBundle(Bundle bundle, GitDetails githubInfo,
297284
logger.error("Error creating URI for RO Bundle", ex);
298285
}
299286
}
300-
}
287+
}*/
301288
}
302289

303290
/**

0 commit comments

Comments
 (0)