19
19
20
20
package org .commonwl .view .researchobject ;
21
21
22
- import org .apache .commons .io .FileUtils ;
23
- import org .apache .commons .io .FilenameUtils ;
24
22
import org .apache .taverna .robundle .Bundle ;
25
23
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 ;
27
27
import org .commonwl .view .cwl .CWLTool ;
28
28
import org .commonwl .view .github .GitDetails ;
29
29
import org .commonwl .view .github .GitService ;
30
30
import org .commonwl .view .graphviz .GraphVizService ;
31
31
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 ;
36
33
import org .slf4j .Logger ;
37
34
import org .slf4j .LoggerFactory ;
38
35
import org .springframework .beans .factory .annotation .Autowired ;
39
36
import org .springframework .beans .factory .annotation .Value ;
40
37
import org .springframework .stereotype .Service ;
41
38
42
- import java .io .File ;
43
39
import java .io .IOException ;
44
40
import java .net .URI ;
45
41
import java .net .URISyntaxException ;
46
42
import java .nio .file .Files ;
47
43
import java .nio .file .Path ;
48
- import java .nio .file .Paths ;
49
- import java .util .ArrayList ;
50
- import java .util .HashSet ;
51
44
import java .util .List ;
52
45
import java .util .Set ;
53
- import java .util .regex .Matcher ;
54
46
import java .util .regex .Pattern ;
55
47
56
48
/**
@@ -102,16 +94,16 @@ public ROBundleService(@Value("${bundleStorage}") Path bundleStorage,
102
94
}
103
95
104
96
/**
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
106
98
* @param workflow The workflow to create the research object for
107
99
* @return The constructed bundle
108
100
*/
109
- public Bundle newBundleFromGithub (Workflow workflow , GitDetails githubInfo ) throws IOException {
101
+ public Bundle createBundle (Workflow workflow , GitDetails gitInfo ) throws IOException {
110
102
111
103
// Create a new RO bundle
112
104
Bundle bundle = Bundles .createBundle ();
113
105
Manifest manifest = bundle .getManifest ();
114
-
106
+ /*
115
107
// Simplified attribution for RO bundle
116
108
try {
117
109
// Tool attribution in createdBy
@@ -121,17 +113,17 @@ public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) thro
121
113
// TODO: Make this importedBy/On/From
122
114
manifest.setRetrievedBy(appAgent);
123
115
manifest.setRetrievedOn(manifest.getCreatedOn());
124
- manifest .setRetrievedFrom (new URI (githubInfo .getUrl ()));
116
+ manifest.setRetrievedFrom(new URI(gitInfo .getUrl()));
125
117
126
118
// Make a directory in the RO bundle to store the files
127
119
Path bundleRoot = bundle.getRoot();
128
120
Path bundleFiles = bundleRoot.resolve("workflow");
129
121
Files.createDirectory(bundleFiles);
130
122
131
123
// Add the files from the Github repo to this workflow
132
- List <RepositoryContents > repoContents = githubService .getContents (githubInfo );
133
124
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);
135
127
136
128
// Add combined authors
137
129
manifest.setAuthoredBy(new ArrayList<>(authors));
@@ -161,13 +153,13 @@ public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) thro
161
153
162
154
// Git2prov history
163
155
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"));
166
158
bundle.getManifest().setHistory(history);
167
159
168
160
} catch (URISyntaxException ex) {
169
161
logger.error("Error creating URI for RO Bundle", ex);
170
- }
162
+ }*/
171
163
172
164
// Return the completed bundle
173
165
return bundle ;
@@ -177,39 +169,34 @@ public Bundle newBundleFromGithub(Workflow workflow, GitDetails githubInfo) thro
177
169
/**
178
170
* Add files to this bundle from a list of Github repository contents
179
171
* @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
182
174
* @param path The path in the Research Object to add the files
183
175
*/
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 ,
186
178
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()) {
193
182
194
183
// 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());
197
186
List<RepositoryContents> subdirectory = githubService.getContents(githubSubdir);
198
187
199
188
// Create a new folder in the RO for it
200
189
Path subdirPath = path.resolve(repoContent.getName());
201
190
Files.createDirectory(subdirPath);
202
191
203
192
// 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);
208
194
195
+ } else {
209
196
try {
210
197
// 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());
213
200
214
201
// Where to store the new file in bundle
215
202
Path bundleFilePath = path.resolve(repoContent.getName());
@@ -297,7 +284,7 @@ private void addFilesToBundle(Bundle bundle, GitDetails githubInfo,
297
284
logger.error("Error creating URI for RO Bundle", ex);
298
285
}
299
286
}
300
- }
287
+ }*/
301
288
}
302
289
303
290
/**
0 commit comments