11package io .github .fvarrui .javapackager .packagers ;
22
33import java .io .File ;
4- import java .io .IOException ;
54import java .util .ArrayList ;
65import java .util .Arrays ;
76import java .util .List ;
87import java .util .stream .Collectors ;
98
109import org .apache .commons .lang3 .StringUtils ;
1110import org .apache .commons .lang3 .SystemUtils ;
12- import org .codehaus .plexus .util .cli .CommandLineException ;
1311
1412import io .github .fvarrui .javapackager .model .Platform ;
1513import io .github .fvarrui .javapackager .utils .CommandUtils ;
@@ -113,14 +111,14 @@ public File doCreateApp() throws Exception {
113111
114112 // copies universalJavaApplicationStub startup file to boot java app
115113 File appStubFile = new File (macOSFolder , "universalJavaApplicationStub" );
116- FileUtils . copyResourceToFile ( "/mac/universalJavaApplicationStub" , appStubFile , true ) ;
117- FileUtils . processFileContent ( appStubFile , content -> {
118- if (! macConfig . isRelocateJar ()) {
119- content = content . replaceAll ( "/Contents/Resources/Java" , "/Contents/Resources" ) ;
120- }
121- content = content . replaceAll ( " \\ $ \\ {info.name \\ }" , this . name ) ;
122- return content ;
123- } );
114+ String universalJavaApplicationStubResource = null ;
115+ switch ( macConfig . getMacStartup ()) {
116+ case UNIVERSAL : universalJavaApplicationStubResource = "universalJavaApplicationStub" ; break ;
117+ case X86_64 : universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64" ; break ;
118+ case ARM64 : universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64" ; break ;
119+ case SCRIPT : universalJavaApplicationStubResource = "universalJavaApplicationStub.sh" ; break ;
120+ }
121+ FileUtils . copyResourceToFile ( "/mac/" + universalJavaApplicationStubResource , appStubFile , true );
124122 appStubFile .setExecutable (true , false );
125123
126124 // process classpath
@@ -152,9 +150,9 @@ public File doCreateApp() throws Exception {
152150 return appFile ;
153151 }
154152
155- private void codesign (String developerId , File entitlements , File appFile )
156- throws IOException , CommandLineException {
153+ private void codesign (String developerId , File entitlements , File appFile ) throws Exception {
157154
155+ // checks --option flags
158156 List <String > flags = new ArrayList <>();
159157 if (macConfig .isHardenedCodesign ()) {
160158 if (VersionUtils .compareVersions ("10.13.6" , SystemUtils .OS_VERSION ) >= 0 ) {
@@ -163,25 +161,31 @@ private void codesign(String developerId, File entitlements, File appFile)
163161 Logger .warn ("Mac OS version detected: " + SystemUtils .OS_VERSION + " ... hardened runtime disabled!" );
164162 }
165163 }
164+
165+ // if entitlements.plist file not specified, use a default one
166+ if (entitlements == null ) {
167+ Logger .warn ("Entitlements file not specified. Using defaults!" );
168+ File entitlementsFile = new File (assetsFolder , "entitlements.plist" );
169+ VelocityUtils .render ("mac/entitlements.plist.vtl" , entitlementsFile , this );
170+ } else if (!entitlements .exists ()) {
171+ throw new Exception ("Entitlements file doesn't exist: " + entitlements );
172+ }
166173
174+ // prepare params array
167175 List <Object > codesignArgs = new ArrayList <>();
168176 codesignArgs .add ("--force" );
169177 if (!flags .isEmpty ()) {
170178 codesignArgs .add ("--options" );
171179 codesignArgs .add (StringUtils .join (flags , "," ));
172180 }
173- codesignArgs .add ("--deep" );
174- if (entitlements == null ) {
175- Logger .warn ("Entitlements file not specified" );
176- } else if (!entitlements .exists ()) {
177- Logger .warn ("Entitlements file doesn't exist: " + entitlements );
178- } else {
179- codesignArgs .add ("--entitlements" );
180- codesignArgs .add (entitlements );
181- }
181+ codesignArgs .add ("--deep" );
182+ codesignArgs .add ("--entitlements" );
183+ codesignArgs .add (entitlements );
182184 codesignArgs .add ("--sign" );
183185 codesignArgs .add (developerId );
184186 codesignArgs .add (appFile );
187+
188+ // run codesign
185189 CommandUtils .execute ("codesign" , codesignArgs .toArray (new Object [codesignArgs .size ()]));
186190 }
187191
0 commit comments