Skip to content

Commit e5ac14a

Browse files
committed
Update AppBundler to current version
see https://github.com/TheInfiniteKind/appbundler
1 parent f4efca2 commit e5ac14a

File tree

7 files changed

+396
-146
lines changed

7 files changed

+396
-146
lines changed

src/com/oracle/appbundler/AppBundlerTask.java

Lines changed: 184 additions & 120 deletions
Large diffs are not rendered by default.

src/com/oracle/appbundler/BundleDocument.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.apache.tools.ant.BuildException;
3131

32+
3233
/**
3334
* Represent a CFBundleDocument.
3435
*/
@@ -47,7 +48,7 @@ private String capitalizeFirst(String string) {
4748
stringArray[0] = Character.toUpperCase(stringArray[0]);
4849
return new String(stringArray);
4950
}
50-
51+
5152
public void setExtensions(String extensionsString) {
5253
extensions = getListFromCommaSeparatedString(extensionsString, "Extensions", true);
5354
}
@@ -64,16 +65,16 @@ public static List<String> getListFromCommaSeparatedString(String listAsString,
6465
final String attributeName) {
6566
return getListFromCommaSeparatedString(listAsString, attributeName, false);
6667
}
67-
68+
6869
public static List<String> getListFromCommaSeparatedString(String listAsString,
6970
final String attributeName, final boolean lowercase) {
7071
if(listAsString == null) {
7172
throw new BuildException(attributeName + " can't be null");
7273
}
73-
74+
7475
String[] splittedListAsString = listAsString.split(",");
7576
List<String> stringList = new ArrayList<String>();
76-
77+
7778
for (String extension : splittedListAsString) {
7879
String cleanExtension = extension.trim();
7980
if (lowercase) {
@@ -83,13 +84,13 @@ public static List<String> getListFromCommaSeparatedString(String listAsString,
8384
stringList.add(cleanExtension);
8485
}
8586
}
86-
87+
8788
if (stringList.size() == 0) {
8889
throw new BuildException(attributeName + " list must not be empty");
8990
}
9091
return stringList;
9192
}
92-
93+
9394
public void setIcon(String icon) {
9495
this.icon = icon;
9596
}
@@ -101,19 +102,19 @@ public void setName(String name) {
101102
public void setRole(String role) {
102103
this.role = capitalizeFirst(role);
103104
}
104-
105+
105106
public void setHandlerRank(String handlerRank) {
106107
this.handlerRank = capitalizeFirst(handlerRank);
107108
}
108-
109+
109110
public void setIsPackage(String isPackageString) {
110111
if(isPackageString.trim().equalsIgnoreCase("true")) {
111112
this.isPackage = true;
112113
} else {
113114
this.isPackage = false;
114115
}
115116
}
116-
117+
117118
public String getIcon() {
118119
return icon;
119120
}
@@ -129,33 +130,33 @@ public String getRole() {
129130
public String getHandlerRank() {
130131
return handlerRank;
131132
}
132-
133+
133134
public List<String> getExtensions() {
134135
return extensions;
135136
}
136-
137+
137138
public List<String> getContentTypes() {
138139
return contentTypes;
139140
}
140-
141+
141142
public List<String> getExportableTypes() {
142143
return exportableTypes;
143144
}
144-
145+
145146
public File getIconFile() {
146147
if (icon == null) { return null; }
147148

148149
File ifile = new File (icon);
149-
150+
150151
if (! ifile.exists ( ) || ifile.isDirectory ( )) { return null; }
151152

152153
return ifile;
153154
}
154-
155+
155156
public boolean hasIcon() {
156157
return icon != null;
157158
}
158-
159+
159160
public boolean isPackage() {
160161
return isPackage;
161162
}
@@ -182,7 +183,7 @@ public String toString() {
182183
s.append(exportableType).append(" ");
183184
}
184185
}
185-
186+
186187
return s.toString();
187188
}
188189
}

src/com/oracle/appbundler/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
package com.oracle.appbundler;
2727

