elharo commented on code in PR #1323:
URL: https://github.com/apache/maven/pull/1323#discussion_r1405403453


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -67,36 +71,36 @@ public void setFile(File file) {
 
     @Override
     public File getFile() {
-        Path result = onChangeTransformer.get();
-        if (result == null) {
-            return null;
+        try {
+            Path result = onChangeTransformer.transform();
+            if (result == null) {
+                return null;
+            }
+            return result.toFile();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
-        return result.toFile();
     }
 
     private static final int BUFFER_SIZE = 8192;
 
-    private static String sha1(Path path) {
-        try {
-            MessageDigest md = MessageDigest.getInstance("SHA-1");
-            try (InputStream fis = Files.newInputStream(path)) {
-                byte[] buffer = new byte[BUFFER_SIZE];
-                int read;
-                while ((read = fis.read(buffer)) != -1) {
-                    md.update(buffer, 0, read);
-                }
-            }
-            StringBuilder result = new StringBuilder();
-            for (byte b : md.digest()) {
-                result.append(String.format("%02x", b));
+    private static String sha1(Path path) throws Exception {
+        MessageDigest md = MessageDigest.getInstance("SHA-1");
+        try (InputStream fis = Files.newInputStream(path)) {
+            byte[] buffer = new byte[BUFFER_SIZE];
+            int read;
+            while ((read = fis.read(buffer)) != -1) {
+                md.update(buffer, 0, read);
             }
-            return result.toString();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
         }
+        StringBuilder result = new StringBuilder();
+        for (byte b : md.digest()) {
+            result.append(String.format("%02x", b));
+        }
+        return result.toString();
     }
 
-    protected abstract void transform(Path src, Path dst);
+    protected abstract void transform(Path src, Path dst) throws Exception;

Review Comment:
   In general, do not throw java.lang.Exception. Use a more specific subclass 
that's appropriate to that point in the code. See Items 72 and 73 of Effective 
Java. 
   
   But it might be possible to not throw any exceptions here, checked or 
runtime. It depends a little on what the method is expected to do. The trick 
would be to avoid reading files during the transformation and do that before 
and/or after the transform. Separate the transform from I/O. 



##########
maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContextBuilder.java:
##########
@@ -106,6 +117,46 @@ private Model findRawModel(Path from, String groupId, 
String artifactId) {
                 return null;
             }
 
+            private void loadFullReactor() {
+                if (!fullReactorLoaded) {
+                    synchronized (this) {
+                        if (!fullReactorLoaded) {
+                            doLoadFullReactor();
+                            fullReactorLoaded = true;
+                        }
+                    }
+                }
+            }
+
+            private void doLoadFullReactor() {
+                Path rootDirectory = request.getRootDirectory();
+                if (rootDirectory == null) {
+                    return;
+                }
+                List<File> toLoad = new ArrayList<>();
+                File root = 
defaultModelBuilder.getModelProcessor().locateExistingPom(rootDirectory.toFile());
+                toLoad.add(root);
+                while (!toLoad.isEmpty()) {
+                    File pom = toLoad.remove(0);
+                    try {
+                        ModelBuildingRequest gaBuildingRequest =
+                                new 
DefaultModelBuildingRequest(request).setModelSource(new FileModelSource(pom));
+                        Model rawModel = 
defaultModelBuilder.readFileModel(gaBuildingRequest, problems);
+                        for (String module : rawModel.getModules()) {
+                            File moduleFile = defaultModelBuilder
+                                    .getModelProcessor()
+                                    .locateExistingPom(new 
File(pom.getParent(), module));
+                            if (moduleFile != null) {
+                                toLoad.add(moduleFile);
+                            }
+                        }
+                    } catch (ModelBuildingException e) {
+                        // gathered with problem collector

Review Comment:
   e.getProblems on line 155. That looks to me like a no-op that can be 
eliminated, but it probably isn't. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to