1818
1919public class OSXNotarize <T extends AbstractTask , S extends AbstractSetupBuilder > extends AbstractBuilder <T , S > {
2020
21- private String username , passwordPlain , passwordKeychainItem , passwordEnvironmentVariable ;
21+ private String username , passwordPlain , passwordKeychainItem ;
2222
23- private String ascProvider ;
23+ private String teamId ;
2424
2525 private boolean debugOutput = false ;
2626
@@ -33,14 +33,13 @@ public OSXNotarize( T task, FileResolver fileResolver, OSXCodeSign<T, S> codesig
3333
3434 /**
3535 * Execute the notarization on the given file
36- *
3736 * @param notarizeFile the file to notarize
3837 */
3938 public void run ( File notarizeFile ) {
4039 task .getProject ().getLogger ().info ( "Notarizing the given file: " + notarizeFile .getAbsolutePath () );
4140
4241 checkForRunningNotarizationProcess ();
43-
42+
4443 codesign .unlockKeychain (); // Unlock the keychain before the action is run
4544 String UUID = requestNotarization ( notarizeFile ); // This will hang and wait until the upload is done
4645 if ( UUID == null ) {
@@ -59,39 +58,15 @@ public void run( File notarizeFile ) {
5958 }
6059
6160 /**
62- * Returns the name of the environment variable that will be used to
63- * retrieve the password used for notarization. PLEASE DO NOT USE.
64- *
65- * @return the name of the environment variable with the password
66- */
67- public String getPasswordEnvironmentVariable () {
68- return passwordEnvironmentVariable ;
69- }
70-
71- /**
72- * Set the name of a keychain item that is going to be used for retrieving the password.
73- * Note: The username in the item has to match the one given in this API
74- *
61+ * Set the name of a keychain item that is going to be used for retrieving the password. Note: The username in the item has to match the one given in this API
7562 * @param passwordKeychainItem the name if the keychain item used for notarization
7663 */
7764 public void setPasswordKeychainItem ( String passwordKeychainItem ) {
7865 this .passwordKeychainItem = passwordKeychainItem ;
7966 }
8067
8168 /**
82- * Set the name of an environment variable that should be used to
83- * retrieve the password used for notarization. Please refrain from using this, use {@link OSXNotarize#setPasswordKeychainItem} instead
84- *
85- * @param passwordEnvironmentVariable the name of an environment variable with the password
86- */
87- public void setPasswordEnvironmentVariable ( String passwordEnvironmentVariable ) {
88- this .passwordEnvironmentVariable = passwordEnvironmentVariable ;
89- }
90-
91- /**
92- * Returns the name of the keychain item that will be used to retrieve the password.
93- * NOTE: the username has to match!
94- *
69+ * Returns the name of the keychain item that will be used to retrieve the password. NOTE: the username has to match!
9570 * @return the name of the keychain item that will be used for retrieving the password
9671 */
9772 public String getPasswordKeychainItem () {
@@ -100,7 +75,6 @@ public String getPasswordKeychainItem() {
10075
10176 /**
10277 * Set a plain password to be used for notarization. THIS IS DISCOURAGED
103- *
10478 * @param passwordPlain the plain password to be used for notarization.
10579 */
10680 public void setPasswordPlain ( String passwordPlain ) {
@@ -109,35 +83,30 @@ public void setPasswordPlain( String passwordPlain ) {
10983
11084 /**
11185 * Returns the plain password used for notarization. PLEASE DO NOT USE!
112- *
11386 * @return the plain password used for notarization.
11487 */
11588 public String getPasswordPlain () {
11689 return passwordPlain ;
11790 }
11891
11992 /**
120- * Set the ASC provider which is equired with --notarize-app and --notarization-history
121- * when a user account is associated with multiple providers.
122- *
123- * @param ascProvider the ASC provider
93+ * Set the team Id which is required for the notarization.
94+ * @param teamId the team Id
12495 */
125- public void setAscProvider ( String ascProvider ) {
126- this .ascProvider = ascProvider ;
96+ public void setTeamId ( String teamId ) {
97+ this .teamId = teamId ;
12798 }
12899
129100 /**
130- * Returns the ASC provider
131- *
132- * @return the ASC provider
101+ * Returns the team ID
102+ * @return the team OD
133103 */
134- public String getAscProvider () {
135- return ascProvider ;
104+ public String getTeamId () {
105+ return teamId ;
136106 }
137107
138108 /**
139109 * Set the state of debugging. If true: will output the XMLContent from the tools
140- *
141110 * @param debugOutput the state of debugging
142111 */
143112 public void setDebugOutput ( boolean debugOutput ) {
@@ -146,56 +115,42 @@ public void setDebugOutput( boolean debugOutput ) {
146115
147116 /**
148117 * Returns the state of debugging. If true: will output the XMLContent from the tools
149- *
150118 * @return the state of debugging.
151119 */
152120 public boolean isDebugOutput () {
153121 return debugOutput ;
154122 }
155123
156124 /**
157- * Returns the password item set for the current request.
158- * It will throw an IllegalArgumentException if none of the fields
159- * for the password items have been set.
160- *
161- * @return the password item set for the current request.
125+ * Adds default commands for the xcrun process
126+ * @param command the list of commands so far
162127 */
163- private String getPasswordElement () {
128+ private void addDefaultOptionsToXCRunCommand ( ArrayList <String > command ) {
129+ command .add ( "--apple-id" );
130+ command .add ( username );
131+
164132 if ( passwordKeychainItem != null ) {
165- return "@keychain:" + passwordKeychainItem ;
166- } else if ( passwordEnvironmentVariable != null ) {
167- return "@env:" + passwordEnvironmentVariable ;
133+ command .add ( "-p" );
134+ command .add ( passwordKeychainItem );
168135 } else if ( passwordPlain != null ) {
169- return passwordPlain ;
136+ command .add ( "-password" );
137+ command .add ( passwordPlain );
170138 } else {
171139 throw new IllegalArgumentException ( "At least on of the parameters has to be set: passwordKeychainItem, passwordEnvironmentVariable or passwordPlain" );
172140 }
173- }
174141
175- /**
176- * Adds default commands for the xcrun process
177- *
178- * @param command the list of commands so far
179- */
180- private void addDefaultOptionsToXCRunCommand ( ArrayList <String > command ) {
181- command .add ( "-u" );
182- command .add ( username );
183- command .add ( "-p" );
184- command .add ( getPasswordElement () );
185-
186- if ( ascProvider != null ) {
187- command .add ( "--asc-provider" );
188- command .add ( ascProvider );
142+ if ( teamId != null ) {
143+ command .add ( "--team-id" );
144+ command .add ( teamId );
189145 }
190146
191147 // Receive an XML answer
192148 command .add ( "--output-format" );
193- command .add ( "xml " );
149+ command .add ( "plist " );
194150 }
195151
196152 /**
197153 * Start the notarization process for the given file
198- *
199154 * @param notarizeFile the file to notarize
200155 * @return the UUID for the process to keep working with
201156 * @throws XmlParseException in case the received plist xml file was erroneous
@@ -205,13 +160,10 @@ private String requestNotarization( File notarizeFile ) {
205160
206161 ArrayList <String > command = new ArrayList <>();
207162 command .add ( "xcrun" );
208- command .add ( "altool" );
209- command .add ( "--notarize-app" );
210- command .add ( "-f" );
211- command .add ( notarizeFile .getAbsolutePath () );
212- command .add ( "--primary-bundle-id" );
213- command .add ( notarizeFile .getName () );
163+ command .add ( "notarytool" );
164+ command .add ( "submit" );
214165 addDefaultOptionsToXCRunCommand ( command );
166+ command .add ( notarizeFile .getAbsolutePath () );
215167
216168 ByteArrayOutputStream error = new ByteArrayOutputStream ();
217169 String output = exec ( true , error , command .toArray ( new String [command .size ()] ) );
@@ -233,7 +185,7 @@ private String requestNotarization( File notarizeFile ) {
233185
234186 } catch ( ClassCastException | XmlParseException e ) {
235187 task .getProject ().getLogger ().error ( "An error occured while checking the noraization response." );
236- if ( !isDebugOutput () ) {
188+ if ( !isDebugOutput () ) {
237189 // Debug in addition
238190 task .getProject ().getLogger ().error ( "Debug output START:" );
239191 task .getProject ().getLogger ().error ( output );
@@ -242,10 +194,10 @@ private String requestNotarization( File notarizeFile ) {
242194
243195 task .getProject ().getLogger ().debug ( "The Error stream produced:" );
244196 task .getProject ().getLogger ().debug ( error .toString () );
245-
197+
246198 ByteArrayOutputStream bos = new ByteArrayOutputStream ();
247199 PrintStream stream = new PrintStream ( bos );
248- e .printStackTrace ( stream );
200+ e .printStackTrace ( stream );
249201 task .getProject ().getLogger ().debug ( "This is the exception it produced:" );
250202 task .getProject ().getLogger ().debug ( bos .toString () );
251203 task .getProject ().getLogger ().debug ( "End of Output." );
@@ -260,7 +212,7 @@ private String requestNotarization( File notarizeFile ) {
260212 * @throws InterruptedException in case the thread was interrupted
261213 */
262214 private void waitWithStatus ( String status ) throws InterruptedException {
263- if ( status != null ) {
215+ if ( status != null ) {
264216 task .getProject ().getLogger ().info ( "Status was: '" + status + "'." );
265217 }
266218
@@ -270,7 +222,6 @@ private void waitWithStatus( String status ) throws InterruptedException {
270222
271223 /**
272224 * Wait until the notarization process is done.
273- *
274225 * @param UUID the ID of the task to check against
275226 * @return true if the process was successful
276227 */
@@ -282,16 +233,16 @@ private boolean waitForNotarization( String UUID ) {
282233 List <String > lastErrors = new ArrayList <>();
283234
284235 while ( true && acceptedFailureCount > 0 ) {
285-
236+
286237 ByteArrayOutputStream error = new ByteArrayOutputStream ();
287238 try {
288239
289240 ArrayList <String > command = new ArrayList <>();
290241 command .add ( "xcrun" );
291- command .add ( "altool" );
292- command .add ( "--notarization-info" );
293- command .add ( UUID );
242+ command .add ( "notarytool" );
243+ command .add ( "info" );
294244 addDefaultOptionsToXCRunCommand ( command );
245+ command .add ( UUID );
295246
296247 output = exec ( true , error , command .toArray ( new String [command .size ()] ) );
297248 task .getProject ().getLogger ().debug ( output );
@@ -325,15 +276,15 @@ private boolean waitForNotarization( String UUID ) {
325276 waitWithStatus ( status );
326277 } catch ( ClassCastException | XmlParseException | InterruptedException e ) {
327278 lastErrors .add ( e .getMessage () );
328-
279+
329280 lastErrors .add ( "The Error stream produced:\n " );
330281 lastErrors .add ( error .toString () + "\n " );
331282
332283 lastErrors .add ( "Output:\n " );
333284 lastErrors .add ( output + "\n \n " );
334285 try {
335286 waitWithStatus ( null );
336- } catch ( InterruptedException ie ) {
287+ } catch ( InterruptedException ie ) {
337288 // ignore
338289 }
339290 }
@@ -343,8 +294,7 @@ private boolean waitForNotarization( String UUID ) {
343294 }
344295
345296 /**
346- * This method checks for other processes running the notarization, since Apple
347- * does not allow multiple uploads simultaneously
297+ * This method checks for other processes running the notarization, since Apple does not allow multiple uploads simultaneously
348298 */
349299 private void checkForRunningNotarizationProcess () {
350300
@@ -355,17 +305,17 @@ private void checkForRunningNotarizationProcess() {
355305 command .add ( "bash" );
356306 command .add ( "-c" );
357307 command .add ( "ps aux | grep notarize-app | grep -v grep | wc -l" );
358-
308+
359309 String output = exec ( command .toArray ( new String [command .size ()] ) );
360- if ( debugOutput ) {
310+ if ( debugOutput ) {
361311 task .getProject ().getLogger ().info ( "Response: `" + output + "`" );
362312 }
363313
364314 Integer lineCount = Integer .valueOf ( output );
365- if ( lineCount .intValue () == 0 ) {
315+ if ( lineCount .intValue () == 0 ) {
366316 return ; // Done
367317 }
368-
318+
369319 // Else continue;
370320 task .getProject ().getLogger ().info ( "There was another process notarizing. Will wait a minute now." );
371321 Thread .sleep ( 1000 * 60 );
@@ -378,7 +328,6 @@ private void checkForRunningNotarizationProcess() {
378328
379329 /**
380330 * Staple the original file with the notarization result
381- *
382331 * @param notarizeFile the file to staple
383332 */
384333 private void stapleApplication ( File notarizeFile ) {
0 commit comments