4444import lucee .commons .net .HTTPUtil ;
4545import lucee .runtime .config .Config ;
4646import lucee .runtime .config .ConfigPro ;
47+ import lucee .runtime .engine .CFMLEngineImpl ;
4748import lucee .runtime .exp .ApplicationException ;
4849import lucee .runtime .mvn .POMReader .Dependency ;
4950import lucee .runtime .op .Caster ;
@@ -220,7 +221,8 @@ public static POM getDependency(Resource localDirectory, POMReader.Dependency rd
220221 // v = resolvePlaceholders(pdm, v, pdm.getProperties());
221222 }
222223 if (v == null ) {
223- throw new IOException ("could not find version for dependency [" + g + ":" + a + "] in [" + current + "]" );
224+ throw new IOException ("No version defined for dependency [" + g + ":" + a + "] in POM [" + current + "]. "
225+ + "Specify a version directly or ensure it is declared in <dependencyManagement>." );
224226 }
225227 }
226228
@@ -503,7 +505,8 @@ else if ("optional".equals(placeholder)) {
503505 if (!modifed ) break ;
504506 }
505507 if (value != null && value .indexOf ("${" ) != -1 ) {
506- throw new IOException ("Cannot resolve [" + value + "] for [" + pom + "], available properties are [" + ListUtil .toList (properties .keySet (), ", " ) + "]" );
508+ throw new IOException ("Cannot resolve placeholder in [" + value + "] for POM [" + pom + "]. " + "Available properties: [" + ListUtil .toList (properties .keySet (), ", " )
509+ + "]. " + "Ensure the property is defined in the POM, parent POM, or system properties." );
507510 }
508511 return value ;
509512 }
@@ -517,8 +520,7 @@ public static void downloadAsync(POM pom, Collection<Repository> repositories, S
517520 try {
518521 download (pom , repositories , type , log );
519522 }
520- catch (IOException e ) {
521- }
523+ catch (IOException e ) {}
522524 }, true ).start ();
523525 }
524526
@@ -527,7 +529,7 @@ public static Resource download(POM pom, Collection<Repository> repositories, St
527529
528530 // file is empty or does not exist
529531 if (!res .isFile ()) {
530- // print.ds("--->" + pom.toString());
532+
531533 synchronized (SystemUtil .createToken ("mvn" , res .getAbsolutePath ())) {
532534 // file is empty or does not exist
533535 if (!res .isFile ()) {
@@ -553,7 +555,10 @@ public static Resource download(POM pom, Collection<Repository> repositories, St
553555 download (pom , repositories , type , log );
554556 return res ;
555557 }
556- throw new IOException ("Failed to download [" + pom + "] " );
558+
559+ throw new IOException ("Maven artifact [" + pom .getGroupId () + ":" + pom .getArtifactId () + ":" + pom .getVersion () + "] "
560+ + "is not available. A previous download attempt failed and is cached for " + (ARTIFACT_UNAVAILABLE_CACHE_DURATION / 60000 ) + " minutes. "
561+ + "Delete the '.lastUpdated' file in the local cache to retry immediately." );
557562 }
558563
559564 String scriptName = pom .getGroupId ().replace ('.' , '/' ) + "/" + pom .getArtifactId () + "/" + pom .getVersion () + "/" + pom .getArtifactId () + "-" + pom .getVersion ()
@@ -563,19 +568,30 @@ public static Resource download(POM pom, Collection<Repository> repositories, St
563568 if (repositories == null || repositories .isEmpty ()) repositories = pom .getRepositories ();
564569
565570 if (repositories == null || repositories .size () == 0 ) {
566- IOException ioe = new IOException ("Failed to download java artifact [" + pom .toString () + "] for type [" + type + "]" );
567- // "Failed to download java artifact [" + pom.toString() + "] for type [" + type + "], attempted
568- // endpoint(s): [" + sb + "]");
569- // if (cause != null) ExceptionUtil.initCauseEL(ioe, cause);
570- throw ioe ;
571+ throw new IOException ("Failed to download Maven artifact [" + pom .getGroupId () + ":" + pom .getArtifactId () + ":" + pom .getVersion () + "] " + "(type: "
572+ + type + "). No repositories are configured. " + "Ensure at least one repository is defined in the POM or Lucee configuration." );
571573 }
572574 // url = pom.getArtifact(type, repositories);
573575 //////// if (log != null) log.info("maven", "download [" + url + "]");
574576 URL url ;
575577 CloseableHttpClient httpClient ;
578+ int policy = CFMLEngineImpl .getActiveDownloadPolicy ();
576579 for (Repository r : sort (repositories )) {
577580 url = null ;
578581 httpClient = null ;
582+ if (policy == CFMLEngineImpl .MAVEN_DOWNLOAD_POLICY_ERROR ) {
583+ throw new IOException ("Lucee is unable to resolve the Maven artifact [" + pom .getGroupId () + ":" + pom .getArtifactId () + ":" + pom .getVersion ()
584+ + "] " + "(type: " + type + ") because Maven downloads are blocked by policy. "
585+ + "To allow downloads, set the system property or environment variable " + "'lucee.maven.download.policy' to 'warn' or 'ignore'. " );
586+ }
587+ else if (policy == CFMLEngineImpl .MAVEN_DOWNLOAD_POLICY_WARN ) {
588+ LogUtil .log (CFMLEngineImpl .MAVEN_DOWNLOAD_POLICY_LOG_LEVEL , "maven" ,
589+ "Downloading Maven artifact [" + pom .getGroupId () + ":" + pom .getArtifactId () + ":" + pom .getVersion () + "] " + "(type: " + type
590+ + "). Maven download policy is set to 'warn'. "
591+ + "Set the system property or environment variable 'lucee.maven.download.policy' to "
592+ + "'error' to block downloads or 'ignore' to suppress this warning." );
593+ }
594+
579595 try {
580596 url = new URL (r .getUrl () + scriptName );
581597 httpClient = HttpClients .createDefault ();
@@ -634,13 +650,16 @@ public static Resource download(POM pom, Collection<Repository> repositories, St
634650 }
635651 catch (IOException ioe ) {
636652 createLastUpdated (res , info );
637- IOException ex = new IOException ("Failed to download [ " + pom + ":" + type + "]" );
653+ IOException ex = new IOException ("Failed to download Maven artifact [" + pom .getGroupId () + ":" + pom .getArtifactId () + ":" + pom .getVersion () + "] "
654+ + "(type: " + type + "). Check network connectivity and repository availability." );
638655 ExceptionUtil .initCauseEL (ex , ioe );
639656 // MUST add again ResourceUtil.deleteEmptyFoldersInside(pom.getLocalDirectory());
640657 throw ex ;
641658 }
642659 createLastUpdated (res , info );
643- throw new IOException ("Failed to download [" + pom + ":" + type + "] from " + repositories .size () + " repositories" );
660+ throw new IOException ("Failed to download Maven artifact [" + pom .getGroupId () + ":" + pom .getArtifactId () + ":" + pom .getVersion () + "] " + "(type: " + type
661+ + ") after trying all " + repositories .size () + " configured repositories. "
662+ + "Verify the artifact coordinates are correct and the repositories are accessible." );
644663 }
645664 }
646665 }
@@ -703,17 +722,20 @@ public static POM toPOM(Resource localDirectory, Collection<Repository> reposito
703722 }
704723
705724 public static int toScopes (String scopes ) throws IOException {
706- if (StringUtil .isEmpty (scopes , true )) throw new IOException ("there is no scope defined" );
725+ if (StringUtil .isEmpty (scopes , true ))
726+ throw new IOException ("No Maven dependency scope defined. " + "Specify at least one scope from: compile, test, provided, runtime, system, import." );
707727 return toScopes (ListUtil .listToStringArray (scopes , ',' ));
708728 }
709729
710730 public static int toScopes (String [] scopes ) throws IOException {
711- if (scopes .length == 0 ) throw new IOException ("there is no scope defined" );
731+ if (scopes .length == 0 ) throw new IOException ("No Maven dependency scope defined. " + "Specify at least one scope from: compile, test, provided, runtime, system, import. " );
712732
713733 int rtn = 0 , tmp ;
714734 for (String scope : scopes ) {
715735 tmp = toScope (scope , 0 );
716- if (tmp == 0 ) throw new IOException ("scope [" + scope + "] is not a supported scope, valid scope names are [compile,test,provided,runtime,system,import]" );
736+ if (tmp == 0 ) {
737+ throw new IOException ("Invalid Maven scope [" + scope .trim () + "]. " + "Supported values are: compile, test, provided, runtime, system, import." );
738+ }
717739 rtn += tmp ;
718740 }
719741 return rtn ;
@@ -1018,8 +1040,7 @@ public static Struct getMetaData(Config config, Class clazz, Struct defaultValue
10181040 data .setEL (KeyConstants ._location , res .getAbsolutePath ());
10191041 return data ;
10201042 }
1021- catch (Exception e ) {
1022- }
1043+ catch (Exception e ) {}
10231044 }
10241045 }
10251046 }
0 commit comments