@@ -11,7 +11,6 @@ import (
1111 "os"
1212 "os/exec"
1313 "path/filepath"
14- "regexp"
1514 "runtime"
1615
1716 "github.com/project-flogo/cli/common"
@@ -103,12 +102,11 @@ func (p *appProjectImpl) Executable() string {
103102 return execPath
104103}
105104
106- func (p * appProjectImpl ) GetPath (pkg string ) (string , error ) {
107-
108- return p .dm .GetPath (pkg )
105+ func (p * appProjectImpl ) GetPath (flogoImport util.Import ) (string , error ) {
106+ return p .dm .GetPath (flogoImport )
109107}
110108
111- func (p * appProjectImpl ) addImportsInGo (ignoreError bool , imports ... string ) error {
109+ func (p * appProjectImpl ) addImportsInGo (ignoreError bool , imports ... util. Import ) error {
112110 importsFile := filepath .Join (p .SrcDir (), fileImportsGo )
113111
114112 fset := token .NewFileSet ()
@@ -117,16 +115,16 @@ func (p *appProjectImpl) addImportsInGo(ignoreError bool, imports ...string) err
117115 return err
118116 }
119117
120- for _ , importPath := range imports {
121- importPath , err := p .DepManager ().AddDependency (importPath , "" , true )
118+ for _ , i := range imports {
119+ err := p .DepManager ().AddDependency (i , true )
122120 if err != nil {
123121 if ignoreError {
124- fmt .Printf ("Warning: unable to install %s\n " , importPath )
122+ fmt .Printf ("Warning: unable to install %s\n " , i )
125123 continue
126124 }
127125 return err
128126 }
129- util .AddImport (fset , file , importPath )
127+ util .AddImport (fset , file , i . ImportPath () )
130128 }
131129
132130 f , err := os .Create (importsFile )
@@ -146,7 +144,7 @@ func (p *appProjectImpl) addImportsInGo(ignoreError bool, imports ...string) err
146144 return nil
147145}
148146
149- func (p * appProjectImpl ) addImportsInJson (ignoreError bool , imports ... string ) error {
147+ func (p * appProjectImpl ) addImportsInJson (ignoreError bool , imports ... util. Import ) error {
150148 appDescriptorFile := filepath .Join (p .appDir , fileFlogoJson )
151149 appDescriptorJsonFile , err := os .Open (appDescriptorFile )
152150 if err != nil {
@@ -162,18 +160,16 @@ func (p *appProjectImpl) addImportsInJson(ignoreError bool, imports ...string) e
162160 var appDescriptor app.Config
163161 json .Unmarshal ([]byte (appDescriptorData ), & appDescriptor )
164162
165- importPattern := regexp .MustCompile (`^([^ ]* )?([^@]*)@?(.*)?$` ) // extract import path even if there is an alias and/or a version
166-
167163 // list existing imports in JSON to avoid duplicates
168164 existingImports := make (map [string ]bool )
169- for _ , e := range appDescriptor .Imports {
170- importPath := importPattern . FindStringSubmatch ( e )[ 2 ]
171- existingImports [importPath ] = true
165+ jsonImports , _ := util . ParseImports ( appDescriptor .Imports )
166+ for _ , e := range jsonImports {
167+ existingImports [e . CanonicalImport () ] = true
172168 }
173169
174170 for _ , i := range imports {
175- if _ , ok := existingImports [i ]; ! ok {
176- appDescriptor .Imports = append (appDescriptor .Imports , importPattern . FindStringSubmatch ( i )[ 2 ] )
171+ if _ , ok := existingImports [i . CanonicalImport () ]; ! ok {
172+ appDescriptor .Imports = append (appDescriptor .Imports , i . CanonicalImport () )
177173 }
178174 }
179175
@@ -192,7 +188,7 @@ func (p *appProjectImpl) addImportsInJson(ignoreError bool, imports ...string) e
192188 return nil
193189}
194190
195- func (p * appProjectImpl ) AddImports (ignoreError bool , imports ... string ) error {
191+ func (p * appProjectImpl ) AddImports (ignoreError bool , imports ... util. Import ) error {
196192 err := p .addImportsInGo (ignoreError , imports ... ) // begin with Go imports as they are more likely to fail
197193 if err != nil {
198194 return err
0 commit comments