Revision 33460
Added by Marek Horst almost 10 years ago
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/deploy.info | ||
---|---|---|
1 |
{ |
|
2 |
"type_source": "SVN", |
|
3 |
"goal": "package -U -T 4C source:jar", |
|
4 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/icm-iis-primer/trunk/", |
|
5 |
"deploy_repository": "dnet4-snapshots", |
|
6 |
"version": "4", |
|
7 |
"mail": "m.horst@icm.edu.pl,m.fedoryszak@icm.edu.pl", |
|
8 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-bootstrap-snapshot", |
|
9 |
"name": "icm-iis-primer" |
|
10 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/FileClassProviderTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.junit.*; |
|
4 |
import org.junit.rules.TemporaryFolder; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.io.FileWriter; |
|
8 |
import java.io.IOException; |
|
9 |
import java.io.Writer; |
|
10 |
import java.util.HashSet; |
|
11 |
import java.util.Set; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
15 |
*/ |
|
16 |
public class FileClassProviderTest { |
|
17 |
@Rule |
|
18 |
public TemporaryFolder folder = new TemporaryFolder(); |
|
19 |
|
|
20 |
@Test |
|
21 |
public void basicTest() throws IOException, UnresolvableResourceException { |
|
22 |
File sourceDir = folder.newFolder(); |
|
23 |
|
|
24 |
File dirs = new File(sourceDir, "some/random/path"); |
|
25 |
if (!dirs.mkdirs()) { |
|
26 |
throw new IOException("Could not create directory " + dirs); |
|
27 |
} |
|
28 |
|
|
29 |
File f1 = new File(sourceDir, "some/random/f1.txt"); |
|
30 |
if (!f1.createNewFile()) { |
|
31 |
throw new IOException("Could not create file " + f1); |
|
32 |
} |
|
33 |
|
|
34 |
File f2 = new File(sourceDir, "some/random/path/f2.txt"); |
|
35 |
if (!f2.createNewFile()) { |
|
36 |
throw new IOException("Could not create file " + f2); |
|
37 |
} |
|
38 |
|
|
39 |
ClassProvider classProvider = new FileSystemClassProvider(sourceDir); |
|
40 |
Loader loader = new Loader(); |
|
41 |
loader.addClassProvider(classProvider); |
|
42 |
|
|
43 |
File dest = folder.newFolder(); |
|
44 |
loader.prime("some/random", dest, new Resolver()); |
|
45 |
|
|
46 |
Assert.assertTrue(new File(dest, "f1.txt").exists()); |
|
47 |
Assert.assertTrue(new File(dest, "path/f2.txt").exists()); |
|
48 |
} |
|
49 |
|
|
50 |
@Test |
|
51 |
public void basicImportTest() throws IOException, UnresolvableResourceException { |
|
52 |
File sourceDir = folder.newFolder(); |
|
53 |
|
|
54 |
File dirs1 = new File(sourceDir, "some/random"); |
|
55 |
if (!dirs1.mkdirs()) { |
|
56 |
throw new IOException("Could not create directory " + dirs1); |
|
57 |
} |
|
58 |
|
|
59 |
File importFile = new File(sourceDir, "some/random/import.txt"); |
|
60 |
Writer writer = new FileWriter(importFile); |
|
61 |
writer.append(ImportLinkFileChecker.IMPORT_LINK_HEADER + '\n'); |
|
62 |
writer.append("path classpath some/other/path/"); |
|
63 |
writer.close(); |
|
64 |
|
|
65 |
File dirs2 = new File(sourceDir, "some/other/path"); |
|
66 |
if (!dirs2.mkdirs()) { |
|
67 |
throw new IOException("Could not create directory " + dirs2); |
|
68 |
} |
|
69 |
|
|
70 |
File f1 = new File(sourceDir, "some/random/f1.txt"); |
|
71 |
if (!f1.createNewFile()) { |
|
72 |
throw new IOException("Could not create file " + f1); |
|
73 |
} |
|
74 |
|
|
75 |
File f2 = new File(sourceDir, "some/other/path/f2.txt"); |
|
76 |
if (!f2.createNewFile()) { |
|
77 |
throw new IOException("Could not create file " + f2); |
|
78 |
} |
|
79 |
|
|
80 |
ClassProvider classProvider = new FileSystemClassProvider(sourceDir); |
|
81 |
Loader loader = new Loader(); |
|
82 |
loader.addClassProvider(classProvider); |
|
83 |
|
|
84 |
Resolver resolver = new Resolver(); |
|
85 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
86 |
|
|
87 |
File dest = folder.newFolder(); |
|
88 |
loader.prime("some/random", dest, resolver); |
|
89 |
|
|
90 |
Assert.assertTrue(new File(dest, "f1.txt").exists()); |
|
91 |
Assert.assertTrue(new File(dest, "path/f2.txt").exists()); |
|
92 |
} |
|
93 |
|
|
94 |
@Test |
|
95 |
public void fileImportTest() throws IOException, UnresolvableResourceException { |
|
96 |
File sourceDir = folder.newFolder(); |
|
97 |
|
|
98 |
File dirs1 = new File(sourceDir, "some/random/path"); |
|
99 |
if (!dirs1.mkdirs()) { |
|
100 |
throw new IOException("Could not create directory " + dirs1); |
|
101 |
} |
|
102 |
|
|
103 |
File importFile = new File(sourceDir, "some/random/path/import.txt"); |
|
104 |
Writer writer = new FileWriter(importFile); |
|
105 |
writer.append(ImportLinkFileChecker.IMPORT_LINK_HEADER + '\n'); |
|
106 |
writer.append("f2.txt classpath some/other/path/f2.txt"); |
|
107 |
writer.close(); |
|
108 |
|
|
109 |
File dirs2 = new File(sourceDir, "some/other/path"); |
|
110 |
if (!dirs2.mkdirs()) { |
|
111 |
throw new IOException("Could not create directory " + dirs2); |
|
112 |
} |
|
113 |
|
|
114 |
File f1 = new File(sourceDir, "some/random/f1.txt"); |
|
115 |
if (!f1.createNewFile()) { |
|
116 |
throw new IOException("Could not create file " + f1); |
|
117 |
} |
|
118 |
|
|
119 |
File f2 = new File(sourceDir, "some/other/path/f2.txt"); |
|
120 |
if (!f2.createNewFile()) { |
|
121 |
throw new IOException("Could not create file " + f2); |
|
122 |
} |
|
123 |
|
|
124 |
ClassProvider classProvider = new FileSystemClassProvider(sourceDir); |
|
125 |
Loader loader = new Loader(); |
|
126 |
loader.addClassProvider(classProvider); |
|
127 |
|
|
128 |
Resolver resolver = new Resolver(); |
|
129 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
130 |
|
|
131 |
File dest = folder.newFolder(); |
|
132 |
loader.prime("some/random", dest, resolver); |
|
133 |
|
|
134 |
Assert.assertTrue(new File(dest, "f1.txt").exists()); |
|
135 |
Assert.assertTrue(new File(dest, "path/f2.txt").exists()); |
|
136 |
} |
|
137 |
|
|
138 |
@Test |
|
139 |
public void getEntryNamesTest() throws IOException { |
|
140 |
File sourceDir = folder.newFolder(); |
|
141 |
|
|
142 |
File dirs1 = new File(sourceDir, "some/random"); |
|
143 |
if (!dirs1.mkdirs()) { |
|
144 |
throw new IOException("Could not create directory " + dirs1); |
|
145 |
} |
|
146 |
|
|
147 |
File importFile = new File(sourceDir, "some/random/import.txt"); |
|
148 |
Writer writer = new FileWriter(importFile); |
|
149 |
writer.append(ImportLinkFileChecker.IMPORT_LINK_HEADER + '\n'); |
|
150 |
writer.append("path classpath some/other/path/"); |
|
151 |
writer.close(); |
|
152 |
|
|
153 |
File dirs2 = new File(sourceDir, "some/other/path"); |
|
154 |
if (!dirs2.mkdirs()) { |
|
155 |
throw new IOException("Could not create directory " + dirs2); |
|
156 |
} |
|
157 |
|
|
158 |
File f1 = new File(sourceDir, "some/random/f1.txt"); |
|
159 |
if (!f1.createNewFile()) { |
|
160 |
throw new IOException("Could not create file " + f1); |
|
161 |
} |
|
162 |
|
|
163 |
File f2 = new File(sourceDir, "some/other/path/f2.txt"); |
|
164 |
if (!f2.createNewFile()) { |
|
165 |
throw new IOException("Could not create file " + f2); |
|
166 |
} |
|
167 |
|
|
168 |
Set entries = new HashSet(new FileSystemClassProvider(sourceDir).getEntryNames()); |
|
169 |
|
|
170 |
Set expected = new HashSet(); |
|
171 |
expected.add("some/"); |
|
172 |
expected.add("some/random/"); |
|
173 |
expected.add("some/random/import.txt"); |
|
174 |
expected.add("some/random/f1.txt"); |
|
175 |
expected.add("some/other/"); |
|
176 |
expected.add("some/other/path/"); |
|
177 |
expected.add("some/other/path/f2.txt"); |
|
178 |
|
|
179 |
Assert.assertEquals(expected, entries); |
|
180 |
} |
|
181 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/CoansysWorkflowPackageTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Rule; |
|
5 |
import org.junit.Test; |
|
6 |
import org.junit.rules.TemporaryFolder; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.io.IOException; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
13 |
*/ |
|
14 |
public class CoansysWorkflowPackageTest { |
|
15 |
@Rule |
|
16 |
public TemporaryFolder folder = new TemporaryFolder(); |
|
17 |
|
|
18 |
@Test |
|
19 |
public void basicTest() throws IOException { |
|
20 |
File dir = folder.newFolder(); |
|
21 |
File packageFile = new File(getClass().getClassLoader() |
|
22 |
.getResource("eu/dnetlib/iis/primer/inner-workflow-1.2-SNAPSHOT-oozie-job.tar.gz").getPath()); |
|
23 |
CoansysWorkflowPackage wfPackage = new CoansysWorkflowPackage(packageFile); |
|
24 |
wfPackage.extract(dir); |
|
25 |
|
|
26 |
Assert.assertEquals(1, dir.list().length); |
|
27 |
Assert.assertTrue(new File(dir, "workflow.xml").exists()); |
|
28 |
} |
|
29 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/MixedClassProviderTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Rule; |
|
5 |
import org.junit.Test; |
|
6 |
import org.junit.rules.TemporaryFolder; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.io.FileWriter; |
|
10 |
import java.io.IOException; |
|
11 |
import java.io.Writer; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
15 |
*/ |
|
16 |
public class MixedClassProviderTest { |
|
17 |
@Rule |
|
18 |
public TemporaryFolder folder = new TemporaryFolder(); |
|
19 |
|
|
20 |
@Test |
|
21 |
public void basicTest() throws IOException, UnresolvableResourceException { |
|
22 |
File sourceDir = folder.newFolder(); |
|
23 |
|
|
24 |
File dirs1 = new File(sourceDir, "some/different"); |
|
25 |
if (!dirs1.mkdirs()) { |
|
26 |
throw new IOException("Could not create directory " + dirs1); |
|
27 |
} |
|
28 |
|
|
29 |
File importFile = new File(sourceDir, "some/different/import.txt"); |
|
30 |
Writer writer = new FileWriter(importFile); |
|
31 |
writer.append(ImportLinkFileChecker.IMPORT_LINK_HEADER + '\n'); |
|
32 |
writer.append("path classpath some/other/path/"); |
|
33 |
writer.close(); |
|
34 |
|
|
35 |
File dirs2 = new File(sourceDir, "some/other/path"); |
|
36 |
if (!dirs2.mkdirs()) { |
|
37 |
throw new IOException("Could not create directory " + dirs2); |
|
38 |
} |
|
39 |
|
|
40 |
File f1 = new File(sourceDir, "some/different/f1.txt"); |
|
41 |
if (!f1.createNewFile()) { |
|
42 |
throw new IOException("Could not create file " + f1); |
|
43 |
} |
|
44 |
|
|
45 |
File f2 = new File(sourceDir, "some/other/path/f2.txt"); |
|
46 |
if (!f2.createNewFile()) { |
|
47 |
throw new IOException("Could not create file " + f2); |
|
48 |
} |
|
49 |
|
|
50 |
ClassProvider fsClassProvider = new FileSystemClassProvider(sourceDir); |
|
51 |
ClassProvider jarClassProvider = new JarClassProvider(new File( |
|
52 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/TestJar.jar").getPath())); |
|
53 |
Loader loader = new Loader(); |
|
54 |
loader.addClassProvider(fsClassProvider); |
|
55 |
loader.addClassProvider(jarClassProvider); |
|
56 |
|
|
57 |
Resolver resolver = new Resolver(); |
|
58 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
59 |
|
|
60 |
File dest = folder.newFolder(); |
|
61 |
loader.prime("some/different", dest, resolver); |
|
62 |
|
|
63 |
Assert.assertTrue(new File(dest, "f1.txt").exists()); |
|
64 |
Assert.assertTrue(new File(dest, "path/f2.txt").exists()); |
|
65 |
Assert.assertFalse(new File(dest, "path/test/import.txt").exists()); |
|
66 |
Assert.assertTrue(new File(dest, "path/test/f3.txt").exists()); |
|
67 |
Assert.assertTrue(new File(dest, "path/test/sth/path/f3.txt").exists()); |
|
68 |
} |
|
69 |
|
|
70 |
public void cyclesTest() throws IOException, UnresolvableResourceException { |
|
71 |
File sourceDir = folder.newFolder(); |
|
72 |
|
|
73 |
File dirs1 = new File(sourceDir, "some/random"); |
|
74 |
if (!dirs1.mkdirs()) { |
|
75 |
throw new IOException("Could not create directory " + dirs1); |
|
76 |
} |
|
77 |
|
|
78 |
File importFile = new File(sourceDir, "some/random/import.txt"); |
|
79 |
Writer writer = new FileWriter(importFile); |
|
80 |
writer.append(ImportLinkFileChecker.IMPORT_LINK_HEADER + '\n'); |
|
81 |
writer.append("path classpath some/other/path/"); |
|
82 |
writer.close(); |
|
83 |
|
|
84 |
File dirs2 = new File(sourceDir, "some/other/path"); |
|
85 |
if (!dirs2.mkdirs()) { |
|
86 |
throw new IOException("Could not create directory " + dirs2); |
|
87 |
} |
|
88 |
|
|
89 |
File f1 = new File(sourceDir, "some/random/f1.txt"); |
|
90 |
if (!f1.createNewFile()) { |
|
91 |
throw new IOException("Could not create file " + f1); |
|
92 |
} |
|
93 |
|
|
94 |
File f2 = new File(sourceDir, "some/other/path/f2.txt"); |
|
95 |
if (!f2.createNewFile()) { |
|
96 |
throw new IOException("Could not create file " + f2); |
|
97 |
} |
|
98 |
|
|
99 |
ClassProvider fsClassProvider = new FileSystemClassProvider(sourceDir); |
|
100 |
ClassProvider jarClassProvider = new JarClassProvider(new File( |
|
101 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/TestJar.jar").getPath())); |
|
102 |
Loader loader = new Loader(); |
|
103 |
loader.addClassProvider(fsClassProvider); |
|
104 |
loader.addClassProvider(jarClassProvider); |
|
105 |
|
|
106 |
Resolver resolver = new Resolver(); |
|
107 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
108 |
|
|
109 |
File dest = folder.newFolder(); |
|
110 |
loader.prime("some/random", dest, resolver); |
|
111 |
|
|
112 |
Assert.assertTrue(new File(dest, "f1.txt").exists()); |
|
113 |
Assert.assertTrue(new File(dest, "path/f2.txt").exists()); |
|
114 |
Assert.assertFalse(new File(dest, "path/test/import.txt").exists()); |
|
115 |
Assert.assertTrue(new File(dest, "path/test/f3.txt").exists()); |
|
116 |
Assert.assertTrue(new File(dest, "path/test/sth/path/f3.txt").exists()); |
|
117 |
} |
|
118 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/CoansysResolvingServiceTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.io.IOUtils; |
|
4 |
import org.junit.Assert; |
|
5 |
import org.junit.Rule; |
|
6 |
import org.junit.Test; |
|
7 |
import org.junit.rules.TemporaryFolder; |
|
8 |
|
|
9 |
import java.io.File; |
|
10 |
import java.io.FileOutputStream; |
|
11 |
import java.io.IOException; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
15 |
*/ |
|
16 |
public class CoansysResolvingServiceTest { |
|
17 |
@Rule |
|
18 |
public TemporaryFolder folder = new TemporaryFolder(); |
|
19 |
|
|
20 |
@Test |
|
21 |
public void basicTest() throws IOException, UnresolvableResourceException { |
|
22 |
File dir = folder.newFolder(); |
|
23 |
File repo = folder.newFolder(); |
|
24 |
String filename = "inner-workflow-1.2-SNAPSHOT-oozie-job.tar.gz"; |
|
25 |
String path = "eu/dnetlib/iis/primer"; |
|
26 |
IOUtils.copy(getClass().getClassLoader().getResourceAsStream(path + "/" + filename), |
|
27 |
new FileOutputStream(new File(repo, filename))); |
|
28 |
|
|
29 |
Resolver resolver = new Resolver(); |
|
30 |
resolver.addService("coansys", new CoansysResolvingService(new FileSystemCoansysWorkflowPackageSupplier(repo))); |
|
31 |
resolver.resolve(dir, "coansys", "pl.edu.icm.coansys:inner-workflow:1.2-SNAPSHOT"); |
|
32 |
|
|
33 |
Assert.assertEquals(1, dir.list().length); |
|
34 |
Assert.assertTrue(new File(dir, "workflow.xml").exists()); |
|
35 |
} |
|
36 |
|
|
37 |
@Test |
|
38 |
public void emptyVersionTest() throws IOException, UnresolvableResourceException { |
|
39 |
File dir = folder.newFolder(); |
|
40 |
File repo = folder.newFolder(); |
|
41 |
String filename = "inner-workflow-1.2-SNAPSHOT-oozie-job.tar.gz"; |
|
42 |
String path = "eu/dnetlib/iis/primer"; |
|
43 |
IOUtils.copy(getClass().getClassLoader().getResourceAsStream(path + "/" + filename), |
|
44 |
new FileOutputStream(new File(repo, filename))); |
|
45 |
|
|
46 |
Resolver resolver = new Resolver(); |
|
47 |
resolver.addService("coansys", new CoansysResolvingService(new FileSystemCoansysWorkflowPackageSupplier(repo))); |
|
48 |
resolver.resolve(dir, "coansys", "pl.edu.icm.coansys:inner-workflow"); |
|
49 |
|
|
50 |
Assert.assertEquals(1, dir.list().length); |
|
51 |
Assert.assertTrue(new File(dir, "workflow.xml").exists()); |
|
52 |
} |
|
53 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/DuplicatesTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Rule; |
|
5 |
import org.junit.Test; |
|
6 |
import org.junit.rules.TemporaryFolder; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.io.IOException; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
13 |
*/ |
|
14 |
public class DuplicatesTest { |
|
15 |
@Rule |
|
16 |
public TemporaryFolder folder = new TemporaryFolder(); |
|
17 |
|
|
18 |
@Test |
|
19 |
public void firstDirTest() throws IOException, UnresolvableResourceException { |
|
20 |
Loader loader = new Loader(); |
|
21 |
|
|
22 |
ClassProvider classProvider1 = new JarClassProvider(new File( |
|
23 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/TestJar.jar").getPath())); |
|
24 |
ClassProvider classProvider2 = new JarClassProvider(new File( |
|
25 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/DuplicateJar.jar").getPath())); |
|
26 |
|
|
27 |
loader.addClassProvider(classProvider1); |
|
28 |
loader.addClassProvider(classProvider2); |
|
29 |
|
|
30 |
Resolver resolver = new Resolver(); |
|
31 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
32 |
|
|
33 |
File dest = folder.newFolder(); |
|
34 |
loader.prime("", dest, resolver); |
|
35 |
|
|
36 |
Assert.assertTrue(new File(dest, "some").exists()); |
|
37 |
Assert.assertTrue(new File(dest, "some").isDirectory()); |
|
38 |
} |
|
39 |
|
|
40 |
@Test |
|
41 |
public void firstFileTest() throws IOException, UnresolvableResourceException { |
|
42 |
Loader loader = new Loader(); |
|
43 |
|
|
44 |
ClassProvider classProvider1 = new JarClassProvider(new File( |
|
45 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/DuplicateJar.jar").getPath())); |
|
46 |
ClassProvider classProvider2 = new JarClassProvider(new File( |
|
47 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/TestJar.jar").getPath())); |
|
48 |
|
|
49 |
loader.addClassProvider(classProvider1); |
|
50 |
loader.addClassProvider(classProvider2); |
|
51 |
|
|
52 |
Resolver resolver = new Resolver(); |
|
53 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
54 |
|
|
55 |
File dest = folder.newFolder(); |
|
56 |
loader.prime("", dest, resolver); |
|
57 |
|
|
58 |
Assert.assertTrue(new File(dest, "some").exists()); |
|
59 |
Assert.assertFalse(new File(dest, "some").isDirectory()); |
|
60 |
} |
|
61 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/ImportLinkFileCheckerTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Test; |
|
5 |
|
|
6 |
/** |
|
7 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
8 |
*/ |
|
9 |
public class ImportLinkFileCheckerTest { |
|
10 |
@Test |
|
11 |
public void checkHeaderBasicTest() { |
|
12 |
Assert.assertFalse(ImportLinkFileChecker.checkHeaderContents( |
|
13 |
"## ala ma kota")); |
|
14 |
Assert.assertTrue(ImportLinkFileChecker.checkHeaderContents( |
|
15 |
"## This is a classpath-based import file (this header is required)")); |
|
16 |
} |
|
17 |
|
|
18 |
@Test |
|
19 |
public void checkHeaderUnderlinesTest() { |
|
20 |
Assert.assertTrue(ImportLinkFileChecker.checkHeaderContents( |
|
21 |
"##_This_is_a_classpath_based_import_file_this_header_is_required")); |
|
22 |
} |
|
23 |
|
|
24 |
@Test |
|
25 |
public void checkHeaderMessInTheBeginningTest() { |
|
26 |
Assert.assertTrue(ImportLinkFileChecker.checkHeaderContents( |
|
27 |
" ##_This_is_a_classpath_based_import_file_this_header_is_required")); |
|
28 |
} |
|
29 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/test/java/eu/dnetlib/iis/primer/JarClassProviderTest.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Rule; |
|
5 |
import org.junit.Test; |
|
6 |
import org.junit.rules.TemporaryFolder; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.io.IOException; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
13 |
*/ |
|
14 |
public class JarClassProviderTest { |
|
15 |
@Rule |
|
16 |
public TemporaryFolder folder = new TemporaryFolder(); |
|
17 |
|
|
18 |
@Test |
|
19 |
public void basicTest() throws IOException, UnresolvableResourceException { |
|
20 |
ClassProvider classProvider = new JarClassProvider(new File( |
|
21 |
getClass().getClassLoader().getResource("eu/dnetlib/iis/primer/TestJar.jar").getPath())); |
|
22 |
Loader loader = new Loader(); |
|
23 |
loader.addClassProvider(classProvider); |
|
24 |
|
|
25 |
Resolver resolver = new Resolver(); |
|
26 |
resolver.addService("classpath", new ClasspathResolvingService(loader)); |
|
27 |
|
|
28 |
File dest = folder.newFolder(); |
|
29 |
loader.prime("some/other/path", dest, resolver); |
|
30 |
|
|
31 |
Assert.assertFalse(new File(dest, "test/import.txt").exists()); |
|
32 |
Assert.assertTrue(new File(dest, "test/f3.txt").exists()); |
|
33 |
Assert.assertTrue(new File(dest, "test/sth/path/f3.txt").exists()); |
|
34 |
} |
|
35 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/FileSystemCoansysWorkflowPackageSupplier.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.io.filefilter.WildcardFileFilter; |
|
4 |
import org.apache.commons.lang.StringUtils; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.io.FileFilter; |
|
8 |
import java.io.FileNotFoundException; |
|
9 |
|
|
10 |
/** |
|
11 |
* Retrieves workflow packages from a local directory. |
|
12 |
* |
|
13 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
14 |
*/ |
|
15 |
public class FileSystemCoansysWorkflowPackageSupplier extends CoansysWorkflowPackageSupplier { |
|
16 |
private File dir; |
|
17 |
private static String ARTIFACT_CLASSIFIER = "oozie-job"; |
|
18 |
private static String ARTIFACT_TYPE = "tar.gz"; |
|
19 |
public FileSystemCoansysWorkflowPackageSupplier(File dir) { |
|
20 |
this.dir = dir; |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public CoansysWorkflowPackage getCoansysWorkflowPackage(String groupId, String artifactId, String version) |
|
25 |
throws FileNotFoundException { |
|
26 |
if(StringUtils.isNotBlank(version)) { |
|
27 |
return new CoansysWorkflowPackage(getWorkflowPackageFile(artifactId, version)); |
|
28 |
} else { |
|
29 |
File[] candidates = dir.listFiles((FileFilter) new WildcardFileFilter(getWorkflowPackageFileName(artifactId, "*"))); |
|
30 |
if (candidates.length == 0) { |
|
31 |
throw new FileNotFoundException(String.format( |
|
32 |
"Could not find CoAnSys workflow package matching pattern %s", |
|
33 |
getWorkflowPackageFile(artifactId, "*").getAbsolutePath())); |
|
34 |
} else if (candidates.length > 1) { |
|
35 |
throw new FileNotFoundException(String.format( |
|
36 |
"Filename pattern %s is ambiguous. Please specify CoAnSys workflow package version.", |
|
37 |
getWorkflowPackageFile(artifactId, "*").getAbsolutePath())); |
|
38 |
} else { |
|
39 |
return new CoansysWorkflowPackage(candidates[0]); |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
private String getWorkflowPackageFileName(String artifactId, String version) { |
|
45 |
return artifactId + "-" + version + "-" + ARTIFACT_CLASSIFIER + "." + ARTIFACT_TYPE; |
|
46 |
} |
|
47 |
|
|
48 |
private File getWorkflowPackageFile(String artifactId, String version) { |
|
49 |
return new File(dir, getWorkflowPackageFileName(artifactId, version)); |
|
50 |
} |
|
51 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/ClassProvider.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.text.ParseException; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
10 |
*/ |
|
11 |
public abstract class ClassProvider { |
|
12 |
/** |
|
13 |
* Returns a list of entries' names available in this class provider. Directory names should have a tailing slash. |
|
14 |
* @return |
|
15 |
*/ |
|
16 |
public abstract List<String> getEntryNames(); |
|
17 |
|
|
18 |
public abstract void primeOne(String classpath, File destination, Resolver resolver) throws IOException, UnresolvableResourceException, ParseException; |
|
19 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/Resolver.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
10 |
*/ |
|
11 |
public class Resolver { |
|
12 |
private Map<String, ResolvingService> services = new HashMap<String, ResolvingService>(); |
|
13 |
public void addService(String protocol, ResolvingService r) { |
|
14 |
r.setParent(this); |
|
15 |
services.put(protocol, r); |
|
16 |
} |
|
17 |
|
|
18 |
public void resolve(File target, String protocol, String args) throws IOException, UnresolvableResourceException { |
|
19 |
ResolvingService r = services.get(protocol); |
|
20 |
if (r == null) { |
|
21 |
throw new RuntimeException("No resolver for protocol " + protocol); |
|
22 |
} |
|
23 |
|
|
24 |
r.resolve(target, args); |
|
25 |
} |
|
26 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/FileSystemClassProvider.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.io.FileUtils; |
|
4 |
import org.apache.commons.lang.StringUtils; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.io.FileInputStream; |
|
8 |
import java.io.IOException; |
|
9 |
import java.text.ParseException; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
15 |
*/ |
|
16 |
public class FileSystemClassProvider extends ClassProvider { |
|
17 |
private File root; |
|
18 |
|
|
19 |
public FileSystemClassProvider(File root) { |
|
20 |
this.root = root; |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public List<String> getEntryNames() { |
|
25 |
List<String> result = new ArrayList<String>(); |
|
26 |
appendChildren("", result); |
|
27 |
return result; |
|
28 |
} |
|
29 |
|
|
30 |
private void appendChildren(String relativePath, List<String> result) { |
|
31 |
for (File f : new File(root, relativePath).listFiles()) { |
|
32 |
String beginning = StringUtils.isNotEmpty(relativePath) ? relativePath : ""; |
|
33 |
String newRelativePath = beginning + f.getName(); |
|
34 |
|
|
35 |
if (f.isDirectory()) { |
|
36 |
newRelativePath = newRelativePath + '/'; |
|
37 |
appendChildren(newRelativePath, result); |
|
38 |
} |
|
39 |
result.add(newRelativePath); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void primeOne(String classpath, File destination, Resolver resolver) throws IOException, UnresolvableResourceException, ParseException { |
|
45 |
File src = new File(root, classpath); |
|
46 |
if (src.isDirectory()) { |
|
47 |
FileUtils.forceMkdir(destination); |
|
48 |
} else if (ImportLinkFileChecker.checkName(src) |
|
49 |
&& ImportLinkFileChecker.checkHeader(new FileInputStream(src))) { |
|
50 |
new ImportLinkReader(new FileInputStream(src)).performResolution(destination.getParentFile(), resolver); |
|
51 |
} else { |
|
52 |
FileUtils.copyFile(src, destination); |
|
53 |
} |
|
54 |
} |
|
55 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/CoansysWorkflowPackage.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; |
|
4 |
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; |
|
5 |
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; |
|
6 |
import org.apache.commons.io.FileUtils; |
|
7 |
import org.apache.commons.io.IOUtils; |
|
8 |
|
|
9 |
import java.io.*; |
|
10 |
|
|
11 |
/** |
|
12 |
* Workflow package abstraction. |
|
13 |
* |
|
14 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
15 |
*/ |
|
16 |
public class CoansysWorkflowPackage { |
|
17 |
private File file; |
|
18 |
|
|
19 |
public CoansysWorkflowPackage(File file) throws FileNotFoundException { |
|
20 |
if (!file.exists()) { |
|
21 |
throw new FileNotFoundException("Could not find CoAnSys workflow package " + file.getAbsolutePath()); |
|
22 |
} |
|
23 |
this.file = file; |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Unpacks a workflow into specified directory. To be more precise: workflow package should contain only a single |
|
28 |
* directory with the workflow. This method will extract its contents into target directory. |
|
29 |
* |
|
30 |
* @param target new workflow root directory |
|
31 |
*/ |
|
32 |
public void extract(File target) throws IOException { |
|
33 |
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); |
|
34 |
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in); |
|
35 |
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); |
|
36 |
TarArchiveEntry entry; |
|
37 |
while ((entry = (TarArchiveEntry)tarIn.getNextEntry()) != null) { |
|
38 |
//The archive should contain only a single directory: we want to unpack its content. |
|
39 |
final File outputFile = new File(target, entry.getName().substring(entry.getName().indexOf('/') + 1)); |
|
40 |
if (entry.isDirectory()) { |
|
41 |
FileUtils.forceMkdir(outputFile); |
|
42 |
} else { |
|
43 |
OutputStream outputFileStream = null; |
|
44 |
try { |
|
45 |
outputFileStream = new FileOutputStream(outputFile); |
|
46 |
IOUtils.copy(tarIn, outputFileStream); |
|
47 |
} finally { |
|
48 |
IOUtils.closeQuietly(outputFileStream); |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/Loader.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
|
|
5 |
import java.io.File; |
|
6 |
import java.util.*; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
10 |
*/ |
|
11 |
public class Loader { |
|
12 |
private final Logger log = Logger.getLogger(Loader.class); |
|
13 |
|
|
14 |
private SortedMap<String, ClassProvider> index = new TreeMap<String, ClassProvider>(); |
|
15 |
|
|
16 |
public void addClassProvider(ClassProvider classProvider) { |
|
17 |
List<String> entryNames = classProvider.getEntryNames(); |
|
18 |
Collections.sort(entryNames); |
|
19 |
String exclusionPrefix = null; |
|
20 |
for (String s : entryNames) { |
|
21 |
if (exclusionPrefix != null && s.startsWith(exclusionPrefix)) { |
|
22 |
log.warn("Omitting " + s + " as it is a descendant of inconsistently duplicated " + exclusionPrefix); |
|
23 |
} else { |
|
24 |
exclusionPrefix = null; |
|
25 |
if (index.containsKey(toggleTailingSlash(s))) { |
|
26 |
log.warn("Inconsistent duplicated entries for " + s + ". Will use the first one."); |
|
27 |
exclusionPrefix = s; |
|
28 |
} else { |
|
29 |
if (index.containsKey(s)) { |
|
30 |
log.warn("Duplicated entries for " + s); |
|
31 |
} |
|
32 |
index.put(s, classProvider); |
|
33 |
} |
|
34 |
} |
|
35 |
} |
|
36 |
} |
|
37 |
|
|
38 |
private static String toggleTailingSlash(String s) { |
|
39 |
if (s.endsWith("/")) { |
|
40 |
return s.substring(0, s.length() - 1); |
|
41 |
} else { |
|
42 |
return s + "/"; |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
public void prime(String classpath, File destination, Resolver resolver) |
|
47 |
throws UnresolvableResourceException { |
|
48 |
boolean didAnything = false; |
|
49 |
SortedMap<String, ClassProvider> tail = index.tailMap(classpath); |
|
50 |
for (Map.Entry<String, ClassProvider> entry : tail.entrySet()) { |
|
51 |
if (!entry.getKey().startsWith(classpath)) { |
|
52 |
break; |
|
53 |
} |
|
54 |
|
|
55 |
try { |
|
56 |
entry.getValue().primeOne( |
|
57 |
entry.getKey(), |
|
58 |
new File(destination, entry.getKey().substring(classpath.length())), |
|
59 |
resolver); |
|
60 |
didAnything = true; |
|
61 |
} catch (Exception e) { |
|
62 |
throw new UnresolvableResourceException(e); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
if (!didAnything) { |
|
67 |
throw new UnresolvableResourceException("Could not resolve " + classpath + " using the classpath"); |
|
68 |
} |
|
69 |
} |
|
70 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/UnresolvableResourceException.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
/** |
|
4 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
5 |
*/ |
|
6 |
public class UnresolvableResourceException extends Exception { |
|
7 |
/** |
|
8 |
* Constructs a new exception with <code>null</code> as its detail message. |
|
9 |
* The cause is not initialized, and may subsequently be initialized by a |
|
10 |
* call to {@link #initCause}. |
|
11 |
*/ |
|
12 |
public UnresolvableResourceException() { |
|
13 |
} |
|
14 |
|
|
15 |
/** |
|
16 |
* Constructs a new exception with the specified detail message. The |
|
17 |
* cause is not initialized, and may subsequently be initialized by |
|
18 |
* a call to {@link #initCause}. |
|
19 |
* |
|
20 |
* @param message the detail message. The detail message is saved for |
|
21 |
* later retrieval by the {@link #getMessage()} method. |
|
22 |
*/ |
|
23 |
public UnresolvableResourceException(String message) { |
|
24 |
super(message); |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* Constructs a new exception with the specified detail message and |
|
29 |
* cause. <p>Note that the detail message associated with |
|
30 |
* <code>cause</code> is <i>not</i> automatically incorporated in |
|
31 |
* this exception's detail message. |
|
32 |
* |
|
33 |
* @param message the detail message (which is saved for later retrieval |
|
34 |
* by the {@link #getMessage()} method). |
|
35 |
* @param cause the cause (which is saved for later retrieval by the |
|
36 |
* {@link #getCause()} method). (A <tt>null</tt> value is |
|
37 |
* permitted, and indicates that the cause is nonexistent or |
|
38 |
* unknown.) |
|
39 |
* @since 1.4 |
|
40 |
*/ |
|
41 |
public UnresolvableResourceException(String message, Throwable cause) { |
|
42 |
super(message, cause); |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Constructs a new exception with the specified cause and a detail |
|
47 |
* message of <tt>(cause==null ? null : cause.toString())</tt> (which |
|
48 |
* typically contains the class and detail message of <tt>cause</tt>). |
|
49 |
* This constructor is useful for exceptions that are little more than |
|
50 |
* wrappers for other throwables (for example, {@link |
|
51 |
* java.security.PrivilegedActionException}). |
|
52 |
* |
|
53 |
* @param cause the cause (which is saved for later retrieval by the |
|
54 |
* {@link #getCause()} method). (A <tt>null</tt> value is |
|
55 |
* permitted, and indicates that the cause is nonexistent or |
|
56 |
* unknown.) |
|
57 |
* @since 1.4 |
|
58 |
*/ |
|
59 |
public UnresolvableResourceException(Throwable cause) { |
|
60 |
super(cause); |
|
61 |
} |
|
62 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/CoansysResolvingService.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileNotFoundException; |
|
5 |
import java.io.IOException; |
|
6 |
|
|
7 |
/** |
|
8 |
* This class enables usage of CoAnSys Oozie Workflow Packages. |
|
9 |
* |
|
10 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
11 |
*/ |
|
12 |
public class CoansysResolvingService extends ResolvingService { |
|
13 |
private CoansysWorkflowPackageSupplier packageSupplier; |
|
14 |
|
|
15 |
public CoansysResolvingService(CoansysWorkflowPackageSupplier packageSupplier) { |
|
16 |
this.packageSupplier = packageSupplier; |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public void resolve(File target, String args) throws IOException, UnresolvableResourceException { |
|
21 |
final String[] splits = args.split(":",3); |
|
22 |
final String groupId = splits[0]; |
|
23 |
final String artifactId = splits[1]; |
|
24 |
final String version = (splits.length == 3) ? splits[2] : null; |
|
25 |
try { |
|
26 |
packageSupplier.getCoansysWorkflowPackage(groupId, artifactId, version).extract(target); |
|
27 |
} catch (FileNotFoundException ex) { |
|
28 |
throw new UnresolvableResourceException("Could not resolve " + args + " CoAnSys workflow package", ex); |
|
29 |
} |
|
30 |
} |
|
31 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/ResolvingService.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
/** |
|
7 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
8 |
*/ |
|
9 |
public abstract class ResolvingService { |
|
10 |
private Resolver parent; |
|
11 |
|
|
12 |
public Resolver getParent() { |
|
13 |
return parent; |
|
14 |
} |
|
15 |
|
|
16 |
public void setParent(Resolver parent) { |
|
17 |
this.parent = parent; |
|
18 |
} |
|
19 |
|
|
20 |
public abstract void resolve(File target, String args) throws IOException, UnresolvableResourceException; |
|
21 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/CoansysWorkflowPackageSupplier.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import java.io.FileNotFoundException; |
|
4 |
|
|
5 |
/** |
|
6 |
* This class retrieves a workflow package given its details. |
|
7 |
* |
|
8 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
9 |
*/ |
|
10 |
public abstract class CoansysWorkflowPackageSupplier { |
|
11 |
public abstract CoansysWorkflowPackage getCoansysWorkflowPackage(String groupId, String artifactId, String version) throws FileNotFoundException; |
|
12 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/ImportLinkReader.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.lang.StringUtils; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
|
|
6 |
import java.io.*; |
|
7 |
import java.text.ParseException; |
|
8 |
|
|
9 |
/** |
|
10 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
11 |
*/ |
|
12 |
public class ImportLinkReader { |
|
13 |
private final Logger log = Logger.getLogger(ImportLinkReader.class); |
|
14 |
|
|
15 |
private BufferedReader reader; |
|
16 |
|
|
17 |
public ImportLinkReader(InputStream is) { |
|
18 |
this.reader = new BufferedReader(new InputStreamReader(is)); |
|
19 |
} |
|
20 |
|
|
21 |
public void performResolution(File workingDir, Resolver resolver) |
|
22 |
throws IOException, UnresolvableResourceException, ParseException { |
|
23 |
log.debug("Performing resolution in " + workingDir); |
|
24 |
String line; |
|
25 |
int lineNo = 0; |
|
26 |
ImportLinkFileChecker.dropHeader(reader); |
|
27 |
while ((line = reader.readLine()) != null) { |
|
28 |
++lineNo; |
|
29 |
if (StringUtils.isBlank(line)) { |
|
30 |
continue; |
|
31 |
} |
|
32 |
final int COLUMN_COUNT = 3; |
|
33 |
String[] splits = line.split("\\s+", COLUMN_COUNT); |
|
34 |
if (splits.length < COLUMN_COUNT) { |
|
35 |
throw new ParseException("Malformed line in " + workingDir + File.separator + "import.txt file", lineNo); |
|
36 |
} |
|
37 |
resolver.resolve(new File(workingDir, splits[0]), splits[1], splits[2]); |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
|
|
42 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/ClasspathResolvingService.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
/** |
|
7 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
8 |
*/ |
|
9 |
public class ClasspathResolvingService extends ResolvingService { |
|
10 |
private final Loader loader; |
|
11 |
|
|
12 |
|
|
13 |
public ClasspathResolvingService(Loader loader) { |
|
14 |
this.loader = loader; |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public void resolve(File target, String args) throws IOException, UnresolvableResourceException { |
|
19 |
loader.prime(args, target, getParent()); |
|
20 |
} |
|
21 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/ImportLinkFileChecker.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.io.IOUtils; |
|
4 |
|
|
5 |
import java.io.*; |
|
6 |
import java.util.Arrays; |
|
7 |
import java.util.Locale; |
|
8 |
|
|
9 |
/** |
|
10 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
11 |
*/ |
|
12 |
public final class ImportLinkFileChecker { |
|
13 |
public static final String IMPORT_LINK_FILE_NAME = "import.txt"; |
|
14 |
public static final String IMPORT_LINK_HEADER = |
|
15 |
"## This is a classpath-based import file (this header is required)"; |
|
16 |
|
|
17 |
private static final String SPLITTING_REGEX = "[^A-Za-z0-9#]+"; |
|
18 |
|
|
19 |
private ImportLinkFileChecker() {} |
|
20 |
|
|
21 |
/** |
|
22 |
* Checks if a file has a name following import link file rules. |
|
23 |
*/ |
|
24 |
public static boolean checkName(File f) { |
|
25 |
return f.getName().equalsIgnoreCase(IMPORT_LINK_FILE_NAME); |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Removes import link file header from a reader. |
|
30 |
*/ |
|
31 |
public static void dropHeader(BufferedReader reader) throws IOException { |
|
32 |
reader.readLine(); |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Checks if a file has a header following import link file rules. |
|
37 |
*/ |
|
38 |
public static boolean checkHeader(InputStream is) { |
|
39 |
BufferedReader reader = null; |
|
40 |
try { |
|
41 |
reader = new BufferedReader(new InputStreamReader(is)); |
|
42 |
String header = reader.readLine(); |
|
43 |
return checkHeaderContents(header); |
|
44 |
} catch (IOException e) { |
|
45 |
return false; |
|
46 |
} finally { |
|
47 |
IOUtils.closeQuietly(reader); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Checks if header contents follow import link file rules. |
|
53 |
*/ |
|
54 |
public static boolean checkHeaderContents(String header) { |
|
55 |
String[] actual = splitHeader(header); |
|
56 |
String[] expected = splitHeader(IMPORT_LINK_HEADER); |
|
57 |
return Arrays.equals(actual, expected); |
|
58 |
} |
|
59 |
|
|
60 |
private static String[] splitHeader(String header) { |
|
61 |
return header.trim().toLowerCase(Locale.ENGLISH).split(SPLITTING_REGEX); |
|
62 |
} |
|
63 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/java/eu/dnetlib/iis/primer/JarClassProvider.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.primer; |
|
2 |
|
|
3 |
import org.apache.commons.io.FileUtils; |
|
4 |
import org.apache.commons.io.IOUtils; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.io.FileOutputStream; |
|
8 |
import java.io.IOException; |
|
9 |
import java.io.InputStream; |
|
10 |
import java.text.ParseException; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Enumeration; |
|
13 |
import java.util.List; |
|
14 |
import java.util.jar.JarEntry; |
|
15 |
import java.util.jar.JarFile; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author Mateusz Fedoryszak (m.fedoryszak@icm.edu.pl) |
|
19 |
*/ |
|
20 |
public class JarClassProvider extends ClassProvider { |
|
21 |
private JarFile jar; |
|
22 |
|
|
23 |
public JarClassProvider(File jar) throws IOException { |
|
24 |
this.jar = new JarFile(jar); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public List<String> getEntryNames() { |
|
29 |
List<String> result = new ArrayList<String>(); |
|
30 |
Enumeration<JarEntry> entries = jar.entries(); |
|
31 |
while (entries.hasMoreElements()) { |
|
32 |
final JarEntry entry = entries.nextElement(); |
|
33 |
result.add(entry.getName()); |
|
34 |
} |
|
35 |
return result; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public void primeOne(String classpath, File target, Resolver resolver) throws IOException, UnresolvableResourceException, ParseException { |
|
40 |
final JarEntry entry = jar.getJarEntry(classpath); |
|
41 |
|
|
42 |
if (entry.isDirectory()) { |
|
43 |
FileUtils.forceMkdir(target); |
|
44 |
} else if (ImportLinkFileChecker.checkName(new File(entry.getName())) |
|
45 |
&& ImportLinkFileChecker.checkHeader(jar.getInputStream(entry))) { |
|
46 |
new ImportLinkReader(jar.getInputStream(entry)).performResolution(target.getParentFile(), resolver); |
|
47 |
} else { |
|
48 |
FileUtils.forceMkdir(target.getParentFile()); |
|
49 |
|
|
50 |
FileOutputStream output = null; |
|
51 |
try { |
|
52 |
output = new FileOutputStream(target); |
|
53 |
InputStream input = jar.getInputStream(entry); |
|
54 |
IOUtils.copy(input, output); |
|
55 |
} finally { |
|
56 |
IOUtils.closeQuietly(output); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
} |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/src/main/resources/log4j.properties | ||
---|---|---|
1 |
log4j.rootLogger=DEBUG, A1 |
|
2 |
log4j.appender.A1=org.apache.log4j.ConsoleAppender |
|
3 |
log4j.appender.A1.layout=org.apache.log4j.PatternLayout |
|
4 |
|
|
5 |
# Print the date in ISO 8601 format |
|
6 |
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/pom.xml | ||
---|---|---|
1 |
<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"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<groupId>eu.dnetlib</groupId> |
|
4 |
<artifactId>icm-iis-primer</artifactId> |
|
5 |
<version>0.0.1</version> |
|
6 |
<packaging>jar</packaging> |
|
7 |
|
|
8 |
<name>icm-iis-classpath-primer</name> |
|
9 |
<url>http://maven.apache.org</url> |
|
10 |
|
|
11 |
<scm> |
|
12 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/icm-iis-primer/tags/icm-iis-primer-0.0.1</developerConnection> |
|
13 |
</scm> |
|
14 |
|
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>junit</groupId> |
|
18 |
<artifactId>junit</artifactId> |
|
19 |
<version>4.10</version> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>commons-io</groupId> |
|
23 |
<artifactId>commons-io</artifactId> |
|
24 |
<version>2.4</version> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>log4j</groupId> |
|
28 |
<artifactId>log4j</artifactId> |
|
29 |
<version>1.2.17</version> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.apache.commons</groupId> |
|
33 |
<artifactId>commons-compress</artifactId> |
|
34 |
<version>1.4.1</version> |
|
35 |
</dependency> |
|
36 |
<dependency> |
|
37 |
<groupId>commons-lang</groupId> |
|
38 |
<artifactId>commons-lang</artifactId> |
|
39 |
<version>2.6</version> |
|
40 |
</dependency> |
|
41 |
</dependencies> |
|
42 |
<properties> |
|
43 |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
44 |
</properties> |
|
45 |
|
|
46 |
<build> |
|
47 |
<plugins> |
|
48 |
<plugin> |
|
49 |
<groupId>org.apache.maven.plugins</groupId> |
|
50 |
<artifactId>maven-compiler-plugin</artifactId> |
|
51 |
<version>3.1</version> |
|
52 |
<configuration> |
|
53 |
<source>1.5</source> |
|
54 |
<target>1.5</target> |
|
55 |
</configuration> |
|
56 |
</plugin> |
|
57 |
</plugins> |
|
58 |
</build> |
|
59 |
|
|
60 |
<distributionManagement> |
|
61 |
<repository> |
|
62 |
<id>dnet4-bootstrap-release</id> |
|
63 |
<url> |
|
64 |
http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-bootstrap-release |
|
65 |
</url> |
|
66 |
</repository> |
|
67 |
</distributionManagement> |
|
68 |
</project> |
modules/icm-iis-primer/tags/icm-iis-primer-0.0.1/README.markdown | ||
---|---|---|
1 |
icm-iis-primer |
|
2 |
============== |
|
3 |
|
|
4 |
The aim of this project is to provide a reusability method for Oozie workflows, |
|
5 |
scripts and other file types by utilising import links. |
|
6 |
|
|
7 |
The Primer traverses a specified Java package, looking for import links. When |
|
8 |
found, it resolves them by creating new elements in the containing directory, |
|
9 |
in accordance with the import link. The primed package is stored in a new |
|
10 |
directory. |
|
11 |
|
|
12 |
## Import links ## |
|
13 |
Import links are defined as files following the specified format. They are |
|
14 |
always named `import.txt`. |
|
15 |
|
|
16 |
### Exemplary import link |
|
17 |
|
|
18 |
## This is a classpath-based import file (this header is required) |
|
19 |
from_jar classpath pl/edu/icm/coansys |
|
20 |
workflow coansys pl.edu.icm.coansys.citations:inner-workflow:1.2-SNAPSHOT |
|
21 |
|
|
22 |
The file starts with a compulsory header. Then, every line consists of the |
|
23 |
following fields separated by whitespaces: |
|
24 |
|
|
25 |
- destination - the name that will be given to the imported element |
|
26 |
- import type - the type of imported element |
|
27 |
- imported element description - additional information indentifying the |
|
28 |
imported element (import type-specific) |
|
29 |
|
|
30 |
The import file presented above will create a directory `from_jar` and |
|
31 |
copy all the contents of `pl/edu/icm/coansys` into it. Additionally, it will |
|
32 |
unpack `inner-workflow` into `workflow` directory. |
|
33 |
|
|
34 |
### Supported import types ### |
|
35 |
|
|
36 |
#### Classpath element #### |
|
37 |
The element will be imported from the classpath (it can be either a file or |
|
38 |
directory). |
|
39 |
|
|
40 |
- **Import type:** `classpath` |
|
41 |
- **Element description:** fully qualified resource name, using forward slashes |
|
42 |
as separators. |
|
43 |
|
|
44 |
#### CoAnSys Oozie Workflow Package #### |
|
45 |
A CoAnSys Oozie Workflow Package will be imported and unpacked. |
|
46 |
|
|
47 |
- **Import type:** `coansys` |
|
48 |
- **Element description:** Maven-style package description, i.e. |
|
49 |
`groupId:artifactId:version` |
|
50 |
|
|
51 |
## Execution ## |
|
52 |
Primer is executed from a Maven plugin implemented in |
|
53 |
`icm-iis-primer-maven-plugin` project. Plugin usage is presented in |
|
54 |
`icm-iis-primer-example` project. |
|
55 |
|
|
56 |
## For developer ## |
|
57 |
The main element of Primer is `Loader` class. It is a close relative of |
|
58 |
Java `ClassLoader`. It should be provided with `ClassProviders`, which tell |
|
59 |
where it should look for resources. By default, `JarClassProvider` and |
|
60 |
`FileSystemClassProvider` are supplied. `Loader.prime` method executes the |
|
61 |
priming process. |
|
62 |
|
|
63 |
Another important class is `Resolver`. It is used when resolving import links. |
|
64 |
It groups various `ResolvingServices`. Each import type should be assigned a |
|
65 |
`ResolvingService`. Currently implemented `ResolvingServices` are |
|
66 |
`ClasspathResolvingService` and `CoansysResolvingService`. |
Also available in: Unified diff
[maven-release-plugin] copy for tag icm-iis-primer-0.0.1