2828
public class Environment extends Option {
29-
29+
3030
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright 2019, ATTO Technology, Inc. All rights reserved.
3+
*
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. ATTO Technology designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by ATTO Technology in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
*/
23+
24+
package com.oracle.appbundler;
25+
26+
import java.io.File;
27+
import java.io.IOException;
28+
import java.util.ArrayList;
29+
30+
import org.apache.tools.ant.BuildException;
31+
import org.apache.tools.ant.taskdefs.ExecTask;
32+
33+
/**
34+
* Class representing a module that will be passed to jlink to build the bundled
35+
* JVM.
36+
*/
37+
public class JLink {
38+
private String runtime = null;
39+
private ArrayList<String> jmods = new ArrayList<>();
40+
private ArrayList<String> arguments = new ArrayList<>();
41+
private ExecTask exec = new ExecTask();
42+
43+
public JLink() {
44+
exec.init();
45+
}
46+
47+
public String getRuntime() {
48+
return runtime;
49+
}
50+
51+
public void setRuntime(String runtime) {
52+
this.runtime = runtime;
53+
}
54+
55+
public void setTask(AppBundlerTask task) {
56+
exec.bindToOwner(task);
57+
}
58+
59+
/* Provide canonical path so that runtime can be specified via a
60+
* version-agnostic path (relative link, e.g. `current-jre`) while
61+
* still preserving the original runtime directory name, e.g.
62+
* `jre1.8.0_45.jre`.
63+
*/
64+
public File getDir() {
65+
File dir = new File(runtime);
66+
try {
67+
return dir.getCanonicalFile();
68+
} catch (IOException e) {
69+
return dir;
70+
}
71+
}
72+
73+
public void addConfiguredJMod(JMod jmod) throws BuildException {
74+
String name = jmod.getName();
75+
76+
if (name == null) {
77+
throw new BuildException("Name is required.");
78+
}
79+
80+
jmods.add(name);
81+
}
82+
83+
public void addConfiguredArgument(Argument argument) throws BuildException {
84+
String value = argument.getValue();
85+
86+
if (value == null) {
87+
throw new BuildException("Value is required.");
88+
}
89+
90+
arguments.add(value);
91+
}
92+
93+
public void copyTo(File targetDir) throws IOException {
94+
File runtimeHomeDirectory = getDir();
95+
File runtimeContentsDirectory = runtimeHomeDirectory.getParentFile();
96+
File runtimeDirectory = runtimeContentsDirectory.getParentFile();
97+
98+
// Create root plug-in directory
99+
File pluginDirectory = new File(targetDir, runtimeDirectory.getName());
100+
pluginDirectory.mkdir();
101+
102+
// Create Contents directory
103+
File pluginContentsDirectory = new File(pluginDirectory, runtimeContentsDirectory.getName());
104+
pluginContentsDirectory.mkdir();
105+
106+
// Copy MacOS directory
107+
File runtimeMacOSDirectory = new File(runtimeContentsDirectory, "MacOS");
108+
AppBundlerTask.copy(runtimeMacOSDirectory, new File(pluginContentsDirectory, runtimeMacOSDirectory.getName()));
109+
110+
111+
// Copy Info.plist file
112+
File runtimeInfoPlistFile = new File(runtimeContentsDirectory, "Info.plist");
113+
AppBundlerTask.copy(runtimeInfoPlistFile, new File(pluginContentsDirectory, runtimeInfoPlistFile.getName()));
114+
115+
// Copy included contents of Home directory
116+
File pluginHomeDirectory = new File(pluginContentsDirectory, runtimeHomeDirectory.getName());
117+
118+
exec.setExecutable(runtimeHomeDirectory.getAbsolutePath() + "/bin/jlink");
119+
exec.setFailIfExecutionFails(true);
120+
exec.setFailonerror(true);
121+
for(String s : this.arguments) {
122+
exec.createArg().setValue(s);
123+
}
124+
125+
exec.createArg().setValue("--no-man-pages");
126+
exec.createArg().setValue("--no-header-files");
127+
exec.createArg().setValue("--strip-native-commands"); /* no bin directory */
128+
exec.createArg().setValue("--add-modules");
129+
exec.createArg().setValue(String.join(",", jmods));
130+
exec.createArg().setValue("--output");
131+
exec.createArg().setValue(pluginHomeDirectory.getAbsolutePath());
132+
133+
exec.execute();
134+
}
135+
136+
@Override
137+
public String toString() {
138+
return runtime;
139+
}
140+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2019, ATTO Technology, Inc. All rights reserved.
3+
*
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. ATTO Technology designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by ATTO Technology in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
*/
23+
24+
package com.oracle.appbundler;
25+
26+
/**
27+
* Class representing a module that will be passed to jlink to build the bundled
28+
* JVM.
29+
*/
30+
public class JMod {
31+
private String name = null;
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public void setName(String name) {
38+
this.name = name;
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return name;
44+
}
45+
}

src/com/oracle/appbundler/Option.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@
3333
* application.<p>
3434
* Assuming your {@code CFBundleIdentifier} (settable via {@link AppBundlerTask#setIdentifier(String)})
3535
* is {@code com.oracle.appbundler}. Then you can override a named option by calling
36-
* <code>
36+
* <pre>
3737
* import java.util.prefs.Preferences;
3838
* [...]
3939
* Preferences jvmOptions = Preferences.userRoot().node("/com/oracle/appbundler/JVMOptions");
4040
* jvmOptions.put("name", "value");
4141
* jvmOptions.flush();
42-
* </code>
42+
* </pre>
4343
* The corresponding entries will be stored in a file called
4444
* {@code ~/Library/Preferences/com.oracle.appbundler.plist}.
4545
* To manipulate the file without Java's {@link java.util.prefs.Preferences} from the command line,
4646
* you should use the tool
4747
* <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/defaults.1.html">defaults</a>.
4848
* For example, to add an entry via the command line, use:
49-
* <code>
49+
* <pre>
5050
* defaults write com.oracle.appbundler /com/oracle/appbundler/ -dict-add JVMOptions/ '{"name"="value";}'
51-
* </code>
51+
* </pre>
5252
*
5353
* @author <a href="mailto:[email protected]">Hendrik Schreiber</a> (preference related code only)
5454
*/

src/com/oracle/appbundler/TypeDeclaration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class TypeDeclaration implements IconContainer {
4747
public TypeDeclaration() {
4848
this.conformsTo = Arrays.asList(new String[]{"public.data"});
4949
}
50-
50+
5151
public boolean isImported() {
5252
return imported;
5353
}
@@ -92,16 +92,16 @@ public File getIconFile() {
9292
if (icon == null) { return null; }
9393

9494
File ifile = new File (icon);
95-
95+
9696
if (! ifile.exists ( ) || ifile.isDirectory ( )) { return null; }
9797

9898
return ifile;
9999
}
100-
100+
101101
public boolean hasIcon() {
102102
return icon != null;
103103
}
104-
104+
105105
public List<String> getConformsTo() {
106106
return conformsTo;
107107
}

0 commit comments

Comments
 (0)