@@ -11,10 +11,7 @@ import (
1111 "strings"
1212
1313 "github.com/agnivade/levenshtein"
14- "github.com/jfrog/build-info-go/flexpack"
15- gofrogcmd "github.com/jfrog/gofrog/io"
1614 artifactoryCLI "github.com/jfrog/jfrog-cli-artifactory/cli"
17- "github.com/jfrog/jfrog-cli-core/v2/common/build"
1815 corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
1916 "github.com/jfrog/jfrog-cli-core/v2/plugins/components"
2017 coreconfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -40,7 +37,6 @@ import (
4037 "github.com/jfrog/jfrog-cli/pipelines"
4138 "github.com/jfrog/jfrog-cli/plugins"
4239 "github.com/jfrog/jfrog-cli/plugins/utils"
43- "github.com/jfrog/jfrog-cli/utils/buildinfo"
4440 "github.com/jfrog/jfrog-cli/utils/cliutils"
4541 "github.com/jfrog/jfrog-client-go/http/httpclient"
4642 clientutils "github.com/jfrog/jfrog-client-go/utils"
@@ -134,38 +130,13 @@ func execMain() error {
134130 if err = setUberTraceIdToken (); err != nil {
135131 clientlog .Warn ("failed generating a trace ID token:" , err .Error ())
136132 }
137- if flexpack .IsFlexPackEnabled () {
138- // If the JFROG_RUN_NATIVE environment variable is set to true, we run the new implementation
139- // but only for package manager commands, not for JFrog CLI commands
140- args := ctx .Args ()
141- if args .Present () && len (args ) > 0 {
142- firstArg := args .Get (0 )
143- if isPackageManagerCommand (firstArg ) {
144- if err = runNativeImplementation (ctx ); err != nil {
145- clientlog .Error ("Failed to run native implementation:" , err )
146- return err
147- }
148- // Native implementation completed successfully
149- return nil
150- }
151- }
152- // For non-package-manager commands, continue with normal CLI processing
153- }
133+ // FlexPack native implementation is now handled through the existing buildtools CLI
134+ // Maven FlexPack works the same way as Poetry FlexPack - through jf mvn commands
154135 return nil
155136 }
156137
157138 app .CommandNotFound = func (c * cli.Context , command string ) {
158- // Try to handle as native package manager command only when JFROG_RUN_NATIVE is true
159- if flexpack .IsFlexPackEnabled () && isPackageManagerCommand (command ) {
160- clientlog .Debug ("Attempting to handle as native package manager command:" , command )
161- err := runNativeImplementation (c )
162- if err != nil {
163- clientlog .Error ("Failed to run native implementation:" , err )
164- os .Exit (1 )
165- }
166- os .Exit (0 )
167- }
168-
139+ // FlexPack native implementation is now handled through existing buildtools CLI
169140 // Original behavior for unknown commands
170141 _ , err = fmt .Fprintf (c .App .Writer , "'%s %s' is not a jf command. See --help\n " , c .App .Name , command )
171142 if err != nil {
@@ -194,13 +165,7 @@ func execMain() error {
194165 // Check if native implementation completed successfully
195166 if err == nil {
196167 displaySurveyLinkIfNeeded ()
197- // Exit normally if native implementation ran successfully
198- if flexpack .IsFlexPackEnabled () && len (args ) > 1 && isPackageManagerCommand (args [1 ]) {
199- // Only exit if we're not in a test environment
200- if ! isTestEnvironment () {
201- os .Exit (0 )
202- }
203- }
168+ // FlexPack native implementation is now handled through existing buildtools CLI
204169 }
205170 return err
206171}
@@ -224,165 +189,6 @@ func displaySurveyLinkIfNeeded() {
224189 fmt .Fprintln (os .Stderr , "\n 💬 Help us improve JFrog CLI! \033 ]8;;https://www.surveymonkey.com/r/JFCLICLI\033 \\ https://www.surveymonkey.com/r/JFCLICLI\033 ]8;;\033 \\ " )
225190}
226191
227- func runNativeImplementation (ctx * cli.Context ) error {
228- clientlog .Debug ("Starting native implementation..." )
229-
230- // Extract the build name and number from the command arguments
231- args , buildArgs , err := build .ExtractBuildDetailsFromArgs (ctx .Args ())
232- if err != nil {
233- clientlog .Error ("Failed to extract build details from args: " , err )
234- return fmt .Errorf ("ExtractBuildDetailsFromArgs failed: %w" , err )
235- }
236-
237- if len (args ) < 2 {
238- return fmt .Errorf ("insufficient arguments: expected at least package-manager and command, got %v" , args )
239- }
240-
241- packageManager := args [0 ]
242- command := args [1 ]
243- clientlog .Debug ("Executing native command: " + packageManager + " " + command )
244-
245- buildName , err := buildArgs .GetBuildName ()
246- if err != nil {
247- clientlog .Error ("Failed to get build name: " , err )
248- return fmt .Errorf ("GetBuildName failed: %w" , err )
249- }
250-
251- buildNumber , err := buildArgs .GetBuildNumber ()
252- if err != nil {
253- clientlog .Error ("Failed to get build number: " , err )
254- return fmt .Errorf ("GetBuildNumber failed: %w" , err )
255- }
256-
257- // Execute the native command
258- err = RunActions (args )
259- if err != nil {
260- clientlog .Error ("Failed to run actions: " , err )
261- return fmt .Errorf ("RunActions failed: %w" , err )
262- }
263-
264- // Collect build info if build name and number are provided
265- if buildName != "" && buildNumber != "" {
266- clientlog .Info ("Collecting build info for executed command..." )
267- workingDir := ctx .GlobalString ("working-dir" )
268- if workingDir == "" {
269- workingDir = "."
270- }
271-
272- // Use the enhanced build info collection that supports Poetry
273- err = buildinfo .GetBuildInfoForPackageManager (packageManager , workingDir , buildArgs )
274- if err != nil {
275- clientlog .Error ("Failed to collect build info: " , err )
276- return fmt .Errorf ("GetBuildInfoForPackageManager failed: %w" , err )
277- }
278- }
279-
280- clientlog .Info ("Native implementation completed successfully." )
281- return nil
282- }
283-
284- // isPackageManagerCommand checks if the command is a supported package manager
285- func isPackageManagerCommand (command string ) bool {
286- supportedPackageManagers := []string {"poetry" , "pip" , "pipenv" , "gem" , "bundle" , "npm" , "yarn" , "gradle" , "mvn" , "maven" , "nuget" , "go" }
287- for _ , pm := range supportedPackageManagers {
288- if command == pm {
289- return true
290- }
291- }
292- return false
293- }
294-
295- // cleanProgressOutput handles carriage returns and progress updates properly
296- func cleanProgressOutput (output string ) string {
297- if output == "" {
298- return ""
299- }
300-
301- // First, split by both \n and \r to handle all line breaks
302- lines := strings .FieldsFunc (output , func (c rune ) bool {
303- return c == '\n' || c == '\r'
304- })
305-
306- var cleanedLines []string
307- var progressLines = make (map [string ]string ) // Track progress lines by filename
308-
309- for _ , line := range lines {
310- line = strings .TrimSpace (line )
311- if line == "" {
312- continue
313- }
314-
315- // Check if this is a progress line (contains % and "Uploading")
316- if strings .Contains (line , "Uploading" ) && strings .Contains (line , "%" ) {
317- // Extract filename for tracking progress
318- if strings .Contains (line , " - Uploading " ) {
319- parts := strings .Split (line , " - Uploading " )
320- if len (parts ) == 2 {
321- filename := strings .Split (parts [1 ], " " )[0 ]
322- progressLines [filename ] = line
323- continue
324- }
325- }
326- }
327-
328- // Add non-progress lines immediately
329- cleanedLines = append (cleanedLines , line )
330- }
331-
332- // Add final progress states
333- for _ , progressLine := range progressLines {
334- cleanedLines = append (cleanedLines , progressLine )
335- }
336-
337- if len (cleanedLines ) > 0 {
338- return strings .Join (cleanedLines , "\n " ) + "\n "
339- }
340- return ""
341- }
342-
343- func RunActions (args []string ) error {
344- if len (args ) < 2 {
345- return fmt .Errorf ("insufficient arguments for RunActions: expected at least 2, got %d" , len (args ))
346- }
347-
348- packageManager := args [0 ]
349- subCommand := args [1 ]
350- executableCommand := append ([]string {}, args [2 :]... )
351-
352- clientlog .Debug ("Executing command: " + packageManager + " " + subCommand )
353- command := gofrogcmd .NewCommand (packageManager , subCommand , executableCommand )
354-
355- // Use RunCmdWithOutputParser but handle the output better
356- clientlog .Debug ("Executing command: " + packageManager + " " + subCommand + " " + strings .Join (executableCommand , " " ))
357- stdout , stderr , exitOk , err := gofrogcmd .RunCmdWithOutputParser (command , false )
358- if err != nil {
359- clientlog .Error ("Command execution failed: " , err )
360- if stdout != "" {
361- clientlog .Error ("Command stdout: " , stdout )
362- }
363- if stderr != "" {
364- clientlog .Error ("Command stderr: " , stderr )
365- }
366- return fmt .Errorf ("command '%s %s %s' failed (exitOk=%t): %w" , packageManager , subCommand , strings .Join (executableCommand , " " ), exitOk , err )
367- }
368-
369- // Print stdout directly without parsing to preserve Poetry's output format
370- if stdout != "" {
371- fmt .Print (stdout )
372- }
373-
374- // Also print stderr, but clean it up for progress information
375- if stderr != "" {
376- cleanStderr := cleanProgressOutput (stderr )
377- if cleanStderr != "" {
378- fmt .Print (cleanStderr )
379- }
380- }
381-
382- clientlog .Debug ("Command executed successfully" )
383- return nil
384- }
385-
386192// This command generates and sets an Uber Trace ID token which will be attached as a header to every request.
387193// This allows users to easily identify which logs on the server side are related to the command executed by the CLI.
388194func setUberTraceIdToken () error {
0 commit comments