21
21
* questions.
22
22
*/
23
23
24
+ import static jdk .internal .util .OperatingSystem .LINUX ;
25
+ import static jdk .internal .util .OperatingSystem .MACOS ;
26
+ import static java .util .stream .Collectors .joining ;
27
+
24
28
import java .io .IOException ;
25
29
import java .nio .file .Files ;
26
30
import java .nio .file .Path ;
27
31
import jdk .jpackage .test .PackageTest ;
28
32
import jdk .jpackage .test .TKit ;
29
33
import jdk .jpackage .test .Annotations .Test ;
30
- import jdk .jpackage .test .Annotations .Parameters ;
34
+ import jdk .jpackage .test .Annotations .Parameter ;
31
35
import java .util .Arrays ;
32
36
import java .util .Collection ;
33
37
import java .util .List ;
34
- import static java .util .stream .Collectors .joining ;
35
38
import java .util .stream .Stream ;
36
39
import jdk .jpackage .internal .util .FileUtils ;
37
40
import jdk .jpackage .internal .util .function .ThrowingFunction ;
@@ -56,6 +59,7 @@ public class AppContentTest {
56
59
57
60
private static final String TEST_JAVA = "apps/PrintEnv.java" ;
58
61
private static final String TEST_DUKE = "apps/dukeplug.png" ;
62
+ private static final String TEST_DUKE_LINK = "dukeplugLink.txt" ;
59
63
private static final String TEST_DIR = "apps" ;
60
64
private static final String TEST_BAD = "non-existant" ;
61
65
@@ -67,24 +71,20 @@ public class AppContentTest {
67
71
// Need to prepare arguments for `--app-content` accordingly.
68
72
private static final boolean copyInResources = TKit .isOSX ();
69
73
70
- private final List <String > testPathArgs ;
71
-
72
- @ Parameters
73
- public static Collection <?> data () {
74
- return List .of (new String [][]{
75
- {TEST_JAVA , TEST_DUKE }, // include two files in two options
76
- {TEST_JAVA , TEST_BAD }, // try to include non-existant content
77
- {TEST_JAVA + "," + TEST_DUKE , TEST_DIR }, // two files in one option,
78
- // and a dir tree in another option.
79
- });
80
- }
81
-
82
- public AppContentTest (String ... testPathArgs ) {
83
- this .testPathArgs = List .of (testPathArgs );
84
- }
74
+ private static final String RESOURCES_DIR = "Resources" ;
75
+ private static final String LINKS_DIR = "Links" ;
85
76
86
77
@ Test
87
- public void test () throws Exception {
78
+ // include two files in two options
79
+ @ Parameter ({TEST_JAVA , TEST_DUKE })
80
+ // try to include non-existant content
81
+ @ Parameter ({TEST_JAVA , TEST_BAD })
82
+ // two files in one option and a dir tree in another option.
83
+ @ Parameter ({TEST_JAVA + "," + TEST_DUKE , TEST_DIR })
84
+ // include one file and one link to the file
85
+ @ Parameter (value = {TEST_JAVA , TEST_DUKE_LINK }, ifOS = {MACOS ,LINUX })
86
+ public void test (String ... args ) throws Exception {
87
+ final List <String > testPathArgs = List .of (args );
88
88
final int expectedJPackageExitCode ;
89
89
if (testPathArgs .contains (TEST_BAD )) {
90
90
expectedJPackageExitCode = 1 ;
@@ -98,15 +98,19 @@ public void test() throws Exception {
98
98
.addRunOnceInitializer (appContentInitializer ::initAppContent )
99
99
.addInitializer (appContentInitializer ::applyTo )
100
100
.addInstallVerifier (cmd -> {
101
- Path baseDir = getAppContentRoot (cmd );
102
101
for (String arg : testPathArgs ) {
103
102
List <String > paths = Arrays .asList (arg .split ("," ));
104
103
for (String p : paths ) {
105
104
Path name = Path .of (p ).getFileName ();
106
- TKit .assertPathExists (baseDir .resolve (name ), true );
105
+ if (isSymlinkPath (name )) {
106
+ TKit .assertSymbolicLinkExists (getAppContentRoot (cmd )
107
+ .resolve (LINKS_DIR ).resolve (name ));
108
+ } else {
109
+ TKit .assertPathExists (getAppContentRoot (cmd )
110
+ .resolve (name ), true );
111
+ }
107
112
}
108
113
}
109
-
110
114
})
111
115
.setExpectedExitCode (expectedJPackageExitCode )
112
116
.run ();
@@ -115,12 +119,16 @@ public void test() throws Exception {
115
119
private static Path getAppContentRoot (JPackageCommand cmd ) {
116
120
Path contentDir = cmd .appLayout ().contentDirectory ();
117
121
if (copyInResources ) {
118
- return contentDir .resolve ("Resources" );
122
+ return contentDir .resolve (RESOURCES_DIR );
119
123
} else {
120
124
return contentDir ;
121
125
}
122
126
}
123
127
128
+ private static boolean isSymlinkPath (Path v ) {
129
+ return v .getFileName ().toString ().contains ("Link" );
130
+ }
131
+
124
132
private static final class AppContentInitializer {
125
133
AppContentInitializer (List <String > appContentArgs ) {
126
134
appContentPathGroups = appContentArgs .stream ().map (arg -> {
@@ -144,28 +152,51 @@ void applyTo(JPackageCommand cmd) {
144
152
}
145
153
146
154
private static Path copyAppContentPath (Path appContentPath ) throws IOException {
147
- var appContentArg = TKit .createTempDirectory ("app-content" ).resolve ("Resources" );
155
+ var appContentArg = TKit .createTempDirectory ("app-content" ).resolve (RESOURCES_DIR );
148
156
var srcPath = TKit .TEST_SRC_ROOT .resolve (appContentPath );
149
157
var dstPath = appContentArg .resolve (srcPath .getFileName ());
150
158
Files .createDirectories (dstPath .getParent ());
151
159
FileUtils .copyRecursive (srcPath , dstPath );
152
160
return appContentArg ;
153
161
}
154
162
155
- private static List <Path > initAppContentPaths (List <Path > appContentPaths ) {
163
+ private static Path createAppContentLink (Path appContentPath ) throws IOException {
164
+ var appContentArg = TKit .createTempDirectory ("app-content" );
156
165
if (copyInResources ) {
157
- return appContentPaths .stream ().map (appContentPath -> {
158
- if (appContentPath .endsWith (TEST_BAD )) {
159
- return appContentPath ;
160
- } else {
161
- return ThrowingFunction .toFunction (
162
- AppContentInitializer ::copyAppContentPath ).apply (
163
- appContentPath );
164
- }
165
- }).toList ();
166
- } else {
167
- return appContentPaths .stream ().map (TKit .TEST_SRC_ROOT ::resolve ).toList ();
166
+ appContentArg = appContentArg .resolve (RESOURCES_DIR ).resolve (LINKS_DIR );
167
+ } else {
168
+ appContentArg = appContentArg .resolve (LINKS_DIR );
168
169
}
170
+
171
+ var dstPath = appContentArg .resolve (appContentPath .getFileName ());
172
+ Files .createDirectories (dstPath .getParent ());
173
+
174
+ // Create target file for a link
175
+ String tagetName = dstPath .getFileName ().toString ().replace ("Link" , "" );
176
+ Path targetPath = dstPath .getParent ().resolve (tagetName );
177
+ Files .write (targetPath , "foo" .getBytes ());
178
+ // Create link
179
+ Files .createSymbolicLink (dstPath , targetPath .getFileName ());
180
+
181
+ return appContentArg ;
182
+ }
183
+
184
+ private static List <Path > initAppContentPaths (List <Path > appContentPaths ) {
185
+ return appContentPaths .stream ().map (appContentPath -> {
186
+ if (appContentPath .endsWith (TEST_BAD )) {
187
+ return appContentPath ;
188
+ } else if (isSymlinkPath (appContentPath )) {
189
+ return ThrowingFunction .toFunction (
190
+ AppContentInitializer ::createAppContentLink ).apply (
191
+ appContentPath );
192
+ } else if (copyInResources ) {
193
+ return ThrowingFunction .toFunction (
194
+ AppContentInitializer ::copyAppContentPath ).apply (
195
+ appContentPath );
196
+ } else {
197
+ return TKit .TEST_SRC_ROOT .resolve (appContentPath );
198
+ }
199
+ }).toList ();
169
200
}
170
201
171
202
private List <String > jpackageArgs ;
0 commit comments